Title: [273683] trunk
Revision
273683
Author
wei...@apple.com
Date
2021-03-01 12:56:56 -0800 (Mon, 01 Mar 2021)

Log Message

Add experimental support for CSS Color 5 color-contrast()
https://bugs.webkit.org/show_bug.cgi?id=222530

Reviewed by Simon Fraser.

Source/WebCore:

This feature is off by default and can be enabled via the CSSColorContrastEnabled
experimental preference flag.

This implementation has the same restriction on it that the recently landed
Relative Color Syntax and color-mix() do, in that it does support system colors
or currentColor as input, since those can't be resolved at parse time. Ultimately,
we will need to add a late binding version of this for those cases.

Test: fast/css/parsing-color-contrast.html

* Headers.cmake:
* WebCore.xcodeproj/project.pbxproj:
Add new ColorLuminance.h header where the generic relative luminance and contrast ratio
functions live.

* css/CSSValueKeywords.in:
Add new keywords, color-contrast and vs, that are needed for the color-contrast() function.

* css/parser/CSSParserContext.cpp:
* css/parser/CSSParserContext.h:
Add a setting for color-contrast.

* css/parser/CSSPropertyParserHelpers.cpp:
(WebCore::CSSPropertyParserHelpers::parseColorContrastFunctionParameters):
(WebCore::CSSPropertyParserHelpers::parseColorFunction):
Add parsing and computation of color-contrast().

* platform/graphics/ColorUtilities.cpp:
(WebCore::lightness): Deleted.
(WebCore::luminance): Deleted.
(WebCore::contrastRatio): Deleted.
Moved luminance related functions to ColorLuminance.h and inlined lightness
to its one caller, Color and noted it should be removed.

* platform/graphics/ColorUtilities.h:
(WebCore::invertedColorWithOverriddenAlpha):
(WebCore::invertedcolorWithOverriddenAlpha): Deleted.
Fix capitalization issue seen. invertedcolorWithOverriddenAlpha -> invertedColorWithOverriddenAlpha.

* platform/graphics/Color.cpp:
(WebCore::Color::lightness const):
Inline implementation and add comment explaining it should be removed.

(WebCore::Color::luminance const):
Re-write to use the new WebCore::relativeLuminance that works for any color type
without conversion to sRGB.

(WebCore::Color::contrastRatio):
Add helper to call generic WebCore::contrastRatio that works on any color types
to avoid callers needing to do the unfolding themselves.

(WebCore::Color::isBlackColor):
(WebCore::Color::isWhiteColor):
* platform/graphics/Color.h:
(WebCore::Color::isBlackColor): Deleted.
(WebCore::Color::isWhiteColor): Deleted.
Move these rare functions out of line to reduce the number of places in the header we are
calling callOnUnderlyingType(), which produces code linerally with the number of color spaces
supported. Calling it in the cpp files means we only expand it once for each function.

* platform/graphics/ColorLuminance.h: Added.
(WebCore::relativeLuminance):
This is a generic version of the old luminance function that works for any color type
by converting to XYZ and taking the Y component. The old function required always
converting to sRGB which could be lossy.

(WebCore::contrastRatio):
Split out computation of contrastRatio based on relative luminace floats into its own
function so that if we have the relative luminance computed already, we don't have to
recompute it. Add version contrastRatio that works for any color type utilizing the
generic relativeLuminance function above.

* rendering/RenderTheme.cpp:
(WebCore::RenderTheme::disabledTextColor const):
* rendering/TextPaintStyle.cpp:
(WebCore::textColorIsLegibleAgainstBackgroundColor):
Update to use new Color::contrastRatio helper that handles all color types.

Source/WTF:

* Scripts/Preferences/WebPreferencesExperimental.yaml:
Add new experimental preference for CSS Color 5 color-contrast()
which is off by default.

Tools:

* TestWebKitAPI/Tests/WebCore/ColorTests.cpp:
(TestWebKitAPI::TEST):
Update luminance values to account for more accurate conversion to
XYZ now that we are usuing the actual matrix values from SRGBADescriptor
and not a truncated copy.

LayoutTests:

* fast/css/parsing-color-contrast-expected.txt: Added.
* fast/css/parsing-color-contrast.html: Added.
Add parsing and computed style computation tests for color-contast().

Modified Paths

Added Paths

Diff

Modified: trunk/LayoutTests/ChangeLog (273682 => 273683)


--- trunk/LayoutTests/ChangeLog	2021-03-01 20:53:49 UTC (rev 273682)
+++ trunk/LayoutTests/ChangeLog	2021-03-01 20:56:56 UTC (rev 273683)
@@ -1,3 +1,14 @@
+2021-03-01  Sam Weinig  <wei...@apple.com>
+
+        Add experimental support for CSS Color 5 color-contrast()
+        https://bugs.webkit.org/show_bug.cgi?id=222530
+
+        Reviewed by Simon Fraser.
+
+        * fast/css/parsing-color-contrast-expected.txt: Added.
+        * fast/css/parsing-color-contrast.html: Added.
+        Add parsing and computed style computation tests for color-contast().
+
 2021-03-01  Said Abou-Hallawa  <s...@apple.com>
 
         [GPU Process] Some DisplayList items may not be replayed back before calling getImageData()

Added: trunk/LayoutTests/fast/css/parsing-color-contrast-expected.txt (0 => 273683)


