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

Unified Diff: third_party/WebKit/Source/platform/graphics/Color.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
« no previous file with comments | « third_party/WebKit/Source/core/html/HTMLElement.cpp ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: third_party/WebKit/Source/platform/graphics/Color.cpp
diff --git a/third_party/WebKit/Source/platform/graphics/Color.cpp b/third_party/WebKit/Source/platform/graphics/Color.cpp
index dc9364edbde2bea1f7c0a43392244b658f961551..aefac181936d30089ca11d4d0cc5cde04c203ad2 100644
--- a/third_party/WebKit/Source/platform/graphics/Color.cpp
+++ b/third_party/WebKit/Source/platform/graphics/Color.cpp
@@ -119,7 +119,7 @@ RGBA32 makeRGBAFromCMYKA(float c, float m, float y, float k, float a)
template <typename CharacterType>
static inline bool parseHexColorInternal(const CharacterType* name, unsigned length, RGBA32& rgb)
{
- if (length != 3 && length != 6)
+ if (length != 3 && length != 4 && length != 6 && length != 8)
return false;
unsigned value = 0;
for (unsigned i = 0; i < length; ++i) {
@@ -132,6 +132,20 @@ static inline bool parseHexColorInternal(const CharacterType* name, unsigned len
rgb = 0xFF000000 | value;
return true;
}
+ if (length == 8) {
+ // We parsed the values into RGBA order, but the RGBA32 type
+ // expects them to be in ARGB order, so we right rotate eight bits.
+ rgb = value << 24 | value >> 8;
+ return true;
+ }
+ if (length == 4) {
+ // #abcd converts to ddaabbcc in RGBA32.
+ rgb = (value & 0xF) << 28 | (value & 0xF) << 24
+ | (value & 0xF000) << 8 | (value & 0xF000) << 4
+ | (value & 0xF00) << 4 | (value & 0xF00)
+ | (value & 0xF0) | (value & 0xF0) >> 4;
+ return true;
+ }
// #abc converts to #aabbcc
rgb = 0xFF000000
| (value & 0xF00) << 12 | (value & 0xF00) << 8
« no previous file with comments | « third_party/WebKit/Source/core/html/HTMLElement.cpp ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698