forked from Floorp-Projects/Floorp
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathnsLookAndFeel.cpp
1292 lines (1149 loc) · 42.1 KB
/
nsLookAndFeel.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
/* vim:expandtab:shiftwidth=4:tabstop=4:
*/
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
// for strtod()
#include <stdlib.h>
#include "nsLookAndFeel.h"
#include <gtk/gtk.h>
#include <gdk/gdk.h>
#include <pango/pango.h>
#include <pango/pango-fontmap.h>
#include <fontconfig/fontconfig.h>
#include "gfxPlatformGtk.h"
#include "nsScreenGtk.h"
#include "gtkdrawing.h"
#include "nsStyleConsts.h"
#include "gfxFontConstants.h"
#include "WidgetUtilsGtk.h"
#include <dlfcn.h>
#include "mozilla/gfx/2D.h"
using mozilla::LookAndFeel;
#define GDK_COLOR_TO_NS_RGB(c) \
((nscolor) NS_RGB(c.red>>8, c.green>>8, c.blue>>8))
#define GDK_RGBA_TO_NS_RGBA(c) \
((nscolor) NS_RGBA((int)((c).red*255), (int)((c).green*255), \
(int)((c).blue*255), (int)((c).alpha*255)))
nsLookAndFeel::nsLookAndFeel()
: nsXPLookAndFeel(),
#if (MOZ_WIDGET_GTK == 2)
mStyle(nullptr),
#else
mBackgroundStyle(nullptr),
mButtonStyle(nullptr),
#endif
mDefaultFontCached(false), mButtonFontCached(false),
mFieldFontCached(false), mMenuFontCached(false)
{
Init();
}
nsLookAndFeel::~nsLookAndFeel()
{
#if (MOZ_WIDGET_GTK == 2)
g_object_unref(mStyle);
#else
g_object_unref(mBackgroundStyle);
g_object_unref(mButtonStyle);
#endif
}
nsresult
nsLookAndFeel::NativeGetColor(ColorID aID, nscolor& aColor)
{
#if (MOZ_WIDGET_GTK == 3)
GdkRGBA gdk_color;
#endif
nsresult res = NS_OK;
switch (aID) {
// These colors don't seem to be used for anything anymore in Mozilla
// (except here at least TextSelectBackground and TextSelectForeground)
// The CSS2 colors below are used.
#if (MOZ_WIDGET_GTK == 2)
case eColorID_WindowBackground:
aColor = GDK_COLOR_TO_NS_RGB(mStyle->base[GTK_STATE_NORMAL]);
break;
case eColorID_WindowForeground:
aColor = GDK_COLOR_TO_NS_RGB(mStyle->text[GTK_STATE_NORMAL]);
break;
case eColorID_WidgetBackground:
aColor = GDK_COLOR_TO_NS_RGB(mStyle->bg[GTK_STATE_NORMAL]);
break;
case eColorID_WidgetForeground:
aColor = GDK_COLOR_TO_NS_RGB(mStyle->fg[GTK_STATE_NORMAL]);
break;
case eColorID_WidgetSelectBackground:
aColor = GDK_COLOR_TO_NS_RGB(mStyle->bg[GTK_STATE_SELECTED]);
break;
case eColorID_WidgetSelectForeground:
aColor = GDK_COLOR_TO_NS_RGB(mStyle->fg[GTK_STATE_SELECTED]);
break;
#else
case eColorID_WindowBackground:
case eColorID_WidgetBackground:
case eColorID_TextBackground:
case eColorID_activecaption: // active window caption background
case eColorID_appworkspace: // MDI background color
case eColorID_background: // desktop background
case eColorID_window:
case eColorID_windowframe:
case eColorID__moz_dialog:
case eColorID__moz_combobox:
aColor = sMozWindowBackground;
break;
case eColorID_WindowForeground:
case eColorID_WidgetForeground:
case eColorID_TextForeground:
case eColorID_captiontext: // text in active window caption, size box, and scrollbar arrow box (!)
case eColorID_windowtext:
case eColorID__moz_dialogtext:
aColor = sMozWindowText;
break;
case eColorID_WidgetSelectBackground:
case eColorID_TextSelectBackground:
case eColorID_IMESelectedRawTextBackground:
case eColorID_IMESelectedConvertedTextBackground:
case eColorID__moz_dragtargetzone:
case eColorID__moz_cellhighlight:
case eColorID__moz_html_cellhighlight:
case eColorID_highlight: // preference selected item,
aColor = sTextSelectedBackground;
break;
case eColorID_WidgetSelectForeground:
case eColorID_TextSelectForeground:
case eColorID_IMESelectedRawTextForeground:
case eColorID_IMESelectedConvertedTextForeground:
case eColorID_highlighttext:
case eColorID__moz_cellhighlighttext:
case eColorID__moz_html_cellhighlighttext:
aColor = sTextSelectedText;
break;
#endif
case eColorID_Widget3DHighlight:
aColor = NS_RGB(0xa0,0xa0,0xa0);
break;
case eColorID_Widget3DShadow:
aColor = NS_RGB(0x40,0x40,0x40);
break;
#if (MOZ_WIDGET_GTK == 2)
case eColorID_TextBackground:
// not used?
aColor = GDK_COLOR_TO_NS_RGB(mStyle->base[GTK_STATE_NORMAL]);
break;
case eColorID_TextForeground:
// not used?
aColor = GDK_COLOR_TO_NS_RGB(mStyle->text[GTK_STATE_NORMAL]);
break;
case eColorID_TextSelectBackground:
case eColorID_IMESelectedRawTextBackground:
case eColorID_IMESelectedConvertedTextBackground:
// still used
aColor = GDK_COLOR_TO_NS_RGB(mStyle->base[GTK_STATE_SELECTED]);
break;
case eColorID_TextSelectForeground:
case eColorID_IMESelectedRawTextForeground:
case eColorID_IMESelectedConvertedTextForeground:
// still used
aColor = GDK_COLOR_TO_NS_RGB(mStyle->text[GTK_STATE_SELECTED]);
break;
#endif
case eColorID_IMERawInputBackground:
case eColorID_IMEConvertedTextBackground:
aColor = NS_TRANSPARENT;
break;
case eColorID_IMERawInputForeground:
case eColorID_IMEConvertedTextForeground:
aColor = NS_SAME_AS_FOREGROUND_COLOR;
break;
case eColorID_IMERawInputUnderline:
case eColorID_IMEConvertedTextUnderline:
aColor = NS_SAME_AS_FOREGROUND_COLOR;
break;
case eColorID_IMESelectedRawTextUnderline:
case eColorID_IMESelectedConvertedTextUnderline:
aColor = NS_TRANSPARENT;
break;
case eColorID_SpellCheckerUnderline:
aColor = NS_RGB(0xff, 0, 0);
break;
#if (MOZ_WIDGET_GTK == 2)
// css2 http://www.w3.org/TR/REC-CSS2/ui.html#system-colors
case eColorID_activeborder:
// active window border
aColor = GDK_COLOR_TO_NS_RGB(mStyle->bg[GTK_STATE_NORMAL]);
break;
case eColorID_activecaption:
// active window caption background
aColor = GDK_COLOR_TO_NS_RGB(mStyle->bg[GTK_STATE_NORMAL]);
break;
case eColorID_appworkspace:
// MDI background color
aColor = GDK_COLOR_TO_NS_RGB(mStyle->bg[GTK_STATE_NORMAL]);
break;
case eColorID_background:
// desktop background
aColor = GDK_COLOR_TO_NS_RGB(mStyle->bg[GTK_STATE_NORMAL]);
break;
case eColorID_captiontext:
// text in active window caption, size box, and scrollbar arrow box (!)
aColor = GDK_COLOR_TO_NS_RGB(mStyle->fg[GTK_STATE_NORMAL]);
break;
case eColorID_graytext:
// disabled text in windows, menus, etc.
aColor = GDK_COLOR_TO_NS_RGB(mStyle->fg[GTK_STATE_INSENSITIVE]);
break;
case eColorID_highlight:
// background of selected item
aColor = GDK_COLOR_TO_NS_RGB(mStyle->base[GTK_STATE_SELECTED]);
break;
case eColorID_highlighttext:
// text of selected item
aColor = GDK_COLOR_TO_NS_RGB(mStyle->text[GTK_STATE_SELECTED]);
break;
case eColorID_inactiveborder:
// inactive window border
aColor = GDK_COLOR_TO_NS_RGB(mStyle->bg[GTK_STATE_NORMAL]);
break;
case eColorID_inactivecaption:
// inactive window caption
aColor = GDK_COLOR_TO_NS_RGB(mStyle->bg[GTK_STATE_INSENSITIVE]);
break;
case eColorID_inactivecaptiontext:
// text in inactive window caption
aColor = GDK_COLOR_TO_NS_RGB(mStyle->fg[GTK_STATE_INSENSITIVE]);
break;
#else
// css2 http://www.w3.org/TR/REC-CSS2/ui.html#system-colors
case eColorID_activeborder:
// active window border
gtk_style_context_get_border_color(mBackgroundStyle,
GTK_STATE_FLAG_NORMAL, &gdk_color);
aColor = GDK_RGBA_TO_NS_RGBA(gdk_color);
break;
case eColorID_inactiveborder:
// inactive window border
gtk_style_context_get_border_color(mBackgroundStyle,
GTK_STATE_FLAG_INSENSITIVE,
&gdk_color);
aColor = GDK_RGBA_TO_NS_RGBA(gdk_color);
break;
case eColorID_graytext: // disabled text in windows, menus, etc.
case eColorID_inactivecaptiontext: // text in inactive window caption
aColor = sMenuTextInactive;
break;
case eColorID_inactivecaption:
// inactive window caption
gtk_style_context_get_background_color(mBackgroundStyle,
GTK_STATE_FLAG_INSENSITIVE,
&gdk_color);
aColor = GDK_RGBA_TO_NS_RGBA(gdk_color);
break;
#endif
case eColorID_infobackground:
// tooltip background color
aColor = sInfoBackground;
break;
case eColorID_infotext:
// tooltip text color
aColor = sInfoText;
break;
case eColorID_menu:
// menu background
aColor = sMenuBackground;
break;
case eColorID_menutext:
// menu text
aColor = sMenuText;
break;
case eColorID_scrollbar:
// scrollbar gray area
#if (MOZ_WIDGET_GTK == 2)
aColor = GDK_COLOR_TO_NS_RGB(mStyle->bg[GTK_STATE_ACTIVE]);
#else
aColor = sMozScrollbar;
#endif
break;
case eColorID_threedlightshadow:
// 3-D highlighted inner edge color
// always same as background in GTK code
case eColorID_threedface:
case eColorID_buttonface:
// 3-D face color
#if (MOZ_WIDGET_GTK == 3)
aColor = sMozWindowBackground;
#else
aColor = sButtonBackground;
#endif
break;
case eColorID_buttontext:
// text on push buttons
aColor = sButtonText;
break;
case eColorID_buttonhighlight:
// 3-D highlighted edge color
case eColorID_threedhighlight:
// 3-D highlighted outer edge color
aColor = sFrameOuterLightBorder;
break;
case eColorID_buttonshadow:
// 3-D shadow edge color
case eColorID_threedshadow:
// 3-D shadow inner edge color
aColor = sFrameInnerDarkBorder;
break;
#if (MOZ_WIDGET_GTK == 2)
case eColorID_threeddarkshadow:
// 3-D shadow outer edge color
aColor = GDK_COLOR_TO_NS_RGB(mStyle->black);
break;
case eColorID_window:
case eColorID_windowframe:
aColor = GDK_COLOR_TO_NS_RGB(mStyle->bg[GTK_STATE_NORMAL]);
break;
case eColorID_windowtext:
aColor = GDK_COLOR_TO_NS_RGB(mStyle->fg[GTK_STATE_NORMAL]);
break;
case eColorID__moz_eventreerow:
case eColorID__moz_field:
aColor = GDK_COLOR_TO_NS_RGB(mStyle->base[GTK_STATE_NORMAL]);
break;
case eColorID__moz_fieldtext:
aColor = GDK_COLOR_TO_NS_RGB(mStyle->text[GTK_STATE_NORMAL]);
break;
case eColorID__moz_dialog:
aColor = GDK_COLOR_TO_NS_RGB(mStyle->bg[GTK_STATE_NORMAL]);
break;
case eColorID__moz_dialogtext:
aColor = GDK_COLOR_TO_NS_RGB(mStyle->fg[GTK_STATE_NORMAL]);
break;
case eColorID__moz_dragtargetzone:
aColor = GDK_COLOR_TO_NS_RGB(mStyle->bg[GTK_STATE_SELECTED]);
break;
case eColorID__moz_buttondefault:
// default button border color
aColor = GDK_COLOR_TO_NS_RGB(mStyle->black);
break;
case eColorID__moz_buttonhoverface:
aColor = GDK_COLOR_TO_NS_RGB(mStyle->bg[GTK_STATE_PRELIGHT]);
break;
case eColorID__moz_buttonhovertext:
aColor = GDK_COLOR_TO_NS_RGB(mStyle->fg[GTK_STATE_PRELIGHT]);
break;
case eColorID__moz_cellhighlight:
case eColorID__moz_html_cellhighlight:
aColor = GDK_COLOR_TO_NS_RGB(mStyle->base[GTK_STATE_ACTIVE]);
break;
case eColorID__moz_cellhighlighttext:
case eColorID__moz_html_cellhighlighttext:
aColor = GDK_COLOR_TO_NS_RGB(mStyle->text[GTK_STATE_ACTIVE]);
break;
#else
case eColorID_threeddarkshadow:
// Hardcode to black
aColor = NS_RGB(0x00,0x00,0x00);;
break;
case eColorID__moz_eventreerow:
case eColorID__moz_field:
aColor = sMozFieldBackground;
break;
case eColorID__moz_fieldtext:
aColor = sMozFieldText;
break;
case eColorID__moz_buttondefault:
// default button border color
gtk_style_context_get_border_color(mButtonStyle,
GTK_STATE_FLAG_NORMAL, &gdk_color);
aColor = GDK_RGBA_TO_NS_RGBA(gdk_color);
break;
case eColorID__moz_buttonhoverface:
gtk_style_context_get_background_color(mButtonStyle,
GTK_STATE_FLAG_PRELIGHT,
&gdk_color);
aColor = GDK_RGBA_TO_NS_RGBA(gdk_color);
break;
case eColorID__moz_buttonhovertext:
aColor = sButtonHoverText;
break;
#endif
case eColorID__moz_menuhover:
aColor = sMenuHover;
break;
case eColorID__moz_menuhovertext:
aColor = sMenuHoverText;
break;
case eColorID__moz_oddtreerow:
aColor = sOddCellBackground;
break;
case eColorID__moz_nativehyperlinktext:
aColor = sNativeHyperLinkText;
break;
case eColorID__moz_comboboxtext:
aColor = sComboBoxText;
break;
#if (MOZ_WIDGET_GTK == 2)
case eColorID__moz_combobox:
aColor = sComboBoxBackground;
break;
#endif
case eColorID__moz_menubartext:
aColor = sMenuBarText;
break;
case eColorID__moz_menubarhovertext:
aColor = sMenuBarHoverText;
break;
case eColorID__moz_gtk_info_bar_text:
#if (MOZ_WIDGET_GTK == 3)
aColor = sInfoBarText;
#else
aColor = sInfoText;
#endif
break;
default:
/* default color is BLACK */
aColor = 0;
res = NS_ERROR_FAILURE;
break;
}
return res;
}
#if (MOZ_WIDGET_GTK == 2)
static void darken_gdk_color(GdkColor *src, GdkColor *dest)
{
gdouble red;
gdouble green;
gdouble blue;
red = (gdouble) src->red / 65535.0;
green = (gdouble) src->green / 65535.0;
blue = (gdouble) src->blue / 65535.0;
red *= 0.93;
green *= 0.93;
blue *= 0.93;
dest->red = red * 65535.0;
dest->green = green * 65535.0;
dest->blue = blue * 65535.0;
}
#endif
static int32_t CheckWidgetStyle(GtkWidget* aWidget, const char* aStyle, int32_t aResult) {
gboolean value = FALSE;
gtk_widget_style_get(aWidget, aStyle, &value, nullptr);
return value ? aResult : 0;
}
static int32_t ConvertGTKStepperStyleToMozillaScrollArrowStyle(GtkWidget* aWidget)
{
if (!aWidget)
return mozilla::LookAndFeel::eScrollArrowStyle_Single;
return
CheckWidgetStyle(aWidget, "has-backward-stepper",
mozilla::LookAndFeel::eScrollArrow_StartBackward) |
CheckWidgetStyle(aWidget, "has-forward-stepper",
mozilla::LookAndFeel::eScrollArrow_EndForward) |
CheckWidgetStyle(aWidget, "has-secondary-backward-stepper",
mozilla::LookAndFeel::eScrollArrow_EndBackward) |
CheckWidgetStyle(aWidget, "has-secondary-forward-stepper",
mozilla::LookAndFeel::eScrollArrow_StartForward);
}
nsresult
nsLookAndFeel::GetIntImpl(IntID aID, int32_t &aResult)
{
nsresult res = NS_OK;
// Set these before they can get overrided in the nsXPLookAndFeel.
switch (aID) {
case eIntID_ScrollButtonLeftMouseButtonAction:
aResult = 0;
return NS_OK;
case eIntID_ScrollButtonMiddleMouseButtonAction:
aResult = 1;
return NS_OK;
case eIntID_ScrollButtonRightMouseButtonAction:
aResult = 2;
return NS_OK;
default:
break;
}
res = nsXPLookAndFeel::GetIntImpl(aID, aResult);
if (NS_SUCCEEDED(res))
return res;
res = NS_OK;
switch (aID) {
case eIntID_CaretBlinkTime:
{
GtkSettings *settings;
gint blink_time;
gboolean blink;
settings = gtk_settings_get_default ();
g_object_get (settings,
"gtk-cursor-blink-time", &blink_time,
"gtk-cursor-blink", &blink,
nullptr);
if (blink)
aResult = (int32_t) blink_time;
else
aResult = 0;
break;
}
case eIntID_CaretWidth:
aResult = 1;
break;
case eIntID_ShowCaretDuringSelection:
aResult = 0;
break;
case eIntID_SelectTextfieldsOnKeyFocus:
{
GtkWidget *entry;
GtkSettings *settings;
gboolean select_on_focus;
entry = gtk_entry_new();
g_object_ref_sink(entry);
settings = gtk_widget_get_settings(entry);
g_object_get(settings,
"gtk-entry-select-on-focus",
&select_on_focus,
nullptr);
if(select_on_focus)
aResult = 1;
else
aResult = 0;
gtk_widget_destroy(entry);
g_object_unref(entry);
}
break;
case eIntID_ScrollToClick:
{
GtkSettings *settings;
gboolean warps_slider = FALSE;
settings = gtk_settings_get_default ();
if (g_object_class_find_property (G_OBJECT_GET_CLASS(settings),
"gtk-primary-button-warps-slider")) {
g_object_get (settings,
"gtk-primary-button-warps-slider",
&warps_slider,
nullptr);
}
if (warps_slider)
aResult = 1;
else
aResult = 0;
}
break;
case eIntID_SubmenuDelay:
{
GtkSettings *settings;
gint delay;
settings = gtk_settings_get_default ();
g_object_get (settings, "gtk-menu-popup-delay", &delay, nullptr);
aResult = (int32_t) delay;
break;
}
case eIntID_TooltipDelay:
{
aResult = 500;
break;
}
case eIntID_MenusCanOverlapOSBar:
// we want XUL popups to be able to overlap the task bar.
aResult = 1;
break;
case eIntID_SkipNavigatingDisabledMenuItem:
aResult = 1;
break;
case eIntID_DragThresholdX:
case eIntID_DragThresholdY:
{
GtkWidget* box = gtk_hbox_new(FALSE, 5);
gint threshold = 0;
g_object_get(gtk_widget_get_settings(box),
"gtk-dnd-drag-threshold", &threshold,
nullptr);
g_object_ref_sink(box);
aResult = threshold;
}
break;
case eIntID_ScrollArrowStyle:
moz_gtk_init();
aResult =
ConvertGTKStepperStyleToMozillaScrollArrowStyle(moz_gtk_get_scrollbar_widget());
break;
case eIntID_ScrollSliderStyle:
aResult = eScrollThumbStyle_Proportional;
break;
case eIntID_TreeOpenDelay:
aResult = 1000;
break;
case eIntID_TreeCloseDelay:
aResult = 1000;
break;
case eIntID_TreeLazyScrollDelay:
aResult = 150;
break;
case eIntID_TreeScrollDelay:
aResult = 100;
break;
case eIntID_TreeScrollLinesMax:
aResult = 3;
break;
case eIntID_DWMCompositor:
case eIntID_WindowsClassic:
case eIntID_WindowsDefaultTheme:
case eIntID_WindowsThemeIdentifier:
case eIntID_OperatingSystemVersionIdentifier:
aResult = 0;
res = NS_ERROR_NOT_IMPLEMENTED;
break;
case eIntID_TouchEnabled:
#if MOZ_WIDGET_GTK == 3
aResult = mozilla::widget::WidgetUtilsGTK::IsTouchDeviceSupportPresent();
break;
#else
aResult = 0;
res = NS_ERROR_NOT_IMPLEMENTED;
#endif
break;
case eIntID_MacGraphiteTheme:
case eIntID_MacLionTheme:
aResult = 0;
res = NS_ERROR_NOT_IMPLEMENTED;
break;
case eIntID_AlertNotificationOrigin:
aResult = NS_ALERT_TOP;
break;
case eIntID_IMERawInputUnderlineStyle:
case eIntID_IMEConvertedTextUnderlineStyle:
aResult = NS_STYLE_TEXT_DECORATION_STYLE_SOLID;
break;
case eIntID_IMESelectedRawTextUnderlineStyle:
case eIntID_IMESelectedConvertedTextUnderline:
aResult = NS_STYLE_TEXT_DECORATION_STYLE_NONE;
break;
case eIntID_SpellCheckerUnderlineStyle:
aResult = NS_STYLE_TEXT_DECORATION_STYLE_WAVY;
break;
case eIntID_ImagesInMenus:
aResult = moz_gtk_images_in_menus();
break;
case eIntID_ImagesInButtons:
aResult = moz_gtk_images_in_buttons();
break;
case eIntID_MenuBarDrag:
aResult = sMenuSupportsDrag;
break;
case eIntID_ScrollbarButtonAutoRepeatBehavior:
aResult = 1;
break;
case eIntID_SwipeAnimationEnabled:
aResult = 0;
break;
case eIntID_ColorPickerAvailable:
aResult = 1;
break;
case eIntID_ContextMenuOffsetVertical:
case eIntID_ContextMenuOffsetHorizontal:
aResult = 2;
break;
default:
aResult = 0;
res = NS_ERROR_FAILURE;
}
return res;
}
nsresult
nsLookAndFeel::GetFloatImpl(FloatID aID, float &aResult)
{
nsresult res = NS_OK;
res = nsXPLookAndFeel::GetFloatImpl(aID, aResult);
if (NS_SUCCEEDED(res))
return res;
res = NS_OK;
switch (aID) {
case eFloatID_IMEUnderlineRelativeSize:
aResult = 1.0f;
break;
case eFloatID_SpellCheckerUnderlineRelativeSize:
aResult = 1.0f;
break;
case eFloatID_CaretAspectRatio:
aResult = sCaretRatio;
break;
default:
aResult = -1.0;
res = NS_ERROR_FAILURE;
}
return res;
}
static void
GetSystemFontInfo(GtkWidget *aWidget,
nsString *aFontName,
gfxFontStyle *aFontStyle)
{
GtkSettings *settings = gtk_widget_get_settings(aWidget);
aFontStyle->style = NS_FONT_STYLE_NORMAL;
gchar *fontname;
g_object_get(settings, "gtk-font-name", &fontname, nullptr);
PangoFontDescription *desc;
desc = pango_font_description_from_string(fontname);
aFontStyle->systemFont = true;
g_free(fontname);
NS_NAMED_LITERAL_STRING(quote, "\"");
NS_ConvertUTF8toUTF16 family(pango_font_description_get_family(desc));
*aFontName = quote + family + quote;
aFontStyle->weight = pango_font_description_get_weight(desc);
// FIXME: Set aFontStyle->stretch correctly!
aFontStyle->stretch = NS_FONT_STRETCH_NORMAL;
float size = float(pango_font_description_get_size(desc)) / PANGO_SCALE;
// |size| is now either pixels or pango-points (not Mozilla-points!)
if (!pango_font_description_get_size_is_absolute(desc)) {
// |size| is in pango-points, so convert to pixels.
size *= float(gfxPlatformGtk::GetDPI()) / POINTS_PER_INCH_FLOAT;
}
// Scale fonts up on HiDPI displays.
// This would be done automatically with cairo, but we manually manage
// the display scale for platform consistency.
size *= nsScreenGtk::GetGtkMonitorScaleFactor();
// |size| is now pixels
aFontStyle->size = size;
pango_font_description_free(desc);
}
static void
GetSystemFontInfo(LookAndFeel::FontID aID,
nsString *aFontName,
gfxFontStyle *aFontStyle)
{
if (aID == LookAndFeel::eFont_Widget) {
GtkWidget *label = gtk_label_new("M");
GtkWidget *parent = gtk_fixed_new();
GtkWidget *window = gtk_window_new(GTK_WINDOW_POPUP);
gtk_container_add(GTK_CONTAINER(parent), label);
gtk_container_add(GTK_CONTAINER(window), parent);
gtk_widget_ensure_style(label);
GetSystemFontInfo(label, aFontName, aFontStyle);
gtk_widget_destroy(window); // no unref, windows are different
} else if (aID == LookAndFeel::eFont_Button) {
GtkWidget *label = gtk_label_new("M");
GtkWidget *parent = gtk_fixed_new();
GtkWidget *button = gtk_button_new();
GtkWidget *window = gtk_window_new(GTK_WINDOW_POPUP);
gtk_container_add(GTK_CONTAINER(button), label);
gtk_container_add(GTK_CONTAINER(parent), button);
gtk_container_add(GTK_CONTAINER(window), parent);
gtk_widget_ensure_style(label);
GetSystemFontInfo(label, aFontName, aFontStyle);
gtk_widget_destroy(window); // no unref, windows are different
} else if (aID == LookAndFeel::eFont_Field) {
GtkWidget *entry = gtk_entry_new();
GtkWidget *parent = gtk_fixed_new();
GtkWidget *window = gtk_window_new(GTK_WINDOW_POPUP);
gtk_container_add(GTK_CONTAINER(parent), entry);
gtk_container_add(GTK_CONTAINER(window), parent);
gtk_widget_ensure_style(entry);
GetSystemFontInfo(entry, aFontName, aFontStyle);
gtk_widget_destroy(window); // no unref, windows are different
} else {
MOZ_ASSERT(aID == LookAndFeel::eFont_Menu, "unexpected font ID");
GtkWidget *accel_label = gtk_accel_label_new("M");
GtkWidget *menuitem = gtk_menu_item_new();
GtkWidget *menu = gtk_menu_new();
g_object_ref_sink(menu);
gtk_container_add(GTK_CONTAINER(menuitem), accel_label);
gtk_menu_shell_append((GtkMenuShell *)GTK_MENU(menu), menuitem);
gtk_widget_ensure_style(accel_label);
GetSystemFontInfo(accel_label, aFontName, aFontStyle);
g_object_unref(menu);
}
}
bool
nsLookAndFeel::GetFontImpl(FontID aID, nsString& aFontName,
gfxFontStyle& aFontStyle,
float aDevPixPerCSSPixel)
{
nsString *cachedFontName = nullptr;
gfxFontStyle *cachedFontStyle = nullptr;
bool *isCached = nullptr;
switch (aID) {
case eFont_Menu: // css2
case eFont_PullDownMenu: // css3
cachedFontName = &mMenuFontName;
cachedFontStyle = &mMenuFontStyle;
isCached = &mMenuFontCached;
aID = eFont_Menu;
break;
case eFont_Field: // css3
case eFont_List: // css3
cachedFontName = &mFieldFontName;
cachedFontStyle = &mFieldFontStyle;
isCached = &mFieldFontCached;
aID = eFont_Field;
break;
case eFont_Button: // css3
cachedFontName = &mButtonFontName;
cachedFontStyle = &mButtonFontStyle;
isCached = &mButtonFontCached;
break;
case eFont_Caption: // css2
case eFont_Icon: // css2
case eFont_MessageBox: // css2
case eFont_SmallCaption: // css2
case eFont_StatusBar: // css2
case eFont_Window: // css3
case eFont_Document: // css3
case eFont_Workspace: // css3
case eFont_Desktop: // css3
case eFont_Info: // css3
case eFont_Dialog: // css3
case eFont_Tooltips: // moz
case eFont_Widget: // moz
cachedFontName = &mDefaultFontName;
cachedFontStyle = &mDefaultFontStyle;
isCached = &mDefaultFontCached;
aID = eFont_Widget;
break;
}
if (!*isCached) {
GetSystemFontInfo(aID, cachedFontName, cachedFontStyle);
*isCached = true;
}
aFontName = *cachedFontName;
aFontStyle = *cachedFontStyle;
return true;
}
#if (MOZ_WIDGET_GTK == 3)
static GtkStyleContext*
create_context(GtkWidgetPath *path)
{
GtkStyleContext *style = gtk_style_context_new();
gtk_style_context_set_path(style, path);
return(style);
}
#endif
void
nsLookAndFeel::Init()
{
GdkColor colorValue;
GdkColor *colorValuePtr;
#if (MOZ_WIDGET_GTK == 2)
NS_ASSERTION(!mStyle, "already initialized");
// GtkInvisibles come with a refcount that is not floating
// (since their initialization code calls g_object_ref_sink) and
// their destroy code releases that reference (which means they
// have to be explicitly destroyed, since calling unref enough
// to cause destruction would lead to *another* unref).
// However, this combination means that it's actually still ok
// to use the normal pattern, which is to g_object_ref_sink
// after construction, and then destroy *and* unref when we're
// done. (Though we could skip the g_object_ref_sink and the
// corresponding g_object_unref, but that's particular to
// GtkInvisibles and GtkWindows.)
GtkWidget *widget = gtk_invisible_new();
g_object_ref_sink(widget); // effectively g_object_ref (see above)
gtk_widget_ensure_style(widget);
mStyle = gtk_style_copy(gtk_widget_get_style(widget));
gtk_widget_destroy(widget);
g_object_unref(widget);
// tooltip foreground and background
GtkStyle *style = gtk_rc_get_style_by_paths(gtk_settings_get_default(),
"gtk-tooltips", "GtkWindow",
GTK_TYPE_WINDOW);
if (style) {
sInfoBackground = GDK_COLOR_TO_NS_RGB(style->bg[GTK_STATE_NORMAL]);
sInfoText = GDK_COLOR_TO_NS_RGB(style->fg[GTK_STATE_NORMAL]);
}
// menu foreground & menu background
GtkWidget *accel_label = gtk_accel_label_new("M");
GtkWidget *menuitem = gtk_menu_item_new();
GtkWidget *menu = gtk_menu_new();
g_object_ref_sink(menu);
gtk_container_add(GTK_CONTAINER(menuitem), accel_label);
gtk_menu_shell_append(GTK_MENU_SHELL(menu), menuitem);
gtk_widget_set_style(accel_label, nullptr);
gtk_widget_set_style(menu, nullptr);
gtk_widget_realize(menu);
gtk_widget_realize(accel_label);
style = gtk_widget_get_style(accel_label);
if (style) {
sMenuText = GDK_COLOR_TO_NS_RGB(style->fg[GTK_STATE_NORMAL]);
}
style = gtk_widget_get_style(menu);
if (style) {
sMenuBackground = GDK_COLOR_TO_NS_RGB(style->bg[GTK_STATE_NORMAL]);
}
style = gtk_widget_get_style(menuitem);
if (style) {
sMenuHover = GDK_COLOR_TO_NS_RGB(style->bg[GTK_STATE_PRELIGHT]);
sMenuHoverText = GDK_COLOR_TO_NS_RGB(style->fg[GTK_STATE_PRELIGHT]);
}
g_object_unref(menu);
#else
GdkRGBA color;
GtkStyleContext *style;
// Gtk manages a screen's CSS in the settings object so we
// ask Gtk to create it explicitly. Otherwise we may end up
// with wrong color theme, see Bug 972382
(void)gtk_settings_get_for_screen(gdk_screen_get_default());
GtkWidgetPath *path = gtk_widget_path_new();
gtk_widget_path_append_type(path, GTK_TYPE_WINDOW);
mBackgroundStyle = create_context(path);
gtk_style_context_add_class(mBackgroundStyle, GTK_STYLE_CLASS_BACKGROUND);
mButtonStyle = create_context(path);
gtk_style_context_add_class(mButtonStyle, GTK_STYLE_CLASS_BUTTON);
// Scrollbar colors
style = create_context(path);
gtk_style_context_add_class(style, GTK_STYLE_CLASS_SCROLLBAR);
gtk_style_context_add_class(style, GTK_STYLE_CLASS_TROUGH);
gtk_style_context_get_background_color(style, GTK_STATE_FLAG_NORMAL, &color);
sMozScrollbar = GDK_RGBA_TO_NS_RGBA(color);
g_object_unref(style);
// Text colors
style = create_context(path);
gtk_style_context_add_class(style, GTK_STYLE_CLASS_VIEW);
gtk_style_context_get_background_color(style, GTK_STATE_FLAG_NORMAL, &color);
sMozFieldBackground = GDK_RGBA_TO_NS_RGBA(color);