Bug 1158076 - Allow Gtk+ theme override for web content when e10s is enabled, r?karlt draft
authorMartin Stransky <stransky@redhat.com>
Mon, 20 Mar 2017 22:25:53 +0100
changeset 501725 0c12843806a4f38e80acad732d32c380036f387a
parent 501530 c206ab53a7925f36047dc4a5db2dd52f00fd1e69
child 549983 f3c3dfceb254ba758017ee22f2f49cc0f7860139
push id50094
push userstransky@redhat.com
push dateMon, 20 Mar 2017 21:26:53 +0000
reviewerskarlt
bugs1158076
milestone55.0a1
Bug 1158076 - Allow Gtk+ theme override for web content when e10s is enabled, r?karlt MozReview-Commit-ID: LVIeMu0wQ1A
widget/gtk/mozgtk/mozgtk.c
widget/gtk/nsLookAndFeel.cpp
--- a/widget/gtk/mozgtk/mozgtk.c
+++ b/widget/gtk/mozgtk/mozgtk.c
@@ -517,16 +517,17 @@ STUB(gdk_display_get_device_manager)
 STUB(gdk_error_trap_pop_ignored)
 STUB(gdk_event_get_source_device)
 STUB(gdk_window_get_type)
 STUB(gdk_x11_window_get_xid)
 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)
 STUB(gtk_get_micro_version)
 STUB(gtk_get_minor_version)
 STUB(gtk_menu_button_new)
 STUB(gtk_offscreen_window_new)
 STUB(gtk_paned_new)
@@ -543,16 +544,17 @@ STUB(gtk_render_frame_gap)
 STUB(gtk_render_handle)
 STUB(gtk_render_line)
 STUB(gtk_render_option)
 STUB(gtk_render_slider)
 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)
 STUB(gtk_style_context_get_border_color)
 STUB(gtk_style_context_get_color)
 STUB(gtk_style_context_get_direction)
 STUB(gtk_style_context_get_margin)
 STUB(gtk_style_context_get_padding)
@@ -568,16 +570,17 @@ STUB(gtk_style_context_remove_class)
 STUB(gtk_style_context_remove_region)
 STUB(gtk_style_context_restore)
 STUB(gtk_style_context_save)
 STUB(gtk_style_context_set_direction)
 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)
 STUB(gtk_widget_get_style_context)
 STUB(gtk_widget_path_append_type)
 STUB(gtk_widget_path_copy)
 STUB(gtk_widget_path_free)
 STUB(gtk_widget_path_iter_add_class)
--- a/widget/gtk/nsLookAndFeel.cpp
+++ b/widget/gtk/nsLookAndFeel.cpp
@@ -1139,33 +1139,47 @@ 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()) {
+    if (!e10sActive || XRE_IsContentProcess()) {
         // 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 allowDarkEnv = static_cast<bool>(PR_GetEnv("MOZ_ALLOW_GTK_DARK_THEME"));
         bool allowDarkPref =
             mozilla::Preferences::GetBool("widget.allow-gtk-dark-theme", false);
 
         if (dark && !allowDarkEnv && !allowDarkPref) {
             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) {
+                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
     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);
     ReleaseStyleContext(style);