Bug 426732 - implement -moz-nativelinktext, r=dbaron, sr=roc
authorRyan A. C. <fittysix@gmail.com>
Fri, 11 Jul 2008 20:34:53 +0200
changeset 15798 dd2a7349ee20ebe974b2ff87be1e851209c7c045
parent 15797 9adc2b7f0210d263ceb80e4c642d577ed136d04d
child 15799 8a99db3f8680b3d066ff49abf1199b25e9781191
push idunknown
push userunknown
push dateunknown
reviewersdbaron, roc
bugs426732
milestone1.9.1a1pre
Bug 426732 - implement -moz-nativelinktext, r=dbaron, sr=roc
layout/style/nsCSSKeywordList.h
layout/style/nsCSSProps.cpp
layout/style/test/property_database.js
widget/public/nsILookAndFeel.h
widget/src/cocoa/nsLookAndFeel.mm
widget/src/gtk2/nsLookAndFeel.cpp
widget/src/gtk2/nsLookAndFeel.h
widget/src/windows/nsLookAndFeel.cpp
widget/src/xpwidgets/nsXPLookAndFeel.cpp
--- a/layout/style/nsCSSKeywordList.h
+++ b/layout/style/nsCSSKeywordList.h
@@ -149,16 +149,17 @@ CSS_KEY(-moz-malayalam, _moz_malayalam)
 CSS_KEY(-moz-marker, _moz_marker) // Disabled because not supported correctly.
 CSS_KEY(-moz-max-content, _moz_max_content)
 CSS_KEY(-moz-menuhover, _moz_menuhover)
 CSS_KEY(-moz-menuhovertext, _moz_menuhovertext)
 CSS_KEY(-moz-menubarhovertext, _moz_menubarhovertext)
 CSS_KEY(-moz-middle-with-baseline, _moz_middle_with_baseline)
 CSS_KEY(-moz-min-content, _moz_min_content)
 CSS_KEY(-moz-myanmar, _moz_myanmar)
+CSS_KEY(-moz-nativehyperlinktext, _moz_nativehyperlinktext)
 CSS_KEY(-moz-none, _moz_none)
 CSS_KEY(-moz-oddtreerow, _moz_oddtreerow)
 CSS_KEY(-moz-oriya, _moz_oriya)
 CSS_KEY(-moz-persian, _moz_persian)
 CSS_KEY(-moz-popup, _moz_popup)
 CSS_KEY(-moz-pre-wrap, _moz_pre_wrap)
 CSS_KEY(-moz-pull-down-menu, _moz_pull_down_menu)
 CSS_KEY(-moz-right, _moz_right)
--- a/layout/style/nsCSSProps.cpp
+++ b/layout/style/nsCSSProps.cpp
@@ -463,16 +463,17 @@ const PRInt32 nsCSSProps::kColorKTable[]
   eCSSKeyword__moz_menuhover, nsILookAndFeel::eColor__moz_menuhover,
   eCSSKeyword__moz_menuhovertext, nsILookAndFeel::eColor__moz_menuhovertext,
   eCSSKeyword__moz_menubarhovertext, nsILookAndFeel::eColor__moz_menubarhovertext,
   eCSSKeyword__moz_oddtreerow, nsILookAndFeel::eColor__moz_oddtreerow,
   eCSSKeyword__moz_visitedhyperlinktext, NS_COLOR_MOZ_VISITEDHYPERLINKTEXT,
   eCSSKeyword_currentcolor, NS_COLOR_CURRENTCOLOR,
   eCSSKeyword__moz_win_mediatext, nsILookAndFeel::eColor__moz_win_mediatext,
   eCSSKeyword__moz_win_communicationstext, nsILookAndFeel::eColor__moz_win_communicationstext,
