Title: [271866] trunk
Revision
271866
Author
wei...@apple.com
Date
2021-01-25 15:32:13 -0800 (Mon, 25 Jan 2021)

Log Message

Support percentages when parsing color(srgb ...) and color(display-p3 ...) per-spec
https://bugs.webkit.org/show_bug.cgi?id=220940

Reviewed by Simon Fraser.

Add support for using percentages when using the color(srgb ) and color(display-p3 ) syntax. Also
fix color(lab ) to allow elliding parameters and defaulting them to 0 as per-spec.

Source/WebCore:

Unfails some WPT tests and adds additional parsing tests for lab to fast/css/parsing-lab-colors.html

* css/parser/CSSPropertyParserHelpers.cpp:
(WebCore::CSSPropertyParserHelpers::parseColorFunctionForSRGBOrDisplayP3Parameters):
(WebCore::CSSPropertyParserHelpers::parseColorFunctionForLabParameters):

LayoutTests:

* TestExpectations:
* fast/css/parsing-lab-colors-expected.txt:
* fast/css/parsing-lab-colors.html:

Modified Paths

Diff

Modified: trunk/LayoutTests/ChangeLog (271865 => 271866)


--- trunk/LayoutTests/ChangeLog	2021-01-25 23:14:11 UTC (rev 271865)
+++ trunk/LayoutTests/ChangeLog	2021-01-25 23:32:13 UTC (rev 271866)
@@ -1,3 +1,17 @@
+2021-01-25  Sam Weinig  <wei...@apple.com>
+
+        Support percentages when parsing color(srgb ...) and color(display-p3 ...) per-spec
+        https://bugs.webkit.org/show_bug.cgi?id=220940
+
+        Reviewed by Simon Fraser.
+
+        Add support for using percentages when using the color(srgb ) and color(display-p3 ) syntax. Also
+        fix color(lab ) to allow elliding parameters and defaulting them to 0 as per-spec.
+
+        * TestExpectations:
+        * fast/css/parsing-lab-colors-expected.txt:
+        * fast/css/parsing-lab-colors.html:
+
 2021-01-25  Aditya Keerthi  <akeer...@apple.com>
 
         [iOS] Obscured elements should not be focusable using the accessory bar

Modified: trunk/LayoutTests/TestExpectations (271865 => 271866)


--- trunk/LayoutTests/TestExpectations	2021-01-25 23:14:11 UTC (rev 271865)
+++ trunk/LayoutTests/TestExpectations	2021-01-25 23:32:13 UTC (rev 271866)
@@ -4576,17 +4576,15 @@
 webkit.org/b/220325 http/wpt/css/css-highlight-api/highlight-text-cascade.html [ ImageOnlyFailure ]
 
 # Unsupported css color() variants
-webkit.org/b/220928 imported/w3c/web-platform-tests/css/css-color/predefined-002.html [ ImageOnlyFailure ]
-webkit.org/b/220928 imported/w3c/web-platform-tests/css/css-color/predefined-003.html [ ImageOnlyFailure ]
-webkit.org/b/220928 imported/w3c/web-platform-tests/css/css-color/predefined-004.html [ ImageOnlyFailure ]
-webkit.org/b/220928 imported/w3c/web-platform-tests/css/css-color/predefined-006.html [ ImageOnlyFailure ]
-webkit.org/b/220928 imported/w3c/web-platform-tests/css/css-color/predefined-007.html [ ImageOnlyFailure ]
-webkit.org/b/220928 imported/w3c/web-platform-tests/css/css-color/predefined-008.html [ ImageOnlyFailure ]
-webkit.org/b/220928 imported/w3c/web-platform-tests/css/css-color/predefined-009.html [ ImageOnlyFailure ]
-webkit.org/b/220928 imported/w3c/web-platform-tests/css/css-color/predefined-010.html [ ImageOnlyFailure ]
-webkit.org/b/220928 imported/w3c/web-platform-tests/css/css-color/predefined-011.html [ ImageOnlyFailure ]
-webkit.org/b/220928 imported/w3c/web-platform-tests/css/css-color/predefined-012.html [ ImageOnlyFailure ]
-webkit.org/b/220928 imported/w3c/web-platform-tests/css/css-color/predefined-014.html [ ImageOnlyFailure ]
-webkit.org/b/220928 imported/w3c/web-platform-tests/css/css-color/predefined-015.html [ ImageOnlyFailure ]
-webkit.org/b/220928 imported/w3c/web-platform-tests/css/css-color/predefined-016.html [ ImageOnlyFailure ]
-webkit.org/b/220928 imported/w3c/web-platform-tests/css/css-color/predefined-017.html [ ImageOnlyFailure ]
+webkit.org/b/220928 imported/w3c/web-platform-tests/css/css-color/predefined-003.html [ ImageOnlyFailure ] # Invalid test, no colorspace specified
+webkit.org/b/220928 imported/w3c/web-platform-tests/css/css-color/predefined-004.html [ ImageOnlyFailure ] # Invalid test, no colorspace specified
+webkit.org/b/220928 imported/w3c/web-platform-tests/css/css-color/predefined-007.html [ ImageOnlyFailure ] # Requires a98-rgb support
+webkit.org/b/220928 imported/w3c/web-platform-tests/css/css-color/predefined-008.html [ ImageOnlyFailure ] # Requires a98-rgb support
+webkit.org/b/220928 imported/w3c/web-platform-tests/css/css-color/predefined-009.html [ ImageOnlyFailure ] # Requires prophoto-rgb support
+webkit.org/b/220928 imported/w3c/web-platform-tests/css/css-color/predefined-010.html [ ImageOnlyFailure ] # Requires prophoto-rgb support
+webkit.org/b/220928 imported/w3c/web-platform-tests/css/css-color/predefined-011.html [ ImageOnlyFailure ] # Requires rec2020 support
+webkit.org/b/220928 imported/w3c/web-platform-tests/css/css-color/predefined-012.html [ ImageOnlyFailure ] # Requires rec2020 support
+webkit.org/b/220928 imported/w3c/web-platform-tests/css/css-color/predefined-014.html [ ImageOnlyFailure ] # Requires fallback (at parse time) support
+webkit.org/b/220928 imported/w3c/web-platform-tests/css/css-color/predefined-015.html [ ImageOnlyFailure ] # Requires fallback (at parse time) support (unclear if this makes sense)
+webkit.org/b/220928 imported/w3c/web-platform-tests/css/css-color/predefined-016.html [ ImageOnlyFailure ] # Requires xyz support
+webkit.org/b/220928 imported/w3c/web-platform-tests/css/css-color/predefined-017.html [ ImageOnlyFailure ] # Requires xyz support

