<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN"
"http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head><meta http-equiv="content-type" content="text/html; charset=utf-8" />
<title>[208060] trunk/Source/WebCore</title>
</head>
<body>

<style type="text/css"><!--
#msg dl.meta { border: 1px #006 solid; background: #369; padding: 6px; color: #fff; }
#msg dl.meta dt { float: left; width: 6em; font-weight: bold; }
#msg dt:after { content:':';}
#msg dl, #msg dt, #msg ul, #msg li, #header, #footer, #logmsg { font-family: verdana,arial,helvetica,sans-serif; font-size: 10pt;  }
#msg dl a { font-weight: bold}
#msg dl a:link    { color:#fc3; }
#msg dl a:active  { color:#ff0; }
#msg dl a:visited { color:#cc6; }
h3 { font-family: verdana,arial,helvetica,sans-serif; font-size: 10pt; font-weight: bold; }
#msg pre { overflow: auto; background: #ffc; border: 1px #fa0 solid; padding: 6px; }
#logmsg { background: #ffc; border: 1px #fa0 solid; padding: 1em 1em 0 1em; }
#logmsg p, #logmsg pre, #logmsg blockquote { margin: 0 0 1em 0; }
#logmsg p, #logmsg li, #logmsg dt, #logmsg dd { line-height: 14pt; }
#logmsg h1, #logmsg h2, #logmsg h3, #logmsg h4, #logmsg h5, #logmsg h6 { margin: .5em 0; }
#logmsg h1:first-child, #logmsg h2:first-child, #logmsg h3:first-child, #logmsg h4:first-child, #logmsg h5:first-child, #logmsg h6:first-child { margin-top: 0; }
#logmsg ul, #logmsg ol { padding: 0; list-style-position: inside; margin: 0 0 0 1em; }
#logmsg ul { text-indent: -1em; padding-left: 1em; }#logmsg ol { text-indent: -1.5em; padding-left: 1.5em; }
#logmsg > ul, #logmsg > ol { margin: 0 0 1em 0; }
#logmsg pre { background: #eee; padding: 1em; }
#logmsg blockquote { border: 1px solid #fa0; border-left-width: 10px; padding: 1em 1em 0 1em; background: white;}
#logmsg dl { margin: 0; }
#logmsg dt { font-weight: bold; }
#logmsg dd { margin: 0; padding: 0 0 0.5em 0; }
#logmsg dd:before { content:'\00bb';}
#logmsg table { border-spacing: 0px; border-collapse: collapse; border-top: 4px solid #fa0; border-bottom: 1px solid #fa0; background: #fff; }
#logmsg table th { text-align: left; font-weight: normal; padding: 0.2em 0.5em; border-top: 1px dotted #fa0; }
#logmsg table td { text-align: right; border-top: 1px dotted #fa0; padding: 0.2em 0.5em; }
#logmsg table thead th { text-align: center; border-bottom: 1px solid #fa0; }
#logmsg table th.Corner { text-align: left; }
#logmsg hr { border: none 0; border-top: 2px dashed #fa0; height: 1px; }
#header, #footer { color: #fff; background: #636; border: 1px #300 solid; padding: 6px; }
#patch { width: 100%; }
#patch h4 {font-family: verdana,arial,helvetica,sans-serif;font-size:10pt;padding:8px;background:#369;color:#fff;margin:0;}
#patch .propset h4, #patch .binary h4 {margin:0;}
#patch pre {padding:0;line-height:1.2em;margin:0;}
#patch .diff {width:100%;background:#eee;padding: 0 0 10px 0;overflow:auto;}
#patch .propset .diff, #patch .binary .diff  {padding:10px 0;}
#patch span {display:block;padding:0 10px;}
#patch .modfile, #patch .addfile, #patch .delfile, #patch .propset, #patch .binary, #patch .copfile {border:1px solid #ccc;margin:10px 0;}
#patch ins {background:#dfd;text-decoration:none;display:block;padding:0 10px;}
#patch del {background:#fdd;text-decoration:none;display:block;padding:0 10px;}
#patch .lines, .info {color:#888;background:#fff;}
--></style>
<div id="msg">
<dl class="meta">
<dt>Revision</dt> <dd><a href="http://trac.webkit.org/projects/webkit/changeset/208060">208060</a></dd>
<dt>Author</dt> <dd>dino@apple.com</dd>
<dt>Date</dt> <dd>2016-10-28 11:53:49 -0700 (Fri, 28 Oct 2016)</dd>
</dl>

<h3>Log Message</h3>
<pre>New CSS Parser should use Colors not RGBA32s
https://bugs.webkit.org/show_bug.cgi?id=164124
&lt;rdar://problem/29000373&gt;

Reviewed by Darin Adler.