--- trunk/LayoutTests/fast/css/parsing-color-contrast-expected.txt	                        (rev 0)
+++ trunk/LayoutTests/fast/css/parsing-color-contrast-expected.txt	2021-03-01 20:56:56 UTC (rev 273683)
@@ -0,0 +1,33 @@
+Test the parsing of CSS Color 5 color-contrast().
+
+On success, you will see a series of "PASS" messages, followed by "TEST COMPLETE".
+
+
+color-contrast(... vs ..., ...)
+PASS computedStyle("background-color", "color-contrast(white vs red, blue)") is "rgb(0, 0, 255)"
+PASS computedStyle("background-color", "color-contrast(white vs blue, red)") is "rgb(0, 0, 255)"
+PASS computedStyle("background-color", "color-contrast(white vs red, blue, green)") is "rgb(0, 0, 255)"
+PASS computedStyle("background-color", "color-contrast(white vs white, white)") is "rgb(255, 255, 255)"
+PASS computedStyle("background-color", "color-contrast(blue vs red, white)") is "rgb(255, 255, 255)"
+PASS computedStyle("background-color", "color-contrast(red vs blue, white, red)") is "rgb(255, 255, 255)"
+PASS computedStyle("background-color", "color-contrast(black vs red, blue)") is "rgb(255, 0, 0)"
+PASS computedStyle("background-color", "color-contrast(black vs blue, red)") is "rgb(255, 0, 0)"
+PASS computedStyle("background-color", "color-contrast(black vs white, white)") is "rgb(255, 255, 255)"
+PASS computedStyle("background-color", "color-contrast(red vs blue, rgb(255, 255, 255, .5))") is "rgba(255, 255, 255, 0.5)"
+
+Test non-sRGB colors
+PASS computedStyle("background-color", "color-contrast(green vs color(display-p3 0 1 0), color(display-p3 0 0 1))") is "color(display-p3 0 1 0)"
+PASS computedStyle("background-color", "color-contrast(color(display-p3 1 1 0) vs color(display-p3 0 1 0), color(display-p3 0 0 1))") is "color(display-p3 0 0 1)"
+PASS computedStyle("background-color", "color-contrast(green vs lab(50% -160 160), lch(20% 50 20deg))") is "lch(20% 50 20)"
+PASS computedStyle("background-color", "color-contrast(lab(50% -160 160) vs green, lch(20% 50 20deg))") is "lch(20% 50 20)"
+
+Test invalid values
+PASS computedStyle("background-color", "color-contrast(white vs red)") is "rgba(0, 0, 0, 0)"
+PASS computedStyle("background-color", "color-contrast(white vs red,)") is "rgba(0, 0, 0, 0)"
+PASS computedStyle("background-color", "color-contrast(white vs )") is "rgba(0, 0, 0, 0)"
+PASS computedStyle("background-color", "color-contrast(white)") is "rgba(0, 0, 0, 0)"
+PASS computedStyle("background-color", "color-contrast(white vs red green)") is "rgba(0, 0, 0, 0)"
+PASS successfullyParsed is true
+
+TEST COMPLETE
+

Added: trunk/LayoutTests/fast/css/parsing-color-contrast.html (0 => 273683)


--- trunk/LayoutTests/fast/css/parsing-color-contrast.html	                        (rev 0)
+++ trunk/LayoutTests/fast/css/parsing-color-contrast.html	2021-03-01 20:56:56 UTC (rev 273683)
@@ -0,0 +1,63 @@
+<!DOCTYPE html><!-- webkit-test-runner [ CSSColorContrastEnabled=true ] -->
+<html>
+    <script src=""
+</head>
+<body>
+<script>
+    description("Test the parsing of CSS Color 5 color-contrast().");
+
+    function computedStyle(property, value)
+    {
+        var div = document.createElement("div");
+        document.body.appendChild(div);
+        div.style.setProperty(property, value);
+        var computedValue = getComputedStyle(div).getPropertyValue(property);
+        document.body.removeChild(div);
+        return computedValue;
+    }
+
+    function testComputedProperty(property, value, expected)
+    {
+        shouldBeEqualToString('computedStyle("' + property + '", "' + value + '")', expected);
+    }
+
+    function testComputed(value, expected)
+    {
+        testComputedProperty("background-color", value, expected);
+    }
+
+    debug('color-contrast(... vs ..., ...)');
+
+    testComputed(`color-contrast(white vs red, blue)`, `rgb(0, 0, 255)`);
+    testComputed(`color-contrast(white vs blue, red)`, `rgb(0, 0, 255)`);
+    testComputed(`color-contrast(white vs red, blue, green)`, `rgb(0, 0, 255)`);
+    testComputed(`color-contrast(white vs white, white)`, `rgb(255, 255, 255)`);
+    testComputed(`color-contrast(blue vs red, white)`, `rgb(255, 255, 255)`);
+    testComputed(`color-contrast(red vs blue, white, red)`, `rgb(255, 255, 255)`);
+    testComputed(`color-contrast(black vs red, blue)`, `rgb(255, 0, 0)`);
+    testComputed(`color-contrast(black vs blue, red)`, `rgb(255, 0, 0)`);
+    testComputed(`color-contrast(black vs white, white)`, `rgb(255, 255, 255)`);
+    testComputed(`color-contrast(red vs blue, rgb(255, 255, 255, .5))`, `rgba(255, 255, 255, 0.5)`);
+
+    debug('');
+    debug('Test non-sRGB colors');
+
+    testComputed(`color-contrast(green vs color(display-p3 0 1 0), color(display-p3 0 0 1))`, `color(display-p3 0 1 0)`);
+    testComputed(`color-contrast(color(display-p3 1 1 0) vs color(display-p3 0 1 0), color(display-p3 0 0 1))`, `color(display-p3 0 0 1)`);
+    testComputed(`color-contrast(green vs lab(50% -160 160), lch(20% 50 20deg))`, `lch(20% 50 20)`);
+    testComputed(`color-contrast(lab(50% -160 160) vs green, lch(20% 50 20deg))`, `lch(20% 50 20)`);
+
+    debug('');
+    debug('Test invalid values');
+
+    testComputed(`color-contrast(white vs red)`, `rgba(0, 0, 0, 0)`);
+    testComputed(`color-contrast(white vs red,)`, `rgba(0, 0, 0, 0)`);
+    testComputed(`color-contrast(white vs )`, `rgba(0, 0, 0, 0)`);
+    testComputed(`color-contrast(white)`, `rgba(0, 0, 0, 0)`);
+    testComputed(`color-contrast(white vs red green)`, `rgba(0, 0, 0, 0)`);
+
+</script>
+    
+<script src=""
+</body>
+</html>

Modified: trunk/Source/WTF/ChangeLog (273682 => 273683)


