commit 4cb65b680138 Author: Martin Stransky Date: Fri Aug 25 10:30:28 2017 +0200 Bug 1314928 - get link text color by GTK_STATE_FLAG_LINK on Gtk3 >= 3.12, r=karlt MozReview-Commit-ID: BPR2AgoUx5H --HG-- extra : rebase_source : c4670cd6b7df84dd00a4d04c3bfc582f917795da --- widget/gtk/nsLookAndFeel.cpp | 32 ++++++++++++++++++++++++-------- 1 file changed, 24 insertions(+), 8 deletions(-) diff --git widget/gtk/nsLookAndFeel.cpp widget/gtk/nsLookAndFeel.cpp index 7cd8e8dcc163..6bb3e27c6653 100644 --- widget/gtk/nsLookAndFeel.cpp +++ widget/gtk/nsLookAndFeel.cpp @@ -43,6 +43,10 @@ using mozilla::LookAndFeel; ((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(1 << 9)) +#endif + nsLookAndFeel::nsLookAndFeel() : nsXPLookAndFeel(), #if (MOZ_WIDGET_GTK == 2) @@ -1457,14 +1461,26 @@ nsLookAndFeel::EnsureInit() } 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