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

Side by Side 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 unified diff | Download patch
« no previous file with comments | « third_party/WebKit/Source/core/html/HTMLElement.cpp ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 /* 1 /*
2 * Copyright (C) 2003, 2004, 2005, 2006, 2008 Apple Inc. All rights reserved. 2 * Copyright (C) 2003, 2004, 2005, 2006, 2008 Apple Inc. All rights reserved.
3 * 3 *
4 * Redistribution and use in source and binary forms, with or without 4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions 5 * modification, are permitted provided that the following conditions
6 * are met: 6 * are met:
7 * 1. Redistributions of source code must retain the above copyright 7 * 1. Redistributions of source code must retain the above copyright
8 * notice, this list of conditions and the following disclaimer. 8 * notice, this list of conditions and the following disclaimer.
9 * 2. Redistributions in binary form must reproduce the above copyright 9 * 2. Redistributions in binary form must reproduce the above copyright
10 * notice, this list of conditions and the following disclaimer in the 10 * notice, this list of conditions and the following disclaimer in the
(...skipping 101 matching lines...) Expand 10 before | Expand all | Expand 10 after
112 int r = static_cast<int>(nextafter(256, 0) * (colors * (1 - c))); 112 int r = static_cast<int>(nextafter(256, 0) * (colors * (1 - c)));
113 int g = static_cast<int>(nextafter(256, 0) * (colors * (1 - m))); 113 int g = static_cast<int>(nextafter(256, 0) * (colors * (1 - m)));
114 int b = static_cast<int>(nextafter(256, 0) * (colors * (1 - y))); 114 int b = static_cast<int>(nextafter(256, 0) * (colors * (1 - y)));
115 return makeRGBA(r, g, b, static_cast<float>(nextafter(256, 0) * a)); 115 return makeRGBA(r, g, b, static_cast<float>(nextafter(256, 0) * a));
116 } 116 }
117 117
118 // originally moved here from the CSS parser 118 // originally moved here from the CSS parser
119 template <typename CharacterType> 119 template <typename CharacterType>
120 static inline bool parseHexColorInternal(const CharacterType* name, unsigned len gth, RGBA32& rgb) 120 static inline bool parseHexColorInternal(const CharacterType* name, unsigned len gth, RGBA32& rgb)
121 { 121 {
122 if (length != 3 && length != 6) 122 if (length != 3 && length != 4 && length != 6 && length != 8)
123 return false; 123 return false;
124 unsigned value = 0; 124 unsigned value = 0;
125 for (unsigned i = 0; i < length; ++i) { 125 for (unsigned i = 0; i < length; ++i) {
126 if (!isASCIIHexDigit(name[i])) 126 if (!isASCIIHexDigit(name[i]))
127 return false; 127 return false;
128 value <<= 4; 128 value <<= 4;
129 value |= toASCIIHexValue(name[i]); 129 value |= toASCIIHexValue(name[i]);
130 } 130 }
131 if (length == 6) { 131 if (length == 6) {
132 rgb = 0xFF000000 | value; 132 rgb = 0xFF000000 | value;
133 return true; 133 return true;
134 } 134 }
135 if (length == 8) {
136 // We parsed the values into RGBA order, but the RGBA32 type
137 // expects them to be in ARGB order, so we right rotate eight bits.
138 rgb = value << 24 | value >> 8;
139 return true;
140 }
141 if (length == 4) {
142 // #abcd converts to ddaabbcc in RGBA32.
143 rgb = (value & 0xF) << 28 | (value & 0xF) << 24
144 | (value & 0xF000) << 8 | (value & 0xF000) << 4
145 | (value & 0xF00) << 4 | (value & 0xF00)
146 | (value & 0xF0) | (value & 0xF0) >> 4;
147 return true;
148 }
135 // #abc converts to #aabbcc 149 // #abc converts to #aabbcc
136 rgb = 0xFF000000 150 rgb = 0xFF000000
137 | (value & 0xF00) << 12 | (value & 0xF00) << 8 151 | (value & 0xF00) << 12 | (value & 0xF00) << 8
138 | (value & 0xF0) << 8 | (value & 0xF0) << 4 152 | (value & 0xF0) << 8 | (value & 0xF0) << 4
139 | (value & 0xF) << 4 | (value & 0xF); 153 | (value & 0xF) << 4 | (value & 0xF);
140 return true; 154 return true;
141 } 155 }
142 156
143 bool Color::parseHexColor(const LChar* name, unsigned length, RGBA32& rgb) 157 bool Color::parseHexColor(const LChar* name, unsigned length, RGBA32& rgb)
144 { 158 {
(...skipping 303 matching lines...) Expand 10 before | Expand all | Expand 10 after
448 (color.green() * alpha + 254) / 255, 462 (color.green() * alpha + 254) / 255,
449 (color.blue() * alpha + 254) / 255, 463 (color.blue() * alpha + 254) / 255,
450 alpha).rgb(); 464 alpha).rgb();
451 } else 465 } else
452 pixelColor = color.rgb(); 466 pixelColor = color.rgb();
453 467
454 return pixelColor; 468 return pixelColor;
455 } 469 }
456 470
457 } // namespace blink 471 } // namespace blink
OLDNEW
« 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