widget/gtk/nsLookAndFeel.cpp

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/widget/gtk/nsLookAndFeel.cpp	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,1251 @@
     1.4 +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
     1.5 +/* vim:expandtab:shiftwidth=4:tabstop=4:
     1.6 + */
     1.7 +/* This Source Code Form is subject to the terms of the Mozilla Public
     1.8 + * License, v. 2.0. If a copy of the MPL was not distributed with this
     1.9 + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
    1.10 +
    1.11 +// for strtod()
    1.12 +#include <stdlib.h>
    1.13 +
    1.14 +#include "nsLookAndFeel.h"
    1.15 +
    1.16 +#include <gtk/gtk.h>
    1.17 +#include <gdk/gdk.h>
    1.18 +
    1.19 +#include <pango/pango.h>
    1.20 +#include <pango/pango-fontmap.h>
    1.21 +
    1.22 +#include <fontconfig/fontconfig.h>
    1.23 +#include "gfxPlatformGtk.h"
    1.24 +
    1.25 +#include "gtkdrawing.h"
    1.26 +#include "nsStyleConsts.h"
    1.27 +#include "gfxFontConstants.h"
    1.28 +#include "mozilla/gfx/2D.h"
    1.29 +
    1.30 +using mozilla::LookAndFeel;
    1.31 +
    1.32 +#define GDK_COLOR_TO_NS_RGB(c) \
    1.33 +    ((nscolor) NS_RGB(c.red>>8, c.green>>8, c.blue>>8))
    1.34 +#define GDK_RGBA_TO_NS_RGBA(c) \
    1.35 +    ((nscolor) NS_RGBA((int)((c).red*255), (int)((c).green*255), \
    1.36 +                       (int)((c).blue*255), (int)((c).alpha*255)))
    1.37 +
    1.38 +nsLookAndFeel::nsLookAndFeel()
    1.39 +    : nsXPLookAndFeel(),
    1.40 +#if (MOZ_WIDGET_GTK == 2)
    1.41 +      mStyle(nullptr),
    1.42 +#else
    1.43 +      mBackgroundStyle(nullptr),
    1.44 +      mViewStyle(nullptr),
    1.45 +      mButtonStyle(nullptr),
    1.46 +#endif
    1.47 +      mDefaultFontCached(false), mButtonFontCached(false),
    1.48 +      mFieldFontCached(false), mMenuFontCached(false)
    1.49 +{
    1.50 +    Init();    
    1.51 +}
    1.52 +
    1.53 +nsLookAndFeel::~nsLookAndFeel()
    1.54 +{
    1.55 +#if (MOZ_WIDGET_GTK == 2)
    1.56 +    g_object_unref(mStyle);
    1.57 +#else
    1.58 +    g_object_unref(mBackgroundStyle);
    1.59 +    g_object_unref(mViewStyle);
    1.60 +    g_object_unref(mButtonStyle);
    1.61 +#endif
    1.62 +}
    1.63 +
    1.64 +nsresult
    1.65 +nsLookAndFeel::NativeGetColor(ColorID aID, nscolor& aColor)
    1.66 +{
    1.67 +#if (MOZ_WIDGET_GTK == 3)
    1.68 +    GdkRGBA gdk_color;
    1.69 +#endif
    1.70 +    nsresult res = NS_OK;
    1.71 +
    1.72 +    switch (aID) {
    1.73 +        // These colors don't seem to be used for anything anymore in Mozilla
    1.74 +        // (except here at least TextSelectBackground and TextSelectForeground)
    1.75 +        // The CSS2 colors below are used.
    1.76 +#if (MOZ_WIDGET_GTK == 2)
    1.77 +    case eColorID_WindowBackground:
    1.78 +        aColor = GDK_COLOR_TO_NS_RGB(mStyle->base[GTK_STATE_NORMAL]);
    1.79 +        break;
    1.80 +    case eColorID_WindowForeground:
    1.81 +        aColor = GDK_COLOR_TO_NS_RGB(mStyle->text[GTK_STATE_NORMAL]);
    1.82 +        break;
    1.83 +    case eColorID_WidgetBackground:
    1.84 +        aColor = GDK_COLOR_TO_NS_RGB(mStyle->bg[GTK_STATE_NORMAL]);
    1.85 +        break;
    1.86 +    case eColorID_WidgetForeground:
    1.87 +        aColor = GDK_COLOR_TO_NS_RGB(mStyle->fg[GTK_STATE_NORMAL]);
    1.88 +        break;
    1.89 +    case eColorID_WidgetSelectBackground:
    1.90 +        aColor = GDK_COLOR_TO_NS_RGB(mStyle->bg[GTK_STATE_SELECTED]);
    1.91 +        break;
    1.92 +    case eColorID_WidgetSelectForeground:
    1.93 +        aColor = GDK_COLOR_TO_NS_RGB(mStyle->fg[GTK_STATE_SELECTED]);
    1.94 +        break;
    1.95 +#else
    1.96 +    case eColorID_WindowBackground:
    1.97 +    case eColorID_WidgetBackground:
    1.98 +    case eColorID_TextBackground:
    1.99 +    case eColorID_activecaption: // active window caption background
   1.100 +    case eColorID_appworkspace: // MDI background color
   1.101 +    case eColorID_background: // desktop background
   1.102 +    case eColorID_window:
   1.103 +    case eColorID_windowframe:
   1.104 +    case eColorID__moz_dialog:
   1.105 +        aColor = sMozWindowBackground;
   1.106 +        break;
   1.107 +    case eColorID_WindowForeground:
   1.108 +    case eColorID_WidgetForeground:
   1.109 +    case eColorID_TextForeground: 
   1.110 +    case eColorID_captiontext: // text in active window caption, size box, and scrollbar arrow box (!)
   1.111 +    case eColorID_windowtext:
   1.112 +    case eColorID__moz_dialogtext:
   1.113 +        aColor = sMozWindowText;
   1.114 +        break;
   1.115 +    case eColorID_WidgetSelectBackground:
   1.116 +    case eColorID_TextSelectBackground:
   1.117 +    case eColorID_IMESelectedRawTextBackground:
   1.118 +    case eColorID_IMESelectedConvertedTextBackground:
   1.119 +    case eColorID__moz_dragtargetzone:
   1.120 +        aColor = sMozWindowSelectedBackground;
   1.121 +        break;
   1.122 +    case eColorID_WidgetSelectForeground:
   1.123 +    case eColorID_TextSelectForeground:
   1.124 +    case eColorID_IMESelectedRawTextForeground:
   1.125 +    case eColorID_IMESelectedConvertedTextForeground:
   1.126 +        aColor = sMozWindowSelectedText;
   1.127 +        break;
   1.128 +#endif
   1.129 +    case eColorID_Widget3DHighlight:
   1.130 +        aColor = NS_RGB(0xa0,0xa0,0xa0);
   1.131 +        break;
   1.132 +    case eColorID_Widget3DShadow:
   1.133 +        aColor = NS_RGB(0x40,0x40,0x40);
   1.134 +        break;
   1.135 +#if (MOZ_WIDGET_GTK == 2)
   1.136 +    case eColorID_TextBackground:
   1.137 +        // not used?
   1.138 +        aColor = GDK_COLOR_TO_NS_RGB(mStyle->base[GTK_STATE_NORMAL]);
   1.139 +        break;
   1.140 +    case eColorID_TextForeground: 
   1.141 +        // not used?
   1.142 +        aColor = GDK_COLOR_TO_NS_RGB(mStyle->text[GTK_STATE_NORMAL]);
   1.143 +        break;
   1.144 +    case eColorID_TextSelectBackground:
   1.145 +    case eColorID_IMESelectedRawTextBackground:
   1.146 +    case eColorID_IMESelectedConvertedTextBackground:
   1.147 +        // still used
   1.148 +        aColor = GDK_COLOR_TO_NS_RGB(mStyle->base[GTK_STATE_SELECTED]);
   1.149 +        break;
   1.150 +    case eColorID_TextSelectForeground:
   1.151 +    case eColorID_IMESelectedRawTextForeground:
   1.152 +    case eColorID_IMESelectedConvertedTextForeground:
   1.153 +        // still used
   1.154 +        aColor = GDK_COLOR_TO_NS_RGB(mStyle->text[GTK_STATE_SELECTED]);
   1.155 +        break;
   1.156 +#endif
   1.157 +    case eColorID_IMERawInputBackground:
   1.158 +    case eColorID_IMEConvertedTextBackground:
   1.159 +        aColor = NS_TRANSPARENT;
   1.160 +        break;
   1.161 +    case eColorID_IMERawInputForeground:
   1.162 +    case eColorID_IMEConvertedTextForeground:
   1.163 +        aColor = NS_SAME_AS_FOREGROUND_COLOR;
   1.164 +        break;
   1.165 +    case eColorID_IMERawInputUnderline:
   1.166 +    case eColorID_IMEConvertedTextUnderline:
   1.167 +        aColor = NS_SAME_AS_FOREGROUND_COLOR;
   1.168 +        break;
   1.169 +    case eColorID_IMESelectedRawTextUnderline:
   1.170 +    case eColorID_IMESelectedConvertedTextUnderline:
   1.171 +        aColor = NS_TRANSPARENT;
   1.172 +        break;
   1.173 +    case eColorID_SpellCheckerUnderline:
   1.174 +      aColor = NS_RGB(0xff, 0, 0);
   1.175 +      break;
   1.176 +
   1.177 +#if (MOZ_WIDGET_GTK == 2)
   1.178 +        // css2  http://www.w3.org/TR/REC-CSS2/ui.html#system-colors
   1.179 +    case eColorID_activeborder:
   1.180 +        // active window border
   1.181 +        aColor = GDK_COLOR_TO_NS_RGB(mStyle->bg[GTK_STATE_NORMAL]);
   1.182 +        break;
   1.183 +    case eColorID_activecaption:
   1.184 +        // active window caption background
   1.185 +        aColor = GDK_COLOR_TO_NS_RGB(mStyle->bg[GTK_STATE_NORMAL]);
   1.186 +        break;
   1.187 +    case eColorID_appworkspace:
   1.188 +        // MDI background color
   1.189 +        aColor = GDK_COLOR_TO_NS_RGB(mStyle->bg[GTK_STATE_NORMAL]);
   1.190 +        break;
   1.191 +    case eColorID_background:
   1.192 +        // desktop background
   1.193 +        aColor = GDK_COLOR_TO_NS_RGB(mStyle->bg[GTK_STATE_NORMAL]);
   1.194 +        break;
   1.195 +    case eColorID_captiontext:
   1.196 +        // text in active window caption, size box, and scrollbar arrow box (!)
   1.197 +        aColor = GDK_COLOR_TO_NS_RGB(mStyle->fg[GTK_STATE_NORMAL]);
   1.198 +        break;
   1.199 +    case eColorID_graytext:
   1.200 +        // disabled text in windows, menus, etc.
   1.201 +        aColor = GDK_COLOR_TO_NS_RGB(mStyle->fg[GTK_STATE_INSENSITIVE]);
   1.202 +        break;
   1.203 +    case eColorID_highlight:
   1.204 +        // background of selected item
   1.205 +        aColor = GDK_COLOR_TO_NS_RGB(mStyle->base[GTK_STATE_SELECTED]);
   1.206 +        break;
   1.207 +    case eColorID_highlighttext:
   1.208 +        // text of selected item
   1.209 +        aColor = GDK_COLOR_TO_NS_RGB(mStyle->text[GTK_STATE_SELECTED]);
   1.210 +        break;
   1.211 +    case eColorID_inactiveborder:
   1.212 +        // inactive window border
   1.213 +        aColor = GDK_COLOR_TO_NS_RGB(mStyle->bg[GTK_STATE_NORMAL]);
   1.214 +        break;
   1.215 +    case eColorID_inactivecaption:
   1.216 +        // inactive window caption
   1.217 +        aColor = GDK_COLOR_TO_NS_RGB(mStyle->bg[GTK_STATE_INSENSITIVE]);
   1.218 +        break;
   1.219 +    case eColorID_inactivecaptiontext:
   1.220 +        // text in inactive window caption
   1.221 +        aColor = GDK_COLOR_TO_NS_RGB(mStyle->fg[GTK_STATE_INSENSITIVE]);
   1.222 +        break;
   1.223 +#else
   1.224 +        // css2  http://www.w3.org/TR/REC-CSS2/ui.html#system-colors
   1.225 +    case eColorID_activeborder:
   1.226 +        // active window border
   1.227 +        gtk_style_context_get_border_color(mBackgroundStyle, 
   1.228 +                                           GTK_STATE_FLAG_NORMAL, &gdk_color);
   1.229 +        aColor = GDK_RGBA_TO_NS_RGBA(gdk_color);
   1.230 +        break;
   1.231 +    case eColorID_inactiveborder:
   1.232 +        // inactive window border
   1.233 +        gtk_style_context_get_border_color(mBackgroundStyle, 
   1.234 +                                           GTK_STATE_FLAG_INSENSITIVE, 
   1.235 +                                           &gdk_color);
   1.236 +        aColor = GDK_RGBA_TO_NS_RGBA(gdk_color);
   1.237 +        break;
   1.238 +    case eColorID_graytext: // disabled text in windows, menus, etc.
   1.239 +    case eColorID_inactivecaptiontext: // text in inactive window caption
   1.240 +        gtk_style_context_get_color(mBackgroundStyle, 
   1.241 +                                    GTK_STATE_FLAG_INSENSITIVE, &gdk_color);
   1.242 +        aColor = GDK_RGBA_TO_NS_RGBA(gdk_color);
   1.243 +        break;
   1.244 +    case eColorID_highlight: // preference selected item,
   1.245 +        // background of selected item
   1.246 +        gtk_style_context_get_background_color(mViewStyle, 
   1.247 +                                               GTK_STATE_FLAG_SELECTED, 
   1.248 +                                               &gdk_color);
   1.249 +        aColor = GDK_RGBA_TO_NS_RGBA(gdk_color);
   1.250 +        break;
   1.251 +    case eColorID_highlighttext:
   1.252 +        // text of selected item
   1.253 +        gtk_style_context_get_color(mViewStyle, 
   1.254 +                                    GTK_STATE_FLAG_SELECTED, &gdk_color);
   1.255 +        aColor = GDK_RGBA_TO_NS_RGBA(gdk_color);
   1.256 +        break;
   1.257 +    case eColorID_inactivecaption:
   1.258 +        // inactive window caption
   1.259 +        gtk_style_context_get_background_color(mBackgroundStyle, 
   1.260 +                                               GTK_STATE_FLAG_INSENSITIVE, 
   1.261 +                                               &gdk_color);
   1.262 +        aColor = GDK_RGBA_TO_NS_RGBA(gdk_color);
   1.263 +        break;
   1.264 +#endif
   1.265 +    case eColorID_infobackground:
   1.266 +        // tooltip background color
   1.267 +        aColor = sInfoBackground;
   1.268 +        break;
   1.269 +    case eColorID_infotext:
   1.270 +        // tooltip text color
   1.271 +        aColor = sInfoText;
   1.272 +        break;
   1.273 +    case eColorID_menu:
   1.274 +        // menu background
   1.275 +        aColor = sMenuBackground;
   1.276 +        break;
   1.277 +    case eColorID_menutext:
   1.278 +        // menu text
   1.279 +        aColor = sMenuText;
   1.280 +        break;
   1.281 +    case eColorID_scrollbar:
   1.282 +        // scrollbar gray area
   1.283 +#if (MOZ_WIDGET_GTK == 2)
   1.284 +        aColor = GDK_COLOR_TO_NS_RGB(mStyle->bg[GTK_STATE_ACTIVE]);
   1.285 +#else
   1.286 +        aColor = sMozScrollbar;
   1.287 +#endif
   1.288 +        break;
   1.289 +
   1.290 +    case eColorID_threedface:
   1.291 +    case eColorID_buttonface:
   1.292 +        // 3-D face color
   1.293 +        aColor = sButtonBackground;
   1.294 +        break;
   1.295 +
   1.296 +    case eColorID_buttontext:
   1.297 +        // text on push buttons
   1.298 +        aColor = sButtonText;
   1.299 +        break;
   1.300 +
   1.301 +    case eColorID_buttonhighlight:
   1.302 +        // 3-D highlighted edge color
   1.303 +    case eColorID_threedhighlight:
   1.304 +        // 3-D highlighted outer edge color
   1.305 +        aColor = sButtonOuterLightBorder;
   1.306 +        break;
   1.307 +
   1.308 +    case eColorID_threedlightshadow:
   1.309 +        // 3-D highlighted inner edge color
   1.310 +        aColor = sButtonBackground; // always same as background in GTK code
   1.311 +        break;
   1.312 +
   1.313 +    case eColorID_buttonshadow:
   1.314 +        // 3-D shadow edge color
   1.315 +    case eColorID_threedshadow:
   1.316 +        // 3-D shadow inner edge color
   1.317 +        aColor = sButtonInnerDarkBorder;
   1.318 +        break;
   1.319 +
   1.320 +#if (MOZ_WIDGET_GTK == 2)
   1.321 +    case eColorID_threeddarkshadow:
   1.322 +        // 3-D shadow outer edge color
   1.323 +        aColor = GDK_COLOR_TO_NS_RGB(mStyle->black);
   1.324 +        break;
   1.325 +
   1.326 +    case eColorID_window:
   1.327 +    case eColorID_windowframe:
   1.328 +        aColor = GDK_COLOR_TO_NS_RGB(mStyle->bg[GTK_STATE_NORMAL]);
   1.329 +        break;
   1.330 +
   1.331 +    case eColorID_windowtext:
   1.332 +        aColor = GDK_COLOR_TO_NS_RGB(mStyle->fg[GTK_STATE_NORMAL]);
   1.333 +        break;
   1.334 +
   1.335 +    case eColorID__moz_eventreerow:
   1.336 +    case eColorID__moz_field:
   1.337 +        aColor = GDK_COLOR_TO_NS_RGB(mStyle->base[GTK_STATE_NORMAL]);
   1.338 +        break;
   1.339 +    case eColorID__moz_fieldtext:
   1.340 +        aColor = GDK_COLOR_TO_NS_RGB(mStyle->text[GTK_STATE_NORMAL]);
   1.341 +        break;
   1.342 +    case eColorID__moz_dialog:
   1.343 +        aColor = GDK_COLOR_TO_NS_RGB(mStyle->bg[GTK_STATE_NORMAL]);
   1.344 +        break;
   1.345 +    case eColorID__moz_dialogtext:
   1.346 +        aColor = GDK_COLOR_TO_NS_RGB(mStyle->fg[GTK_STATE_NORMAL]);
   1.347 +        break;
   1.348 +    case eColorID__moz_dragtargetzone:
   1.349 +        aColor = GDK_COLOR_TO_NS_RGB(mStyle->bg[GTK_STATE_SELECTED]);
   1.350 +        break; 
   1.351 +    case eColorID__moz_buttondefault:
   1.352 +        // default button border color
   1.353 +        aColor = GDK_COLOR_TO_NS_RGB(mStyle->black);
   1.354 +        break;
   1.355 +    case eColorID__moz_buttonhoverface:
   1.356 +        aColor = GDK_COLOR_TO_NS_RGB(mStyle->bg[GTK_STATE_PRELIGHT]);
   1.357 +        break;
   1.358 +    case eColorID__moz_buttonhovertext:
   1.359 +        aColor = GDK_COLOR_TO_NS_RGB(mStyle->fg[GTK_STATE_PRELIGHT]);
   1.360 +        break;
   1.361 +    case eColorID__moz_cellhighlight:
   1.362 +    case eColorID__moz_html_cellhighlight:
   1.363 +        aColor = GDK_COLOR_TO_NS_RGB(mStyle->base[GTK_STATE_ACTIVE]);
   1.364 +        break;
   1.365 +    case eColorID__moz_cellhighlighttext:
   1.366 +    case eColorID__moz_html_cellhighlighttext:
   1.367 +        aColor = GDK_COLOR_TO_NS_RGB(mStyle->text[GTK_STATE_ACTIVE]);
   1.368 +        break;
   1.369 +#else
   1.370 +    case eColorID_threeddarkshadow:
   1.371 +        // Hardcode to black
   1.372 +        aColor = NS_RGB(0x00,0x00,0x00);;
   1.373 +        break;
   1.374 +
   1.375 +    case eColorID__moz_eventreerow:
   1.376 +    case eColorID__moz_field:
   1.377 +        aColor = sMozFieldBackground;
   1.378 +        break;
   1.379 +    case eColorID__moz_fieldtext:
   1.380 +        aColor = sMozFieldText;
   1.381 +        break;
   1.382 +    case eColorID__moz_buttondefault:
   1.383 +      // default button border color
   1.384 +        gtk_style_context_get_border_color(mButtonStyle, 
   1.385 +                                           GTK_STATE_FLAG_NORMAL, &gdk_color);
   1.386 +        aColor = GDK_RGBA_TO_NS_RGBA(gdk_color);
   1.387 +        break;
   1.388 +    case eColorID__moz_buttonhoverface:
   1.389 +        gtk_style_context_get_background_color(mButtonStyle, 
   1.390 +                                               GTK_STATE_FLAG_PRELIGHT, 
   1.391 +                                               &gdk_color);
   1.392 +        aColor = GDK_RGBA_TO_NS_RGBA(gdk_color);
   1.393 +        break;
   1.394 +    case eColorID__moz_buttonhovertext:
   1.395 +        aColor = sButtonHoverText;
   1.396 +        break;
   1.397 +    case eColorID__moz_cellhighlight:
   1.398 +    case eColorID__moz_html_cellhighlight:
   1.399 +        gtk_style_context_get_background_color(mViewStyle, 
   1.400 +                                               GTK_STATE_FLAG_SELECTED, 
   1.401 +                                               &gdk_color);
   1.402 +        aColor = GDK_RGBA_TO_NS_RGBA(gdk_color);
   1.403 +        break;
   1.404 +    case eColorID__moz_cellhighlighttext:
   1.405 +    case eColorID__moz_html_cellhighlighttext:
   1.406 +        gtk_style_context_get_color(mViewStyle, 
   1.407 +                                    GTK_STATE_FLAG_SELECTED, &gdk_color);
   1.408 +        aColor = GDK_RGBA_TO_NS_RGBA(gdk_color);
   1.409 +        break;
   1.410 +#endif
   1.411 +    case eColorID__moz_menuhover:
   1.412 +        aColor = sMenuHover;
   1.413 +        break;
   1.414 +    case eColorID__moz_menuhovertext:
   1.415 +        aColor = sMenuHoverText;
   1.416 +        break;
   1.417 +    case eColorID__moz_oddtreerow:
   1.418 +        aColor = sOddCellBackground;
   1.419 +        break;
   1.420 +    case eColorID__moz_nativehyperlinktext:
   1.421 +        aColor = sNativeHyperLinkText;
   1.422 +        break;
   1.423 +    case eColorID__moz_comboboxtext:
   1.424 +        aColor = sComboBoxText;
   1.425 +        break;
   1.426 +    case eColorID__moz_combobox:
   1.427 +        aColor = sComboBoxBackground;
   1.428 +        break;
   1.429 +    case eColorID__moz_menubartext:
   1.430 +        aColor = sMenuBarText;
   1.431 +        break;
   1.432 +    case eColorID__moz_menubarhovertext:
   1.433 +        aColor = sMenuBarHoverText;
   1.434 +        break;
   1.435 +    default:
   1.436 +        /* default color is BLACK */
   1.437 +        aColor = 0;
   1.438 +        res    = NS_ERROR_FAILURE;
   1.439 +        break;
   1.440 +    }
   1.441 +
   1.442 +    return res;
   1.443 +}
   1.444 +
   1.445 +#if (MOZ_WIDGET_GTK == 2)
   1.446 +static void darken_gdk_color(GdkColor *src, GdkColor *dest)
   1.447 +{
   1.448 +    gdouble red;
   1.449 +    gdouble green;
   1.450 +    gdouble blue;
   1.451 +
   1.452 +    red = (gdouble) src->red / 65535.0;
   1.453 +    green = (gdouble) src->green / 65535.0;
   1.454 +    blue = (gdouble) src->blue / 65535.0;
   1.455 +
   1.456 +    red *= 0.93;
   1.457 +    green *= 0.93;
   1.458 +    blue *= 0.93;
   1.459 +
   1.460 +    dest->red = red * 65535.0;
   1.461 +    dest->green = green * 65535.0;
   1.462 +    dest->blue = blue * 65535.0;
   1.463 +}
   1.464 +#endif
   1.465 +
   1.466 +static int32_t CheckWidgetStyle(GtkWidget* aWidget, const char* aStyle, int32_t aResult) {
   1.467 +    gboolean value = FALSE;
   1.468 +    gtk_widget_style_get(aWidget, aStyle, &value, nullptr);
   1.469 +    return value ? aResult : 0;
   1.470 +}
   1.471 +
   1.472 +static int32_t ConvertGTKStepperStyleToMozillaScrollArrowStyle(GtkWidget* aWidget)
   1.473 +{
   1.474 +    if (!aWidget)
   1.475 +        return mozilla::LookAndFeel::eScrollArrowStyle_Single;
   1.476 +  
   1.477 +    return
   1.478 +        CheckWidgetStyle(aWidget, "has-backward-stepper",
   1.479 +                         mozilla::LookAndFeel::eScrollArrow_StartBackward) |
   1.480 +        CheckWidgetStyle(aWidget, "has-forward-stepper",
   1.481 +                         mozilla::LookAndFeel::eScrollArrow_EndForward) |
   1.482 +        CheckWidgetStyle(aWidget, "has-secondary-backward-stepper",
   1.483 +                         mozilla::LookAndFeel::eScrollArrow_EndBackward) |
   1.484 +        CheckWidgetStyle(aWidget, "has-secondary-forward-stepper",
   1.485 +                         mozilla::LookAndFeel::eScrollArrow_StartForward);
   1.486 +}
   1.487 +
   1.488 +nsresult
   1.489 +nsLookAndFeel::GetIntImpl(IntID aID, int32_t &aResult)
   1.490 +{
   1.491 +    nsresult res = NS_OK;
   1.492 +
   1.493 +    // Set these before they can get overrided in the nsXPLookAndFeel. 
   1.494 +    switch (aID) {
   1.495 +    case eIntID_ScrollButtonLeftMouseButtonAction:
   1.496 +        aResult = 0;
   1.497 +        return NS_OK;
   1.498 +    case eIntID_ScrollButtonMiddleMouseButtonAction:
   1.499 +        aResult = 1;
   1.500 +        return NS_OK;
   1.501 +    case eIntID_ScrollButtonRightMouseButtonAction:
   1.502 +        aResult = 2;
   1.503 +        return NS_OK;
   1.504 +    default:
   1.505 +        break;
   1.506 +    }
   1.507 +
   1.508 +    res = nsXPLookAndFeel::GetIntImpl(aID, aResult);
   1.509 +    if (NS_SUCCEEDED(res))
   1.510 +        return res;
   1.511 +    res = NS_OK;
   1.512 +
   1.513 +    switch (aID) {
   1.514 +    case eIntID_CaretBlinkTime:
   1.515 +        {
   1.516 +            GtkSettings *settings;
   1.517 +            gint blink_time;
   1.518 +            gboolean blink;
   1.519 +
   1.520 +            settings = gtk_settings_get_default ();
   1.521 +            g_object_get (settings,
   1.522 +                          "gtk-cursor-blink-time", &blink_time,
   1.523 +                          "gtk-cursor-blink", &blink,
   1.524 +                          nullptr);
   1.525 + 
   1.526 +            if (blink)
   1.527 +                aResult = (int32_t) blink_time;
   1.528 +            else
   1.529 +                aResult = 0;
   1.530 +            break;
   1.531 +        }
   1.532 +    case eIntID_CaretWidth:
   1.533 +        aResult = 1;
   1.534 +        break;
   1.535 +    case eIntID_ShowCaretDuringSelection:
   1.536 +        aResult = 0;
   1.537 +        break;
   1.538 +    case eIntID_SelectTextfieldsOnKeyFocus:
   1.539 +        {
   1.540 +            GtkWidget *entry;
   1.541 +            GtkSettings *settings;
   1.542 +            gboolean select_on_focus;
   1.543 +
   1.544 +            entry = gtk_entry_new();
   1.545 +            g_object_ref_sink(entry);
   1.546 +            settings = gtk_widget_get_settings(entry);
   1.547 +            g_object_get(settings, 
   1.548 +                         "gtk-entry-select-on-focus",
   1.549 +                         &select_on_focus,
   1.550 +                         nullptr);
   1.551 +            
   1.552 +            if(select_on_focus)
   1.553 +                aResult = 1;
   1.554 +            else
   1.555 +                aResult = 0;
   1.556 +
   1.557 +            gtk_widget_destroy(entry);
   1.558 +            g_object_unref(entry);
   1.559 +        }
   1.560 +        break;
   1.561 +    case eIntID_SubmenuDelay:
   1.562 +        {
   1.563 +            GtkSettings *settings;
   1.564 +            gint delay;
   1.565 +
   1.566 +            settings = gtk_settings_get_default ();
   1.567 +            g_object_get (settings, "gtk-menu-popup-delay", &delay, nullptr);
   1.568 +            aResult = (int32_t) delay;
   1.569 +            break;
   1.570 +        }
   1.571 +    case eIntID_TooltipDelay:
   1.572 +        {
   1.573 +            aResult = 500;
   1.574 +            break;
   1.575 +        }
   1.576 +    case eIntID_MenusCanOverlapOSBar:
   1.577 +        // we want XUL popups to be able to overlap the task bar.
   1.578 +        aResult = 1;
   1.579 +        break;
   1.580 +    case eIntID_SkipNavigatingDisabledMenuItem:
   1.581 +        aResult = 1;
   1.582 +        break;
   1.583 +    case eIntID_DragThresholdX:
   1.584 +    case eIntID_DragThresholdY:
   1.585 +        {
   1.586 +            GtkWidget* box = gtk_hbox_new(FALSE, 5);
   1.587 +            gint threshold = 0;
   1.588 +            g_object_get(gtk_widget_get_settings(box),
   1.589 +                         "gtk-dnd-drag-threshold", &threshold,
   1.590 +                         nullptr);
   1.591 +            g_object_ref_sink(box);
   1.592 +            
   1.593 +            aResult = threshold;
   1.594 +        }
   1.595 +        break;
   1.596 +    case eIntID_ScrollArrowStyle:
   1.597 +        moz_gtk_init();
   1.598 +        aResult =
   1.599 +            ConvertGTKStepperStyleToMozillaScrollArrowStyle(moz_gtk_get_scrollbar_widget());
   1.600 +        break;
   1.601 +    case eIntID_ScrollSliderStyle:
   1.602 +        aResult = eScrollThumbStyle_Proportional;
   1.603 +        break;
   1.604 +    case eIntID_TreeOpenDelay:
   1.605 +        aResult = 1000;
   1.606 +        break;
   1.607 +    case eIntID_TreeCloseDelay:
   1.608 +        aResult = 1000;
   1.609 +        break;
   1.610 +    case eIntID_TreeLazyScrollDelay:
   1.611 +        aResult = 150;
   1.612 +        break;
   1.613 +    case eIntID_TreeScrollDelay:
   1.614 +        aResult = 100;
   1.615 +        break;
   1.616 +    case eIntID_TreeScrollLinesMax:
   1.617 +        aResult = 3;
   1.618 +        break;
   1.619 +    case eIntID_DWMCompositor:
   1.620 +    case eIntID_WindowsClassic:
   1.621 +    case eIntID_WindowsDefaultTheme:
   1.622 +    case eIntID_WindowsThemeIdentifier:
   1.623 +    case eIntID_OperatingSystemVersionIdentifier:
   1.624 +        aResult = 0;
   1.625 +        res = NS_ERROR_NOT_IMPLEMENTED;
   1.626 +        break;
   1.627 +    case eIntID_TouchEnabled:
   1.628 +        aResult = 0;
   1.629 +        res = NS_ERROR_NOT_IMPLEMENTED;
   1.630 +        break;
   1.631 +    case eIntID_MacGraphiteTheme:
   1.632 +    case eIntID_MacLionTheme:
   1.633 +        aResult = 0;
   1.634 +        res = NS_ERROR_NOT_IMPLEMENTED;
   1.635 +        break;
   1.636 +    case eIntID_AlertNotificationOrigin:
   1.637 +        aResult = NS_ALERT_TOP;
   1.638 +        break;
   1.639 +    case eIntID_IMERawInputUnderlineStyle:
   1.640 +    case eIntID_IMEConvertedTextUnderlineStyle:
   1.641 +        aResult = NS_STYLE_TEXT_DECORATION_STYLE_SOLID;
   1.642 +        break;
   1.643 +    case eIntID_IMESelectedRawTextUnderlineStyle:
   1.644 +    case eIntID_IMESelectedConvertedTextUnderline:
   1.645 +        aResult = NS_STYLE_TEXT_DECORATION_STYLE_NONE;
   1.646 +        break;
   1.647 +    case eIntID_SpellCheckerUnderlineStyle:
   1.648 +        aResult = NS_STYLE_TEXT_DECORATION_STYLE_WAVY;
   1.649 +        break;
   1.650 +    case eIntID_ImagesInMenus:
   1.651 +        aResult = moz_gtk_images_in_menus();
   1.652 +        break;
   1.653 +    case eIntID_ImagesInButtons:
   1.654 +        aResult = moz_gtk_images_in_buttons();
   1.655 +        break;
   1.656 +    case eIntID_MenuBarDrag:
   1.657 +        aResult = sMenuSupportsDrag;
   1.658 +        break;
   1.659 +    case eIntID_ScrollbarButtonAutoRepeatBehavior:
   1.660 +        aResult = 1;
   1.661 +        break;
   1.662 +    case eIntID_SwipeAnimationEnabled:
   1.663 +        aResult = 0;
   1.664 +        break;
   1.665 +    case eIntID_ColorPickerAvailable:
   1.666 +        aResult = 1;
   1.667 +        break;
   1.668 +    default:
   1.669 +        aResult = 0;
   1.670 +        res     = NS_ERROR_FAILURE;
   1.671 +    }
   1.672 +
   1.673 +    return res;
   1.674 +}
   1.675 +
   1.676 +nsresult
   1.677 +nsLookAndFeel::GetFloatImpl(FloatID aID, float &aResult)
   1.678 +{
   1.679 +    nsresult res = NS_OK;
   1.680 +    res = nsXPLookAndFeel::GetFloatImpl(aID, aResult);
   1.681 +    if (NS_SUCCEEDED(res))
   1.682 +        return res;
   1.683 +    res = NS_OK;
   1.684 +
   1.685 +    switch (aID) {
   1.686 +    case eFloatID_IMEUnderlineRelativeSize:
   1.687 +        aResult = 1.0f;
   1.688 +        break;
   1.689 +    case eFloatID_SpellCheckerUnderlineRelativeSize:
   1.690 +        aResult = 1.0f;
   1.691 +        break;
   1.692 +    case eFloatID_CaretAspectRatio:
   1.693 +        aResult = sCaretRatio;
   1.694 +        break;
   1.695 +    default:
   1.696 +        aResult = -1.0;
   1.697 +        res = NS_ERROR_FAILURE;
   1.698 +    }
   1.699 +    return res;
   1.700 +}
   1.701 +
   1.702 +static void
   1.703 +GetSystemFontInfo(GtkWidget *aWidget,
   1.704 +                  nsString *aFontName,
   1.705 +                  gfxFontStyle *aFontStyle)
   1.706 +{
   1.707 +    GtkSettings *settings = gtk_widget_get_settings(aWidget);
   1.708 +
   1.709 +    aFontStyle->style       = NS_FONT_STYLE_NORMAL;
   1.710 +
   1.711 +    gchar *fontname;
   1.712 +    g_object_get(settings, "gtk-font-name", &fontname, nullptr);
   1.713 +
   1.714 +    PangoFontDescription *desc;
   1.715 +    desc = pango_font_description_from_string(fontname);
   1.716 +
   1.717 +    aFontStyle->systemFont = true;
   1.718 +
   1.719 +    g_free(fontname);
   1.720 +
   1.721 +    NS_NAMED_LITERAL_STRING(quote, "\"");
   1.722 +    NS_ConvertUTF8toUTF16 family(pango_font_description_get_family(desc));
   1.723 +    *aFontName = quote + family + quote;
   1.724 +
   1.725 +    aFontStyle->weight = pango_font_description_get_weight(desc);
   1.726 +
   1.727 +    // FIXME: Set aFontStyle->stretch correctly!
   1.728 +    aFontStyle->stretch = NS_FONT_STRETCH_NORMAL;
   1.729 +
   1.730 +    float size = float(pango_font_description_get_size(desc)) / PANGO_SCALE;
   1.731 +
   1.732 +    // |size| is now either pixels or pango-points (not Mozilla-points!)
   1.733 +
   1.734 +    if (!pango_font_description_get_size_is_absolute(desc)) {
   1.735 +        // |size| is in pango-points, so convert to pixels.
   1.736 +        size *= float(gfxPlatformGtk::GetDPI()) / POINTS_PER_INCH_FLOAT;
   1.737 +    }
   1.738 +
   1.739 +    // |size| is now pixels
   1.740 +
   1.741 +    aFontStyle->size = size;
   1.742 +
   1.743 +    pango_font_description_free(desc);
   1.744 +}
   1.745 +
   1.746 +static void
   1.747 +GetSystemFontInfo(LookAndFeel::FontID aID,
   1.748 +                  nsString *aFontName,
   1.749 +                  gfxFontStyle *aFontStyle)
   1.750 +{
   1.751 +    if (aID == LookAndFeel::eFont_Widget) {
   1.752 +        GtkWidget *label = gtk_label_new("M");
   1.753 +        GtkWidget *parent = gtk_fixed_new();
   1.754 +        GtkWidget *window = gtk_window_new(GTK_WINDOW_POPUP);
   1.755 +
   1.756 +        gtk_container_add(GTK_CONTAINER(parent), label);
   1.757 +        gtk_container_add(GTK_CONTAINER(window), parent);
   1.758 +
   1.759 +        gtk_widget_ensure_style(label);
   1.760 +        GetSystemFontInfo(label, aFontName, aFontStyle);
   1.761 +        gtk_widget_destroy(window);  // no unref, windows are different
   1.762 +
   1.763 +    } else if (aID == LookAndFeel::eFont_Button) {
   1.764 +        GtkWidget *label = gtk_label_new("M");
   1.765 +        GtkWidget *parent = gtk_fixed_new();
   1.766 +        GtkWidget *button = gtk_button_new();
   1.767 +        GtkWidget *window = gtk_window_new(GTK_WINDOW_POPUP);
   1.768 +
   1.769 +        gtk_container_add(GTK_CONTAINER(button), label);
   1.770 +        gtk_container_add(GTK_CONTAINER(parent), button);
   1.771 +        gtk_container_add(GTK_CONTAINER(window), parent);
   1.772 +
   1.773 +        gtk_widget_ensure_style(label);
   1.774 +        GetSystemFontInfo(label, aFontName, aFontStyle);
   1.775 +        gtk_widget_destroy(window);  // no unref, windows are different
   1.776 +
   1.777 +    } else if (aID == LookAndFeel::eFont_Field) {
   1.778 +        GtkWidget *entry = gtk_entry_new();
   1.779 +        GtkWidget *parent = gtk_fixed_new();
   1.780 +        GtkWidget *window = gtk_window_new(GTK_WINDOW_POPUP);
   1.781 +
   1.782 +        gtk_container_add(GTK_CONTAINER(parent), entry);
   1.783 +        gtk_container_add(GTK_CONTAINER(window), parent);
   1.784 +
   1.785 +        gtk_widget_ensure_style(entry);
   1.786 +        GetSystemFontInfo(entry, aFontName, aFontStyle);
   1.787 +        gtk_widget_destroy(window);  // no unref, windows are different
   1.788 +
   1.789 +    } else {
   1.790 +        NS_ABORT_IF_FALSE(aID == LookAndFeel::eFont_Menu, "unexpected font ID");
   1.791 +        GtkWidget *accel_label = gtk_accel_label_new("M");
   1.792 +        GtkWidget *menuitem = gtk_menu_item_new();
   1.793 +        GtkWidget *menu = gtk_menu_new();
   1.794 +        g_object_ref_sink(menu);
   1.795 +
   1.796 +        gtk_container_add(GTK_CONTAINER(menuitem), accel_label);
   1.797 +        gtk_menu_shell_append((GtkMenuShell *)GTK_MENU(menu), menuitem);
   1.798 +
   1.799 +        gtk_widget_ensure_style(accel_label);
   1.800 +        GetSystemFontInfo(accel_label, aFontName, aFontStyle);
   1.801 +        g_object_unref(menu);
   1.802 +    }
   1.803 +}
   1.804 +
   1.805 +bool
   1.806 +nsLookAndFeel::GetFontImpl(FontID aID, nsString& aFontName,
   1.807 +                           gfxFontStyle& aFontStyle,
   1.808 +                           float aDevPixPerCSSPixel)
   1.809 +{
   1.810 +  nsString *cachedFontName = nullptr;
   1.811 +  gfxFontStyle *cachedFontStyle = nullptr;
   1.812 +  bool *isCached = nullptr;
   1.813 +
   1.814 +  switch (aID) {
   1.815 +    case eFont_Menu:         // css2
   1.816 +    case eFont_PullDownMenu: // css3
   1.817 +      cachedFontName = &mMenuFontName;
   1.818 +      cachedFontStyle = &mMenuFontStyle;
   1.819 +      isCached = &mMenuFontCached;
   1.820 +      aID = eFont_Menu;
   1.821 +      break;
   1.822 +
   1.823 +    case eFont_Field:        // css3
   1.824 +    case eFont_List:         // css3
   1.825 +      cachedFontName = &mFieldFontName;
   1.826 +      cachedFontStyle = &mFieldFontStyle;
   1.827 +      isCached = &mFieldFontCached;
   1.828 +      aID = eFont_Field;
   1.829 +      break;
   1.830 +
   1.831 +    case eFont_Button:       // css3
   1.832 +      cachedFontName = &mButtonFontName;
   1.833 +      cachedFontStyle = &mButtonFontStyle;
   1.834 +      isCached = &mButtonFontCached;
   1.835 +      break;
   1.836 +
   1.837 +    case eFont_Caption:      // css2
   1.838 +    case eFont_Icon:         // css2
   1.839 +    case eFont_MessageBox:   // css2
   1.840 +    case eFont_SmallCaption: // css2
   1.841 +    case eFont_StatusBar:    // css2
   1.842 +    case eFont_Window:       // css3
   1.843 +    case eFont_Document:     // css3
   1.844 +    case eFont_Workspace:    // css3
   1.845 +    case eFont_Desktop:      // css3
   1.846 +    case eFont_Info:         // css3
   1.847 +    case eFont_Dialog:       // css3
   1.848 +    case eFont_Tooltips:     // moz
   1.849 +    case eFont_Widget:       // moz
   1.850 +      cachedFontName = &mDefaultFontName;
   1.851 +      cachedFontStyle = &mDefaultFontStyle;
   1.852 +      isCached = &mDefaultFontCached;
   1.853 +      aID = eFont_Widget;
   1.854 +      break;
   1.855 +  }
   1.856 +
   1.857 +  if (!*isCached) {
   1.858 +    GetSystemFontInfo(aID, cachedFontName, cachedFontStyle);
   1.859 +    *isCached = true;
   1.860 +  }
   1.861 +
   1.862 +  aFontName = *cachedFontName;
   1.863 +  aFontStyle = *cachedFontStyle;
   1.864 +  return true;
   1.865 +}
   1.866 +
   1.867 +#if (MOZ_WIDGET_GTK == 3)
   1.868 +static GtkStyleContext*
   1.869 +create_context(GtkWidgetPath *path)
   1.870 +{
   1.871 +    GtkStyleContext *style = gtk_style_context_new();
   1.872 +    gtk_style_context_set_path(style, path);
   1.873 +    return(style);
   1.874 +}
   1.875 +#endif
   1.876 +
   1.877 +void
   1.878 +nsLookAndFeel::Init()
   1.879 +{
   1.880 +    GdkColor colorValue;
   1.881 +    GdkColor *colorValuePtr;
   1.882 +
   1.883 +#if (MOZ_WIDGET_GTK == 2)
   1.884 +    NS_ASSERTION(!mStyle, "already initialized");
   1.885 +    // GtkInvisibles come with a refcount that is not floating
   1.886 +    // (since their initialization code calls g_object_ref_sink) and
   1.887 +    // their destroy code releases that reference (which means they
   1.888 +    // have to be explicitly destroyed, since calling unref enough
   1.889 +    // to cause destruction would lead to *another* unref).
   1.890 +    // However, this combination means that it's actually still ok
   1.891 +    // to use the normal pattern, which is to g_object_ref_sink
   1.892 +    // after construction, and then destroy *and* unref when we're
   1.893 +    // done.  (Though we could skip the g_object_ref_sink and the
   1.894 +    // corresponding g_object_unref, but that's particular to
   1.895 +    // GtkInvisibles and GtkWindows.)
   1.896 +    GtkWidget *widget = gtk_invisible_new();
   1.897 +    g_object_ref_sink(widget); // effectively g_object_ref (see above)
   1.898 +
   1.899 +    gtk_widget_ensure_style(widget);
   1.900 +    mStyle = gtk_style_copy(gtk_widget_get_style(widget));
   1.901 +
   1.902 +    gtk_widget_destroy(widget);
   1.903 +    g_object_unref(widget);
   1.904 +        
   1.905 +    // tooltip foreground and background
   1.906 +    GtkStyle *style = gtk_rc_get_style_by_paths(gtk_settings_get_default(),
   1.907 +                                                "gtk-tooltips", "GtkWindow",
   1.908 +                                                GTK_TYPE_WINDOW);
   1.909 +    if (style) {
   1.910 +        sInfoBackground = GDK_COLOR_TO_NS_RGB(style->bg[GTK_STATE_NORMAL]);
   1.911 +        sInfoText = GDK_COLOR_TO_NS_RGB(style->fg[GTK_STATE_NORMAL]);
   1.912 +    }
   1.913 +
   1.914 +    // menu foreground & menu background
   1.915 +    GtkWidget *accel_label = gtk_accel_label_new("M");
   1.916 +    GtkWidget *menuitem = gtk_menu_item_new();
   1.917 +    GtkWidget *menu = gtk_menu_new();
   1.918 +
   1.919 +    g_object_ref_sink(menu);
   1.920 +
   1.921 +    gtk_container_add(GTK_CONTAINER(menuitem), accel_label);
   1.922 +    gtk_menu_shell_append(GTK_MENU_SHELL(menu), menuitem);
   1.923 +
   1.924 +    gtk_widget_set_style(accel_label, nullptr);
   1.925 +    gtk_widget_set_style(menu, nullptr);
   1.926 +    gtk_widget_realize(menu);
   1.927 +    gtk_widget_realize(accel_label);
   1.928 +
   1.929 +    style = gtk_widget_get_style(accel_label);
   1.930 +    if (style) {
   1.931 +        sMenuText = GDK_COLOR_TO_NS_RGB(style->fg[GTK_STATE_NORMAL]);
   1.932 +    }
   1.933 +
   1.934 +    style = gtk_widget_get_style(menu);
   1.935 +    if (style) {
   1.936 +        sMenuBackground = GDK_COLOR_TO_NS_RGB(style->bg[GTK_STATE_NORMAL]);
   1.937 +    }
   1.938 +    
   1.939 +    style = gtk_widget_get_style(menuitem);
   1.940 +    if (style) {
   1.941 +        sMenuHover = GDK_COLOR_TO_NS_RGB(style->bg[GTK_STATE_PRELIGHT]);
   1.942 +        sMenuHoverText = GDK_COLOR_TO_NS_RGB(style->fg[GTK_STATE_PRELIGHT]);
   1.943 +    }
   1.944 +
   1.945 +    g_object_unref(menu);
   1.946 +#else
   1.947 +    GdkRGBA color;
   1.948 +    GtkStyleContext *style;
   1.949 +
   1.950 +    // Gtk manages a screen's CSS in the settings object so we
   1.951 +    // ask Gtk to create it explicitly. Otherwise we may end up 
   1.952 +    // with wrong color theme, see Bug 972382
   1.953 +    (void)gtk_settings_get_for_screen(gdk_screen_get_default());
   1.954 +
   1.955 +    GtkWidgetPath *path = gtk_widget_path_new();
   1.956 +    gtk_widget_path_append_type(path, GTK_TYPE_WINDOW);
   1.957 +
   1.958 +    mBackgroundStyle = create_context(path);
   1.959 +    gtk_style_context_add_class(mBackgroundStyle, GTK_STYLE_CLASS_BACKGROUND);
   1.960 +
   1.961 +    mViewStyle = create_context(path);
   1.962 +    gtk_style_context_add_class(mViewStyle, GTK_STYLE_CLASS_VIEW);
   1.963 +
   1.964 +    mButtonStyle = create_context(path);
   1.965 +    gtk_style_context_add_class(mButtonStyle, GTK_STYLE_CLASS_BUTTON); 
   1.966 +
   1.967 +    // Scrollbar colors
   1.968 +    style = create_context(path);
   1.969 +    gtk_style_context_add_class(style, GTK_STYLE_CLASS_SCROLLBAR);
   1.970 +    gtk_style_context_add_class(style, GTK_STYLE_CLASS_TROUGH);
   1.971 +    gtk_style_context_get_background_color(style, GTK_STATE_FLAG_NORMAL, &color);
   1.972 +    sMozScrollbar = GDK_RGBA_TO_NS_RGBA(color);
   1.973 +    g_object_unref(style);
   1.974 +
   1.975 +    // Text colors
   1.976 +    gtk_style_context_get_background_color(mViewStyle, GTK_STATE_FLAG_NORMAL, &color);
   1.977 +    sMozFieldBackground = GDK_RGBA_TO_NS_RGBA(color);
   1.978 +    gtk_style_context_get_color(mViewStyle, GTK_STATE_FLAG_NORMAL, &color);
   1.979 +    sMozFieldText = GDK_RGBA_TO_NS_RGBA(color);
   1.980 +
   1.981 +    // Window colors
   1.982 +    style = create_context(path);
   1.983 +    gtk_style_context_save(style);
   1.984 +    gtk_style_context_add_class(style, GTK_STYLE_CLASS_BACKGROUND);
   1.985 +    gtk_style_context_get_background_color(style, GTK_STATE_FLAG_NORMAL, &color);
   1.986 +    sMozWindowBackground = GDK_RGBA_TO_NS_RGBA(color);
   1.987 +    gtk_style_context_get_color(style, GTK_STATE_FLAG_NORMAL, &color);
   1.988 +    sMozWindowText = GDK_RGBA_TO_NS_RGBA(color);
   1.989 +
   1.990 +    // Selected text and background
   1.991 +    gtk_style_context_get_background_color(style, GTK_STATE_FLAG_SELECTED, &color);
   1.992 +    sMozWindowSelectedBackground = GDK_RGBA_TO_NS_RGBA(color);
   1.993 +    gtk_style_context_get_color(style, GTK_STATE_FLAG_SELECTED, &color);
   1.994 +    sMozWindowSelectedText = GDK_RGBA_TO_NS_RGBA(color);
   1.995 +    gtk_style_context_restore(style);
   1.996 +
   1.997 +    // tooltip foreground and background
   1.998 +    gtk_style_context_add_class(style, GTK_STYLE_CLASS_TOOLTIP);
   1.999 +    gtk_style_context_get_background_color(style, GTK_STATE_FLAG_NORMAL, &color);
  1.1000 +    sInfoBackground = GDK_RGBA_TO_NS_RGBA(color);
  1.1001 +    gtk_style_context_get_color(style, GTK_STATE_FLAG_NORMAL, &color);
  1.1002 +    sInfoText = GDK_RGBA_TO_NS_RGBA(color);
  1.1003 +    g_object_unref(style);
  1.1004 +
  1.1005 +    // menu foreground & menu background
  1.1006 +    GtkWidget *accel_label = gtk_accel_label_new("M");
  1.1007 +    GtkWidget *menuitem = gtk_menu_item_new();
  1.1008 +    GtkWidget *menu = gtk_menu_new();
  1.1009 +
  1.1010 +    g_object_ref_sink(menu);
  1.1011 +
  1.1012 +    gtk_container_add(GTK_CONTAINER(menuitem), accel_label);
  1.1013 +    gtk_menu_shell_append(GTK_MENU_SHELL(menu), menuitem);
  1.1014 +
  1.1015 +    style = gtk_widget_get_style_context(accel_label);
  1.1016 +    gtk_style_context_get_color(style, GTK_STATE_FLAG_NORMAL, &color);
  1.1017 +    sMenuText = GDK_RGBA_TO_NS_RGBA(color);
  1.1018 +
  1.1019 +    style = gtk_widget_get_style_context(menu);
  1.1020 +    gtk_style_context_get_background_color(style, GTK_STATE_FLAG_NORMAL, &color);
  1.1021 +    sMenuBackground = GDK_RGBA_TO_NS_RGBA(color);
  1.1022 +
  1.1023 +    style = gtk_widget_get_style_context(menuitem);
  1.1024 +    gtk_style_context_get_background_color(style, GTK_STATE_FLAG_PRELIGHT, &color);
  1.1025 +    sMenuHover = GDK_RGBA_TO_NS_RGBA(color);
  1.1026 +    gtk_style_context_get_color(style, GTK_STATE_FLAG_PRELIGHT, &color);
  1.1027 +    sMenuHoverText = GDK_RGBA_TO_NS_RGBA(color);
  1.1028 +
  1.1029 +    g_object_unref(menu);
  1.1030 +#endif
  1.1031 +
  1.1032 +    // button styles
  1.1033 +    GtkWidget *parent = gtk_fixed_new();
  1.1034 +    GtkWidget *button = gtk_button_new();
  1.1035 +    GtkWidget *label = gtk_label_new("M");
  1.1036 +#if (MOZ_WIDGET_GTK == 2)
  1.1037 +    GtkWidget *combobox = gtk_combo_box_new();
  1.1038 +    GtkWidget *comboboxLabel = gtk_label_new("M");
  1.1039 +    gtk_container_add(GTK_CONTAINER(combobox), comboboxLabel);
  1.1040 +#else
  1.1041 +    GtkWidget *combobox = gtk_combo_box_new_with_entry();
  1.1042 +    GtkWidget *comboboxLabel = gtk_bin_get_child(GTK_BIN(combobox));
  1.1043 +#endif
  1.1044 +    GtkWidget *window = gtk_window_new(GTK_WINDOW_POPUP);
  1.1045 +    GtkWidget *treeView = gtk_tree_view_new();
  1.1046 +    GtkWidget *linkButton = gtk_link_button_new("http://example.com/");
  1.1047 +    GtkWidget *menuBar = gtk_menu_bar_new();
  1.1048 +    GtkWidget *entry = gtk_entry_new();
  1.1049 +
  1.1050 +    gtk_container_add(GTK_CONTAINER(button), label);
  1.1051 +    gtk_container_add(GTK_CONTAINER(parent), button);
  1.1052 +    gtk_container_add(GTK_CONTAINER(parent), treeView);
  1.1053 +    gtk_container_add(GTK_CONTAINER(parent), linkButton);
  1.1054 +    gtk_container_add(GTK_CONTAINER(parent), combobox);
  1.1055 +    gtk_container_add(GTK_CONTAINER(parent), menuBar);
  1.1056 +    gtk_container_add(GTK_CONTAINER(window), parent);
  1.1057 +    gtk_container_add(GTK_CONTAINER(parent), entry);
  1.1058 +    
  1.1059 +#if (MOZ_WIDGET_GTK == 2)
  1.1060 +    gtk_widget_set_style(button, nullptr);
  1.1061 +    gtk_widget_set_style(label, nullptr);
  1.1062 +    gtk_widget_set_style(treeView, nullptr);
  1.1063 +    gtk_widget_set_style(linkButton, nullptr);
  1.1064 +    gtk_widget_set_style(combobox, nullptr);
  1.1065 +    gtk_widget_set_style(comboboxLabel, nullptr);
  1.1066 +    gtk_widget_set_style(menuBar, nullptr);
  1.1067 +    gtk_widget_set_style(entry, nullptr);
  1.1068 +
  1.1069 +    gtk_widget_realize(button);
  1.1070 +    gtk_widget_realize(label);
  1.1071 +    gtk_widget_realize(treeView);
  1.1072 +    gtk_widget_realize(linkButton);
  1.1073 +    gtk_widget_realize(combobox);
  1.1074 +    gtk_widget_realize(comboboxLabel);
  1.1075 +    gtk_widget_realize(menuBar);
  1.1076 +    gtk_widget_realize(entry);
  1.1077 +
  1.1078 +    style = gtk_widget_get_style(label);
  1.1079 +    if (style) {
  1.1080 +        sButtonText = GDK_COLOR_TO_NS_RGB(style->fg[GTK_STATE_NORMAL]);
  1.1081 +    }
  1.1082 +
  1.1083 +    style = gtk_widget_get_style(comboboxLabel);
  1.1084 +    if (style) {
  1.1085 +        sComboBoxText = GDK_COLOR_TO_NS_RGB(style->fg[GTK_STATE_NORMAL]);
  1.1086 +    }
  1.1087 +    style = gtk_widget_get_style(combobox);
  1.1088 +    if (style) {
  1.1089 +        sComboBoxBackground = GDK_COLOR_TO_NS_RGB(style->bg[GTK_STATE_NORMAL]);
  1.1090 +    }
  1.1091 +
  1.1092 +    style = gtk_widget_get_style(menuBar);
  1.1093 +    if (style) {
  1.1094 +        sMenuBarText = GDK_COLOR_TO_NS_RGB(style->fg[GTK_STATE_NORMAL]);
  1.1095 +        sMenuBarHoverText = GDK_COLOR_TO_NS_RGB(style->fg[GTK_STATE_SELECTED]);
  1.1096 +    }
  1.1097 +
  1.1098 +    // GTK's guide to fancy odd row background colors:
  1.1099 +    // 1) Check if a theme explicitly defines an odd row color
  1.1100 +    // 2) If not, check if it defines an even row color, and darken it
  1.1101 +    //    slightly by a hardcoded value (gtkstyle.c)
  1.1102 +    // 3) If neither are defined, take the base background color and
  1.1103 +    //    darken that by a hardcoded value
  1.1104 +    colorValuePtr = nullptr;
  1.1105 +    gtk_widget_style_get(treeView,
  1.1106 +                         "odd-row-color", &colorValuePtr,
  1.1107 +                         nullptr);
  1.1108 +
  1.1109 +    if (colorValuePtr) {
  1.1110 +        colorValue = *colorValuePtr;
  1.1111 +    } else {
  1.1112 +        gtk_widget_style_get(treeView,
  1.1113 +                             "even-row-color", &colorValuePtr,
  1.1114 +                             nullptr);
  1.1115 +        if (colorValuePtr)
  1.1116 +            darken_gdk_color(colorValuePtr, &colorValue);
  1.1117 +        else
  1.1118 +            darken_gdk_color(&treeView->style->base[GTK_STATE_NORMAL], &colorValue);
  1.1119 +    }
  1.1120 +
  1.1121 +    sOddCellBackground = GDK_COLOR_TO_NS_RGB(colorValue);
  1.1122 +    if (colorValuePtr)
  1.1123 +        gdk_color_free(colorValuePtr);
  1.1124 +
  1.1125 +    style = gtk_widget_get_style(button);
  1.1126 +    if (style) {
  1.1127 +        sButtonBackground = GDK_COLOR_TO_NS_RGB(style->bg[GTK_STATE_NORMAL]);
  1.1128 +        sButtonOuterLightBorder =
  1.1129 +            GDK_COLOR_TO_NS_RGB(style->light[GTK_STATE_NORMAL]);
  1.1130 +        sButtonInnerDarkBorder =
  1.1131 +            GDK_COLOR_TO_NS_RGB(style->dark[GTK_STATE_NORMAL]);
  1.1132 +    }
  1.1133 +#else
  1.1134 +    // Button text, background, border
  1.1135 +    style = gtk_widget_get_style_context(label);
  1.1136 +    gtk_style_context_get_color(style, GTK_STATE_FLAG_NORMAL, &color);
  1.1137 +    sButtonText = GDK_RGBA_TO_NS_RGBA(color);
  1.1138 +    gtk_style_context_get_color(style, GTK_STATE_FLAG_PRELIGHT, &color);
  1.1139 +    sButtonHoverText = GDK_RGBA_TO_NS_RGBA(color);
  1.1140 +
  1.1141 +    // Combobox label and background colors
  1.1142 +    style = gtk_widget_get_style_context(comboboxLabel);
  1.1143 +    gtk_style_context_get_color(style, GTK_STATE_FLAG_NORMAL, &color);
  1.1144 +    sComboBoxText = GDK_RGBA_TO_NS_RGBA(color);
  1.1145 +
  1.1146 +    style = gtk_widget_get_style_context(combobox);
  1.1147 +    gtk_style_context_get_background_color(style, GTK_STATE_FLAG_NORMAL, &color);
  1.1148 +    sComboBoxBackground = GDK_RGBA_TO_NS_RGBA(color);
  1.1149 +
  1.1150 +    // Menubar text and hover text colors    
  1.1151 +    style = gtk_widget_get_style_context(menuBar);
  1.1152 +    gtk_style_context_get_color(style, GTK_STATE_FLAG_NORMAL, &color);
  1.1153 +    sMenuBarText = GDK_RGBA_TO_NS_RGBA(color);
  1.1154 +    gtk_style_context_get_color(style, GTK_STATE_FLAG_PRELIGHT, &color);
  1.1155 +    sMenuBarHoverText = GDK_RGBA_TO_NS_RGBA(color);
  1.1156 +
  1.1157 +    // GTK's guide to fancy odd row background colors:
  1.1158 +    // 1) Check if a theme explicitly defines an odd row color
  1.1159 +    // 2) If not, check if it defines an even row color, and darken it
  1.1160 +    //    slightly by a hardcoded value (gtkstyle.c)
  1.1161 +    // 3) If neither are defined, take the base background color and
  1.1162 +    //    darken that by a hardcoded value
  1.1163 +    style = gtk_widget_get_style_context(treeView);
  1.1164 +
  1.1165 +    // Get odd row background color
  1.1166 +    gtk_style_context_save(style);
  1.1167 +    gtk_style_context_add_region(style, GTK_STYLE_REGION_ROW, GTK_REGION_ODD);
  1.1168 +    gtk_style_context_get_background_color(style, GTK_STATE_FLAG_NORMAL, &color);
  1.1169 +    sOddCellBackground = GDK_RGBA_TO_NS_RGBA(color);
  1.1170 +    gtk_style_context_restore(style);
  1.1171 +
  1.1172 +    style = gtk_widget_get_style_context(button);
  1.1173 +    gtk_style_context_get_background_color(style, GTK_STATE_FLAG_NORMAL, &color);
  1.1174 +    sButtonBackground = GDK_RGBA_TO_NS_RGBA(color);
  1.1175 +
  1.1176 +    gtk_style_context_get_border_color(style, GTK_STATE_FLAG_PRELIGHT, &color);
  1.1177 +    sButtonInnerDarkBorder = GDK_RGBA_TO_NS_RGBA(color);
  1.1178 +    gtk_style_context_get_border_color(style, GTK_STATE_FLAG_NORMAL, &color);
  1.1179 +    sButtonOuterLightBorder = GDK_RGBA_TO_NS_RGBA(color);
  1.1180 +#endif
  1.1181 +    // Some themes have a unified menu bar, and support window dragging on it
  1.1182 +    gboolean supports_menubar_drag = FALSE;
  1.1183 +    GParamSpec *param_spec =
  1.1184 +        gtk_widget_class_find_style_property(GTK_WIDGET_GET_CLASS(menuBar),
  1.1185 +                                             "window-dragging");
  1.1186 +    if (param_spec) {
  1.1187 +        if (g_type_is_a(G_PARAM_SPEC_VALUE_TYPE(param_spec), G_TYPE_BOOLEAN)) {
  1.1188 +            gtk_widget_style_get(menuBar,
  1.1189 +                                 "window-dragging", &supports_menubar_drag,
  1.1190 +                                 nullptr);
  1.1191 +        }
  1.1192 +    }
  1.1193 +    sMenuSupportsDrag = supports_menubar_drag;
  1.1194 +
  1.1195 +    colorValuePtr = nullptr;
  1.1196 +    gtk_widget_style_get(linkButton, "link-color", &colorValuePtr, nullptr);
  1.1197 +    if (colorValuePtr) {
  1.1198 +        colorValue = *colorValuePtr; // we can't pass deref pointers to GDK_COLOR_TO_NS_RGB
  1.1199 +        sNativeHyperLinkText = GDK_COLOR_TO_NS_RGB(colorValue);
  1.1200 +        gdk_color_free(colorValuePtr);
  1.1201 +    } else {
  1.1202 +        sNativeHyperLinkText = NS_RGB(0x00,0x00,0xEE);
  1.1203 +    }
  1.1204 +
  1.1205 +    // invisible character styles
  1.1206 +    guint value;
  1.1207 +    g_object_get (entry, "invisible-char", &value, nullptr);
  1.1208 +    sInvisibleCharacter = char16_t(value);
  1.1209 +
  1.1210 +    // caret styles
  1.1211 +    gtk_widget_style_get(entry,
  1.1212 +                         "cursor-aspect-ratio", &sCaretRatio,
  1.1213 +                         nullptr);
  1.1214 +
  1.1215 +    gtk_widget_destroy(window);
  1.1216 +}
  1.1217 +
  1.1218 +// virtual
  1.1219 +char16_t
  1.1220 +nsLookAndFeel::GetPasswordCharacterImpl()
  1.1221 +{
  1.1222 +    return sInvisibleCharacter;
  1.1223 +}
  1.1224 +
  1.1225 +void
  1.1226 +nsLookAndFeel::RefreshImpl()
  1.1227 +{
  1.1228 +    nsXPLookAndFeel::RefreshImpl();
  1.1229 +
  1.1230 +    mDefaultFontCached = false;
  1.1231 +    mButtonFontCached = false;
  1.1232 +    mFieldFontCached = false;
  1.1233 +    mMenuFontCached = false;
  1.1234 +
  1.1235 +#if (MOZ_WIDGET_GTK == 2)
  1.1236 +    g_object_unref(mStyle);
  1.1237 +    mStyle = nullptr;
  1.1238 +#else
  1.1239 +    g_object_unref(mBackgroundStyle);
  1.1240 +    g_object_unref(mViewStyle);
  1.1241 +    g_object_unref(mButtonStyle);
  1.1242 +
  1.1243 +    mBackgroundStyle = nullptr;
  1.1244 +    mViewStyle = nullptr;
  1.1245 +    mButtonStyle = nullptr;
  1.1246 +#endif
  1.1247 +
  1.1248 +    Init();
  1.1249 +}
  1.1250 +
  1.1251 +bool
  1.1252 +nsLookAndFeel::GetEchoPasswordImpl() {
  1.1253 +    return false;
  1.1254 +}

mercurial