[Webkit-unassigned] [Bug 39140] Add support for 4 and 8 hexit CSS hexcolor values
bugzilla-daemon at webkit.org
bugzilla-daemon at webkit.org
Fri May 14 17:26:02 PDT 2010
https://bugs.webkit.org/show_bug.cgi?id=39140
--- Comment #7 from Michael Nordman <michaeln at google.com> 2010-05-14 17:26:01 PST ---
(From update of attachment 56120)
> Index: WebCore/ChangeLog
> ===================================================================
> --- WebCore/ChangeLog (revision 59490)
> +++ WebCore/ChangeLog (working copy)
> @@ -1,3 +1,16 @@
> +2010-05-14 Tab Atkins <tabatkins at google.com>
> +
> + Reviewed by NOBODY (OOPS!).
> +
> + Adds support for 4 and 8 hexit CSS hexcolors
> + https://bugs.webkit.org/show_bug.cgi?id=39140
> +
> + Tested by fast/css/4-or-8-hexit-colors.html
> +
> + * css/tokenizer.flex:
> + * platform/graphics/Color.cpp:
> + (WebCore::Color::parseHexColor):
> +
> 2010-05-14 Eric Seidel <eric at webkit.org>
>
> Unreviewed, rolling out r59489.
> Index: WebCore/platform/graphics/Color.cpp
> ===================================================================
> --- WebCore/platform/graphics/Color.cpp (revision 59365)
> +++ WebCore/platform/graphics/Color.cpp (working copy)
> @@ -129,21 +129,36 @@
> bool Color::parseHexColor(const String& name, RGBA32& rgb)
> {
> unsigned length = name.length();
> - if (length != 3 && length != 6)
> + if (length != 3 && length != 4 && length != 6 && length != 8)
> return false;
> unsigned value = 0;
> + unsigned alpha = 0;
> for (unsigned i = 0; i < length; ++i) {
> if (!isASCIIHexDigit(name[i]))
> return false;
> value <<= 4;
> value |= toASCIIHexValue(name[i]);
> }
> - if (length == 6) {
> - rgb = 0xFF000000 | value;
> +
> + if (length == 8) {
> + alpha = 0xFF & value;
> + value >>= 8;
> + }
> + if (length == 6)
> + alpha = 0xFF;
> + if (length == 4) {
> + alpha = 0xF & value;
> + value >>= 4;
> + }
> + if (length == 3)
> + alpha = 0xF;
> +
> + if (length == 6 || length == 8) {
> + rgb = alpha << 24 | value;
> return true;
> }
> - // #abc converts to #aabbcc
> - rgb = 0xFF000000
> + // #abc converts to #aabbcc, #abcd converts to #aabbccdd
> + rgb = alpha << 28 | alpha << 24
> | (value & 0xF00) << 12 | (value & 0xF00) << 8
> | (value & 0xF0) << 8 | (value & 0xF0) << 4
> | (value & 0xF) << 4 | (value & 0xF);
> Index: WebCore/css/tokenizer.flex
> ===================================================================
> --- WebCore/css/tokenizer.flex (revision 59365)
> +++ WebCore/css/tokenizer.flex (working copy)
> @@ -13,7 +13,7 @@
> nmchar [_a-zA-Z0-9-]|{nonascii}|{escape}
> string1 \"([\t !#$%&(-~]|\\{nl}|\'|{nonascii}|{escape})*\"
> string2 \'([\t !#$%&(-~]|\\{nl}|\"|{nonascii}|{escape})*\'
> -hexcolor {h}{3}|{h}{6}
> +hexcolor {h}{3}|{h}{4}|{h}{6}|{h}{8}
>
> ident -?{nmstart}{nmchar}*
> name {nmchar}+
> Index: LayoutTests/fast/css/script-tests/4-or-8-hexit-colors.js
> ===================================================================
> --- LayoutTests/fast/css/script-tests/4-or-8-hexit-colors.js (revision 0)
> +++ LayoutTests/fast/css/script-tests/4-or-8-hexit-colors.js (revision 0)
> @@ -0,0 +1,32 @@
> +description(
> +'This test checks if CSS 4-hexit and 8-hexit color values are handled correctly..'
> +);
> +
> +var inputs = ["#0000ffff",
> + "#0000ff00",
> + "#00ff",
> + "#00f0",
> + "#f00f",
> + "#0f0f",
> + "#ff0000ff",
> + "#00ff00ff",
> + "#0000ff80",
> + "#00f8"];
> +var expected = ["rgb(0, 0, 255)",
> + "rgba(0, 0, 255, 0)",
> + "rgb(0, 0, 255)",
> + "rgba(0, 0, 255, 0)",
> + "rgb(255, 0, 0)",
> + "rgb(0, 255, 0)",
> + "rgb(255, 0, 0)",
> + "rgb(0, 255, 0)",
> + "rgba(0, 0, 255, 0.5)",
> + "rgba(0, 0, 255, 0.53125)"];
> +
> +var testElement = document.createElement('div');
> +for (var i = 0; i < inputs.length; ++i) {
> + testElement.style.color = inputs[i];
> + shouldBeEqualToString('testElement.style.color = "' + inputs[i] + '"; testElement.style.color', expected[i]);
> +}
> +
> +successfullyParsed = true;
> Index: LayoutTests/fast/css/4-or-8-hexit-colors.html
> ===================================================================
> --- LayoutTests/fast/css/4-or-8-hexit-colors.html (revision 0)
> +++ LayoutTests/fast/css/4-or-8-hexit-colors.html (revision 0)
> @@ -0,0 +1,13 @@
> +<!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML//EN">
> +<html>
> +<head>
> +<link rel="stylesheet" href="../js/resources/js-test-style.css">
> +<script src="../js/resources/js-test-pre.js"></script>
> +</head>
> +<body>
> +<p id="description"></p>
> +<div id="console"></div>
> +<script src="script-tests/4-or-8-hexit-colors.js"></script>
> +<script src="../js/resources/js-test-post.js"></script>
> +</body>
> +</html>
> Index: LayoutTests/fast/css/4-or-8-hexit-colors-expected.txt
> ===================================================================
> --- LayoutTests/fast/css/4-or-8-hexit-colors-expected.txt (revision 0)
> +++ LayoutTests/fast/css/4-or-8-hexit-colors-expected.txt (revision 0)
> @@ -0,0 +1,38 @@
> +This test checks if CSS 4-hexit and 8-hexit color values are handled correctly..
+
> +
+
> +On success, you will see a series of "PASS" messages, followed by "TEST COMPLETE".
+
> +
+
> +
+
> +PASS testElement.style.color = "#0000ffff"; testElement.style.color is "rgb(0, 0, 255)"
+
> +PASS testElement.style.color = "#0000ff00"; testElement.style.color is "rgba(0, 0, 255, 0)"
+
> +PASS testElement.style.color = "#00ff"; testElement.style.color is "rgb(0, 0, 255)"
+
> +PASS testElement.style.color = "#00f0"; testElement.style.color is "rgba(0, 0, 255, 0)"
+
> +PASS testElement.style.color = "#f00f"; testElement.style.color is "rgb(255, 0, 0)"
+
> +PASS testElement.style.color = "#0f0f"; testElement.style.color is "rgb(0, 255, 0)"
+
> +PASS testElement.style.color = "#ff0000ff"; testElement.style.color is "rgb(255, 0, 0)"
+
> +PASS testElement.style.color = "#00ff00ff"; testElement.style.color is "rgb(0, 255, 0)"
+
> +PASS testElement.style.color = "#0000ff80"; testElement.style.color is "rgba(0, 0, 255, 0.5)"
+
> +PASS testElement.style.color = "#00f8"; testElement.style.color is "rgba(0, 0, 255, 0.53125)"
+
> +PASS successfullyParsed is true
+
> +
+
> +TEST COMPLETE
+
> +
+
> Index: LayoutTests/ChangeLog
> ===================================================================
> --- LayoutTests/ChangeLog (revision 59492)
> +++ LayoutTests/ChangeLog (working copy)
> @@ -1,3 +1,14 @@
> +2010-05-14 Tab Atkins <tabatkins at google.com>
> +
> + Reviewed by NOBODY (OOPS!).
> +
> + Tests for 4 and 8 hexit CSS hexcolors.
> + https://bugs.webkit.org/show_bug.cgi?id=39140
> +
> + * fast/css/4-or-8-hexit-colors-expected.txt: Added.
> + * fast/css/4-or-8-hexit-colors.html: Added.
> + * fast/css/script-tests/4-or-8-hexit-colors.js: Added.
> +
> 2010-05-14 Eric Seidel <eric at webkit.org>
>
> Unreviewed, rolling out r59489.
WebCore/platform/graphics/Color.cpp:154
+ alpha = 0xF;
Since only one of these branches will get taken, I'd use a construct that doesn't test for all of the conditions once that one branch is found. Either an if else or a switch maybe?
--
Configure bugmail: https://bugs.webkit.org/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
You are the assignee for the bug.
More information about the webkit-unassigned
mailing list