haikuwebkit/LayoutTests/fast/css/parsing-color-contrast-expe...

50 lines
3.7 KiB
Plaintext
Raw Permalink Normal View History

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(). Canonical link: https://commits.webkit.org/234706@main git-svn-id: https://svn.webkit.org/repository/webkit/trunk@273683 268f45cc-cd09-0410-ab3c-d52691b4dbfc
2021-03-01 20:56:56 +00:00
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 ..., ... [to ...])
Test with no specified target contrast
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(). Canonical link: https://commits.webkit.org/234706@main git-svn-id: https://svn.webkit.org/repository/webkit/trunk@273683 268f45cc-cd09-0410-ab3c-d52691b4dbfc
2021-03-01 20:56:56 +00:00
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 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
PASS computedStyle("background-color", "color-contrast(wheat vs bisque, darkgoldenrod, olive to 100)") is "rgb(0, 0, 0)"
PASS computedStyle("background-color", "color-contrast(green vs bisque, darkgoldenrod, olive to 100)") is "rgb(255, 255, 255)"
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(). Canonical link: https://commits.webkit.org/234706@main git-svn-id: https://svn.webkit.org/repository/webkit/trunk@273683 268f45cc-cd09-0410-ab3c-d52691b4dbfc
2021-03-01 20:56:56 +00:00
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 computedStyle("background-color", "color-contrast(white vs red, green to)") is "rgba(0, 0, 0, 0)"
PASS computedStyle("background-color", "color-contrast(white vs red, green to invalid)") is "rgba(0, 0, 0, 0)"
PASS computedStyle("background-color", "color-contrast(white vs red to AA)") is "rgba(0, 0, 0, 0)"
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(). Canonical link: https://commits.webkit.org/234706@main git-svn-id: https://svn.webkit.org/repository/webkit/trunk@273683 268f45cc-cd09-0410-ab3c-d52691b4dbfc
2021-03-01 20:56:56 +00:00
PASS successfullyParsed is true
TEST COMPLETE