Bug 1250704 - use same widget heirarchy as GTK for tooltip text color. r=stransky
MozReview-Commit-ID: 41sDYu3IqYq
--- a/widget/gtk/WidgetStyleCache.cpp
+++ b/widget/gtk/WidgetStyleCache.cpp
@@ -159,16 +159,39 @@ GetWidget(WidgetNodeType aWidgetType)
if (!widget) {
widget = CreateWidget(aWidgetType);
sWidgetStorage[aWidgetType] = widget;
}
return widget;
}
GtkStyleContext*
+CreateStyleForWidget(GtkWidget* aWidget, GtkStyleContext* aParentStyle)
+{
+ GtkWidgetPath* path =
+ gtk_widget_path_copy(gtk_style_context_get_path(aParentStyle));
+
+ // Work around https://bugzilla.gnome.org/show_bug.cgi?id=767312
+ // which exists in GTK+ 3.20.
+ gtk_widget_get_style_context(aWidget);
+
+ gtk_widget_path_append_for_widget(path, aWidget);
+ // Release any floating reference on aWidget.
+ g_object_ref_sink(aWidget);
+ g_object_unref(aWidget);
+
+ GtkStyleContext *context = gtk_style_context_new();
+ gtk_style_context_set_path(context, path);
+ gtk_style_context_set_parent(context, aParentStyle);
+ gtk_widget_path_unref(path);
+
+ return context;
+}
+
+GtkStyleContext*
CreateCSSNode(const char* aName, GtkStyleContext* aParentStyle, GType aType)
{
static auto sGtkWidgetPathIterSetObjectName =
reinterpret_cast<void (*)(GtkWidgetPath *, gint, const char *)>
(dlsym(RTLD_DEFAULT, "gtk_widget_path_iter_set_object_name"));
GtkWidgetPath* path = aParentStyle ?
gtk_widget_path_copy(gtk_style_context_get_path(aParentStyle)) :
--- a/widget/gtk/WidgetStyleCache.h
+++ b/widget/gtk/WidgetStyleCache.h
@@ -16,16 +16,23 @@ typedef unsigned StyleFlags;
enum : StyleFlags {
NO_STYLE_FLAGS,
WHATEVER_MIGHT_BE_NEEDED = 1U << 0,
};
GtkWidget*
GetWidget(WidgetNodeType aNodeType);
+/*
+ * Return a new style context based on aWidget, as a child of aParentStyle.
+ * If aWidget still has a floating reference, then it is sunk and released.
+ */
+GtkStyleContext*
+CreateStyleForWidget(GtkWidget* aWidget, GtkStyleContext* aParentStyle);
+
// CreateCSSNode is implemented for gtk >= 3.20 only.
GtkStyleContext*
CreateCSSNode(const char* aName,
GtkStyleContext* aParentStyle,
GType aType = G_TYPE_NONE);
// Callers must call ReleaseStyleContext() on the returned context.
GtkStyleContext*
--- a/widget/gtk/mozgtk/mozgtk.c
+++ b/widget/gtk/mozgtk/mozgtk.c
@@ -513,16 +513,17 @@ STUB(gdk_device_manager_get_client_point
STUB(gdk_disable_multidevice)
STUB(gdk_device_manager_list_devices)
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_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)
@@ -568,16 +569,17 @@ 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_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_for_widget)
STUB(gtk_widget_path_append_type)
STUB(gtk_widget_path_copy)
STUB(gtk_widget_path_free)
STUB(gtk_widget_path_new)
STUB(gtk_widget_path_unref)
STUB(gtk_widget_set_visual)
STUB(gtk_app_chooser_dialog_new_for_content_type)
STUB(gtk_app_chooser_get_type)
--- a/widget/gtk/nsLookAndFeel.cpp
+++ b/widget/gtk/nsLookAndFeel.cpp
@@ -1137,17 +1137,26 @@ nsLookAndFeel::Init()
sMozWindowText = GDK_RGBA_TO_NS_RGBA(color);
gtk_style_context_restore(style);
g_object_unref(style);
// tooltip foreground and background
style = ClaimStyleContext(MOZ_GTK_TOOLTIP);
gtk_style_context_get_background_color(style, GTK_STATE_FLAG_NORMAL, &color);
sInfoBackground = GDK_RGBA_TO_NS_RGBA(color);
- gtk_style_context_get_color(style, GTK_STATE_FLAG_NORMAL, &color);
+ {
+ GtkStyleContext* boxStyle =
+ CreateStyleForWidget(gtk_box_new(GTK_ORIENTATION_HORIZONTAL, 0),
+ style);
+ GtkStyleContext* labelStyle =
+ CreateStyleForWidget(gtk_label_new(nullptr), boxStyle);
+ gtk_style_context_get_color(labelStyle, GTK_STATE_FLAG_NORMAL, &color);
+ g_object_unref(labelStyle);
+ g_object_unref(boxStyle);
+ }
sInfoText = GDK_RGBA_TO_NS_RGBA(color);
ReleaseStyleContext(style);
// menu foreground & menu background
GtkWidget *accel_label = gtk_accel_label_new("M");
GtkWidget *menuitem = gtk_menu_item_new();
GtkWidget *menu = gtk_menu_new();