Bug 1158076 - add widget.allow-gtk-dark-theme pref to enable gtk dark theme, r?karlt draft
authorMartin Stransky <stransky@redhat.com>
Mon, 27 Mar 2017 12:41:41 +0200
changeset 551714 77b4983bba20f95731fc9fcf0330d6a817db9908
parent 502501 707fa511080555b655b103690e9d363fe07563de
child 621631 9b3a498b681b9e753cfd3ca43d309f57769d8b0b
push id51150
push userstransky@redhat.com
push dateMon, 27 Mar 2017 11:52:29 +0000
reviewerskarlt
bugs1158076
milestone55.0a1
Bug 1158076 - add widget.allow-gtk-dark-theme pref to enable gtk dark theme, r?karlt MozReview-Commit-ID: 8cUtVuWpnKS
modules/libpref/init/all.js
widget/gtk/nsLookAndFeel.cpp
--- a/modules/libpref/init/all.js
+++ b/modules/libpref/init/all.js
@@ -4700,16 +4700,17 @@ pref("gfx.content.always-paint", false);
 
 #ifdef ANDROID
 pref("gfx.apitrace.enabled",false);
 #endif
 
 #ifdef MOZ_X11
 #ifdef MOZ_WIDGET_GTK
 pref("gfx.xrender.enabled",false);
+pref("widget.allow-gtk-dark-theme", false);
 #endif
 #endif
 
 #ifdef XP_WIN
 // Whether to disable the automatic detection and use of direct2d.
 pref("gfx.direct2d.disabled", false);
 
 // Whether to attempt to enable Direct2D regardless of automatic detection or
--- a/widget/gtk/nsLookAndFeel.cpp
+++ b/widget/gtk/nsLookAndFeel.cpp
@@ -1138,27 +1138,38 @@ nsLookAndFeel::EnsureInit()
 #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
     GtkSettings *settings = gtk_settings_get_for_screen(gdk_screen_get_default());
+    bool e10sActive = mozilla::BrowserTabsRemoteAutostart();
 
-    if (!mozilla::BrowserTabsRemoteAutostart() || XRE_IsContentProcess()) {
+    const gchar* dark_setting = "gtk-application-prefer-dark-theme";
+    gboolean darkThemeDefault;
+    g_object_get(settings, dark_setting, &darkThemeDefault, nullptr);
+
+    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);
+        if (darkThemeDefault) {
+            g_object_set(settings, dark_setting, FALSE, nullptr);
+        }
+    } else {
+        // Disable dark theme in main process behind preference
+        // due to possible side effects in UI.
+        bool allowDarkEnv = PR_GetEnv("MOZ_ALLOW_GTK_DARK_THEME") != nullptr;
+        bool allowDarkPref =
+            mozilla::Preferences::GetBool("widget.allow-gtk-dark-theme", false);
 
-        if (dark && !PR_GetEnv("MOZ_ALLOW_GTK_DARK_THEME")) {
+        if (darkThemeDefault && !allowDarkEnv && !allowDarkPref) {
             g_object_set(settings, dark_setting, FALSE, nullptr);
         }
     }
 
     // Scrollbar colors
     style = ClaimStyleContext(MOZ_GTK_SCROLLBAR_TROUGH_VERTICAL);
     gtk_style_context_get_background_color(style, GTK_STATE_FLAG_NORMAL, &color);
     sMozScrollbar = GDK_RGBA_TO_NS_RGBA(color);