--- trunk/Source/WTF/ChangeLog	2021-03-01 20:53:49 UTC (rev 273682)
+++ trunk/Source/WTF/ChangeLog	2021-03-01 20:56:56 UTC (rev 273683)
@@ -1,3 +1,14 @@
+2021-03-01  Sam Weinig  <wei...@apple.com>
+
+        Add experimental support for CSS Color 5 color-contrast()
+        https://bugs.webkit.org/show_bug.cgi?id=222530
+
+        Reviewed by Simon Fraser.
+
+        * Scripts/Preferences/WebPreferencesExperimental.yaml:
+        Add new experimental preference for CSS Color 5 color-contrast()
+        which is off by default.
+
 2021-02-25  Simon Fraser  <simon.fra...@apple.com>
 
         Remove ENABLE_WEBPROCESS_WINDOWSERVER_BLOCKING which is always true for macOS

Modified: trunk/Source/WTF/Scripts/Preferences/WebPreferencesExperimental.yaml (273682 => 273683)


--- trunk/Source/WTF/Scripts/Preferences/WebPreferencesExperimental.yaml	2021-03-01 20:53:49 UTC (rev 273682)
+++ trunk/Source/WTF/Scripts/Preferences/WebPreferencesExperimental.yaml	2021-03-01 20:56:56 UTC (rev 273683)
@@ -113,6 +113,18 @@
     WebKit:
       default: false
 
+CSSColorContrastEnabled:
+  type: bool
+  humanReadableName: "CSS color-contrast()"
+  humanReadableDescription: "Enable support for CSS color-contrast() defined in CSS Color 5"
+  defaultValue:
+    WebKitLegacy:
+      default: false
+    WebKit:
+      default: false
+    WebCore:
+      default: false
+
 CSSColorMixEnabled:
   type: bool
   humanReadableName: "CSS color-mix()"

Modified: trunk/Source/WebCore/ChangeLog (273682 => 273683)


--- trunk/Source/WebCore/ChangeLog	2021-03-01 20:53:49 UTC (rev 273682)
+++ trunk/Source/WebCore/ChangeLog	2021-03-01 20:56:56 UTC (rev 273683)
@@ -1,3 +1,88 @@
+2021-03-01  Sam Weinig  <wei...@apple.com>
+
+        Add experimental support for CSS Color 5 color-contrast()
+        https://bugs.webkit.org/show_bug.cgi?id=222530
+
+        Reviewed by Simon Fraser.
+
+        This feature is off by default and can be enabled via the CSSColorContrastEnabled
+        experimental preference flag.
+
+        This implementation has the same restriction on it that the recently landed
+        Relative Color Syntax and color-mix() do, in that it does support system colors
+        or currentColor as input, since those can't be resolved at parse time. Ultimately,
+        we will need to add a late binding version of this for those cases.
+
+        Test: fast/css/parsing-color-contrast.html
+
+        * Headers.cmake:
+        * WebCore.xcodeproj/project.pbxproj:
+        Add new ColorLuminance.h header where the generic relative luminance and contrast ratio
+        functions live.
+
+        * css/CSSValueKeywords.in:
+        Add new keywords, color-contrast and vs, that are needed for the color-contrast() function.
+
+        * css/parser/CSSParserContext.cpp:
+        * css/parser/CSSParserContext.h:
+        Add a setting for color-contrast.
+
+        * css/parser/CSSPropertyParserHelpers.cpp:
+        (WebCore::CSSPropertyParserHelpers::parseColorContrastFunctionParameters):
+        (WebCore::CSSPropertyParserHelpers::parseColorFunction):
+        Add parsing and computation of color-contrast().
+
+        * platform/graphics/ColorUtilities.cpp:
+        (WebCore::lightness): Deleted.
+        (WebCore::luminance): Deleted.
+        (WebCore::contrastRatio): Deleted.
+        Moved luminance related functions to ColorLuminance.h and inlined lightness
+        to its one caller, Color and noted it should be removed.
+        
+        * platform/graphics/ColorUtilities.h:
+        (WebCore::invertedColorWithOverriddenAlpha):
+        (WebCore::invertedcolorWithOverriddenAlpha): Deleted.
+        Fix capitalization issue seen. invertedcolorWithOverriddenAlpha -> invertedColorWithOverriddenAlpha.
+
+        * platform/graphics/Color.cpp:
+        (WebCore::Color::lightness const):
+        Inline implementation and add comment explaining it should be removed.
+
+        (WebCore::Color::luminance const):
+        Re-write to use the new WebCore::relativeLuminance that works for any color type
+        without conversion to sRGB.
+
+        (WebCore::Color::contrastRatio):
+        Add helper to call generic WebCore::contrastRatio that works on any color types
+        to avoid callers needing to do the unfolding themselves.
+ 
+        (WebCore::Color::isBlackColor):
+        (WebCore::Color::isWhiteColor):
+        * platform/graphics/Color.h:
+        (WebCore::Color::isBlackColor): Deleted.
+        (WebCore::Color::isWhiteColor): Deleted.
+        Move these rare functions out of line to reduce the number of places in the header we are
+        calling callOnUnderlyingType(), which produces code linerally with the number of color spaces
+        supported. Calling it in the cpp files means we only expand it once for each function.
+
+        * platform/graphics/ColorLuminance.h: Added.
+        (WebCore::relativeLuminance):
+        This is a generic version of the old luminance function that works for any color type
+        by converting to XYZ and taking the Y component. The old function required always
+        converting to sRGB which could be lossy.
+
+        (WebCore::contrastRatio):
+        Split out computation of contrastRatio based on relative luminace floats into its own
+        function so that if we have the relative luminance computed already, we don't have to
+        recompute it. Add version contrastRatio that works for any color type utilizing the
+        generic relativeLuminance function above.
+
+        * rendering/RenderTheme.cpp:
+        (WebCore::RenderTheme::disabledTextColor const):
+        * rendering/TextPaintStyle.cpp:
+        (WebCore::textColorIsLegibleAgainstBackgroundColor):
+        Update to use new Color::contrastRatio helper that handles all color types.
+
 2021-03-01  Zalan Bujtas  <za...@apple.com>
 
         [LFC][IFC] Change LineBoxBuilder::m_inlineLevelBoxesNeedVerticalAlignment to m_useSimplifiedVerticalAlignment

Modified: trunk/Source/WebCore/Headers.cmake (273682 => 273683)


