Bug 1365556 - remove text-button class from MOZ_GTK_BUTTON style, r?karlt draft
authorMartin Stransky <stransky@redhat.com>
Wed, 26 Jul 2017 19:22:52 +0200
changeset 616071 c954ca62841c59d3ea3d2914e6b7c115de420bb6
parent 615935 388d81ed93fa640f91d155f36254667c734157cf
child 639355 1f113fae0fae888f834abe31fa94076a9c9c542b
push id70561
push userstransky@redhat.com
push dateWed, 26 Jul 2017 17:26:11 +0000
reviewerskarlt
bugs1365556
milestone56.0a1
Bug 1365556 - remove text-button class from MOZ_GTK_BUTTON style, r?karlt When GtkButton is created by gtk_button_new_with_label() it has text-button class. When any child widget is added this class is removed. We want to emulate the GtkLabel placed inside GtkButton so remove temporary text-button class on Gtk+ <= 3.10 where it causes issues with Adwaita theme. MozReview-Commit-ID: HYWSKUVcvyI
widget/gtk/nsLookAndFeel.cpp
--- a/widget/gtk/nsLookAndFeel.cpp
+++ b/widget/gtk/nsLookAndFeel.cpp
@@ -1362,23 +1362,35 @@ nsLookAndFeel::EnsureInit()
         static_cast<GtkStateFlags>(GTK_STATE_FLAG_FOCUSED|GTK_STATE_FLAG_SELECTED),
         &color);
     sTextSelectedText = GDK_RGBA_TO_NS_RGBA(color);
     ReleaseStyleContext(style);
 
     // Button text color
     style = ClaimStyleContext(MOZ_GTK_BUTTON);
     {
+        // MOZ_GTK_BUTTON creates GtkButton by gtk_button_new_with_label()
+        // which confuses Adwaita theme on Gtk+ 3.10 (Bug 1365556).
+        bool removeTextClass = (gtk_major_version == 3 && gtk_minor_version <= 10);
+        if (removeTextClass) {
+            gtk_style_context_remove_class(style, "text-button");
+            gtk_style_context_invalidate(style);
+        }
+
         GtkStyleContext* labelStyle =
             CreateStyleForWidget(gtk_label_new("M"), style);
         gtk_style_context_get_color(labelStyle, GTK_STATE_FLAG_NORMAL, &color);
         sButtonText = GDK_RGBA_TO_NS_RGBA(color);
         gtk_style_context_get_color(labelStyle, GTK_STATE_FLAG_PRELIGHT, &color);
         sButtonHoverText = GDK_RGBA_TO_NS_RGBA(color);
         g_object_unref(labelStyle);
+
+        if (removeTextClass) {
+            gtk_style_context_add_class(style, "text-button");
+        }
     }
     ReleaseStyleContext(style);
 
     // Combobox text color
     style = ClaimStyleContext(MOZ_GTK_COMBOBOX_ENTRY_TEXTAREA);
     gtk_style_context_get_color(style, GTK_STATE_FLAG_NORMAL, &color);
     sComboBoxText = GDK_RGBA_TO_NS_RGBA(color);
     ReleaseStyleContext(style);