Bug 1272332 - Allow gtk the global dark theme behind a pref. r=karlt
authorNicolas Silva <nsilva@mozilla.com>
Tue, 21 Jun 2016 14:51:03 +0200
changeset 327268 0f052f1a6a058ae9b0d9f25f46ca60d2baa19e3a
parent 327267 1db92044b8deda84d12afcca650587ba94f9a961
child 327269 1f812f8563fb46faceae3e7f53d05d627f108c06
push id9858
push userjlund@mozilla.com
push dateMon, 01 Aug 2016 14:37:10 +0000
treeherdermozilla-aurora@203106ef6cb6 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerskarlt
bugs1272332
milestone50.0a1
Bug 1272332 - Allow gtk the global dark theme behind a pref. r=karlt
modules/libpref/init/all.js
widget/gtk/nsLookAndFeel.cpp
--- a/modules/libpref/init/all.js
+++ b/modules/libpref/init/all.js
@@ -4559,16 +4559,17 @@ pref("gfx.content.use-native-pushlayer",
 #ifdef ANDROID
 pref("gfx.apitrace.enabled",false);
 #endif
 
 #ifdef MOZ_X11
 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
 
 #ifdef XP_WIN
 pref("gfx.content.use-native-pushlayer", true);
 
 // Whether to disable the automatic detection and use of direct2d.
 pref("gfx.direct2d.disabled", false);
--- a/widget/gtk/nsLookAndFeel.cpp
+++ b/widget/gtk/nsLookAndFeel.cpp
@@ -1093,26 +1093,31 @@ nsLookAndFeel::Init()
     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());
 
-    // 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);
+
+    bool allowDarkTheme = mozilla::Preferences::GetBool("widget.allow-gtk-dark-theme", false);
 
-    if (dark) {
-        g_object_set(settings, dark_setting, FALSE, nullptr);
+    if (!allowDarkTheme) {
+        // 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) {
+            g_object_set(settings, dark_setting, FALSE, nullptr);
+        }
     }
 
     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);