--- trunk/Source/WebCore/Headers.cmake	2021-03-01 20:53:49 UTC (rev 273682)
+++ trunk/Source/WebCore/Headers.cmake	2021-03-01 20:56:56 UTC (rev 273683)
@@ -1166,6 +1166,7 @@
     platform/graphics/ColorComponents.h
     platform/graphics/ColorConversion.h
     platform/graphics/ColorHash.h
+    platform/graphics/ColorLuminance.h
     platform/graphics/ColorMatrix.h
     platform/graphics/ColorModels.h
     platform/graphics/ColorSerialization.h

Modified: trunk/Source/WebCore/WebCore.xcodeproj/project.pbxproj (273682 => 273683)


--- trunk/Source/WebCore/WebCore.xcodeproj/project.pbxproj	2021-03-01 20:53:49 UTC (rev 273682)
+++ trunk/Source/WebCore/WebCore.xcodeproj/project.pbxproj	2021-03-01 20:56:56 UTC (rev 273683)
@@ -3972,6 +3972,7 @@
 		BC4918C70BFEA050009D6316 /* JSHTMLFrameElement.h in Headers */ = {isa = PBXBuildFile; fileRef = BC4918C10BFEA050009D6316 /* JSHTMLFrameElement.h */; };
 		BC4918C90BFEA050009D6316 /* JSHTMLIFrameElement.h in Headers */ = {isa = PBXBuildFile; fileRef = BC4918C30BFEA050009D6316 /* JSHTMLIFrameElement.h */; };
 		BC491B790C023EFD009D6316 /* JSHTMLMarqueeElement.h in Headers */ = {isa = PBXBuildFile; fileRef = BC491B770C023EFD009D6316 /* JSHTMLMarqueeElement.h */; };
+		BC4A23EC25EC160200AAC630 /* ColorLuminance.h in Headers */ = {isa = PBXBuildFile; fileRef = BC4A23EB25EC160200AAC630 /* ColorLuminance.h */; settings = {ATTRIBUTES = (Private, ); }; };
 		BC4A5323256052760028C592 /* EditableLinkBehavior.h in Headers */ = {isa = PBXBuildFile; fileRef = BC4A5321256052700028C592 /* EditableLinkBehavior.h */; settings = {ATTRIBUTES = (Private, ); }; };
 		BC4A53252560555F0028C592 /* TextDirectionSubmenuInclusionBehavior.h in Headers */ = {isa = PBXBuildFile; fileRef = BC4A5324256055590028C592 /* TextDirectionSubmenuInclusionBehavior.h */; settings = {ATTRIBUTES = (Private, ); }; };
 		BC4A5327256055D30028C592 /* UserInterfaceDirectionPolicy.h in Headers */ = {isa = PBXBuildFile; fileRef = BC4A5326256055D30028C592 /* UserInterfaceDirectionPolicy.h */; settings = {ATTRIBUTES = (Private, ); }; };
@@ -14034,6 +14035,7 @@
 		BC491B4E0C023E2D009D6316 /* HTMLMarqueeElement.idl */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text; path = HTMLMarqueeElement.idl; sourceTree = "<group>"; };
 		BC491B760C023EFD009D6316 /* JSHTMLMarqueeElement.cpp */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.cpp.cpp; path = JSHTMLMarqueeElement.cpp; sourceTree = "<group>"; };
 		BC491B770C023EFD009D6316 /* JSHTMLMarqueeElement.h */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.c.h; path = JSHTMLMarqueeElement.h; sourceTree = "<group>"; };
+		BC4A23EB25EC160200AAC630 /* ColorLuminance.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = ColorLuminance.h; sourceTree = "<group>"; };
 		BC4A5321256052700028C592 /* EditableLinkBehavior.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = EditableLinkBehavior.h; sourceTree = "<group>"; };
 		BC4A5324256055590028C592 /* TextDirectionSubmenuInclusionBehavior.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = TextDirectionSubmenuInclusionBehavior.h; sourceTree = "<group>"; };
 		BC4A5326256055D30028C592 /* UserInterfaceDirectionPolicy.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = UserInterfaceDirectionPolicy.h; sourceTree = "<group>"; };
@@ -26659,6 +26661,7 @@
 				3103B7DE1DB01556008BB890 /* ColorHash.h */,
 				7CAC6AE8247F082000E61D59 /* ColorMatrix.h */,
 				BC10137B25C3624B00DC773C /* ColorModels.h */,
+				BC4A23EB25EC160200AAC630 /* ColorLuminance.h */,
 				7CD1E69224ABF6240089C419 /* ColorSerialization.cpp */,
 				7CD1E69124ABF6240089C419 /* ColorSerialization.h */,
 				BCAFEDAF25966D050030E6AA /* ColorSpace.cpp */,
@@ -31145,8 +31148,6 @@
 				CDC26B41160A8CCE0026757B /* LegacyMockCDM.h in Headers */,
 				A1BF6B831AA96C7D00AF4A8A /* MockContentFilter.h in Headers */,
 				A1B5B29F1AAA846F008B6042 /* MockContentFilterSettings.h in Headers */,
-				51058ADC1D6792C1009A538C /* MockGamepad.h in Headers */,
-				51058ADE1D6792C1009A538C /* MockGamepadProvider.h in Headers */,
 				4157EBFB1E3AB67F00AC9FE9 /* MockLibWebRTCPeerConnection.h in Headers */,
 				2D6F3E911C1ECB2F0061DBD4 /* MockPageOverlay.h in Headers */,
 				2D97F04819DD4140001EE9C3 /* MockPageOverlayClient.h in Headers */,
@@ -31872,6 +31873,7 @@
 				A882DA231593848D000115ED /* CSSToStyleMap.h in Headers */,
 				715AD7212050513F00D592DC /* CSSTransition.h in Headers */,
 				371F53E90D2704F900ECE0D5 /* CSSUnicodeRangeValue.h in Headers */,
+				BC4A23EC25EC160200AAC630 /* ColorLuminance.h in Headers */,
 				0F6B707A237BC36D0052CA47 /* CSSUnits.h in Headers */,
 				DD7CDF250A23CF9800069928 /* CSSUnknownRule.h in Headers */,
 				BC7D8FF01BD03B6400FFE540 /* CSSUnsetValue.h in Headers */,

Modified: trunk/Source/WebCore/css/CSSValueKeywords.in (273682 => 273683)


