Implement the HTML5 algorithm for parsing a legacy color value: reject 'transparent'. (Bug 227072) r=sicking
authorL. David Baron <dbaron@dbaron.org>
Thu, 03 Jun 2010 13:11:34 -0700
changeset 43059 61dc8ace52f1dc452ff4ef2490675517268c0b55
parent 43058 02daa34b047eba10d6eb73b45df3918aab164a9d
child 43060 fae3332168ec1d34c4b3774a26b4179c475cc734
push idunknown
push userunknown
push dateunknown
reviewerssicking
bugs227072
milestone1.9.3a5pre
Implement the HTML5 algorithm for parsing a legacy color value: reject 'transparent'. (Bug 227072) r=sicking
content/base/src/nsAttrValue.cpp
content/base/src/nsAttrValue.h
gfx/src/nsColor.cpp
--- a/content/base/src/nsAttrValue.cpp
+++ b/content/base/src/nsAttrValue.cpp
@@ -1165,19 +1165,22 @@ nsAttrValue::ParseColor(const nsAString&
   }
 
   if (aDocument->GetCompatibilityMode() != eCompatibility_NavQuirks) {
     return PR_FALSE;
   }
 
   // In compatibility mode, try LooseHexToRGB as a fallback for either
   // of the above two possibilities.
-  NS_LooseHexToRGB(colorStr, &color);
-  SetColorValue(color, aString);
-  return PR_TRUE;
+  if (NS_LooseHexToRGB(colorStr, &color)) {
+    SetColorValue(color, aString);
+    return PR_TRUE;
+  }
+
+  return PR_FALSE;
 }
 
 PRBool nsAttrValue::ParseFloatValue(const nsAString& aString)
 {
   ResetIfSet();
 
   PRInt32 ec;
   float val = PromiseFlatString(aString).ToFloat(&ec);
--- a/content/base/src/nsAttrValue.h
+++ b/content/base/src/nsAttrValue.h
@@ -269,17 +269,18 @@ public:
    * http://dev.w3.org/html5/spec/common-dom-interfaces.html#limited-to-only-non-negative-numbers-greater-than-zero
    *
    * @param aString       the string to parse
    * @return              whether the value was valid
    */
   PRBool ParsePositiveIntValue(const nsAString& aString);
 
   /**
-   * Parse a string into a color.
+   * Parse a string into a color.  This implements what HTML5 calls the
+   * "rules for parsing a legacy color value".
    *
    * @param aString the string to parse
    * @param aDocument the document (to find out whether we're in quirks mode)
    * @return whether the value could be parsed
    */
   PRBool ParseColor(const nsAString& aString, nsIDocument* aDocument);
 
   /**
--- a/gfx/src/nsColor.cpp
+++ b/gfx/src/nsColor.cpp
@@ -163,16 +163,20 @@ NS_GFX_(PRBool) NS_HexToRGB(const nsStri
 
   // Improperly formatted color value
   return PR_FALSE;
 }
 
 // compatible with legacy Nav behavior
 NS_GFX_(PRBool) NS_LooseHexToRGB(const nsString& aColorSpec, nscolor* aResult)
 {
+  if (aColorSpec.EqualsLiteral("transparent")) {
+    return PR_FALSE;
+  }
+
   int nameLen = aColorSpec.Length();
   const PRUnichar* colorSpec = aColorSpec.get();
   if ('#' == colorSpec[0]) {
     ++colorSpec;
     --nameLen;
   }
 
   if (3 < nameLen) {