summaryrefslogtreecommitdiff
path: root/mozilla-1158076.patch
blob: 8a90be5c5971123eca968aaa1f35e71b026a1c69 (plain)
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
diff -up firefox-52.0/modules/libpref/init/all.js.1158076 firefox-52.0/modules/libpref/init/all.js
--- firefox-52.0/modules/libpref/init/all.js.1158076	2017-03-22 10:05:22.318067553 +0100
+++ firefox-52.0/modules/libpref/init/all.js	2017-03-22 10:07:15.360555913 +0100
@@ -4646,6 +4646,7 @@ pref("gfx.apitrace.enabled",false);
 pref("gfx.content.use-native-pushlayer", true);
 #ifdef MOZ_WIDGET_GTK
 pref("gfx.xrender.enabled",false);
+pref("widget.allow-gtk-dark-theme", false);
 #endif
 #endif
 
diff -up firefox-52.0/widget/gtk/mozgtk/mozgtk.c.1158076 firefox-52.0/widget/gtk/mozgtk/mozgtk.c
--- firefox-52.0/widget/gtk/mozgtk/mozgtk.c.1158076	2017-03-22 10:05:22.313067576 +0100
+++ firefox-52.0/widget/gtk/mozgtk/mozgtk.c	2017-03-22 10:08:34.122199432 +0100
@@ -522,6 +522,7 @@ STUB(gdk_x11_display_get_type)
 STUB(gtk_box_new)
 STUB(gtk_cairo_should_draw_window)
 STUB(gtk_cairo_transform_to_window)
+STUB(gtk_css_provider_get_named)
 STUB(gtk_combo_box_text_append)
 STUB(gtk_drag_set_icon_surface)
 STUB(gtk_get_major_version)
@@ -548,6 +549,7 @@ STUB(gtk_scale_new)
 STUB(gtk_scrollbar_new)
 STUB(gtk_style_context_add_class)
 STUB(gtk_style_context_add_region)
+STUB(gtk_style_context_add_provider_for_screen)
 STUB(gtk_style_context_get)
 STUB(gtk_style_context_get_background_color)
 STUB(gtk_style_context_get_border)
@@ -573,6 +575,7 @@ STUB(gtk_style_context_set_path)
 STUB(gtk_style_context_set_parent)
 STUB(gtk_style_context_set_state)
 STUB(gtk_style_properties_lookup_property)
+STUB(gtk_style_provider_get_type)
 STUB(gtk_tree_view_column_get_button)
 STUB(gtk_widget_get_preferred_size)
 STUB(gtk_widget_get_state_flags)
diff -up firefox-52.0/widget/gtk/nsLookAndFeel.cpp.1158076 firefox-52.0/widget/gtk/nsLookAndFeel.cpp
--- firefox-52.0/widget/gtk/nsLookAndFeel.cpp.1158076	2017-03-22 10:05:22.314067571 +0100
+++ firefox-52.0/widget/gtk/nsLookAndFeel.cpp	2017-03-22 10:07:56.914367838 +0100
@@ -50,9 +50,9 @@ nsLookAndFeel::nsLookAndFeel()
       mStyle(nullptr),
 #endif
       mDefaultFontCached(false), mButtonFontCached(false),
-      mFieldFontCached(false), mMenuFontCached(false)
+      mFieldFontCached(false), mMenuFontCached(false),
+      mInitialized(false)
 {
-    Init();    
 }
 
 nsLookAndFeel::~nsLookAndFeel()