--- trunk/Source/WebCore/css/CSSValueKeywords.in	2021-03-01 20:53:49 UTC (rev 273682)
+++ trunk/Source/WebCore/css/CSSValueKeywords.in	2021-03-01 20:56:56 UTC (rev 273683)
@@ -1434,6 +1434,10 @@
 // sRGB
 xyz
 
+// color-contast()
+color-contrast
+vs
+
 // color-mix()
 color-mix
 shorter

Modified: trunk/Source/WebCore/css/parser/CSSParserContext.cpp (273682 => 273683)


--- trunk/Source/WebCore/css/parser/CSSParserContext.cpp	2021-03-01 20:53:49 UTC (rev 273682)
+++ trunk/Source/WebCore/css/parser/CSSParserContext.cpp	2021-03-01 20:56:56 UTC (rev 273683)
@@ -68,6 +68,7 @@
     , hasDocumentSecurityOrigin { sheetBaseURL.isNull() || document.securityOrigin().canRequest(baseURL) }
     , useSystemAppearance { document.page() ? document.page()->useSystemAppearance() : false }
     , aspectRatioEnabled { document.settings().aspectRatioEnabled() }
+    , colorContrastEnabled { document.settings().cssColorContrastEnabled() }
     , colorFilterEnabled { document.settings().colorFilterEnabled() }
     , colorMixEnabled { document.settings().cssColorMixEnabled() }
     , constantPropertiesEnabled { document.settings().constantPropertiesEnabled() }
@@ -106,6 +107,7 @@
         && a.isContentOpaque == b.isContentOpaque
         && a.useSystemAppearance == b.useSystemAppearance
         && a.aspectRatioEnabled == b.aspectRatioEnabled
+        && a.colorContrastEnabled == b.colorContrastEnabled
         && a.colorFilterEnabled == b.colorFilterEnabled
         && a.colorMixEnabled == b.colorMixEnabled
         && a.constantPropertiesEnabled == b.constantPropertiesEnabled

Modified: trunk/Source/WebCore/css/parser/CSSParserContext.h (273682 => 273683)


--- trunk/Source/WebCore/css/parser/CSSParserContext.h	2021-03-01 20:53:49 UTC (rev 273682)
+++ trunk/Source/WebCore/css/parser/CSSParserContext.h	2021-03-01 20:56:56 UTC (rev 273683)
@@ -58,6 +58,7 @@
 
     // Settings.
     bool aspectRatioEnabled { false };
+    bool colorContrastEnabled { false };
     bool colorFilterEnabled { false };
     bool colorMixEnabled { false };
     bool constantPropertiesEnabled { false };
@@ -109,31 +110,32 @@
             & key.isContentOpaque                           << 2
             & key.useSystemAppearance                       << 3
             & key.aspectRatioEnabled                        << 4
-            & key.colorFilterEnabled                        << 5
-            & key.colorMixEnabled                           << 6
-            & key.constantPropertiesEnabled                 << 7
-            & key.deferredCSSParserEnabled                  << 8
-            & key.enforcesCSSMIMETypeInNoQuirksMode         << 9
-            & key.individualTransformPropertiesEnabled      << 10
+            & key.colorContrastEnabled                      << 5
+            & key.colorFilterEnabled                        << 6
+            & key.colorMixEnabled                           << 7
+            & key.constantPropertiesEnabled                 << 8
+            & key.deferredCSSParserEnabled                  << 9
+            & key.enforcesCSSMIMETypeInNoQuirksMode         << 10
+            & key.individualTransformPropertiesEnabled      << 11
 #if ENABLE(OVERFLOW_SCROLLING_TOUCH)
-            & key.legacyOverflowScrollingTouchEnabled       << 11
+            & key.legacyOverflowScrollingTouchEnabled       << 12
 #endif
-            & key.overscrollBehaviorEnabled                 << 12
-            & key.relativeColorSyntaxEnabled                << 13
-            & key.scrollBehaviorEnabled                     << 14
-            & key.springTimingFunctionEnabled               << 15
+            & key.overscrollBehaviorEnabled                 << 13
+            & key.relativeColorSyntaxEnabled                << 14
+            & key.scrollBehaviorEnabled                     << 15
+            & key.springTimingFunctionEnabled               << 16
 #if ENABLE(TEXT_AUTOSIZING)
-            & key.textAutosizingEnabled                     << 16
+            & key.textAutosizingEnabled                     << 17
 #endif
 #if ENABLE(CSS_TRANSFORM_STYLE_OPTIMIZED_3D)
-            & key.transformStyleOptimized3DEnabled          << 17
+            & key.transformStyleOptimized3DEnabled          << 18
 #endif
-            & key.useLegacyBackgroundSizeShorthandBehavior  << 18
-            & key.focusVisibleEnabled                       << 19
+            & key.useLegacyBackgroundSizeShorthandBehavior  << 19
+            & key.focusVisibleEnabled                       << 20
 #if ENABLE(ATTACHMENT_ELEMENT)
-            & key.attachmentEnabled                         << 20
+            & key.attachmentEnabled                         << 21
 #endif
-            & key.mode                                      << 21; // Keep this last.
+            & key.mode                                      << 22; // Keep this last.
         hash ^= WTF::intHash(bits);
         return hash;
     }

Modified: trunk/Source/WebCore/css/parser/CSSPropertyParserHelpers.cpp (273682 => 273683)


--- trunk/Source/WebCore/css/parser/CSSPropertyParserHelpers.cpp	2021-03-01 20:53:49 UTC (rev 273682)
+++ trunk/Source/WebCore/css/parser/CSSPropertyParserHelpers.cpp	2021-03-01 20:56:56 UTC (rev 273683)
@@ -42,6 +42,7 @@
 #include "CSSParserIdioms.h"
 #include "CSSValuePool.h"
 #include "ColorConversion.h"
+#include "ColorLuminance.h"
 #include "Pair.h"
 #include "RuntimeEnabledFeatures.h"
 #include "StyleColor.h"
@@ -1482,6 +1483,49 @@
     return color;
 }
 
