From 8c5debe5af6e954a1d7148ad7c7c6dd9340e2f94 Mon Sep 17 00:00:00 2001 From: Karl Tomlinson Date: Tue, 7 Jun 2016 18:06:04 +1200 Subject: [PATCH] Bug 1250704 - use same widget heirarchy as GTK for tooltip text color. r=stransky MozReview-Commit-ID: 41sDYu3IqYq --HG-- extra : rebase_source : 425a04503441f3edfd4ebbd71a21921013690426 --- widget/gtk/WidgetStyleCache.cpp | 23 +++++++++++++++++++++++ widget/gtk/WidgetStyleCache.h | 7 +++++++ widget/gtk/mozgtk/mozgtk.c | 2 ++ widget/gtk/nsLookAndFeel.cpp | 11 ++++++++++- 4 files changed, 42 insertions(+), 1 deletion(-) diff --git a/widget/gtk/WidgetStyleCache.cpp b/widget/gtk/WidgetStyleCache.cpp index d413398be5fb..920fb934616c 100644 --- a/widget/gtk/WidgetStyleCache.cpp +++ b/widget/gtk/WidgetStyleCache.cpp @@ -163,6 +163,29 @@ GetWidget(WidgetNodeType aWidgetType) 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) { diff --git a/widget/gtk/WidgetStyleCache.h b/widget/gtk/WidgetStyleCache.h index f7da79889361..2dbf671f4746 100644 --- a/widget/gtk/WidgetStyleCache.h +++ b/widget/gtk/WidgetStyleCache.h @@ -21,6 +21,13 @@ enum : StyleFlags { 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, diff --git a/widget/gtk/mozgtk/mozgtk.c b/widget/gtk/mozgtk/mozgtk.c index ebf82e546bd0..8b427b52f828 100644 --- a/widget/gtk/mozgtk/mozgtk.c +++ b/widget/gtk/mozgtk/mozgtk.c @@ -518,6 +518,7 @@ 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) @@ -573,6 +574,7 @@ 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) diff --git a/widget/gtk/nsLookAndFeel.cpp b/widget/gtk/nsLookAndFeel.cpp index 3e3437be9a42..9661a5255756 100644 --- a/widget/gtk/nsLookAndFeel.cpp +++ b/widget/gtk/nsLookAndFeel.cpp @@ -1142,7 +1142,16 @@ nsLookAndFeel::Init() 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);