Title: [278262] trunk
Revision
278262
Author
wei...@apple.com
Date
2021-05-30 17:52:19 -0700 (Sun, 30 May 2021)

Log Message

Add additional target luminance keywords for color-contrast() added for https://github.com/w3c/csswg-drafts/issues/6311
https://bugs.webkit.org/show_bug.cgi?id=226438

Reviewed by Chris Dumez.

Source/WebCore:

Add newly spec'd target luminance keywords.

* css/CSSValueKeywords.in:
Add AAA and AAA-large keywords.

* css/parser/CSSPropertyParserHelpers.cpp:
(WebCore::CSSPropertyParserHelpers::parseColorContrastFunctionParameters):
Add target luminance mappings for "AAA" -> 7 and "AAA-large" -> 4.5

LayoutTests:

Update test and results for new AAA and AAA-large target luminance keywords.

* fast/css/parsing-color-contrast-expected.txt:
* fast/css/parsing-color-contrast.html:

Modified Paths

Diff

Modified: trunk/LayoutTests/ChangeLog (278261 => 278262)


--- trunk/LayoutTests/ChangeLog	2021-05-31 00:29:18 UTC (rev 278261)
+++ trunk/LayoutTests/ChangeLog	2021-05-31 00:52:19 UTC (rev 278262)
@@ -1,5 +1,17 @@
 2021-05-30  Sam Weinig  <wei...@apple.com>
 
+        Add additional target luminance keywords for color-contrast() added for https://github.com/w3c/csswg-drafts/issues/6311
+        https://bugs.webkit.org/show_bug.cgi?id=226438
+
+        Reviewed by Chris Dumez.
+
+        Update test and results for new AAA and AAA-large target luminance keywords.
+
+        * fast/css/parsing-color-contrast-expected.txt:
+        * fast/css/parsing-color-contrast.html:
+
+2021-05-30  Sam Weinig  <wei...@apple.com>
+
         Support calc() on components inside relative color syntax colors
         https://bugs.webkit.org/show_bug.cgi?id=226272
 

Modified: trunk/LayoutTests/fast/css/parsing-color-contrast-expected.txt (278261 => 278262)


--- trunk/LayoutTests/fast/css/parsing-color-contrast-expected.txt	2021-05-31 00:29:18 UTC (rev 278261)
+++ trunk/LayoutTests/fast/css/parsing-color-contrast-expected.txt	2021-05-31 00:52:19 UTC (rev 278262)
@@ -20,6 +20,8 @@
 Test with specified target contrast
 PASS computedStyle("background-color", "color-contrast(wheat vs bisque, darkgoldenrod, olive, sienna, darkgreen, maroon to AA)") is "rgb(0, 100, 0)"
 PASS computedStyle("background-color", "color-contrast(wheat vs bisque, darkgoldenrod, olive, sienna, darkgreen, maroon to AA-large)") is "rgb(128, 128, 0)"
+PASS computedStyle("background-color", "color-contrast(wheat vs bisque, darkgoldenrod, olive, sienna, darkgreen, maroon to AAA)") is "rgb(128, 0, 0)"
+PASS computedStyle("background-color", "color-contrast(wheat vs bisque, darkgoldenrod, olive, sienna, darkgreen, maroon to AAA-large)") is "rgb(0, 100, 0)"
 PASS computedStyle("background-color", "color-contrast(wheat vs bisque, darkgoldenrod, olive, sienna, darkgreen, maroon to 5.8)") is "rgb(128, 0, 0)"
 
 Test with specified target contrast that none meet

Modified: trunk/LayoutTests/fast/css/parsing-color-contrast.html (278261 => 278262)


--- trunk/LayoutTests/fast/css/parsing-color-contrast.html	2021-05-31 00:29:18 UTC (rev 278261)
+++ trunk/LayoutTests/fast/css/parsing-color-contrast.html	2021-05-31 00:52:19 UTC (rev 278262)
@@ -47,7 +47,9 @@
 
     testComputed(`color-contrast(wheat vs bisque, darkgoldenrod, olive, sienna, darkgreen, maroon to AA)`, `rgb(0, 100, 0)`); // darkgreen
     testComputed(`color-contrast(wheat vs bisque, darkgoldenrod, olive, sienna, darkgreen, maroon to AA-large)`, `rgb(128, 128, 0)`); // olive