Modified: trunk/LayoutTests/fast/css/parsing-lab-colors-expected.txt (271865 => 271866)


--- trunk/LayoutTests/fast/css/parsing-lab-colors-expected.txt	2021-01-25 23:14:11 UTC (rev 271865)
+++ trunk/LayoutTests/fast/css/parsing-lab-colors-expected.txt	2021-01-25 23:32:13 UTC (rev 271866)
@@ -46,6 +46,12 @@
 PASS computedStyle("background-color", "color(lab 0% 0 0 / -10%)") is "lab(0% 0 0 / 0)"
 PASS computedStyle("background-color", "color(lab 0% 0 0 / 110%)") is "lab(0% 0 0)"
 PASS computedStyle("background-color", "color(lab 0% 0 0 / 300%)") is "lab(0% 0 0)"
+PASS computedStyle("background-color", "color(lab 50% -200)") is "lab(50% -200 0)"
+PASS computedStyle("background-color", "color(lab 50%)") is "lab(50% 0 0)"
+PASS computedStyle("background-color", "color(lab)") is "lab(0% 0 0)"
+PASS computedStyle("background-color", "color(lab 50% -200 / 0.5)") is "lab(50% -200 0 / 0.5)"
+PASS computedStyle("background-color", "color(lab 50% / 0.5)") is "lab(50% 0 0 / 0.5)"
+PASS computedStyle("background-color", "color(lab / 0.5)") is "lab(0% 0 0 / 0.5)"
 
 Test invalid values
 PASS computedStyle("background-color", "lab(0 0 0)") is "rgba(0, 0, 0, 0)"

Modified: trunk/LayoutTests/fast/css/parsing-lab-colors.html (271865 => 271866)


--- trunk/LayoutTests/fast/css/parsing-lab-colors.html	2021-01-25 23:14:11 UTC (rev 271865)
+++ trunk/LayoutTests/fast/css/parsing-lab-colors.html	2021-01-25 23:32:13 UTC (rev 271866)
@@ -80,6 +80,12 @@
     testComputed("background-color", "color(lab 0% 0 0 / -10%)", "lab(0% 0 0 / 0)");
     testComputed("background-color", "color(lab 0% 0 0 / 110%)", "lab(0% 0 0)");
     testComputed("background-color", "color(lab 0% 0 0 / 300%)", "lab(0% 0 0)");
+    testComputed("background-color", "color(lab 50% -200)", "lab(50% -200 0)");
+    testComputed("background-color", "color(lab 50%)", "lab(50% 0 0)");
+    testComputed("background-color", "color(lab)", "lab(0% 0 0)");
+    testComputed("background-color", "color(lab 50% -200 / 0.5)", "lab(50% -200 0 / 0.5)");
+    testComputed("background-color", "color(lab 50% / 0.5)", "lab(50% 0 0 / 0.5)");
+    testComputed("background-color", "color(lab / 0.5)", "lab(0% 0 0 / 0.5)");
 
     debug('');
     debug('Test invalid values');

