Title: [101870] trunk/Source/WebCore
Revision
101870
Author
kl...@webkit.org
Date
2011-12-02 15:48:34 -0800 (Fri, 02 Dec 2011)

Log Message

StyledElement: Simplify addCSSColor().
<http://webkit.org/b/73703>

Reviewed by Darin Adler.

The Color(const String&) constructor handles both named and 3/6-digit
hex colors, so there's no need to handle those separately here.
Also tweaked some comments and minor things.

* dom/StyledElement.cpp:
(WebCore::StyledElement::addCSSColor):

Modified Paths

Diff

Modified: trunk/Source/WebCore/ChangeLog (101869 => 101870)


--- trunk/Source/WebCore/ChangeLog	2011-12-02 23:45:39 UTC (rev 101869)
+++ trunk/Source/WebCore/ChangeLog	2011-12-02 23:48:34 UTC (rev 101870)
@@ -1,3 +1,17 @@
+2011-12-02  Andreas Kling  <kl...@webkit.org>
+
+        StyledElement: Simplify addCSSColor().
+        <http://webkit.org/b/73703>
+
+        Reviewed by Darin Adler.
+
+        The Color(const String&) constructor handles both named and 3/6-digit
+        hex colors, so there's no need to handle those separately here.
+        Also tweaked some comments and minor things.
+
+        * dom/StyledElement.cpp:
+        (WebCore::StyledElement::addCSSColor):
+
 2011-12-02  Benjamin Poulain  <bpoul...@apple.com>
 
         Update platform/iphone to platform/ios

Modified: trunk/Source/WebCore/dom/StyledElement.cpp (101869 => 101870)


--- trunk/Source/WebCore/dom/StyledElement.cpp	2011-12-02 23:45:39 UTC (rev 101869)
+++ trunk/Source/WebCore/dom/StyledElement.cpp	2011-12-02 23:48:34 UTC (rev 101870)
@@ -371,32 +371,27 @@
 // Color parsing that matches HTML's "rules for parsing a legacy color value"
 void StyledElement::addCSSColor(Attribute* attribute, int id, const String& attributeValue)
 {
-    // The empty string doesn't apply a color. (Just whitespace does, which is why this check occurs before trimming.)
-    if (!attributeValue.length())
+    // An empty string doesn't apply a color. (One containing only whitespace does, which is why this check occurs before stripping.)
+    if (attributeValue.isEmpty())
         return;
-    
-    String color = attributeValue.stripWhiteSpace();
 
+    String colorString = attributeValue.stripWhiteSpace();
+
     // "transparent" doesn't apply a color either.
-    if (equalIgnoringCase(color, "transparent"))
+    if (equalIgnoringCase(colorString, "transparent"))
         return;
 
     if (!attribute->decl())
         createMappedDecl(attribute);
 
-    // If the string is a named CSS color, use that color.
-    Color foundColor;
-    foundColor.setNamedColor(color);
-    if (foundColor.isValid()) {
-        attribute->decl()->setProperty(id, color, false);
+    // If the string is a named CSS color or a 3/6-digit hex color, use that.
+    Color parsedColor(colorString);
+    if (parsedColor.isValid()) {
+        attribute->decl()->setProperty(id, colorString, false);
         return;
     }
 
-    // If the string is a 3 or 6-digit hex color, use that color.
-    if (color[0] == '#' && (color.length() == 4 || color.length() == 7) && attribute->decl()->setProperty(id, color, false))
-        return;
-
-    attribute->decl()->setProperty(id, parseColorStringWithCrazyLegacyRules(color), false);
+    attribute->decl()->setProperty(id, parseColorStringWithCrazyLegacyRules(colorString), false);
 }
 
 void StyledElement::createMappedDecl(Attribute* attr)
_______________________________________________
webkit-changes mailing list
webkit-changes@lists.webkit.org
http://lists.webkit.org/mailman/listinfo.cgi/webkit-changes

Reply via email to