+static Color parseColorContrastFunctionParameters(CSSParserTokenRange& range, const CSSParserContext& context)
+{
+    ASSERT(range.peek().functionId() == CSSValueColorContrast);
+
+    if (!context.colorContrastEnabled)
+        return { };
+
+    auto args = consumeFunction(range);
+
+    auto originBackgroundColor = consumeOriginColor(args, context);
+    if (!originBackgroundColor.isValid())
+        return { };
+
+    if (!consumeIdentRaw<CSSValueVs>(args))
+        return { };
+
+    Vector<Color> colorsToCompareAgainst;
+    do {
+        auto colorToCompareAgainst = consumeOriginColor(args, context);
+        if (!colorToCompareAgainst.isValid())
+            return { };
+
+        colorsToCompareAgainst.append(WTFMove(colorToCompareAgainst));
+    } while (consumeCommaIncludingWhitespace(args));
+
+    if (colorsToCompareAgainst.size() == 1)
+        return { };
+
+    auto originBackgroundColorLuminance = originBackgroundColor.luminance();
+
+    size_t indexOfColorWithHigestContrastRatio = 0;
+    float highestContrastRatioSoFar = 0;
+    for (size_t i = 0; i < colorsToCompareAgainst.size(); ++i) {
+        auto contrastRatio = WebCore::contrastRatio(originBackgroundColorLuminance, colorsToCompareAgainst[i].luminance());
+        if (contrastRatio > highestContrastRatioSoFar) {
+            highestContrastRatioSoFar = contrastRatio;
+            indexOfColorWithHigestContrastRatio = i;
+        }
+    }
+
+    return colorsToCompareAgainst[indexOfColorWithHigestContrastRatio];
+}
+
 struct HueColorAdjuster {
     enum class Type {
         Shorter,
@@ -1925,6 +1969,9 @@
     case CSSValueColor:
         color = parseColorFunctionParameters(colorRange);
         break;
+    case CSSValueColorContrast:
+        color = parseColorContrastFunctionParameters(colorRange, context);
+        break;
     case CSSValueColorMix:
         color = parseColorMixFunctionParameters(colorRange, context);
         break;

Modified: trunk/Source/WebCore/platform/graphics/Color.cpp (273682 => 273683)


--- trunk/Source/WebCore/platform/graphics/Color.cpp	2021-03-01 20:53:49 UTC (rev 273682)
+++ trunk/Source/WebCore/platform/graphics/Color.cpp	2021-03-01 20:56:56 UTC (rev 273683)
@@ -26,8 +26,8 @@
 #include "config.h"
 #include "Color.h"
 
+#include "ColorLuminance.h"
 #include "ColorSerialization.h"
-#include "ColorUtilities.h"
 #include <wtf/Assertions.h>
 #include <wtf/text/TextStream.h>
 
@@ -111,17 +111,28 @@
 
 float Color::lightness() const
 {
-    // FIXME: This can probably avoid conversion to sRGB by having per-colorspace algorithms for HSL.
-    return WebCore::lightness(toSRGBALossy<float>());
+    // FIXME: Replace remaining uses with luminance.
+    auto [r, g, b, a] = toSRGBALossy<float>();
+    auto [min, max] = std::minmax({ r, g, b });
+    return 0.5f * (max + min);
 }
 
 float Color::luminance() const
 {
-    // FIXME: This can probably avoid conversion to sRGB by having per-colorspace algorithms
-    // for luminance (e.g. convertToXYZ(c).yComponent()).
-    return WebCore::luminance(toSRGBALossy<float>());
+    return callOnUnderlyingType([&] (const auto& underlyingColor) {
+        return WebCore::relativeLuminance(underlyingColor);
+    });
 }
 
+float Color::contrastRatio(const Color& colorA, const Color& colorB)
+{
+    return colorA.callOnUnderlyingType([&] (const auto& underlyingColorA) {
+        return colorB.callOnUnderlyingType([&] (const auto& underlyingColorB) {
+            return WebCore::contrastRatio(underlyingColorA, underlyingColorB);
+        });
+    });
+}
+
 Color Color::colorWithAlpha(float alpha) const
 {
     return callOnUnderlyingType([&] (const auto& underlyingColor) -> Color {
@@ -144,9 +155,9 @@
         // better for non-invertible color types like Lab or consider removing this in favor
         // of alternatives.
         if constexpr (ColorType::Model::isInvertible)
-            return invertedcolorWithOverriddenAlpha(underlyingColor, alpha);
+            return invertedColorWithOverriddenAlpha(underlyingColor, alpha);
         else
-            return invertedcolorWithOverriddenAlpha(convertColor<SRGBA<float>>(underlyingColor), alpha);
+            return invertedColorWithOverriddenAlpha(convertColor<SRGBA<float>>(underlyingColor), alpha);
     });
 }
 
@@ -167,6 +178,20 @@
     return { ColorSpace::SRGB, asColorComponents(convertColor<SRGBA<float>>(asInline())) };
 }
 
+bool Color::isBlackColor(const Color& color)
+{
+    return color.callOnUnderlyingType([] (const auto& underlyingColor) {
+        return WebCore::isBlack(underlyingColor);
+    });
+}
+
+bool Color::isWhiteColor(const Color& color)
+{
+    return color.callOnUnderlyingType([] (const auto& underlyingColor) {
+        return WebCore::isWhite(underlyingColor);
+    });
+}
+
 TextStream& operator<<(TextStream& ts, const Color& color)
 {
     return ts << serializationForRenderTreeAsText(color);

Modified: trunk/Source/WebCore/platform/graphics/Color.h (273682 => 273683)


--- trunk/Source/WebCore/platform/graphics/Color.h	2021-03-01 20:53:49 UTC (rev 273682)
+++ trunk/Source/WebCore/platform/graphics/Color.h	2021-03-01 20:56:56 UTC (rev 273683)
@@ -105,6 +105,7 @@
 
     WEBCORE_EXPORT float luminance() const;
     WEBCORE_EXPORT float lightness() const; // FIXME: Replace remaining uses with luminance.
+    WEBCORE_EXPORT static float contrastRatio(const Color&, const Color&);
 
     template<typename Functor> decltype(auto) callOnUnderlyingType(Functor&&) const;
 
@@ -494,20 +495,6 @@
     ASSERT(isExtended());
 }
 
-inline bool Color::isBlackColor(const Color& color)
-{
-    return color.callOnUnderlyingType([] (const auto& underlyingColor) {
-        return WebCore::isBlack(underlyingColor);
-    });
-}
-
-inline bool Color::isWhiteColor(const Color& color)
-{
-    return color.callOnUnderlyingType([] (const auto& underlyingColor) {
-        return WebCore::isWhite(underlyingColor);
-    });
-}
-
 template<class Encoder> void Color::encode(Encoder& encoder) const
 {
     if (!isValid()) {

Added: trunk/Source/WebCore/platform/graphics/ColorLuminance.h (0 => 273683)


--- trunk/Source/WebCore/platform/graphics/ColorLuminance.h	                        (rev 0)
+++ trunk/Source/WebCore/platform/graphics/ColorLuminance.h	2021-03-01 20:56:56 UTC (rev 273683)
@@ -0,0 +1,67 @@
+/*
+ * Copyright (C) 2021 Apple Inc. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS''
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
+ * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS
+ * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
+ * THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#pragma once
+
+#include "ColorConversion.h"
+
+namespace WebCore {
+
+template<typename ColorType> inline float relativeLuminance(const ColorType& color)
+{
+    // https://en.wikipedia.org/wiki/Relative_luminance
+
+    // FIXME: This can be optimized a bit by observing that in some cases the conversion
+    // to XYZA<float, WhitePoint::D65> in its entirety is unnecessary to get just the Y
+    // component. For instance, for SRGBA<float>, this could be done as:
+    //
+    //     convertColor<LinearSRGBA<float>>(color) * LinearSRGBA<float>::linearToXYZ.row(1)
+    //
+    // (for a hypothetical row() function on ColorMatrix). We would probably want to implement
+    // this in ColorConversion.h as a sibling function to convertColor which can get a channel
+    // of a color in another space in this kind of optimal way.
+
+    return convertColor<XYZA<float, WhitePoint::D65>>(color).y;
+}
+
+inline float contrastRatio(float relativeLuminanceA, float relativeLuminanceB)
+{
+    // Uses the WCAG 2.0 definition of contrast ratio.
+    // https://www.w3.org/TR/WCAG20/#contrast-ratiodef
+    auto lighterLuminance = relativeLuminanceA;
+    auto darkerLuminance = relativeLuminanceB;
+
+    if (lighterLuminance < darkerLuminance)
+        std::swap(lighterLuminance, darkerLuminance);
+
+    return (lighterLuminance + 0.05) / (darkerLuminance + 0.05);
+}
+
+template<typename ColorTypeA, typename ColorTypeB> inline float contrastRatio(const ColorTypeA& colorA, const ColorTypeB& colorB)
+{
+    return contrastRatio(relativeLuminance(colorA), relativeLuminance(colorB));
+}
+
+}

Modified: trunk/Source/WebCore/platform/graphics/ColorUtilities.cpp (273682 => 273683)


--- trunk/Source/WebCore/platform/graphics/ColorUtilities.cpp	2021-03-01 20:53:49 UTC (rev 273682)
+++ trunk/Source/WebCore/platform/graphics/ColorUtilities.cpp	2021-03-01 20:56:56 UTC (rev 273683)
@@ -26,39 +26,8 @@
 #include "config.h"
 #include "ColorUtilities.h"
 
-#include "ColorConversion.h"
-
 namespace WebCore {
 
-float lightness(const SRGBA<float>& color)
-{
-    auto [r, g, b, a] = color;
-    auto [min, max] = std::minmax({ r, g, b });
-    return 0.5f * (max + min);
-}
-
-float luminance(const SRGBA<float>& color)
-{
-    // NOTE: This is the equivalent of convertColor<XYZA<float, WhitePoint::D65>>(color).y
-    // FIMXE: If we can generalize ColorMatrix a bit more, it might be nice to write this as:
-    //      return convertColor<LinearSRGBA<float>>(color) * linearSRGBToXYZMatrix.row(1);
-    auto [r, g, b, a] = convertColor<LinearSRGBA<float>>(color);
-    return 0.2126f * r + 0.7152f * g + 0.0722f * b;
-}
-
-float contrastRatio(const SRGBA<float>& colorA, const SRGBA<float>& colorB)
-{
-    // Uses the WCAG 2.0 definition of contrast ratio.
-    // https://www.w3.org/TR/WCAG20/#contrast-ratiodef
-    float lighterLuminance = luminance(colorA);
-    float darkerLuminance = luminance(colorB);
-
-    if (lighterLuminance < darkerLuminance)
-        std::swap(lighterLuminance, darkerLuminance);
-
-    return (lighterLuminance + 0.05) / (darkerLuminance + 0.05);
-}
-
 SRGBA<float> premultiplied(const SRGBA<float>& color)
 {
     auto [r, g, b, a] = color;

Modified: trunk/Source/WebCore/platform/graphics/ColorUtilities.h (273682 => 273683)


--- trunk/Source/WebCore/platform/graphics/ColorUtilities.h	2021-03-01 20:53:49 UTC (rev 273682)
+++ trunk/Source/WebCore/platform/graphics/ColorUtilities.h	2021-03-01 20:56:56 UTC (rev 273683)
@@ -34,10 +34,6 @@
 
 namespace WebCore {
 
-float lightness(const SRGBA<float>&);
-float luminance(const SRGBA<float>&);
-float contrastRatio(const SRGBA<float>&, const SRGBA<float>&);
-
 SRGBA<float> premultiplied(const SRGBA<float>&);
 SRGBA<float> unpremultiplied(const SRGBA<float>&);
 
@@ -55,8 +51,8 @@
 template<typename ColorType> constexpr ColorType colorWithOverriddenAlpha(const ColorType&, uint8_t overrideAlpha);
 template<typename ColorType> ColorType colorWithOverriddenAlpha(const ColorType&, float overrideAlpha);
 
-template<typename ColorType> constexpr ColorType invertedcolorWithOverriddenAlpha(const ColorType&, uint8_t overrideAlpha);
-template<typename ColorType> ColorType invertedcolorWithOverriddenAlpha(const ColorType&, float overrideAlpha);
+template<typename ColorType> constexpr ColorType invertedColorWithOverriddenAlpha(const ColorType&, uint8_t overrideAlpha);
+template<typename ColorType> ColorType invertedColorWithOverriddenAlpha(const ColorType&, float overrideAlpha);
 
 template<typename ColorType, typename std::enable_if_t<std::is_same_v<typename ColorType::Model, RGBModel<typename ColorType::ComponentType>>>* = nullptr> constexpr bool isBlack(const ColorType&);
 template<WhitePoint W> constexpr bool isBlack(const XYZA<float, W>&);
@@ -121,7 +117,7 @@
     return copy;
 }
 
-template<typename ColorType> constexpr ColorType invertedcolorWithOverriddenAlpha(const ColorType& color, uint8_t overrideAlpha)
+template<typename ColorType> constexpr ColorType invertedColorWithOverriddenAlpha(const ColorType& color, uint8_t overrideAlpha)
 {
     static_assert(ColorType::Model::isInvertible);
 
@@ -135,7 +131,7 @@
     return makeFromComponents<ColorType>(copy);
 }
 
-template<typename ColorType> ColorType invertedcolorWithOverriddenAlpha(const ColorType& color, float overrideAlpha)
+template<typename ColorType> ColorType invertedColorWithOverriddenAlpha(const ColorType& color, float overrideAlpha)
 {
     static_assert(ColorType::Model::isInvertible);
 

Modified: trunk/Source/WebCore/rendering/RenderTheme.cpp (273682 => 273683)


--- trunk/Source/WebCore/rendering/RenderTheme.cpp	2021-03-01 20:53:49 UTC (rev 273682)
+++ trunk/Source/WebCore/rendering/RenderTheme.cpp	2021-03-01 20:56:56 UTC (rev 273683)
@@ -1407,7 +1407,7 @@
     // If there's not very much contrast between the disabled color and the background color,
     // just leave the text color alone. We don't want to change a good contrast color scheme so that it has really bad contrast.
     // If the contrast was already poor, then it doesn't do any good to change it to a different poor contrast color scheme.
-    if (contrastRatio(disabledColor.toSRGBALossy<float>(), backgroundColor.toSRGBALossy<float>()) < minColorContrastValue)
+    if (Color::contrastRatio(disabledColor, backgroundColor) < minColorContrastValue)
         return textColor;
 
     return disabledColor;

Modified: trunk/Source/WebCore/rendering/TextPaintStyle.cpp (273682 => 273683)


--- trunk/Source/WebCore/rendering/TextPaintStyle.cpp	2021-03-01 20:53:49 UTC (rev 273682)
+++ trunk/Source/WebCore/rendering/TextPaintStyle.cpp	2021-03-01 20:56:56 UTC (rev 273683)
@@ -63,7 +63,7 @@
 {
     // Uses the WCAG 2.0 definition of legibility: a contrast ratio of 4.5:1 or greater.
     // https://www.w3.org/TR/WCAG20/#visual-audio-contrast-contrast
-    return contrastRatio(textColor.toSRGBALossy<float>(), backgroundColor.toSRGBALossy<float>()) > 4.5;
+    return Color::contrastRatio(textColor, backgroundColor) > 4.5;
 }
 
 static Color adjustColorForVisibilityOnBackground(const Color& textColor, const Color& backgroundColor)

Modified: trunk/Tools/ChangeLog (273682 => 273683)


--- trunk/Tools/ChangeLog	2021-03-01 20:53:49 UTC (rev 273682)
+++ trunk/Tools/ChangeLog	2021-03-01 20:56:56 UTC (rev 273683)
@@ -1,3 +1,16 @@
+2021-03-01  Sam Weinig  <wei...@apple.com>
+
+        Add experimental support for CSS Color 5 color-contrast()
+        https://bugs.webkit.org/show_bug.cgi?id=222530
+
+        Reviewed by Simon Fraser.
+
+        * TestWebKitAPI/Tests/WebCore/ColorTests.cpp:
+        (TestWebKitAPI::TEST):
+        Update luminance values to account for more accurate conversion to
+        XYZ now that we are usuing the actual matrix values from SRGBADescriptor
+        and not a truncated copy.
+
 2021-03-01  Megan Gardner  <megan_gard...@apple.com>
 
         Restoring App Highlight crashes if no range is found.

Modified: trunk/Tools/TestWebKitAPI/Tests/WebCore/ColorTests.cpp (273682 => 273683)


--- trunk/Tools/TestWebKitAPI/Tests/WebCore/ColorTests.cpp	2021-03-01 20:53:49 UTC (rev 273682)
+++ trunk/Tools/TestWebKitAPI/Tests/WebCore/ColorTests.cpp	2021-03-01 20:56:56 UTC (rev 273683)
@@ -214,7 +214,7 @@
     EXPECT_FLOAT_EQ(Color(Color::white).luminance(), 1);
 
     auto cComponents = SRGBA<uint8_t> { 85, 90, 160 };
-    EXPECT_FLOAT_EQ(Color(cComponents).luminance(), 0.11781692);
+    EXPECT_FLOAT_EQ(Color(cComponents).luminance(), 0.11781455);
 
     EXPECT_EQ(cComponents.red, 85);
     EXPECT_EQ(cComponents.green, 90);
@@ -221,13 +221,13 @@
     EXPECT_EQ(cComponents.blue, 160);
 
     auto cLigtened = Color(cComponents).lightened().toSRGBALossy<uint8_t>();
-    EXPECT_FLOAT_EQ(Color(cLigtened).luminance(), 0.29168808);
+    EXPECT_FLOAT_EQ(Color(cLigtened).luminance(), 0.291682);
     EXPECT_EQ(cLigtened.red, 130);
     EXPECT_EQ(cLigtened.green, 137);
     EXPECT_EQ(cLigtened.blue, 244);
 
     auto cDarkened = Color(cComponents).darkened().toSRGBALossy<uint8_t>();
-    EXPECT_FLOAT_EQ(Color(cDarkened).luminance(), 0.027006727);
+    EXPECT_FLOAT_EQ(Color(cDarkened).luminance(), 0.027006242);
     EXPECT_EQ(cDarkened.red, 40);
     EXPECT_EQ(cDarkened.green, 43);
     EXPECT_EQ(cDarkened.blue, 76);
_______________________________________________
webkit-changes mailing list
webkit-changes@lists.webkit.org
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to