+  eCSSKeyword__moz_nativehyperlinktext, nsILookAndFeel::eColor__moz_nativehyperlinktext,
   eCSSKeyword_UNKNOWN,-1
 };
 
 const PRInt32 nsCSSProps::kContentKTable[] = {
   eCSSKeyword_open_quote, NS_STYLE_CONTENT_OPEN_QUOTE,
   eCSSKeyword_close_quote, NS_STYLE_CONTENT_CLOSE_QUOTE,
   eCSSKeyword_no_open_quote, NS_STYLE_CONTENT_NO_OPEN_QUOTE,
   eCSSKeyword_no_close_quote, NS_STYLE_CONTENT_NO_CLOSE_QUOTE,
--- a/layout/style/test/property_database.js
+++ b/layout/style/test/property_database.js
@@ -787,17 +787,17 @@ var gCSSProperties = {
 		invalid_values: [ "rect(auto, 3em, 2%, 5px)" ]
 	},
 	"color": {
 		domProp: "color",
 		inherited: true,
 		type: CSS_TYPE_LONGHAND,
 		/* XXX should test currentColor, but may or may not be initial */
 		initial_values: [ "black", "#000" ],
-		other_values: [ "green", "#f3c", "#fed292", "rgba(45,300,12,2)", "transparent" ],
+		other_values: [ "green", "#f3c", "#fed292", "rgba(45,300,12,2)", "transparent", "-moz-nativehyperlinktext", "rgba(255,128,0,0.5)" ],
 		invalid_values: [ "fff", "ffffff", "#f", "#ff", "#ffff", "#fffff", "#fffffff", "#ffffffff", "#fffffffff" ]
 	},
 	"content": {
 		domProp: "content",
 		inherited: false,
 		type: CSS_TYPE_LONGHAND,
 		/* XXX needs to be on pseudo-elements */
 		initial_values: [ "normal", "none" ],
--- a/widget/public/nsILookAndFeel.h
+++ b/widget/public/nsILookAndFeel.h
@@ -160,16 +160,21 @@ public:
     //new in 10.2
     eColor__moz_mac_alternateprimaryhighlight, //active list highlight
     eColor__moz_mac_secondaryhighlight,        //inactive light hightlight
 
     // vista rebars
     eColor__moz_win_mediatext,                     // media rebar text
     eColor__moz_win_communicationstext,            // communications rebar text
 
+    // Hyperlink color extracted from the system, not affected by the browser.anchor_color user pref.
+    // There is no OS-specified safe background color for this text, 
+    // but it is used regularly within Windows and the Gnome DE on Dialog and Window colors.
+    eColor__moz_nativehyperlinktext,		
+
     // keep this one last, please
     eColor_LAST_COLOR
   } nsColorID;
 
   // When modifying this list, also modify nsXPLookAndFeel::sIntPrefs
   // in widget/src/xpwidgts/nsXPLookAndFeel.cpp.
   typedef enum {
     eMetric_WindowTitleHeight,
--- a/widget/src/cocoa/nsLookAndFeel.mm
+++ b/widget/src/cocoa/nsLookAndFeel.mm
@@ -345,16 +345,20 @@ nsresult nsLookAndFeel::NativeGetColor(c
     case eColor__moz_eventreerow:
       // Background color of even list rows. Note that Apple's row index is different from ours.
       res = GetMacBrushColor(kThemeBrushListViewOddRowBackground, aColor, NS_RGB(0xFF,0xFF,0xFF));
       break;
     case eColor__moz_oddtreerow:
       // Background color of odd list rows.
       res = GetMacBrushColor(kThemeBrushListViewEvenRowBackground, aColor, NS_RGB(0xF0,0xF0,0xF0));
       break;
+    case eColor__moz_nativehyperlinktext:
+      // There appears to be no available system defined color. HARDCODING to the appropriate color.
+      aColor = NS_RGB(0x14,0x4F,0xAE);
+      break;
     default:
       NS_WARNING("Someone asked nsILookAndFeel for a color I don't know about");
       aColor = NS_RGB(0xff,0xff,0xff);
       res = NS_ERROR_FAILURE;
       break;
     }
   
   return res;
--- a/widget/src/gtk2/nsLookAndFeel.cpp
+++ b/widget/src/gtk2/nsLookAndFeel.cpp
@@ -52,16 +52,17 @@ nscolor   nsLookAndFeel::sMenuText = 0;
 nscolor   nsLookAndFeel::sMenuHover = 0;
 nscolor   nsLookAndFeel::sMenuHoverText = 0;
 nscolor   nsLookAndFeel::sMenuBackground = 0;
 nscolor   nsLookAndFeel::sButtonBackground = 0;
 nscolor   nsLookAndFeel::sButtonText = 0;
 nscolor   nsLookAndFeel::sButtonOuterLightBorder = 0;
 nscolor   nsLookAndFeel::sButtonInnerDarkBorder = 0;
 nscolor   nsLookAndFeel::sOddCellBackground = 0;
+nscolor   nsLookAndFeel::sNativeHyperLinkText = 0;
 PRUnichar nsLookAndFeel::sInvisibleCharacter = PRUnichar('*');
 float     nsLookAndFeel::sCaretRatio = 0;
 
 //-------------------------------------------------------------------------
 //
 // Query interface implementation
 //
 //-------------------------------------------------------------------------
@@ -300,16 +301,19 @@ nsresult nsLookAndFeel::NativeGetColor(c
         aColor = sMenuHover;
         break;
     case eColor__moz_menuhovertext:
         aColor = sMenuHoverText;
         break;
     case eColor__moz_oddtreerow:
         aColor = sOddCellBackground;
         break;
+    case eColor__moz_nativehyperlinktext:
+        aColor = sNativeHyperLinkText;
+        break;
     default:
         /* default color is BLACK */
         aColor = 0;
         res    = NS_ERROR_FAILURE;
         break;
     }
 
     return res;
@@ -669,29 +673,33 @@ nsLookAndFeel::InitLookAndFeel()
 
 
     // button styles
     GtkWidget *parent = gtk_fixed_new();
     GtkWidget *button = gtk_button_new();
     GtkWidget *label = gtk_label_new("M");
     GtkWidget *window = gtk_window_new(GTK_WINDOW_POPUP);
     GtkWidget *treeView = gtk_tree_view_new();
+    GtkWidget *linkButton = gtk_link_button_new("http://example.com/");
 
     gtk_container_add(GTK_CONTAINER(button), label);
     gtk_container_add(GTK_CONTAINER(parent), button);
     gtk_container_add(GTK_CONTAINER(parent), treeView);
+    gtk_container_add(GTK_CONTAINER(parent), linkButton);
     gtk_container_add(GTK_CONTAINER(window), parent);
 
     gtk_widget_set_rc_style(button);
     gtk_widget_set_rc_style(label);
     gtk_widget_set_rc_style(treeView);
+    gtk_widget_set_rc_style(linkButton);
 
     gtk_widget_realize(button);
     gtk_widget_realize(label);
     gtk_widget_realize(treeView);
+    gtk_widget_realize(linkButton);
 
     style = gtk_widget_get_style(label);
     if (style) {
         sButtonText = GDK_COLOR_TO_NS_RGB(style->fg[GTK_STATE_NORMAL]);
     }
 
     // GTK's guide to fancy odd row background colors:
     // 1) Check if a theme explicitly defines an odd row color
@@ -725,16 +733,26 @@ nsLookAndFeel::InitLookAndFeel()
     if (style) {
         sButtonBackground = GDK_COLOR_TO_NS_RGB(style->bg[GTK_STATE_NORMAL]);
         sButtonOuterLightBorder =
             GDK_COLOR_TO_NS_RGB(style->light[GTK_STATE_NORMAL]);
         sButtonInnerDarkBorder =
             GDK_COLOR_TO_NS_RGB(style->dark[GTK_STATE_NORMAL]);
     }
 
+    colorValuePtr = NULL;
+    gtk_widget_style_get(linkButton, "link-color", &colorValuePtr, NULL);
+    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);
+    }
+
     gtk_widget_destroy(window);
 
     // invisible character styles
     GtkWidget *entry = gtk_entry_new();
     guint value;
     g_object_get (entry, "invisible-char", &value, NULL);
     sInvisibleCharacter = PRUnichar(value);
 
