Thu, 22 Jan 2015 13:21:57 +0100
Incorporate requested changes from Mozilla in review:
https://bugzilla.mozilla.org/show_bug.cgi?id=1123480#c6
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /* vim:expandtab:shiftwidth=4:tabstop=4:
3 */
4 /* This Source Code Form is subject to the terms of the Mozilla Public
5 * License, v. 2.0. If a copy of the MPL was not distributed with this
6 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
8 // for strtod()
9 #include <stdlib.h>
11 #include "nsLookAndFeel.h"
13 #include <gtk/gtk.h>
14 #include <gdk/gdk.h>
16 #include <pango/pango.h>
17 #include <pango/pango-fontmap.h>
19 #include <fontconfig/fontconfig.h>
20 #include "gfxPlatformGtk.h"
22 #include "gtkdrawing.h"
23 #include "nsStyleConsts.h"
24 #include "gfxFontConstants.h"
25 #include "mozilla/gfx/2D.h"
27 using mozilla::LookAndFeel;
29 #define GDK_COLOR_TO_NS_RGB(c) \
30 ((nscolor) NS_RGB(c.red>>8, c.green>>8, c.blue>>8))
31 #define GDK_RGBA_TO_NS_RGBA(c) \
32 ((nscolor) NS_RGBA((int)((c).red*255), (int)((c).green*255), \
33 (int)((c).blue*255), (int)((c).alpha*255)))
35 nsLookAndFeel::nsLookAndFeel()
36 : nsXPLookAndFeel(),
37 #if (MOZ_WIDGET_GTK == 2)
38 mStyle(nullptr),
39 #else
40 mBackgroundStyle(nullptr),
41 mViewStyle(nullptr),
42 mButtonStyle(nullptr),
43 #endif
44 mDefaultFontCached(false), mButtonFontCached(false),
45 mFieldFontCached(false), mMenuFontCached(false)
46 {
47 Init();
48 }
50 nsLookAndFeel::~nsLookAndFeel()
51 {
52 #if (MOZ_WIDGET_GTK == 2)
53 g_object_unref(mStyle);
54 #else
55 g_object_unref(mBackgroundStyle);
56 g_object_unref(mViewStyle);
57 g_object_unref(mButtonStyle);
58 #endif
59 }
61 nsresult
62 nsLookAndFeel::NativeGetColor(ColorID aID, nscolor& aColor)
63 {
64 #if (MOZ_WIDGET_GTK == 3)
65 GdkRGBA gdk_color;
66 #endif
67 nsresult res = NS_OK;
69 switch (aID) {
70 // These colors don't seem to be used for anything anymore in Mozilla
71 // (except here at least TextSelectBackground and TextSelectForeground)
72 // The CSS2 colors below are used.
73 #if (MOZ_WIDGET_GTK == 2)
74 case eColorID_WindowBackground:
75 aColor = GDK_COLOR_TO_NS_RGB(mStyle->base[GTK_STATE_NORMAL]);
76 break;
77 case eColorID_WindowForeground:
78 aColor = GDK_COLOR_TO_NS_RGB(mStyle->text[GTK_STATE_NORMAL]);
79 break;
80 case eColorID_WidgetBackground:
81 aColor = GDK_COLOR_TO_NS_RGB(mStyle->bg[GTK_STATE_NORMAL]);
82 break;
83 case eColorID_WidgetForeground:
84 aColor = GDK_COLOR_TO_NS_RGB(mStyle->fg[GTK_STATE_NORMAL]);
85 break;
86 case eColorID_WidgetSelectBackground:
87 aColor = GDK_COLOR_TO_NS_RGB(mStyle->bg[GTK_STATE_SELECTED]);
88 break;
89 case eColorID_WidgetSelectForeground:
90 aColor = GDK_COLOR_TO_NS_RGB(mStyle->fg[GTK_STATE_SELECTED]);
91 break;
92 #else
93 case eColorID_WindowBackground:
94 case eColorID_WidgetBackground:
95 case eColorID_TextBackground:
96 case eColorID_activecaption: // active window caption background
97 case eColorID_appworkspace: // MDI background color
98 case eColorID_background: // desktop background
99 case eColorID_window:
100 case eColorID_windowframe:
101 case eColorID__moz_dialog:
102 aColor = sMozWindowBackground;
103 break;
104 case eColorID_WindowForeground:
105 case eColorID_WidgetForeground:
106 case eColorID_TextForeground:
107 case eColorID_captiontext: // text in active window caption, size box, and scrollbar arrow box (!)
108 case eColorID_windowtext:
109 case eColorID__moz_dialogtext:
110 aColor = sMozWindowText;
111 break;
112 case eColorID_WidgetSelectBackground:
113 case eColorID_TextSelectBackground:
114 case eColorID_IMESelectedRawTextBackground:
115 case eColorID_IMESelectedConvertedTextBackground:
116 case eColorID__moz_dragtargetzone:
117 aColor = sMozWindowSelectedBackground;
118 break;
119 case eColorID_WidgetSelectForeground:
120 case eColorID_TextSelectForeground:
121 case eColorID_IMESelectedRawTextForeground:
122 case eColorID_IMESelectedConvertedTextForeground:
123 aColor = sMozWindowSelectedText;
124 break;
125 #endif
126 case eColorID_Widget3DHighlight:
127 aColor = NS_RGB(0xa0,0xa0,0xa0);
128 break;
129 case eColorID_Widget3DShadow:
130 aColor = NS_RGB(0x40,0x40,0x40);
131 break;
132 #if (MOZ_WIDGET_GTK == 2)
133 case eColorID_TextBackground:
134 // not used?
135 aColor = GDK_COLOR_TO_NS_RGB(mStyle->base[GTK_STATE_NORMAL]);
136 break;
137 case eColorID_TextForeground:
138 // not used?
139 aColor = GDK_COLOR_TO_NS_RGB(mStyle->text[GTK_STATE_NORMAL]);
140 break;
141 case eColorID_TextSelectBackground:
142 case eColorID_IMESelectedRawTextBackground:
143 case eColorID_IMESelectedConvertedTextBackground:
144 // still used
145 aColor = GDK_COLOR_TO_NS_RGB(mStyle->base[GTK_STATE_SELECTED]);
146 break;
147 case eColorID_TextSelectForeground:
148 case eColorID_IMESelectedRawTextForeground:
149 case eColorID_IMESelectedConvertedTextForeground:
150 // still used
151 aColor = GDK_COLOR_TO_NS_RGB(mStyle->text[GTK_STATE_SELECTED]);
152 break;
153 #endif
154 case eColorID_IMERawInputBackground:
155 case eColorID_IMEConvertedTextBackground:
156 aColor = NS_TRANSPARENT;
157 break;
158 case eColorID_IMERawInputForeground:
159 case eColorID_IMEConvertedTextForeground:
160 aColor = NS_SAME_AS_FOREGROUND_COLOR;
161 break;
162 case eColorID_IMERawInputUnderline:
163 case eColorID_IMEConvertedTextUnderline:
164 aColor = NS_SAME_AS_FOREGROUND_COLOR;
165 break;
166 case eColorID_IMESelectedRawTextUnderline:
167 case eColorID_IMESelectedConvertedTextUnderline:
168 aColor = NS_TRANSPARENT;
169 break;
170 case eColorID_SpellCheckerUnderline:
171 aColor = NS_RGB(0xff, 0, 0);
172 break;
174 #if (MOZ_WIDGET_GTK == 2)
175 // css2 http://www.w3.org/TR/REC-CSS2/ui.html#system-colors
176 case eColorID_activeborder:
177 // active window border
178 aColor = GDK_COLOR_TO_NS_RGB(mStyle->bg[GTK_STATE_NORMAL]);
179 break;
180 case eColorID_activecaption:
181 // active window caption background
182 aColor = GDK_COLOR_TO_NS_RGB(mStyle->bg[GTK_STATE_NORMAL]);
183 break;
184 case eColorID_appworkspace:
185 // MDI background color
186 aColor = GDK_COLOR_TO_NS_RGB(mStyle->bg[GTK_STATE_NORMAL]);
187 break;
188 case eColorID_background:
189 // desktop background
190 aColor = GDK_COLOR_TO_NS_RGB(mStyle->bg[GTK_STATE_NORMAL]);
191 break;
192 case eColorID_captiontext:
193 // text in active window caption, size box, and scrollbar arrow box (!)
194 aColor = GDK_COLOR_TO_NS_RGB(mStyle->fg[GTK_STATE_NORMAL]);
195 break;
196 case eColorID_graytext:
197 // disabled text in windows, menus, etc.
198 aColor = GDK_COLOR_TO_NS_RGB(mStyle->fg[GTK_STATE_INSENSITIVE]);
199 break;
200 case eColorID_highlight:
201 // background of selected item
202 aColor = GDK_COLOR_TO_NS_RGB(mStyle->base[GTK_STATE_SELECTED]);
203 break;
204 case eColorID_highlighttext:
205 // text of selected item
206 aColor = GDK_COLOR_TO_NS_RGB(mStyle->text[GTK_STATE_SELECTED]);
207 break;
208 case eColorID_inactiveborder:
209 // inactive window border
210 aColor = GDK_COLOR_TO_NS_RGB(mStyle->bg[GTK_STATE_NORMAL]);
211 break;
212 case eColorID_inactivecaption:
213 // inactive window caption
214 aColor = GDK_COLOR_TO_NS_RGB(mStyle->bg[GTK_STATE_INSENSITIVE]);
215 break;
216 case eColorID_inactivecaptiontext:
217 // text in inactive window caption
218 aColor = GDK_COLOR_TO_NS_RGB(mStyle->fg[GTK_STATE_INSENSITIVE]);
219 break;
220 #else
221 // css2 http://www.w3.org/TR/REC-CSS2/ui.html#system-colors
222 case eColorID_activeborder:
223 // active window border
224 gtk_style_context_get_border_color(mBackgroundStyle,
225 GTK_STATE_FLAG_NORMAL, &gdk_color);
226 aColor = GDK_RGBA_TO_NS_RGBA(gdk_color);
227 break;
228 case eColorID_inactiveborder:
229 // inactive window border
230 gtk_style_context_get_border_color(mBackgroundStyle,
231 GTK_STATE_FLAG_INSENSITIVE,
232 &gdk_color);
233 aColor = GDK_RGBA_TO_NS_RGBA(gdk_color);
234 break;
235 case eColorID_graytext: // disabled text in windows, menus, etc.
236 case eColorID_inactivecaptiontext: // text in inactive window caption
237 gtk_style_context_get_color(mBackgroundStyle,
238 GTK_STATE_FLAG_INSENSITIVE, &gdk_color);
239 aColor = GDK_RGBA_TO_NS_RGBA(gdk_color);
240 break;
241 case eColorID_highlight: // preference selected item,
242 // background of selected item
243 gtk_style_context_get_background_color(mViewStyle,
244 GTK_STATE_FLAG_SELECTED,
245 &gdk_color);
246 aColor = GDK_RGBA_TO_NS_RGBA(gdk_color);
247 break;
248 case eColorID_highlighttext:
249 // text of selected item
250 gtk_style_context_get_color(mViewStyle,
251 GTK_STATE_FLAG_SELECTED, &gdk_color);
252 aColor = GDK_RGBA_TO_NS_RGBA(gdk_color);
253 break;
254 case eColorID_inactivecaption:
255 // inactive window caption
256 gtk_style_context_get_background_color(mBackgroundStyle,
257 GTK_STATE_FLAG_INSENSITIVE,
258 &gdk_color);
259 aColor = GDK_RGBA_TO_NS_RGBA(gdk_color);
260 break;
261 #endif
262 case eColorID_infobackground:
263 // tooltip background color
264 aColor = sInfoBackground;
265 break;
266 case eColorID_infotext:
267 // tooltip text color
268 aColor = sInfoText;
269 break;
270 case eColorID_menu:
271 // menu background
272 aColor = sMenuBackground;
273 break;
274 case eColorID_menutext:
275 // menu text
276 aColor = sMenuText;
277 break;
278 case eColorID_scrollbar:
279 // scrollbar gray area
280 #if (MOZ_WIDGET_GTK == 2)
281 aColor = GDK_COLOR_TO_NS_RGB(mStyle->bg[GTK_STATE_ACTIVE]);
282 #else
283 aColor = sMozScrollbar;
284 #endif
285 break;
287 case eColorID_threedface:
288 case eColorID_buttonface:
289 // 3-D face color
290 aColor = sButtonBackground;
291 break;
293 case eColorID_buttontext:
294 // text on push buttons
295 aColor = sButtonText;
296 break;
298 case eColorID_buttonhighlight:
299 // 3-D highlighted edge color
300 case eColorID_threedhighlight:
301 // 3-D highlighted outer edge color
302 aColor = sButtonOuterLightBorder;
303 break;
305 case eColorID_threedlightshadow:
306 // 3-D highlighted inner edge color
307 aColor = sButtonBackground; // always same as background in GTK code
308 break;
310 case eColorID_buttonshadow:
311 // 3-D shadow edge color
312 case eColorID_threedshadow:
313 // 3-D shadow inner edge color
314 aColor = sButtonInnerDarkBorder;
315 break;
317 #if (MOZ_WIDGET_GTK == 2)
318 case eColorID_threeddarkshadow:
319 // 3-D shadow outer edge color
320 aColor = GDK_COLOR_TO_NS_RGB(mStyle->black);
321 break;
323 case eColorID_window:
324 case eColorID_windowframe:
325 aColor = GDK_COLOR_TO_NS_RGB(mStyle->bg[GTK_STATE_NORMAL]);
326 break;
328 case eColorID_windowtext:
329 aColor = GDK_COLOR_TO_NS_RGB(mStyle->fg[GTK_STATE_NORMAL]);
330 break;
332 case eColorID__moz_eventreerow:
333 case eColorID__moz_field:
334 aColor = GDK_COLOR_TO_NS_RGB(mStyle->base[GTK_STATE_NORMAL]);
335 break;
336 case eColorID__moz_fieldtext:
337 aColor = GDK_COLOR_TO_NS_RGB(mStyle->text[GTK_STATE_NORMAL]);
338 break;
339 case eColorID__moz_dialog:
340 aColor = GDK_COLOR_TO_NS_RGB(mStyle->bg[GTK_STATE_NORMAL]);
341 break;
342 case eColorID__moz_dialogtext:
343 aColor = GDK_COLOR_TO_NS_RGB(mStyle->fg[GTK_STATE_NORMAL]);
344 break;
345 case eColorID__moz_dragtargetzone:
346 aColor = GDK_COLOR_TO_NS_RGB(mStyle->bg[GTK_STATE_SELECTED]);
347 break;
348 case eColorID__moz_buttondefault:
349 // default button border color
350 aColor = GDK_COLOR_TO_NS_RGB(mStyle->black);
351 break;
352 case eColorID__moz_buttonhoverface:
353 aColor = GDK_COLOR_TO_NS_RGB(mStyle->bg[GTK_STATE_PRELIGHT]);
354 break;
355 case eColorID__moz_buttonhovertext:
356 aColor = GDK_COLOR_TO_NS_RGB(mStyle->fg[GTK_STATE_PRELIGHT]);
357 break;
358 case eColorID__moz_cellhighlight:
359 case eColorID__moz_html_cellhighlight:
360 aColor = GDK_COLOR_TO_NS_RGB(mStyle->base[GTK_STATE_ACTIVE]);
361 break;
362 case eColorID__moz_cellhighlighttext:
363 case eColorID__moz_html_cellhighlighttext:
364 aColor = GDK_COLOR_TO_NS_RGB(mStyle->text[GTK_STATE_ACTIVE]);
365 break;
366 #else
367 case eColorID_threeddarkshadow:
368 // Hardcode to black
369 aColor = NS_RGB(0x00,0x00,0x00);;
370 break;
372 case eColorID__moz_eventreerow:
373 case eColorID__moz_field:
374 aColor = sMozFieldBackground;
375 break;
376 case eColorID__moz_fieldtext:
377 aColor = sMozFieldText;
378 break;
379 case eColorID__moz_buttondefault:
380 // default button border color
381 gtk_style_context_get_border_color(mButtonStyle,
382 GTK_STATE_FLAG_NORMAL, &gdk_color);
383 aColor = GDK_RGBA_TO_NS_RGBA(gdk_color);
384 break;
385 case eColorID__moz_buttonhoverface:
386 gtk_style_context_get_background_color(mButtonStyle,
387 GTK_STATE_FLAG_PRELIGHT,
388 &gdk_color);
389 aColor = GDK_RGBA_TO_NS_RGBA(gdk_color);
390 break;
391 case eColorID__moz_buttonhovertext:
392 aColor = sButtonHoverText;
393 break;
394 case eColorID__moz_cellhighlight:
395 case eColorID__moz_html_cellhighlight:
396 gtk_style_context_get_background_color(mViewStyle,
397 GTK_STATE_FLAG_SELECTED,
398 &gdk_color);
399 aColor = GDK_RGBA_TO_NS_RGBA(gdk_color);
400 break;
401 case eColorID__moz_cellhighlighttext:
402 case eColorID__moz_html_cellhighlighttext:
403 gtk_style_context_get_color(mViewStyle,
404 GTK_STATE_FLAG_SELECTED, &gdk_color);
405 aColor = GDK_RGBA_TO_NS_RGBA(gdk_color);
406 break;
407 #endif
408 case eColorID__moz_menuhover:
409 aColor = sMenuHover;
410 break;
411 case eColorID__moz_menuhovertext:
412 aColor = sMenuHoverText;
413 break;
414 case eColorID__moz_oddtreerow:
415 aColor = sOddCellBackground;
416 break;
417 case eColorID__moz_nativehyperlinktext:
418 aColor = sNativeHyperLinkText;
419 break;
420 case eColorID__moz_comboboxtext:
421 aColor = sComboBoxText;
422 break;
423 case eColorID__moz_combobox:
424 aColor = sComboBoxBackground;
425 break;
426 case eColorID__moz_menubartext:
427 aColor = sMenuBarText;
428 break;
429 case eColorID__moz_menubarhovertext:
430 aColor = sMenuBarHoverText;
431 break;
432 default:
433 /* default color is BLACK */
434 aColor = 0;
435 res = NS_ERROR_FAILURE;
436 break;
437 }
439 return res;
440 }
442 #if (MOZ_WIDGET_GTK == 2)
443 static void darken_gdk_color(GdkColor *src, GdkColor *dest)
444 {
445 gdouble red;
446 gdouble green;
447 gdouble blue;
449 red = (gdouble) src->red / 65535.0;
450 green = (gdouble) src->green / 65535.0;
451 blue = (gdouble) src->blue / 65535.0;
453 red *= 0.93;
454 green *= 0.93;
455 blue *= 0.93;
457 dest->red = red * 65535.0;
458 dest->green = green * 65535.0;
459 dest->blue = blue * 65535.0;
460 }
461 #endif
463 static int32_t CheckWidgetStyle(GtkWidget* aWidget, const char* aStyle, int32_t aResult) {
464 gboolean value = FALSE;
465 gtk_widget_style_get(aWidget, aStyle, &value, nullptr);
466 return value ? aResult : 0;
467 }
469 static int32_t ConvertGTKStepperStyleToMozillaScrollArrowStyle(GtkWidget* aWidget)
470 {
471 if (!aWidget)
472 return mozilla::LookAndFeel::eScrollArrowStyle_Single;
474 return
475 CheckWidgetStyle(aWidget, "has-backward-stepper",
476 mozilla::LookAndFeel::eScrollArrow_StartBackward) |
477 CheckWidgetStyle(aWidget, "has-forward-stepper",
478 mozilla::LookAndFeel::eScrollArrow_EndForward) |
479 CheckWidgetStyle(aWidget, "has-secondary-backward-stepper",
480 mozilla::LookAndFeel::eScrollArrow_EndBackward) |
481 CheckWidgetStyle(aWidget, "has-secondary-forward-stepper",
482 mozilla::LookAndFeel::eScrollArrow_StartForward);
483 }
485 nsresult
486 nsLookAndFeel::GetIntImpl(IntID aID, int32_t &aResult)
487 {
488 nsresult res = NS_OK;
490 // Set these before they can get overrided in the nsXPLookAndFeel.
491 switch (aID) {
492 case eIntID_ScrollButtonLeftMouseButtonAction:
493 aResult = 0;
494 return NS_OK;
495 case eIntID_ScrollButtonMiddleMouseButtonAction:
496 aResult = 1;
497 return NS_OK;
498 case eIntID_ScrollButtonRightMouseButtonAction:
499 aResult = 2;
500 return NS_OK;
501 default:
502 break;
503 }
505 res = nsXPLookAndFeel::GetIntImpl(aID, aResult);
506 if (NS_SUCCEEDED(res))
507 return res;
508 res = NS_OK;
510 switch (aID) {
511 case eIntID_CaretBlinkTime:
512 {
513 GtkSettings *settings;
514 gint blink_time;
515 gboolean blink;
517 settings = gtk_settings_get_default ();
518 g_object_get (settings,
519 "gtk-cursor-blink-time", &blink_time,
520 "gtk-cursor-blink", &blink,
521 nullptr);
523 if (blink)
524 aResult = (int32_t) blink_time;
525 else
526 aResult = 0;
527 break;
528 }
529 case eIntID_CaretWidth:
530 aResult = 1;
531 break;
532 case eIntID_ShowCaretDuringSelection:
533 aResult = 0;
534 break;
535 case eIntID_SelectTextfieldsOnKeyFocus:
536 {
537 GtkWidget *entry;
538 GtkSettings *settings;
539 gboolean select_on_focus;
541 entry = gtk_entry_new();
542 g_object_ref_sink(entry);
543 settings = gtk_widget_get_settings(entry);
544 g_object_get(settings,
545 "gtk-entry-select-on-focus",
546 &select_on_focus,
547 nullptr);
549 if(select_on_focus)
550 aResult = 1;
551 else
552 aResult = 0;
554 gtk_widget_destroy(entry);
555 g_object_unref(entry);
556 }
557 break;
558 case eIntID_SubmenuDelay:
559 {
560 GtkSettings *settings;
561 gint delay;
563 settings = gtk_settings_get_default ();
564 g_object_get (settings, "gtk-menu-popup-delay", &delay, nullptr);
565 aResult = (int32_t) delay;
566 break;
567 }
568 case eIntID_TooltipDelay:
569 {
570 aResult = 500;
571 break;
572 }
573 case eIntID_MenusCanOverlapOSBar:
574 // we want XUL popups to be able to overlap the task bar.
575 aResult = 1;
576 break;
577 case eIntID_SkipNavigatingDisabledMenuItem:
578 aResult = 1;
579 break;
580 case eIntID_DragThresholdX:
581 case eIntID_DragThresholdY:
582 {
583 GtkWidget* box = gtk_hbox_new(FALSE, 5);
584 gint threshold = 0;
585 g_object_get(gtk_widget_get_settings(box),
586 "gtk-dnd-drag-threshold", &threshold,
587 nullptr);
588 g_object_ref_sink(box);
590 aResult = threshold;
591 }
592 break;
593 case eIntID_ScrollArrowStyle:
594 moz_gtk_init();
595 aResult =
596 ConvertGTKStepperStyleToMozillaScrollArrowStyle(moz_gtk_get_scrollbar_widget());
597 break;
598 case eIntID_ScrollSliderStyle:
599 aResult = eScrollThumbStyle_Proportional;
600 break;
601 case eIntID_TreeOpenDelay:
602 aResult = 1000;
603 break;
604 case eIntID_TreeCloseDelay:
605 aResult = 1000;
606 break;
607 case eIntID_TreeLazyScrollDelay:
608 aResult = 150;
609 break;
610 case eIntID_TreeScrollDelay:
611 aResult = 100;
612 break;
613 case eIntID_TreeScrollLinesMax:
614 aResult = 3;
615 break;
616 case eIntID_DWMCompositor:
617 case eIntID_WindowsClassic:
618 case eIntID_WindowsDefaultTheme:
619 case eIntID_WindowsThemeIdentifier:
620 case eIntID_OperatingSystemVersionIdentifier:
621 aResult = 0;
622 res = NS_ERROR_NOT_IMPLEMENTED;
623 break;
624 case eIntID_TouchEnabled:
625 aResult = 0;
626 res = NS_ERROR_NOT_IMPLEMENTED;
627 break;
628 case eIntID_MacGraphiteTheme:
629 case eIntID_MacLionTheme:
630 aResult = 0;
631 res = NS_ERROR_NOT_IMPLEMENTED;
632 break;
633 case eIntID_AlertNotificationOrigin:
634 aResult = NS_ALERT_TOP;
635 break;
636 case eIntID_IMERawInputUnderlineStyle:
637 case eIntID_IMEConvertedTextUnderlineStyle:
638 aResult = NS_STYLE_TEXT_DECORATION_STYLE_SOLID;
639 break;
640 case eIntID_IMESelectedRawTextUnderlineStyle:
641 case eIntID_IMESelectedConvertedTextUnderline:
642 aResult = NS_STYLE_TEXT_DECORATION_STYLE_NONE;
643 break;
644 case eIntID_SpellCheckerUnderlineStyle:
645 aResult = NS_STYLE_TEXT_DECORATION_STYLE_WAVY;
646 break;
647 case eIntID_ImagesInMenus:
648 aResult = moz_gtk_images_in_menus();
649 break;
650 case eIntID_ImagesInButtons:
651 aResult = moz_gtk_images_in_buttons();
652 break;
653 case eIntID_MenuBarDrag:
654 aResult = sMenuSupportsDrag;
655 break;
656 case eIntID_ScrollbarButtonAutoRepeatBehavior:
657 aResult = 1;
658 break;
659 case eIntID_SwipeAnimationEnabled:
660 aResult = 0;
661 break;
662 case eIntID_ColorPickerAvailable:
663 aResult = 1;
664 break;
665 default:
666 aResult = 0;
667 res = NS_ERROR_FAILURE;
668 }
670 return res;
671 }
673 nsresult
674 nsLookAndFeel::GetFloatImpl(FloatID aID, float &aResult)
675 {
676 nsresult res = NS_OK;
677 res = nsXPLookAndFeel::GetFloatImpl(aID, aResult);
678 if (NS_SUCCEEDED(res))
679 return res;
680 res = NS_OK;
682 switch (aID) {
683 case eFloatID_IMEUnderlineRelativeSize:
684 aResult = 1.0f;
685 break;
686 case eFloatID_SpellCheckerUnderlineRelativeSize:
687 aResult = 1.0f;
688 break;
689 case eFloatID_CaretAspectRatio:
690 aResult = sCaretRatio;
691 break;
692 default:
693 aResult = -1.0;
694 res = NS_ERROR_FAILURE;
695 }
696 return res;
697 }
699 static void
700 GetSystemFontInfo(GtkWidget *aWidget,
701 nsString *aFontName,
702 gfxFontStyle *aFontStyle)
703 {
704 GtkSettings *settings = gtk_widget_get_settings(aWidget);
706 aFontStyle->style = NS_FONT_STYLE_NORMAL;
708 gchar *fontname;
709 g_object_get(settings, "gtk-font-name", &fontname, nullptr);
711 PangoFontDescription *desc;
712 desc = pango_font_description_from_string(fontname);
714 aFontStyle->systemFont = true;
716 g_free(fontname);
718 NS_NAMED_LITERAL_STRING(quote, "\"");
719 NS_ConvertUTF8toUTF16 family(pango_font_description_get_family(desc));
720 *aFontName = quote + family + quote;
722 aFontStyle->weight = pango_font_description_get_weight(desc);
724 // FIXME: Set aFontStyle->stretch correctly!
725 aFontStyle->stretch = NS_FONT_STRETCH_NORMAL;
727 float size = float(pango_font_description_get_size(desc)) / PANGO_SCALE;
729 // |size| is now either pixels or pango-points (not Mozilla-points!)
731 if (!pango_font_description_get_size_is_absolute(desc)) {
732 // |size| is in pango-points, so convert to pixels.
733 size *= float(gfxPlatformGtk::GetDPI()) / POINTS_PER_INCH_FLOAT;
734 }
736 // |size| is now pixels
738 aFontStyle->size = size;
740 pango_font_description_free(desc);
741 }
743 static void
744 GetSystemFontInfo(LookAndFeel::FontID aID,
745 nsString *aFontName,
746 gfxFontStyle *aFontStyle)
747 {
748 if (aID == LookAndFeel::eFont_Widget) {
749 GtkWidget *label = gtk_label_new("M");
750 GtkWidget *parent = gtk_fixed_new();
751 GtkWidget *window = gtk_window_new(GTK_WINDOW_POPUP);
753 gtk_container_add(GTK_CONTAINER(parent), label);
754 gtk_container_add(GTK_CONTAINER(window), parent);
756 gtk_widget_ensure_style(label);
757 GetSystemFontInfo(label, aFontName, aFontStyle);
758 gtk_widget_destroy(window); // no unref, windows are different
760 } else if (aID == LookAndFeel::eFont_Button) {
761 GtkWidget *label = gtk_label_new("M");
762 GtkWidget *parent = gtk_fixed_new();
763 GtkWidget *button = gtk_button_new();
764 GtkWidget *window = gtk_window_new(GTK_WINDOW_POPUP);
766 gtk_container_add(GTK_CONTAINER(button), label);
767 gtk_container_add(GTK_CONTAINER(parent), button);
768 gtk_container_add(GTK_CONTAINER(window), parent);
770 gtk_widget_ensure_style(label);
771 GetSystemFontInfo(label, aFontName, aFontStyle);
772 gtk_widget_destroy(window); // no unref, windows are different
774 } else if (aID == LookAndFeel::eFont_Field) {
775 GtkWidget *entry = gtk_entry_new();
776 GtkWidget *parent = gtk_fixed_new();
777 GtkWidget *window = gtk_window_new(GTK_WINDOW_POPUP);
779 gtk_container_add(GTK_CONTAINER(parent), entry);
780 gtk_container_add(GTK_CONTAINER(window), parent);
782 gtk_widget_ensure_style(entry);
783 GetSystemFontInfo(entry, aFontName, aFontStyle);
784 gtk_widget_destroy(window); // no unref, windows are different
786 } else {
787 NS_ABORT_IF_FALSE(aID == LookAndFeel::eFont_Menu, "unexpected font ID");
788 GtkWidget *accel_label = gtk_accel_label_new("M");
789 GtkWidget *menuitem = gtk_menu_item_new();
790 GtkWidget *menu = gtk_menu_new();
791 g_object_ref_sink(menu);
793 gtk_container_add(GTK_CONTAINER(menuitem), accel_label);
794 gtk_menu_shell_append((GtkMenuShell *)GTK_MENU(menu), menuitem);
796 gtk_widget_ensure_style(accel_label);
797 GetSystemFontInfo(accel_label, aFontName, aFontStyle);
798 g_object_unref(menu);
799 }
800 }
802 bool
803 nsLookAndFeel::GetFontImpl(FontID aID, nsString& aFontName,
804 gfxFontStyle& aFontStyle,
805 float aDevPixPerCSSPixel)
806 {
807 nsString *cachedFontName = nullptr;
808 gfxFontStyle *cachedFontStyle = nullptr;
809 bool *isCached = nullptr;
811 switch (aID) {
812 case eFont_Menu: // css2
813 case eFont_PullDownMenu: // css3
814 cachedFontName = &mMenuFontName;
815 cachedFontStyle = &mMenuFontStyle;
816 isCached = &mMenuFontCached;
817 aID = eFont_Menu;
818 break;
820 case eFont_Field: // css3
821 case eFont_List: // css3
822 cachedFontName = &mFieldFontName;
823 cachedFontStyle = &mFieldFontStyle;
824 isCached = &mFieldFontCached;
825 aID = eFont_Field;
826 break;
828 case eFont_Button: // css3
829 cachedFontName = &mButtonFontName;
830 cachedFontStyle = &mButtonFontStyle;
831 isCached = &mButtonFontCached;
832 break;
834 case eFont_Caption: // css2
835 case eFont_Icon: // css2
836 case eFont_MessageBox: // css2
837 case eFont_SmallCaption: // css2
838 case eFont_StatusBar: // css2
839 case eFont_Window: // css3
840 case eFont_Document: // css3
841 case eFont_Workspace: // css3
842 case eFont_Desktop: // css3
843 case eFont_Info: // css3
844 case eFont_Dialog: // css3
845 case eFont_Tooltips: // moz
846 case eFont_Widget: // moz
847 cachedFontName = &mDefaultFontName;
848 cachedFontStyle = &mDefaultFontStyle;
849 isCached = &mDefaultFontCached;
850 aID = eFont_Widget;
851 break;
852 }
854 if (!*isCached) {
855 GetSystemFontInfo(aID, cachedFontName, cachedFontStyle);
856 *isCached = true;
857 }
859 aFontName = *cachedFontName;
860 aFontStyle = *cachedFontStyle;
861 return true;
862 }
864 #if (MOZ_WIDGET_GTK == 3)
865 static GtkStyleContext*
866 create_context(GtkWidgetPath *path)
867 {
868 GtkStyleContext *style = gtk_style_context_new();
869 gtk_style_context_set_path(style, path);
870 return(style);
871 }
872 #endif
874 void
875 nsLookAndFeel::Init()
876 {
877 GdkColor colorValue;
878 GdkColor *colorValuePtr;
880 #if (MOZ_WIDGET_GTK == 2)
881 NS_ASSERTION(!mStyle, "already initialized");
882 // GtkInvisibles come with a refcount that is not floating
883 // (since their initialization code calls g_object_ref_sink) and
884 // their destroy code releases that reference (which means they
885 // have to be explicitly destroyed, since calling unref enough
886 // to cause destruction would lead to *another* unref).
887 // However, this combination means that it's actually still ok
888 // to use the normal pattern, which is to g_object_ref_sink
889 // after construction, and then destroy *and* unref when we're
890 // done. (Though we could skip the g_object_ref_sink and the
891 // corresponding g_object_unref, but that's particular to
892 // GtkInvisibles and GtkWindows.)
893 GtkWidget *widget = gtk_invisible_new();
894 g_object_ref_sink(widget); // effectively g_object_ref (see above)
896 gtk_widget_ensure_style(widget);
897 mStyle = gtk_style_copy(gtk_widget_get_style(widget));
899 gtk_widget_destroy(widget);
900 g_object_unref(widget);
902 // tooltip foreground and background
903 GtkStyle *style = gtk_rc_get_style_by_paths(gtk_settings_get_default(),
904 "gtk-tooltips", "GtkWindow",
905 GTK_TYPE_WINDOW);
906 if (style) {
907 sInfoBackground = GDK_COLOR_TO_NS_RGB(style->bg[GTK_STATE_NORMAL]);
908 sInfoText = GDK_COLOR_TO_NS_RGB(style->fg[GTK_STATE_NORMAL]);
909 }
911 // menu foreground & menu background
912 GtkWidget *accel_label = gtk_accel_label_new("M");
913 GtkWidget *menuitem = gtk_menu_item_new();
914 GtkWidget *menu = gtk_menu_new();
916 g_object_ref_sink(menu);
918 gtk_container_add(GTK_CONTAINER(menuitem), accel_label);
919 gtk_menu_shell_append(GTK_MENU_SHELL(menu), menuitem);
921 gtk_widget_set_style(accel_label, nullptr);
922 gtk_widget_set_style(menu, nullptr);
923 gtk_widget_realize(menu);
924 gtk_widget_realize(accel_label);
926 style = gtk_widget_get_style(accel_label);
927 if (style) {
928 sMenuText = GDK_COLOR_TO_NS_RGB(style->fg[GTK_STATE_NORMAL]);
929 }
931 style = gtk_widget_get_style(menu);
932 if (style) {
933 sMenuBackground = GDK_COLOR_TO_NS_RGB(style->bg[GTK_STATE_NORMAL]);
934 }
936 style = gtk_widget_get_style(menuitem);
937 if (style) {
938 sMenuHover = GDK_COLOR_TO_NS_RGB(style->bg[GTK_STATE_PRELIGHT]);
939 sMenuHoverText = GDK_COLOR_TO_NS_RGB(style->fg[GTK_STATE_PRELIGHT]);
940 }
942 g_object_unref(menu);
943 #else
944 GdkRGBA color;
945 GtkStyleContext *style;
947 // Gtk manages a screen's CSS in the settings object so we
948 // ask Gtk to create it explicitly. Otherwise we may end up
949 // with wrong color theme, see Bug 972382
950 (void)gtk_settings_get_for_screen(gdk_screen_get_default());
952 GtkWidgetPath *path = gtk_widget_path_new();
953 gtk_widget_path_append_type(path, GTK_TYPE_WINDOW);
955 mBackgroundStyle = create_context(path);
956 gtk_style_context_add_class(mBackgroundStyle, GTK_STYLE_CLASS_BACKGROUND);
958 mViewStyle = create_context(path);
959 gtk_style_context_add_class(mViewStyle, GTK_STYLE_CLASS_VIEW);
961 mButtonStyle = create_context(path);
962 gtk_style_context_add_class(mButtonStyle, GTK_STYLE_CLASS_BUTTON);
964 // Scrollbar colors
965 style = create_context(path);
966 gtk_style_context_add_class(style, GTK_STYLE_CLASS_SCROLLBAR);
967 gtk_style_context_add_class(style, GTK_STYLE_CLASS_TROUGH);
968 gtk_style_context_get_background_color(style, GTK_STATE_FLAG_NORMAL, &color);
969 sMozScrollbar = GDK_RGBA_TO_NS_RGBA(color);
970 g_object_unref(style);
972 // Text colors
973 gtk_style_context_get_background_color(mViewStyle, GTK_STATE_FLAG_NORMAL, &color);
974 sMozFieldBackground = GDK_RGBA_TO_NS_RGBA(color);
975 gtk_style_context_get_color(mViewStyle, GTK_STATE_FLAG_NORMAL, &color);
976 sMozFieldText = GDK_RGBA_TO_NS_RGBA(color);
978 // Window colors
979 style = create_context(path);
980 gtk_style_context_save(style);
981 gtk_style_context_add_class(style, GTK_STYLE_CLASS_BACKGROUND);
982 gtk_style_context_get_background_color(style, GTK_STATE_FLAG_NORMAL, &color);
983 sMozWindowBackground = GDK_RGBA_TO_NS_RGBA(color);
984 gtk_style_context_get_color(style, GTK_STATE_FLAG_NORMAL, &color);
985 sMozWindowText = GDK_RGBA_TO_NS_RGBA(color);
987 // Selected text and background
988 gtk_style_context_get_background_color(style, GTK_STATE_FLAG_SELECTED, &color);
989 sMozWindowSelectedBackground = GDK_RGBA_TO_NS_RGBA(color);
990 gtk_style_context_get_color(style, GTK_STATE_FLAG_SELECTED, &color);
991 sMozWindowSelectedText = GDK_RGBA_TO_NS_RGBA(color);
992 gtk_style_context_restore(style);
994 // tooltip foreground and background
995 gtk_style_context_add_class(style, GTK_STYLE_CLASS_TOOLTIP);
996 gtk_style_context_get_background_color(style, GTK_STATE_FLAG_NORMAL, &color);
997 sInfoBackground = GDK_RGBA_TO_NS_RGBA(color);
998 gtk_style_context_get_color(style, GTK_STATE_FLAG_NORMAL, &color);
999 sInfoText = GDK_RGBA_TO_NS_RGBA(color);
1000 g_object_unref(style);
1002 // menu foreground & menu background
1003 GtkWidget *accel_label = gtk_accel_label_new("M");
1004 GtkWidget *menuitem = gtk_menu_item_new();
1005 GtkWidget *menu = gtk_menu_new();
1007 g_object_ref_sink(menu);
1009 gtk_container_add(GTK_CONTAINER(menuitem), accel_label);
1010 gtk_menu_shell_append(GTK_MENU_SHELL(menu), menuitem);
1012 style = gtk_widget_get_style_context(accel_label);
1013 gtk_style_context_get_color(style, GTK_STATE_FLAG_NORMAL, &color);
1014 sMenuText = GDK_RGBA_TO_NS_RGBA(color);
1016 style = gtk_widget_get_style_context(menu);
1017 gtk_style_context_get_background_color(style, GTK_STATE_FLAG_NORMAL, &color);
1018 sMenuBackground = GDK_RGBA_TO_NS_RGBA(color);
1020 style = gtk_widget_get_style_context(menuitem);
1021 gtk_style_context_get_background_color(style, GTK_STATE_FLAG_PRELIGHT, &color);
1022 sMenuHover = GDK_RGBA_TO_NS_RGBA(color);
1023 gtk_style_context_get_color(style, GTK_STATE_FLAG_PRELIGHT, &color);
1024 sMenuHoverText = GDK_RGBA_TO_NS_RGBA(color);
1026 g_object_unref(menu);
1027 #endif
1029 // button styles
1030 GtkWidget *parent = gtk_fixed_new();
1031 GtkWidget *button = gtk_button_new();
1032 GtkWidget *label = gtk_label_new("M");
1033 #if (MOZ_WIDGET_GTK == 2)
1034 GtkWidget *combobox = gtk_combo_box_new();
1035 GtkWidget *comboboxLabel = gtk_label_new("M");
1036 gtk_container_add(GTK_CONTAINER(combobox), comboboxLabel);
1037 #else
1038 GtkWidget *combobox = gtk_combo_box_new_with_entry();
1039 GtkWidget *comboboxLabel = gtk_bin_get_child(GTK_BIN(combobox));
1040 #endif
1041 GtkWidget *window = gtk_window_new(GTK_WINDOW_POPUP);
1042 GtkWidget *treeView = gtk_tree_view_new();
1043 GtkWidget *linkButton = gtk_link_button_new("http://example.com/");
1044 GtkWidget *menuBar = gtk_menu_bar_new();
1045 GtkWidget *entry = gtk_entry_new();
1047 gtk_container_add(GTK_CONTAINER(button), label);
1048 gtk_container_add(GTK_CONTAINER(parent), button);
1049 gtk_container_add(GTK_CONTAINER(parent), treeView);
1050 gtk_container_add(GTK_CONTAINER(parent), linkButton);
1051 gtk_container_add(GTK_CONTAINER(parent), combobox);
1052 gtk_container_add(GTK_CONTAINER(parent), menuBar);
1053 gtk_container_add(GTK_CONTAINER(window), parent);
1054 gtk_container_add(GTK_CONTAINER(parent), entry);
1056 #if (MOZ_WIDGET_GTK == 2)
1057 gtk_widget_set_style(button, nullptr);
1058 gtk_widget_set_style(label, nullptr);
1059 gtk_widget_set_style(treeView, nullptr);
1060 gtk_widget_set_style(linkButton, nullptr);
1061 gtk_widget_set_style(combobox, nullptr);
1062 gtk_widget_set_style(comboboxLabel, nullptr);
1063 gtk_widget_set_style(menuBar, nullptr);
1064 gtk_widget_set_style(entry, nullptr);
1066 gtk_widget_realize(button);
1067 gtk_widget_realize(label);
1068 gtk_widget_realize(treeView);
1069 gtk_widget_realize(linkButton);
1070 gtk_widget_realize(combobox);
1071 gtk_widget_realize(comboboxLabel);
1072 gtk_widget_realize(menuBar);
1073 gtk_widget_realize(entry);
1075 style = gtk_widget_get_style(label);
1076 if (style) {
1077 sButtonText = GDK_COLOR_TO_NS_RGB(style->fg[GTK_STATE_NORMAL]);
1078 }
1080 style = gtk_widget_get_style(comboboxLabel);
1081 if (style) {
1082 sComboBoxText = GDK_COLOR_TO_NS_RGB(style->fg[GTK_STATE_NORMAL]);
1083 }
1084 style = gtk_widget_get_style(combobox);
1085 if (style) {
1086 sComboBoxBackground = GDK_COLOR_TO_NS_RGB(style->bg[GTK_STATE_NORMAL]);
1087 }
1089 style = gtk_widget_get_style(menuBar);
1090 if (style) {
1091 sMenuBarText = GDK_COLOR_TO_NS_RGB(style->fg[GTK_STATE_NORMAL]);
1092 sMenuBarHoverText = GDK_COLOR_TO_NS_RGB(style->fg[GTK_STATE_SELECTED]);
1093 }
1095 // GTK's guide to fancy odd row background colors:
1096 // 1) Check if a theme explicitly defines an odd row color
1097 // 2) If not, check if it defines an even row color, and darken it
1098 // slightly by a hardcoded value (gtkstyle.c)
1099 // 3) If neither are defined, take the base background color and
1100 // darken that by a hardcoded value
1101 colorValuePtr = nullptr;
1102 gtk_widget_style_get(treeView,
1103 "odd-row-color", &colorValuePtr,
1104 nullptr);
1106 if (colorValuePtr) {
1107 colorValue = *colorValuePtr;
1108 } else {
1109 gtk_widget_style_get(treeView,
1110 "even-row-color", &colorValuePtr,
1111 nullptr);
1112 if (colorValuePtr)
1113 darken_gdk_color(colorValuePtr, &colorValue);
1114 else
1115 darken_gdk_color(&treeView->style->base[GTK_STATE_NORMAL], &colorValue);
1116 }
1118 sOddCellBackground = GDK_COLOR_TO_NS_RGB(colorValue);
1119 if (colorValuePtr)
1120 gdk_color_free(colorValuePtr);
1122 style = gtk_widget_get_style(button);
1123 if (style) {
1124 sButtonBackground = GDK_COLOR_TO_NS_RGB(style->bg[GTK_STATE_NORMAL]);
1125 sButtonOuterLightBorder =
1126 GDK_COLOR_TO_NS_RGB(style->light[GTK_STATE_NORMAL]);
1127 sButtonInnerDarkBorder =
1128 GDK_COLOR_TO_NS_RGB(style->dark[GTK_STATE_NORMAL]);
1129 }
1130 #else
1131 // Button text, background, border
1132 style = gtk_widget_get_style_context(label);
1133 gtk_style_context_get_color(style, GTK_STATE_FLAG_NORMAL, &color);
1134 sButtonText = GDK_RGBA_TO_NS_RGBA(color);
1135 gtk_style_context_get_color(style, GTK_STATE_FLAG_PRELIGHT, &color);
1136 sButtonHoverText = GDK_RGBA_TO_NS_RGBA(color);
1138 // Combobox label and background colors
1139 style = gtk_widget_get_style_context(comboboxLabel);
1140 gtk_style_context_get_color(style, GTK_STATE_FLAG_NORMAL, &color);
1141 sComboBoxText = GDK_RGBA_TO_NS_RGBA(color);
1143 style = gtk_widget_get_style_context(combobox);
1144 gtk_style_context_get_background_color(style, GTK_STATE_FLAG_NORMAL, &color);
1145 sComboBoxBackground = GDK_RGBA_TO_NS_RGBA(color);
1147 // Menubar text and hover text colors
1148 style = gtk_widget_get_style_context(menuBar);
1149 gtk_style_context_get_color(style, GTK_STATE_FLAG_NORMAL, &color);
1150 sMenuBarText = GDK_RGBA_TO_NS_RGBA(color);
1151 gtk_style_context_get_color(style, GTK_STATE_FLAG_PRELIGHT, &color);
1152 sMenuBarHoverText = GDK_RGBA_TO_NS_RGBA(color);
1154 // GTK's guide to fancy odd row background colors:
1155 // 1) Check if a theme explicitly defines an odd row color
1156 // 2) If not, check if it defines an even row color, and darken it
1157 // slightly by a hardcoded value (gtkstyle.c)
1158 // 3) If neither are defined, take the base background color and
1159 // darken that by a hardcoded value
1160 style = gtk_widget_get_style_context(treeView);
1162 // Get odd row background color
1163 gtk_style_context_save(style);
1164 gtk_style_context_add_region(style, GTK_STYLE_REGION_ROW, GTK_REGION_ODD);
1165 gtk_style_context_get_background_color(style, GTK_STATE_FLAG_NORMAL, &color);
1166 sOddCellBackground = GDK_RGBA_TO_NS_RGBA(color);
1167 gtk_style_context_restore(style);
1169 style = gtk_widget_get_style_context(button);
1170 gtk_style_context_get_background_color(style, GTK_STATE_FLAG_NORMAL, &color);
1171 sButtonBackground = GDK_RGBA_TO_NS_RGBA(color);
1173 gtk_style_context_get_border_color(style, GTK_STATE_FLAG_PRELIGHT, &color);
1174 sButtonInnerDarkBorder = GDK_RGBA_TO_NS_RGBA(color);
1175 gtk_style_context_get_border_color(style, GTK_STATE_FLAG_NORMAL, &color);
1176 sButtonOuterLightBorder = GDK_RGBA_TO_NS_RGBA(color);
1177 #endif
1178 // Some themes have a unified menu bar, and support window dragging on it
1179 gboolean supports_menubar_drag = FALSE;
1180 GParamSpec *param_spec =
1181 gtk_widget_class_find_style_property(GTK_WIDGET_GET_CLASS(menuBar),
1182 "window-dragging");
1183 if (param_spec) {
1184 if (g_type_is_a(G_PARAM_SPEC_VALUE_TYPE(param_spec), G_TYPE_BOOLEAN)) {
1185 gtk_widget_style_get(menuBar,
1186 "window-dragging", &supports_menubar_drag,
1187 nullptr);
1188 }
1189 }
1190 sMenuSupportsDrag = supports_menubar_drag;
1192 colorValuePtr = nullptr;
1193 gtk_widget_style_get(linkButton, "link-color", &colorValuePtr, nullptr);
1194 if (colorValuePtr) {
1195 colorValue = *colorValuePtr; // we can't pass deref pointers to GDK_COLOR_TO_NS_RGB
1196 sNativeHyperLinkText = GDK_COLOR_TO_NS_RGB(colorValue);
1197 gdk_color_free(colorValuePtr);
1198 } else {
1199 sNativeHyperLinkText = NS_RGB(0x00,0x00,0xEE);
1200 }
1202 // invisible character styles
1203 guint value;
1204 g_object_get (entry, "invisible-char", &value, nullptr);
1205 sInvisibleCharacter = char16_t(value);
1207 // caret styles
1208 gtk_widget_style_get(entry,
1209 "cursor-aspect-ratio", &sCaretRatio,
1210 nullptr);
1212 gtk_widget_destroy(window);
1213 }
1215 // virtual
1216 char16_t
1217 nsLookAndFeel::GetPasswordCharacterImpl()
1218 {
1219 return sInvisibleCharacter;
1220 }
1222 void
1223 nsLookAndFeel::RefreshImpl()
1224 {
1225 nsXPLookAndFeel::RefreshImpl();
1227 mDefaultFontCached = false;
1228 mButtonFontCached = false;
1229 mFieldFontCached = false;
1230 mMenuFontCached = false;
1232 #if (MOZ_WIDGET_GTK == 2)
1233 g_object_unref(mStyle);
1234 mStyle = nullptr;
1235 #else
1236 g_object_unref(mBackgroundStyle);
1237 g_object_unref(mViewStyle);
1238 g_object_unref(mButtonStyle);
1240 mBackgroundStyle = nullptr;
1241 mViewStyle = nullptr;
1242 mButtonStyle = nullptr;
1243 #endif
1245 Init();
1246 }
1248 bool
1249 nsLookAndFeel::GetEchoPasswordImpl() {
1250 return false;
1251 }