Bug 1158076 - add widget.allow-gtk-dark-theme pref to enable gtk dark theme, r?karlt draft
authorMartin Stransky <stransky@redhat.com>
Tue, 21 Mar 2017 17:38:47 +0100
changeset 502468 88f0bfd9a6d0421b6829f5c5ffef476977bb638b
parent 502294 50f7b364e03b8ca713604bbe98f7aaceac20f1b7
child 502469 3fa1f09ddb8f41bef52d1f2049f8904855254164
push id50286
push userstransky@redhat.com
push dateTue, 21 Mar 2017 20:25:17 +0000
reviewerskarlt
bugs1158076
milestone55.0a1
Bug 1158076 - add widget.allow-gtk-dark-theme pref to enable gtk dark theme, r?karlt MozReview-Commit-ID: 6Tfp7QAtTFi
modules/libpref/init/all.js
widget/gtk/nsLookAndFeel.cpp
--- a/modules/libpref/init/all.js
+++ b/modules/libpref/init/all.js
@@ -4701,16 +4701,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
@@ -1148,17 +1148,21 @@ nsLookAndFeel::EnsureInit()
         // 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 (dark && !PR_GetEnv("MOZ_ALLOW_GTK_DARK_THEME")) {
+        bool allowDarkEnv = PR_GetEnv("MOZ_ALLOW_GTK_DARK_THEME") != nullptr;
+        bool allowDarkPref =
+            mozilla::Preferences::GetBool("widget.allow-gtk-dark-theme", false);
+
+        if (dark && !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);