Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(31)

Unified Diff: third_party/WebKit/Source/core/html/HTMLElement.cpp

Issue 1936913002: [CSS] Accept 8 (#RRGGBBAA) and 4 (#RGBA) value hex colors (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Add quirks mode fastParseColorInternal() test cases. Created 4 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: third_party/WebKit/Source/core/html/HTMLElement.cpp
diff --git a/third_party/WebKit/Source/core/html/HTMLElement.cpp b/third_party/WebKit/Source/core/html/HTMLElement.cpp
index 6315b9278f5133ba3187559df498d20f6070aa9b..428b7c8a8c0610c1f390cf3332eb7f3a199ab1ad 100644
--- a/third_party/WebKit/Source/core/html/HTMLElement.cpp
+++ b/third_party/WebKit/Source/core/html/HTMLElement.cpp
@@ -925,12 +925,20 @@ void HTMLElement::addHTMLColorToStyle(MutableStylePropertySet* style, CSSPropert
if (equalIgnoringCase(colorString, "transparent"))
return;
- // If the string is a named CSS color or a 3/6-digit hex color, use that.
- Color parsedColor;
- if (!parsedColor.setFromString(colorString))
- parsedColor.setRGB(parseColorStringWithCrazyLegacyRules(colorString));
+ Color color;
- style->setProperty(propertyID, cssValuePool().createColorValue(parsedColor.rgb()));
+ // If the string is a 3/6-digit hex color or a named CSS color, use that. Apply legacy rules otherwise. Note color.setFromString()
+ // accepts 4/8-digit hex color, so restrict its use with length checks here to support legacy HTML attributes.
+
+ bool success = false;
+ if ((colorString.length() == 4 || colorString.length() == 7) && colorString[0] == '#')
+ success = color.setFromString(colorString);
+ if (!success)
+ success = color.setNamedColor(colorString);
+ if (!success)
+ color.setRGB(parseColorStringWithCrazyLegacyRules(colorString));
+
+ style->setProperty(propertyID, cssValuePool().createColorValue(color.rgb()));
}
bool HTMLElement::isInteractiveContent() const

Powered by Google App Engine
This is Rietveld 408576698