--- a/widget/src/gtk2/nsLookAndFeel.h
+++ b/widget/src/gtk2/nsLookAndFeel.h
@@ -67,16 +67,17 @@ protected:
     static nscolor sMenuText;
     static nscolor sMenuHover;
     static nscolor sMenuHoverText;
     static nscolor sButtonBackground;
     static nscolor sButtonText;
     static nscolor sButtonOuterLightBorder;
     static nscolor sButtonInnerDarkBorder;
     static nscolor sOddCellBackground;
+    static nscolor sNativeHyperLinkText;
     static PRUnichar sInvisibleCharacter;
     static float   sCaretRatio;
 
     static void InitLookAndFeel();
     void InitWidget() {
         mWidget = gtk_invisible_new();
         gtk_object_ref(GTK_OBJECT(mWidget));
         gtk_object_sink(GTK_OBJECT(mWidget));
--- a/widget/src/windows/nsLookAndFeel.cpp
+++ b/widget/src/windows/nsLookAndFeel.cpp
@@ -393,16 +393,19 @@ nsresult nsLookAndFeel::NativeGetColor(c
       idx = COLOR_WINDOWTEXT;
       break;
     case eColor__moz_dragtargetzone:
       idx = COLOR_HIGHLIGHTTEXT;
       break;
     case eColor__moz_buttondefault:
       idx = COLOR_3DDKSHADOW;
       break;
+    case eColor__moz_nativehyperlinktext:
+      idx = COLOR_HOTLIGHT;
+      break;
     default:
       idx = COLOR_WINDOW;
       break;
     }
 
   DWORD color = ::GetSysColor(idx);
   aColor = COLOREF_2_NSRGB(color);
 
--- a/widget/src/xpwidgets/nsXPLookAndFeel.cpp
+++ b/widget/src/xpwidgets/nsXPLookAndFeel.cpp
@@ -237,17 +237,18 @@ const char nsXPLookAndFeel::sColorPrefs[
   "ui.-moz-mac-accentface",
   "ui.-moz-mac-accentlightshadow",
   "ui.-moz-mac-accentregularshadow",
   "ui.-moz-mac-accentdarkshadow",
   "ui.-moz-mac-accentdarkestshadow",
   "ui.-moz-mac-alternateprimaryhighlight",
   "ui.-moz-mac-secondaryhighlight",
   "ui.-moz-win-mediatext",
-  "ui.-moz-win-communicationstext"
+  "ui.-moz-win-communicationstext",
+  "ui.-moz-nativehyperlinktext"
 };
 
 PRInt32 nsXPLookAndFeel::sCachedColors[nsILookAndFeel::eColor_LAST_COLOR] = {0};
 PRInt32 nsXPLookAndFeel::sCachedColorBits[COLOR_CACHE_SIZE] = {0};
 
 PRBool nsXPLookAndFeel::sInitialized = PR_FALSE;
 
 nsXPLookAndFeel::nsXPLookAndFeel() : nsILookAndFeel()