@@ -224,6 +224,8 @@ GetBorderColors(GtkStyleContext* aContex
 nsresult
 nsLookAndFeel::NativeGetColor(ColorID aID, nscolor& aColor)
 {
+    EnsureInit();
+
 #if (MOZ_WIDGET_GTK == 3)
     GdkRGBA gdk_color;
 #endif
@@ -675,6 +677,8 @@ nsLookAndFeel::GetIntImpl(IntID aID, int
         return res;
     res = NS_OK;
 
+    // We use delayed initialization by EnsureInit() here
+    // to ensure mozilla::Preferences is available (see Bug 1158076).
     switch (aID) {
     case eIntID_CaretBlinkTime:
         {
@@ -837,6 +841,7 @@ nsLookAndFeel::GetIntImpl(IntID aID, int
         aResult = NS_STYLE_TEXT_DECORATION_STYLE_WAVY;
         break;
     case eIntID_MenuBarDrag:
+        EnsureInit();
         aResult = sMenuSupportsDrag;
         break;
     case eIntID_ScrollbarButtonAutoRepeatBehavior:
@@ -877,6 +882,7 @@ nsLookAndFeel::GetFloatImpl(FloatID aID,
         aResult = 1.0f;
         break;
     case eFloatID_CaretAspectRatio:
+        EnsureInit();
         aResult = sCaretRatio;
         break;
     default:
@@ -1057,11 +1063,15 @@ nsLookAndFeel::GetFontImpl(FontID aID, n
 }
 
 void
-nsLookAndFeel::Init()
+nsLookAndFeel::EnsureInit()
 {
     GdkColor colorValue;
     GdkColor *colorValuePtr;
 
+    if (mInitialized)
+        return;
+    mInitialized = true;
+
 #if (MOZ_WIDGET_GTK == 2)
     NS_ASSERTION(!mStyle, "already initialized");
     // GtkInvisibles come with a refcount that is not floating
@@ -1133,17 +1143,40 @@ nsLookAndFeel::Init()
     // ask Gtk to create it explicitly. Otherwise we may end up
     // with wrong color theme, see Bug 972382
     GtkSettings *settings = gtk_settings_get_for_screen(gdk_screen_get_default());
+    bool e10sActive = mozilla::BrowserTabsRemoteAutostart();
+
+    if (!e10sActive || XRE_IsContentProcess()) {
+        // Disable dark theme in processes with web content because it
+        // interacts poorly with widget styling (see bug 1216658).
+        // To avoid triggering reload of theme settings unnecessarily, only set the
+        // setting when necessary.
+        const gchar* dark_setting = "gtk-application-prefer-dark-theme";
+        gboolean dark;
+        g_object_get(settings, dark_setting, &dark, nullptr);
+
+        bool allowDarkEnv = PR_GetEnv("MOZ_ALLOW_GTK_DARK_THEME") != nullptr;
+        bool allowDarkPref =
+            mozilla::Preferences::GetBool("widget.allow-gtk-dark-theme", false);
 
-    // Disable dark theme because it interacts poorly with widget styling in
-    // web content (see bug 1216658).
-    // To avoid triggering reload of theme settings unnecessarily, only set the
-    // setting when necessary.
-    const gchar* dark_setting = "gtk-application-prefer-dark-theme";
-    gboolean dark;
-    g_object_get(settings, dark_setting, &dark, nullptr);
+        if (dark && !allowDarkEnv && !allowDarkPref) {
+            g_object_set(settings, dark_setting, FALSE, nullptr);
+        }
 
-    if (dark && !PR_GetEnv("MOZ_ALLOW_GTK_DARK_THEME")) {
-        g_object_set(settings, dark_setting, FALSE, nullptr);
+        // Allow Gtk+ theme override for web content only.
+        if (e10sActive) {
+            auto contentThemeName =
+                mozilla::Preferences::GetCString("widget.content-gtk-theme");
+            if (!contentThemeName.IsEmpty()) {
+                // TODO: It should be enough to change theme by "gtk-theme-name"
+                // settings but that does not have any effect here. Maybe we
+                // call it too late?
+                GtkCssProvider *styleProvider =
+                    gtk_css_provider_get_named(contentThemeName, NULL);
+                gtk_style_context_add_provider_for_screen(gdk_screen_get_default(),
+                    GTK_STYLE_PROVIDER(styleProvider),
+                    GTK_STYLE_PROVIDER_PRIORITY_APPLICATION);
+            }
+        }
     }
 
     // Scrollbar colors
@@ -1439,6 +1472,7 @@ nsLookAndFeel::Init()
 char16_t
 nsLookAndFeel::GetPasswordCharacterImpl()
 {
+    EnsureInit();
     return sInvisibleCharacter;
 }
 
@@ -1457,7 +1491,7 @@ nsLookAndFeel::RefreshImpl()
     mStyle = nullptr;
 #endif
 
-    Init();
+    mInitialized = false;
 }
 
 bool
diff -up firefox-52.0/widget/gtk/nsLookAndFeel.h.1158076 firefox-52.0/widget/gtk/nsLookAndFeel.h
--- firefox-52.0/widget/gtk/nsLookAndFeel.h.1158076	2016-05-12 19:13:34.000000000 +0200
+++ firefox-52.0/widget/gtk/nsLookAndFeel.h	2017-03-22 10:06:36.461731972 +0100
@@ -84,8 +84,9 @@ protected:
     char16_t sInvisibleCharacter;
     float   sCaretRatio;
     bool    sMenuSupportsDrag;
+    bool    mInitialized;
 
-    void Init();
+    void EnsureInit();
 };
 
 #endif
bgstack15