Bug 1314928 - get link text color by GTK_STATE_FLAG_LINK on Gtk3 >= 3.12, r=karlt
MozReview-Commit-ID: BPR2AgoUx5H
--- 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