Bug 1314928 - get link text color by GTK_STATE_FLAG_LINK on Gtk3 >= 3.12, r=karlt draft
authorMartin Stransky <stransky@redhat.com>
Fri, 25 Aug 2017 10:30:28 +0200
changeset 652884 c4670cd6b7df84dd00a4d04c3bfc582f917795da
parent 652622 2306e153fba9ca55726ffcce889eaca7a479c29f
child 728213 b2e93f38a6f1133d770f76eb609b51ca620e0103
push id76188
push userstransky@redhat.com
push dateFri, 25 Aug 2017 09:29:50 +0000
reviewerskarlt
bugs1314928
milestone57.0a1
Bug 1314928 - get link text color by GTK_STATE_FLAG_LINK on Gtk3 >= 3.12, r=karlt MozReview-Commit-ID: BPR2AgoUx5H
widget/gtk/nsLookAndFeel.cpp
--- a/widget/gtk/nsLookAndFeel.cpp
+++ b/widget/gtk/nsLookAndFeel.cpp
@@ -38,16 +38,20 @@
 using mozilla::LookAndFeel;
 
 #define GDK_COLOR_TO_NS_RGB(c) \
     ((nscolor) NS_RGB(c.red>>8, c.green>>8, c.blue>>8))
 #define GDK_RGBA_TO_NS_RGBA(c) \
     ((nscolor) NS_RGBA((int)((c).red*255), (int)((c).green*255), \
                        (int)((c).blue*255), (int)((c).alpha*255)))
 
+#if !GTK_CHECK_VERSION(3,12,0)
+#define GTK_STATE_FLAG_LINK (static_cast<GtkStateFlags>(1 << 9))
+#endif
+
 nsLookAndFeel::nsLookAndFeel()
     : nsXPLookAndFeel(),
 #if (MOZ_WIDGET_GTK == 2)
       mStyle(nullptr),
 #endif
       mDefaultFontCached(false), mButtonFontCached(false),
       mFieldFontCached(false), mMenuFontCached(false),
       mInitialized(false)
@@ -1452,24 +1456,36 @@ nsLookAndFeel::EnsureInit()
         if (g_type_is_a(G_PARAM_SPEC_VALUE_TYPE(param_spec), G_TYPE_BOOLEAN)) {
             gtk_widget_style_get(menuBar,
                                  "window-dragging", &supports_menubar_drag,
                                  nullptr);
         }
     }
     sMenuSupportsDrag = supports_menubar_drag;
 
-    colorValuePtr = nullptr;
-    gtk_widget_style_get(linkButton, "link-color", &colorValuePtr, nullptr);
-    if (colorValuePtr) {
-        colorValue = *colorValuePtr; // we can't pass deref pointers to GDK_COLOR_TO_NS_RGB
-        sNativeHyperLinkText = GDK_COLOR_TO_NS_RGB(colorValue);
-        gdk_color_free(colorValuePtr);
-    } else {
-        sNativeHyperLinkText = NS_RGB(0x00,0x00,0xEE);
+#if (MOZ_WIDGET_GTK == 3)
+    if (gtk_check_version(3, 12, 0) == nullptr) {
+        // TODO: It returns wrong color for themes which
+        // sets link color for GtkLabel only as we query
+        // GtkLinkButton style here.
+        style = gtk_widget_get_style_context(linkButton);
+        gtk_style_context_get_color(style, GTK_STATE_FLAG_LINK, &color);
+        sNativeHyperLinkText = GDK_RGBA_TO_NS_RGBA(color);
+    } else
+#endif
+    {
+        colorValuePtr = nullptr;
+        gtk_widget_style_get(linkButton, "link-color", &colorValuePtr, nullptr);
+        if (colorValuePtr) {
+            colorValue = *colorValuePtr; // we can't pass deref pointers to GDK_COLOR_TO_NS_RGB
+            sNativeHyperLinkText = GDK_COLOR_TO_NS_RGB(colorValue);
+            gdk_color_free(colorValuePtr);
+        } else {
+            sNativeHyperLinkText = NS_RGB(0x00,0x00,0xEE);
+        }
     }
 
     // invisible character styles
     guint value;
     g_object_get (entry, "invisible-char", &value, nullptr);
     sInvisibleCharacter = char16_t(value);
 
     // caret styles