-    testComputed(`color-contrast(wheat vs bisque, darkgoldenrod, olive, sienna, darkgreen, maroon to 5.8)`, `rgb(128, 0, 0)`); // olive maroon
+    testComputed(`color-contrast(wheat vs bisque, darkgoldenrod, olive, sienna, darkgreen, maroon to AAA)`, `rgb(128, 0, 0)`); // maroon
+    testComputed(`color-contrast(wheat vs bisque, darkgoldenrod, olive, sienna, darkgreen, maroon to AAA-large)`, `rgb(0, 100, 0)`); // darkgreen
+    testComputed(`color-contrast(wheat vs bisque, darkgoldenrod, olive, sienna, darkgreen, maroon to 5.8)`, `rgb(128, 0, 0)`); // maroon
     
     debug('');
     debug('Test with specified target contrast that none meet')

Modified: trunk/Source/WebCore/ChangeLog (278261 => 278262)


--- trunk/Source/WebCore/ChangeLog	2021-05-31 00:29:18 UTC (rev 278261)
+++ trunk/Source/WebCore/ChangeLog	2021-05-31 00:52:19 UTC (rev 278262)
@@ -1,5 +1,21 @@
 2021-05-30  Sam Weinig  <wei...@apple.com>
 
+        Add additional target luminance keywords for color-contrast() added for https://github.com/w3c/csswg-drafts/issues/6311
+        https://bugs.webkit.org/show_bug.cgi?id=226438
+
+        Reviewed by Chris Dumez.
+
+        Add newly spec'd target luminance keywords. 
+
+        * css/CSSValueKeywords.in:
+        Add AAA and AAA-large keywords.
+
+        * css/parser/CSSPropertyParserHelpers.cpp:
+        (WebCore::CSSPropertyParserHelpers::parseColorContrastFunctionParameters):
+        Add target luminance mappings for "AAA" -> 7 and "AAA-large" -> 4.5
+
+2021-05-30  Sam Weinig  <wei...@apple.com>
+
         Support calc() on components inside relative color syntax colors
         https://bugs.webkit.org/show_bug.cgi?id=226272
 

Modified: trunk/Source/WebCore/css/CSSValueKeywords.in (278261 => 278262)


--- trunk/Source/WebCore/css/CSSValueKeywords.in	2021-05-31 00:29:18 UTC (rev 278261)
+++ trunk/Source/WebCore/css/CSSValueKeywords.in	2021-05-31 00:52:19 UTC (rev 278262)
@@ -1448,6 +1448,8 @@
 vs
 AA
 AA-large
+AAA
+AAA-large
 
 // color-mix()
 color-mix

Modified: trunk/Source/WebCore/css/parser/CSSPropertyParserHelpers.cpp (278261 => 278262)


--- trunk/Source/WebCore/css/parser/CSSPropertyParserHelpers.cpp	2021-05-31 00:29:18 UTC (rev 278261)
+++ trunk/Source/WebCore/css/parser/CSSPropertyParserHelpers.cpp	2021-05-31 00:52:19 UTC (rev 278262)
@@ -1736,12 +1736,23 @@
     if (colorsToCompareAgainst.size() == 1)
         return { };
 
+    constexpr std::pair<CSSValueID, double> targetLuminanceMappings[] {
+        { CSSValueAA, 4.5 },
+        { CSSValueAALarge, 3.0 },
+        { CSSValueAAA, 7.0 },
+        { CSSValueAAALarge, 4.5 },
+    };
+
     if (consumedTo) {
         auto targetContrast = [&] () -> std::optional<double> {
-            if (consumeIdentRaw<CSSValueAA>(args))
-                return 4.5;
-            if (consumeIdentRaw<CSSValueAALarge>(args))
-                return 3.0;
+            if (args.peek().type() == IdentToken) {
+                auto id = args.consumeIncludingWhitespace().id();
+                for (auto& [identifier, luminance] : targetLuminanceMappings) {
+                    if (identifier == id)
+                        return luminance;
+                }
+                return std::nullopt;
+            }
             return consumeNumberRaw(args);
         }();
 
_______________________________________________
webkit-changes mailing list
webkit-changes@lists.webkit.org
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to