The old parser has moved from using RGBA32 values to using
Colors directly. This was so we could support ExtendedColors
via the new color() syntax.

Update the new CSS parser to do the same.

* css/parser/CSSPropertyParserHelpers.cpp:
(WebCore::CSSPropertyParserHelpers::parseRGBParameters):
(WebCore::CSSPropertyParserHelpers::parseHSLParameters):
(WebCore::CSSPropertyParserHelpers::parseHexColor):
(WebCore::CSSPropertyParserHelpers::parseColorFunction):
(WebCore::CSSPropertyParserHelpers::consumeColor):</pre>

<h3>Modified Paths</h3>
<ul>
<li><a href="#trunkSourceWebCoreChangeLog">trunk/Source/WebCore/ChangeLog</a></li>
<li><a href="#trunkSourceWebCorecssparserCSSPropertyParserHelperscpp">trunk/Source/WebCore/css/parser/CSSPropertyParserHelpers.cpp</a></li>
</ul>

</div>
<div id="patch">
<h3>Diff</h3>
<a id="trunkSourceWebCoreChangeLog"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/ChangeLog (208059 => 208060)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/ChangeLog        2016-10-28 18:49:43 UTC (rev 208059)
+++ trunk/Source/WebCore/ChangeLog        2016-10-28 18:53:49 UTC (rev 208060)
</span><span class="lines">@@ -1,5 +1,26 @@
</span><span class="cx"> 2016-10-28  Dean Jackson  &lt;dino@apple.com&gt;
</span><span class="cx"> 
</span><ins>+        New CSS Parser should use Colors not RGBA32s
+        https://bugs.webkit.org/show_bug.cgi?id=164124
+        &lt;rdar://problem/29000373&gt;
+
+        Reviewed by Darin Adler.
+
+        The old parser has moved from using RGBA32 values to using
+        Colors directly. This was so we could support ExtendedColors
+        via the new color() syntax.
+
+        Update the new CSS parser to do the same.
+
+        * css/parser/CSSPropertyParserHelpers.cpp:
+        (WebCore::CSSPropertyParserHelpers::parseRGBParameters):
+        (WebCore::CSSPropertyParserHelpers::parseHSLParameters):
+        (WebCore::CSSPropertyParserHelpers::parseHexColor):
+        (WebCore::CSSPropertyParserHelpers::parseColorFunction):
+        (WebCore::CSSPropertyParserHelpers::consumeColor):
+
+2016-10-28  Dean Jackson  &lt;dino@apple.com&gt;
+
</ins><span class="cx">         Allow new CSS parser to handle insertRule, etc via parseRule
</span><span class="cx">         https://bugs.webkit.org/show_bug.cgi?id=164122
</span><span class="cx">         &lt;rdar://problem/29000101&gt;
</span></span></pre></div>
<a id="trunkSourceWebCorecssparserCSSPropertyParserHelperscpp"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/css/parser/CSSPropertyParserHelpers.cpp (208059 => 208060)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/css/parser/CSSPropertyParserHelpers.cpp        2016-10-28 18:49:43 UTC (rev 208059)
+++ trunk/Source/WebCore/css/parser/CSSPropertyParserHelpers.cpp        2016-10-28 18:53:49 UTC (rev 208060)
</span><span class="lines">@@ -389,57 +389,62 @@
</span><span class="cx">     return clampTo&lt;int&gt;(result, 0, 255);
</span><span class="cx"> }
</span><span class="cx"> 
</span><del>-static bool parseRGBParameters(CSSParserTokenRange&amp; range, RGBA32&amp; result, bool parseAlpha)
</del><ins>+static Color parseRGBParameters(CSSParserTokenRange&amp; range, bool parseAlpha)
</ins><span class="cx"> {
</span><span class="cx">     ASSERT(range.peek().functionId() == CSSValueRgb || range.peek().functionId() == CSSValueRgba);
</span><ins>+    Color result;
</ins><span class="cx">     CSSParserTokenRange args = consumeFunction(range);
</span><span class="cx">     RefPtr&lt;CSSPrimitiveValue&gt; colorParameter = consumeInteger(args);
</span><span class="cx">     if (!colorParameter)
</span><span class="cx">         colorParameter = consumePercent(args, ValueRangeAll);
</span><span class="cx">     if (!colorParameter)
</span><del>-        return false;
</del><ins>+        return Color();
</ins><span class="cx">     const bool isPercent = colorParameter-&gt;isPercentage();
</span><span class="cx">     int colorArray[3];
</span><span class="cx">     colorArray[0] = clampRGBComponent(*colorParameter);
</span><span class="cx">     for (int i = 1; i &lt; 3; i++) {
</span><span class="cx">         if (!consumeCommaIncludingWhitespace(args))
</span><del>-            return false;
</del><ins>+            return Color();
</ins><span class="cx">         colorParameter = isPercent ? consumePercent(args, ValueRangeAll) : consumeInteger(args);
</span><span class="cx">         if (!colorParameter)
</span><del>-            return false;
</del><ins>+            return Color();
</ins><span class="cx">         colorArray[i] = clampRGBComponent(*colorParameter);
</span><span class="cx">     }
</span><span class="cx">     if (parseAlpha) {
</span><span class="cx">         if (!consumeCommaIncludingWhitespace(args))
</span><del>-            return false;
</del><ins>+            return Color();
</ins><span class="cx">         double alpha;
</span><span class="cx">         if (!consumeNumberRaw(args, alpha))
</span><del>-            return false;
</del><ins>+            return Color();
</ins><span class="cx">         // Convert the floating pointer number of alpha to an integer in the range [0, 256),
</span><span class="cx">         // with an equal distribution across all 256 values.
</span><span class="cx">         int alphaComponent = static_cast&lt;int&gt;(clampTo&lt;double&gt;(alpha, 0.0, 1.0) * nextafter(256.0, 0.0));
</span><del>-        result = makeRGBA(colorArray[0], colorArray[1], colorArray[2], alphaComponent);
</del><ins>+        result = Color(makeRGBA(colorArray[0], colorArray[1], colorArray[2], alphaComponent));
</ins><span class="cx">     } else {
</span><del>-        result = makeRGB(colorArray[0], colorArray[1], colorArray[2]);
</del><ins>+        result = Color(makeRGB(colorArray[0], colorArray[1], colorArray[2]));
</ins><span class="cx">     }
</span><del>-    return args.atEnd();
</del><ins>+
+    if (!args.atEnd())
+        return Color();
+
+    return result;
</ins><span class="cx"> }
</span><span class="cx"> 
</span><del>-static bool parseHSLParameters(CSSParserTokenRange&amp; range, RGBA32&amp; result, bool parseAlpha)
</del><ins>+static Color parseHSLParameters(CSSParserTokenRange&amp; range, bool parseAlpha)
</ins><span class="cx"> {
</span><span class="cx">     ASSERT(range.peek().functionId() == CSSValueHsl || range.peek().functionId() == CSSValueHsla);
</span><span class="cx">     CSSParserTokenRange args = consumeFunction(range);
</span><span class="cx">     RefPtr&lt;CSSPrimitiveValue&gt; hslValue = consumeNumber(args, ValueRangeAll);
</span><span class="cx">     if (!hslValue)
</span><del>-        return false;
</del><ins>+        return Color();
</ins><span class="cx">     double colorArray[3];
</span><span class="cx">     colorArray[0] = (((hslValue-&gt;intValue() % 360) + 360) % 360) / 360.0;
</span><span class="cx">     for (int i = 1; i &lt; 3; i++) {
</span><span class="cx">         if (!consumeCommaIncludingWhitespace(args))
</span><del>-            return false;
</del><ins>+            return Color();
</ins><span class="cx">         hslValue = consumePercent(args, ValueRangeAll);
</span><span class="cx">         if (!hslValue)
</span><del>-            return false;
</del><ins>+            return Color();
</ins><span class="cx">         double doubleValue = hslValue-&gt;doubleValue();
</span><span class="cx">         colorArray[i] = clampTo&lt;double&gt;(doubleValue, 0.0, 100.0) / 100.0; // Needs to be value between 0 and 1.0.
</span><span class="cx">     }
</span><span class="lines">@@ -446,27 +451,31 @@
</span><span class="cx">     double alpha = 1.0;
</span><span class="cx">     if (parseAlpha) {
</span><span class="cx">         if (!consumeCommaIncludingWhitespace(args))
</span><del>-            return false;
</del><ins>+            return Color();
</ins><span class="cx">         if (!consumeNumberRaw(args, alpha))
</span><del>-            return false;
</del><ins>+            return Color();
</ins><span class="cx">         alpha = clampTo&lt;double&gt;(alpha, 0.0, 1.0);
</span><span class="cx">     }
</span><del>-    result = makeRGBAFromHSLA(colorArray[0], colorArray[1], colorArray[2], alpha);
-    return args.atEnd();
</del><ins>+
+    if (!args.atEnd())
+        return Color();
+
+    return Color(makeRGBAFromHSLA(colorArray[0], colorArray[1], colorArray[2], alpha));
</ins><span class="cx"> }
</span><span class="cx"> 
</span><del>-static bool parseHexColor(CSSParserTokenRange&amp; range, RGBA32&amp; result, bool acceptQuirkyColors)
</del><ins>+static Color parseHexColor(CSSParserTokenRange&amp; range, bool acceptQuirkyColors)
</ins><span class="cx"> {
</span><ins>+    RGBA32 result;
</ins><span class="cx">     const CSSParserToken&amp; token = range.peek();
</span><span class="cx">     if (token.type() == HashToken) {
</span><span class="cx">         if (!Color::parseHexColor(token.value(), result))
</span><del>-            return false;
</del><ins>+            return Color();
</ins><span class="cx">     } else if (acceptQuirkyColors) {
</span><span class="cx">         String color;
</span><span class="cx">         if (token.type() == NumberToken || token.type() == DimensionToken) {
</span><span class="cx">             if (token.numericValueType() != IntegerValueType
</span><span class="cx">                 || token.numericValue() &lt; 0. || token.numericValue() &gt;= 1000000.)
</span><del>-                return false;
</del><ins>+                return Color();
</ins><span class="cx">             if (token.type() == NumberToken) // e.g. 112233
</span><span class="cx">                 color = String::format(&quot;%d&quot;, static_cast&lt;int&gt;(token.numericValue()));
</span><span class="cx">             else // e.g. 0001FF
</span><span class="lines">@@ -478,27 +487,38 @@
</span><span class="cx">         }
</span><span class="cx">         unsigned length = color.length();
</span><span class="cx">         if (length != 3 &amp;&amp; length != 6)
</span><del>-            return false;
</del><ins>+            return Color();
</ins><span class="cx">         if (!Color::parseHexColor(color, result))
</span><del>-            return false;
</del><ins>+            return Color();
</ins><span class="cx">     } else {
</span><del>-        return false;
</del><ins>+        return Color();
</ins><span class="cx">     }
</span><span class="cx">     range.consumeIncludingWhitespace();
</span><del>-    return true;
</del><ins>+    return Color(result);
</ins><span class="cx"> }
</span><span class="cx"> 
</span><del>-static bool parseColorFunction(CSSParserTokenRange&amp; range, RGBA32&amp; result)
</del><ins>+static Color parseColorFunction(CSSParserTokenRange&amp; range)
</ins><span class="cx"> {
</span><ins>+    CSSParserTokenRange colorRange = range;
</ins><span class="cx">     CSSValueID functionId = range.peek().functionId();
</span><del>-    if (functionId &lt; CSSValueRgb || functionId &gt; CSSValueHsla)
-        return false;
-    CSSParserTokenRange colorRange = range;
-    if ((functionId &lt;= CSSValueRgba &amp;&amp; !parseRGBParameters(colorRange, result, functionId == CSSValueRgba))
-        || (functionId &gt;= CSSValueHsl &amp;&amp; !parseHSLParameters(colorRange, result, functionId == CSSValueHsla)))
-        return false;
</del><ins>+    Color color;
+    switch (functionId) {
+    case CSSValueRgb:
+    case CSSValueRgba:
+        color = parseRGBParameters(colorRange, functionId == CSSValueRgba);
+        break;
+    case CSSValueHsl:
+    case CSSValueHsla:
+        color = parseHSLParameters(colorRange, functionId == CSSValueHsla);
+        break;
+    case CSSValueColor:
+        // FIXME-NEWPARSER: Add support for color().
+        return Color();
+    default:
+        return Color();
+    }
</ins><span class="cx">     range = colorRange;
</span><del>-    return true;
</del><ins>+    return color;
</ins><span class="cx"> }
</span><span class="cx"> 
</span><span class="cx"> RefPtr&lt;CSSPrimitiveValue&gt; consumeColor(CSSParserTokenRange&amp; range, CSSParserMode cssParserMode, bool acceptQuirkyColors)
</span><span class="lines">@@ -509,10 +529,12 @@
</span><span class="cx">             return nullptr;
</span><span class="cx">         return consumeIdent(range);
</span><span class="cx">     }
</span><del>-    RGBA32 color = Color::transparent;
-    if (!parseHexColor(range, color, acceptQuirkyColors) &amp;&amp; !parseColorFunction(range, color))
</del><ins>+    Color color = parseHexColor(range, acceptQuirkyColors);
+    if (!color.isValid())
+        color = parseColorFunction(range);
+    if (!color.isValid())
</ins><span class="cx">         return nullptr;
</span><del>-    return CSSValuePool::singleton().createValue(Color(color));
</del><ins>+    return CSSValuePool::singleton().createValue(color);
</ins><span class="cx"> }
</span><span class="cx"> 
</span><span class="cx"> static RefPtr&lt;CSSPrimitiveValue&gt; consumePositionComponent(CSSParserTokenRange&amp; range, CSSParserMode cssParserMode, UnitlessQuirk unitless)
</span></span></pre>
</div>
</div>

</body>
</html>