Bug 1158076 - Allow Gtk+ theme override for web content when e10s is enabled, r?karlt
MozReview-Commit-ID: 6OgUybWaA40
--- 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
@@ -1138,33 +1138,50 @@ 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 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);
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.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
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);