Modified: trunk/Source/WebCore/ChangeLog (271865 => 271866)


--- trunk/Source/WebCore/ChangeLog	2021-01-25 23:14:11 UTC (rev 271865)
+++ trunk/Source/WebCore/ChangeLog	2021-01-25 23:32:13 UTC (rev 271866)
@@ -1,3 +1,19 @@
+2021-01-25  Sam Weinig  <wei...@apple.com>
+
+        Support percentages when parsing color(srgb ...) and color(display-p3 ...) per-spec
+        https://bugs.webkit.org/show_bug.cgi?id=220940
+
+        Reviewed by Simon Fraser.
+
+        Add support for using percentages when using the color(srgb ) and color(display-p3 ) syntax. Also
+        fix color(lab ) to allow elliding parameters and defaulting them to 0 as per-spec.
+
+        Unfails some WPT tests and adds additional parsing tests for lab to fast/css/parsing-lab-colors.html
+
+        * css/parser/CSSPropertyParserHelpers.cpp:
+        (WebCore::CSSPropertyParserHelpers::parseColorFunctionForSRGBOrDisplayP3Parameters):
+        (WebCore::CSSPropertyParserHelpers::parseColorFunctionForLabParameters):
+
 2021-01-25  Aditya Keerthi  <akeer...@apple.com>
 
         [iOS] Obscured elements should not be focusable using the accessory bar

Modified: trunk/Source/WebCore/css/parser/CSSPropertyParserHelpers.cpp (271865 => 271866)


--- trunk/Source/WebCore/css/parser/CSSPropertyParserHelpers.cpp	2021-01-25 23:14:11 UTC (rev 271865)
+++ trunk/Source/WebCore/css/parser/CSSPropertyParserHelpers.cpp	2021-01-25 23:32:13 UTC (rev 271866)
@@ -880,11 +880,13 @@
     ASSERT(args.peek().id() == CSSValueSRGB || args.peek().id() == CSSValueDisplayP3);
     consumeIdentRaw(args);
 
-    double colorChannels[3] = { 0, 0, 0 };
+    double channels[3] = { 0, 0, 0 };
     for (int i = 0; i < 3; ++i) {
         double value;
         if (consumeNumberRaw(args, value))
-            colorChannels[i] = value;
+            channels[i] = value;
+        else if (auto percent = consumePercentRaw(args))
+            channels[i] = *percent / 100.0;
         else
             break;
     }
@@ -893,7 +895,7 @@
     if (!alpha)
         return { };
 
-    return ColorType { clampTo<float>(colorChannels[0], 0.0, 1.0), clampTo<float>(colorChannels[1], 0.0, 1.0), clampTo<float>(colorChannels[2], 0.0, 1.0), *alpha };
+    return ColorType { clampTo<float>(channels[0], 0.0, 1.0), clampTo<float>(channels[1], 0.0, 1.0), clampTo<float>(channels[2], 0.0, 1.0), *alpha };
 }
 
 static Color parseColorFunctionForLabParameters(CSSParserTokenRange& args)
@@ -901,23 +903,29 @@
     ASSERT(args.peek().id() == CSSValueLab);
     consumeIdentRaw(args);
 
-    auto lightness = consumePercentRaw(args, ValueRangeAll);
-    if (!lightness)
-        return { };
+    double channels[3] = { 0, 0, 0 };
+    [&] {
+        auto lightness = consumePercentRaw(args, ValueRangeAll);
+        if (!lightness)
+            return;
+        channels[0] = *lightness;
 
-    double aValue;
-    if (!consumeNumberRaw(args, aValue, ValueRangeAll))
-        return { };
+        double aValue;
+        if (!consumeNumberRaw(args, aValue, ValueRangeAll))
+            return;
+        channels[1] = aValue;
 
-    double bValue;
-    if (!consumeNumberRaw(args, bValue, ValueRangeAll))
-        return { };
+        double bValue;
+        if (!consumeNumberRaw(args, bValue, ValueRangeAll))
+            return;
+        channels[2] = bValue;
+    }();
 
     auto alpha = parseOptionalAlpha(args);
     if (!alpha)
         return { };
 
-    return Lab<float> { static_cast<float>(*lightness), static_cast<float>(aValue), static_cast<float>(bValue), *alpha };
+    return Lab<float> { static_cast<float>(channels[0]), static_cast<float>(channels[1]), static_cast<float>(channels[2]), *alpha };
 }
 
 static Color parseColorFunctionParameters(CSSParserTokenRange& range)
_______________________________________________
webkit-changes mailing list
webkit-changes@lists.webkit.org
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to