Changeset 273683 in webkit
- Timestamp:
- Mar 1, 2021 12:56:56 PM (17 months ago)
- Location:
- trunk
- Files:
-
- 3 added
- 18 edited
-
LayoutTests/ChangeLog (modified) (1 diff)
-
LayoutTests/fast/css/parsing-color-contrast-expected.txt (added)
-
LayoutTests/fast/css/parsing-color-contrast.html (added)
-
Source/WTF/ChangeLog (modified) (1 diff)
-
Source/WTF/Scripts/Preferences/WebPreferencesExperimental.yaml (modified) (1 diff)
-
Source/WebCore/ChangeLog (modified) (1 diff)
-
Source/WebCore/Headers.cmake (modified) (1 diff)
-
Source/WebCore/WebCore.xcodeproj/project.pbxproj (modified) (5 diffs)
-
Source/WebCore/css/CSSValueKeywords.in (modified) (1 diff)
-
Source/WebCore/css/parser/CSSParserContext.cpp (modified) (2 diffs)
-
Source/WebCore/css/parser/CSSParserContext.h (modified) (2 diffs)
-
Source/WebCore/css/parser/CSSPropertyParserHelpers.cpp (modified) (3 diffs)
-
Source/WebCore/platform/graphics/Color.cpp (modified) (4 diffs)
-
Source/WebCore/platform/graphics/Color.h (modified) (2 diffs)
-
Source/WebCore/platform/graphics/ColorLuminance.h (added)
-
Source/WebCore/platform/graphics/ColorUtilities.cpp (modified) (1 diff)
-
Source/WebCore/platform/graphics/ColorUtilities.h (modified) (4 diffs)
-
Source/WebCore/rendering/RenderTheme.cpp (modified) (1 diff)
-
Source/WebCore/rendering/TextPaintStyle.cpp (modified) (1 diff)
-
Tools/ChangeLog (modified) (1 diff)
-
Tools/TestWebKitAPI/Tests/WebCore/ColorTests.cpp (modified) (3 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/LayoutTests/ChangeLog
r273672 r273683 1 2021-03-01 Sam Weinig <weinig@apple.com> 2 3 Add experimental support for CSS Color 5 color-contrast() 4 https://bugs.webkit.org/show_bug.cgi?id=222530 5 6 Reviewed by Simon Fraser. 7 8 * fast/css/parsing-color-contrast-expected.txt: Added. 9 * fast/css/parsing-color-contrast.html: Added. 10 Add parsing and computed style computation tests for color-contast(). 11 1 12 2021-03-01 Said Abou-Hallawa <said@apple.com> 2 13 -
trunk/Source/WTF/ChangeLog
r273657 r273683 1 2021-03-01 Sam Weinig <weinig@apple.com> 2 3 Add experimental support for CSS Color 5 color-contrast() 4 https://bugs.webkit.org/show_bug.cgi?id=222530 5 6 Reviewed by Simon Fraser. 7 8 * Scripts/Preferences/WebPreferencesExperimental.yaml: 9 Add new experimental preference for CSS Color 5 color-contrast() 10 which is off by default. 11 1 12 2021-02-25 Simon Fraser <simon.fraser@apple.com> 2 13 -
trunk/Source/WTF/Scripts/Preferences/WebPreferencesExperimental.yaml
r273244 r273683 114 114 default: false 115 115 116 CSSColorContrastEnabled: 117 type: bool 118 humanReadableName: "CSS color-contrast()" 119 humanReadableDescription: "Enable support for CSS color-contrast() defined in CSS Color 5" 120 defaultValue: 121 WebKitLegacy: 122 default: false 123 WebKit: 124 default: false 125 WebCore: 126 default: false 127 116 128 CSSColorMixEnabled: 117 129 type: bool -
trunk/Source/WebCore/ChangeLog
r273681 r273683 1 2021-03-01 Sam Weinig <weinig@apple.com> 2 3 Add experimental support for CSS Color 5 color-contrast() 4 https://bugs.webkit.org/show_bug.cgi?id=222530 5 6 Reviewed by Simon Fraser. 7 8 This feature is off by default and can be enabled via the CSSColorContrastEnabled 9 experimental preference flag. 10 11 This implementation has the same restriction on it that the recently landed 12 Relative Color Syntax and color-mix() do, in that it does support system colors 13 or currentColor as input, since those can't be resolved at parse time. Ultimately, 14 we will need to add a late binding version of this for those cases. 15 16 Test: fast/css/parsing-color-contrast.html 17 18 * Headers.cmake: 19 * WebCore.xcodeproj/project.pbxproj: 20 Add new ColorLuminance.h header where the generic relative luminance and contrast ratio 21 functions live. 22 23 * css/CSSValueKeywords.in: 24 Add new keywords, color-contrast and vs, that are needed for the color-contrast() function. 25 26 * css/parser/CSSParserContext.cpp: 27 * css/parser/CSSParserContext.h: 28 Add a setting for color-contrast. 29 30 * css/parser/CSSPropertyParserHelpers.cpp: 31 (WebCore::CSSPropertyParserHelpers::parseColorContrastFunctionParameters): 32 (WebCore::CSSPropertyParserHelpers::parseColorFunction): 33 Add parsing and computation of color-contrast(). 34 35 * platform/graphics/ColorUtilities.cpp: 36 (WebCore::lightness): Deleted. 37 (WebCore::luminance): Deleted. 38 (WebCore::contrastRatio): Deleted. 39 Moved luminance related functions to ColorLuminance.h and inlined lightness 40 to its one caller, Color and noted it should be removed. 41 42 * platform/graphics/ColorUtilities.h: 43 (WebCore::invertedColorWithOverriddenAlpha): 44 (WebCore::invertedcolorWithOverriddenAlpha): Deleted. 45 Fix capitalization issue seen. invertedcolorWithOverriddenAlpha -> invertedColorWithOverriddenAlpha. 46 47 * platform/graphics/Color.cpp: 48 (WebCore::Color::lightness const): 49 Inline implementation and add comment explaining it should be removed. 50 51 (WebCore::Color::luminance const): 52 Re-write to use the new WebCore::relativeLuminance that works for any color type 53 without conversion to sRGB. 54 55 (WebCore::Color::contrastRatio): 56 Add helper to call generic WebCore::contrastRatio that works on any color types 57 to avoid callers needing to do the unfolding themselves. 58 59 (WebCore::Color::isBlackColor): 60 (WebCore::Color::isWhiteColor): 61 * platform/graphics/Color.h: 62 (WebCore::Color::isBlackColor): Deleted. 63 (WebCore::Color::isWhiteColor): Deleted. 64 Move these rare functions out of line to reduce the number of places in the header we are 65 calling callOnUnderlyingType(), which produces code linerally with the number of color spaces 66 supported. Calling it in the cpp files means we only expand it once for each function. 67 68 * platform/graphics/ColorLuminance.h: Added. 69 (WebCore::relativeLuminance): 70 This is a generic version of the old luminance function that works for any color type 71 by converting to XYZ and taking the Y component. The old function required always 72 converting to sRGB which could be lossy. 73 74 (WebCore::contrastRatio): 75 Split out computation of contrastRatio based on relative luminace floats into its own 76 function so that if we have the relative luminance computed already, we don't have to 77 recompute it. Add version contrastRatio that works for any color type utilizing the 78 generic relativeLuminance function above. 79 80 * rendering/RenderTheme.cpp: 81 (WebCore::RenderTheme::disabledTextColor const): 82 * rendering/TextPaintStyle.cpp: 83 (WebCore::textColorIsLegibleAgainstBackgroundColor): 84 Update to use new Color::contrastRatio helper that handles all color types. 85 1 86 2021-03-01 Zalan Bujtas <zalan@apple.com> 2 87 -
trunk/Source/WebCore/Headers.cmake
r273504 r273683 1167 1167 platform/graphics/ColorConversion.h 1168 1168 platform/graphics/ColorHash.h 1169 platform/graphics/ColorLuminance.h 1169 1170 platform/graphics/ColorMatrix.h 1170 1171 platform/graphics/ColorModels.h -
trunk/Source/WebCore/WebCore.xcodeproj/project.pbxproj
r273550 r273683 3973 3973 BC4918C90BFEA050009D6316 /* JSHTMLIFrameElement.h in Headers */ = {isa = PBXBuildFile; fileRef = BC4918C30BFEA050009D6316 /* JSHTMLIFrameElement.h */; }; 3974 3974 BC491B790C023EFD009D6316 /* JSHTMLMarqueeElement.h in Headers */ = {isa = PBXBuildFile; fileRef = BC491B770C023EFD009D6316 /* JSHTMLMarqueeElement.h */; }; 3975 BC4A23EC25EC160200AAC630 /* ColorLuminance.h in Headers */ = {isa = PBXBuildFile; fileRef = BC4A23EB25EC160200AAC630 /* ColorLuminance.h */; settings = {ATTRIBUTES = (Private, ); }; }; 3975 3976 BC4A5323256052760028C592 /* EditableLinkBehavior.h in Headers */ = {isa = PBXBuildFile; fileRef = BC4A5321256052700028C592 /* EditableLinkBehavior.h */; settings = {ATTRIBUTES = (Private, ); }; }; 3976 3977 BC4A53252560555F0028C592 /* TextDirectionSubmenuInclusionBehavior.h in Headers */ = {isa = PBXBuildFile; fileRef = BC4A5324256055590028C592 /* TextDirectionSubmenuInclusionBehavior.h */; settings = {ATTRIBUTES = (Private, ); }; }; … … 14035 14036 BC491B760C023EFD009D6316 /* JSHTMLMarqueeElement.cpp */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.cpp.cpp; path = JSHTMLMarqueeElement.cpp; sourceTree = "<group>"; }; 14036 14037 BC491B770C023EFD009D6316 /* JSHTMLMarqueeElement.h */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.c.h; path = JSHTMLMarqueeElement.h; sourceTree = "<group>"; }; 14038 BC4A23EB25EC160200AAC630 /* ColorLuminance.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = ColorLuminance.h; sourceTree = "<group>"; }; 14037 14039 BC4A5321256052700028C592 /* EditableLinkBehavior.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = EditableLinkBehavior.h; sourceTree = "<group>"; }; 14038 14040 BC4A5324256055590028C592 /* TextDirectionSubmenuInclusionBehavior.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = TextDirectionSubmenuInclusionBehavior.h; sourceTree = "<group>"; }; … … 26660 26662 7CAC6AE8247F082000E61D59 /* ColorMatrix.h */, 26661 26663 BC10137B25C3624B00DC773C /* ColorModels.h */, 26664 BC4A23EB25EC160200AAC630 /* ColorLuminance.h */, 26662 26665 7CD1E69224ABF6240089C419 /* ColorSerialization.cpp */, 26663 26666 7CD1E69124ABF6240089C419 /* ColorSerialization.h */, … … 31146 31149 A1BF6B831AA96C7D00AF4A8A /* MockContentFilter.h in Headers */, 31147 31150 A1B5B29F1AAA846F008B6042 /* MockContentFilterSettings.h in Headers */, 31148 51058ADC1D6792C1009A538C /* MockGamepad.h in Headers */,31149 51058ADE1D6792C1009A538C /* MockGamepadProvider.h in Headers */,31150 31151 4157EBFB1E3AB67F00AC9FE9 /* MockLibWebRTCPeerConnection.h in Headers */, 31151 31152 2D6F3E911C1ECB2F0061DBD4 /* MockPageOverlay.h in Headers */, … … 31873 31874 715AD7212050513F00D592DC /* CSSTransition.h in Headers */, 31874 31875 371F53E90D2704F900ECE0D5 /* CSSUnicodeRangeValue.h in Headers */, 31876 BC4A23EC25EC160200AAC630 /* ColorLuminance.h in Headers */, 31875 31877 0F6B707A237BC36D0052CA47 /* CSSUnits.h in Headers */, 31876 31878 DD7CDF250A23CF9800069928 /* CSSUnknownRule.h in Headers */, -
trunk/Source/WebCore/css/CSSValueKeywords.in
r273244 r273683 1435 1435 xyz 1436 1436 1437 // color-contast() 1438 color-contrast 1439 vs 1440 1437 1441 // color-mix() 1438 1442 color-mix -
trunk/Source/WebCore/css/parser/CSSParserContext.cpp
r273244 r273683 69 69 , useSystemAppearance { document.page() ? document.page()->useSystemAppearance() : false } 70 70 , aspectRatioEnabled { document.settings().aspectRatioEnabled() } 71 , colorContrastEnabled { document.settings().cssColorContrastEnabled() } 71 72 , colorFilterEnabled { document.settings().colorFilterEnabled() } 72 73 , colorMixEnabled { document.settings().cssColorMixEnabled() } … … 107 108 && a.useSystemAppearance == b.useSystemAppearance 108 109 && a.aspectRatioEnabled == b.aspectRatioEnabled 110 && a.colorContrastEnabled == b.colorContrastEnabled 109 111 && a.colorFilterEnabled == b.colorFilterEnabled 110 112 && a.colorMixEnabled == b.colorMixEnabled -
trunk/Source/WebCore/css/parser/CSSParserContext.h
r273244 r273683 59 59 // Settings. 60 60 bool aspectRatioEnabled { false }; 61 bool colorContrastEnabled { false }; 61 62 bool colorFilterEnabled { false }; 62 63 bool colorMixEnabled { false }; … … 110 111 & key.useSystemAppearance << 3 111 112 & key.aspectRatioEnabled << 4 112 & key.colorFilterEnabled << 5 113 & key.colorMixEnabled << 6 114 & key.constantPropertiesEnabled << 7 115 & key.deferredCSSParserEnabled << 8 116 & key.enforcesCSSMIMETypeInNoQuirksMode << 9 117 & key.individualTransformPropertiesEnabled << 10 113 & key.colorContrastEnabled << 5 114 & key.colorFilterEnabled << 6 115 & key.colorMixEnabled << 7 116 & key.constantPropertiesEnabled << 8 117 & key.deferredCSSParserEnabled << 9 118 & key.enforcesCSSMIMETypeInNoQuirksMode << 10 119 & key.individualTransformPropertiesEnabled << 11 118 120 #if ENABLE(OVERFLOW_SCROLLING_TOUCH) 119 & key.legacyOverflowScrollingTouchEnabled << 1 1121 & key.legacyOverflowScrollingTouchEnabled << 12 120 122 #endif 121 & key.overscrollBehaviorEnabled << 1 2122 & key.relativeColorSyntaxEnabled << 1 3123 & key.scrollBehaviorEnabled << 1 4124 & key.springTimingFunctionEnabled << 1 5123 & key.overscrollBehaviorEnabled << 13 124 & key.relativeColorSyntaxEnabled << 14 125 & key.scrollBehaviorEnabled << 15 126 & key.springTimingFunctionEnabled << 16 125 127 #if ENABLE(TEXT_AUTOSIZING) 126 & key.textAutosizingEnabled << 1 6128 & key.textAutosizingEnabled << 17 127 129 #endif 128 130 #if ENABLE(CSS_TRANSFORM_STYLE_OPTIMIZED_3D) 129 & key.transformStyleOptimized3DEnabled << 1 7131 & key.transformStyleOptimized3DEnabled << 18 130 132 #endif 131 & key.useLegacyBackgroundSizeShorthandBehavior << 1 8132 & key.focusVisibleEnabled << 19133 & key.useLegacyBackgroundSizeShorthandBehavior << 19 134 & key.focusVisibleEnabled << 20 133 135 #if ENABLE(ATTACHMENT_ELEMENT) 134 & key.attachmentEnabled << 2 0136 & key.attachmentEnabled << 21 135 137 #endif 136 & key.mode << 2 1; // Keep this last.138 & key.mode << 22; // Keep this last. 137 139 hash ^= WTF::intHash(bits); 138 140 return hash; -
trunk/Source/WebCore/css/parser/CSSPropertyParserHelpers.cpp
r273428 r273683 43 43 #include "CSSValuePool.h" 44 44 #include "ColorConversion.h" 45 #include "ColorLuminance.h" 45 46 #include "Pair.h" 46 47 #include "RuntimeEnabledFeatures.h" … … 1483 1484 } 1484 1485 1486 static Color parseColorContrastFunctionParameters(CSSParserTokenRange& range, const CSSParserContext& context) 1487 { 1488 ASSERT(range.peek().functionId() == CSSValueColorContrast); 1489 1490 if (!context.colorContrastEnabled) 1491 return { }; 1492 1493 auto args = consumeFunction(range); 1494 1495 auto originBackgroundColor = consumeOriginColor(args, context); 1496 if (!originBackgroundColor.isValid()) 1497 return { }; 1498 1499 if (!consumeIdentRaw<CSSValueVs>(args)) 1500 return { }; 1501 1502 Vector<Color> colorsToCompareAgainst; 1503 do { 1504 auto colorToCompareAgainst = consumeOriginColor(args, context); 1505 if (!colorToCompareAgainst.isValid()) 1506 return { }; 1507 1508 colorsToCompareAgainst.append(WTFMove(colorToCompareAgainst)); 1509 } while (consumeCommaIncludingWhitespace(args)); 1510 1511 if (colorsToCompareAgainst.size() == 1) 1512 return { }; 1513 1514 auto originBackgroundColorLuminance = originBackgroundColor.luminance(); 1515 1516 size_t indexOfColorWithHigestContrastRatio = 0; 1517 float highestContrastRatioSoFar = 0; 1518 for (size_t i = 0; i < colorsToCompareAgainst.size(); ++i) { 1519 auto contrastRatio = WebCore::contrastRatio(originBackgroundColorLuminance, colorsToCompareAgainst[i].luminance()); 1520 if (contrastRatio > highestContrastRatioSoFar) { 1521 highestContrastRatioSoFar = contrastRatio; 1522 indexOfColorWithHigestContrastRatio = i; 1523 } 1524 } 1525 1526 return colorsToCompareAgainst[indexOfColorWithHigestContrastRatio]; 1527 } 1528 1485 1529 struct HueColorAdjuster { 1486 1530 enum class Type { … … 1925 1969 case CSSValueColor: 1926 1970 color = parseColorFunctionParameters(colorRange); 1971 break; 1972 case CSSValueColorContrast: 1973 color = parseColorContrastFunctionParameters(colorRange, context); 1927 1974 break; 1928 1975 case CSSValueColorMix: -
trunk/Source/WebCore/platform/graphics/Color.cpp
r273211 r273683 27 27 #include "Color.h" 28 28 29 #include "ColorLuminance.h" 29 30 #include "ColorSerialization.h" 30 #include "ColorUtilities.h"31 31 #include <wtf/Assertions.h> 32 32 #include <wtf/text/TextStream.h> … … 112 112 float Color::lightness() const 113 113 { 114 // FIXME: This can probably avoid conversion to sRGB by having per-colorspace algorithms for HSL. 115 return WebCore::lightness(toSRGBALossy<float>()); 114 // FIXME: Replace remaining uses with luminance. 115 auto [r, g, b, a] = toSRGBALossy<float>(); 116 auto [min, max] = std::minmax({ r, g, b }); 117 return 0.5f * (max + min); 116 118 } 117 119 118 120 float Color::luminance() const 119 121 { 120 // FIXME: This can probably avoid conversion to sRGB by having per-colorspace algorithms 121 // for luminance (e.g. convertToXYZ(c).yComponent()). 122 return WebCore::luminance(toSRGBALossy<float>()); 122 return callOnUnderlyingType([&] (const auto& underlyingColor) { 123 return WebCore::relativeLuminance(underlyingColor); 124 }); 125 } 126 127 float Color::contrastRatio(const Color& colorA, const Color& colorB) 128 { 129 return colorA.callOnUnderlyingType([&] (const auto& underlyingColorA) { 130 return colorB.callOnUnderlyingType([&] (const auto& underlyingColorB) { 131 return WebCore::contrastRatio(underlyingColorA, underlyingColorB); 132 }); 133 }); 123 134 } 124 135 … … 145 156 // of alternatives. 146 157 if constexpr (ColorType::Model::isInvertible) 147 return inverted colorWithOverriddenAlpha(underlyingColor, alpha);158 return invertedColorWithOverriddenAlpha(underlyingColor, alpha); 148 159 else 149 return inverted colorWithOverriddenAlpha(convertColor<SRGBA<float>>(underlyingColor), alpha);160 return invertedColorWithOverriddenAlpha(convertColor<SRGBA<float>>(underlyingColor), alpha); 150 161 }); 151 162 } … … 168 179 } 169 180 181 bool Color::isBlackColor(const Color& color) 182 { 183 return color.callOnUnderlyingType([] (const auto& underlyingColor) { 184 return WebCore::isBlack(underlyingColor); 185 }); 186 } 187 188 bool Color::isWhiteColor(const Color& color) 189 { 190 return color.callOnUnderlyingType([] (const auto& underlyingColor) { 191 return WebCore::isWhite(underlyingColor); 192 }); 193 } 194 170 195 TextStream& operator<<(TextStream& ts, const Color& color) 171 196 { -
trunk/Source/WebCore/platform/graphics/Color.h
r273244 r273683 106 106 WEBCORE_EXPORT float luminance() const; 107 107 WEBCORE_EXPORT float lightness() const; // FIXME: Replace remaining uses with luminance. 108 WEBCORE_EXPORT static float contrastRatio(const Color&, const Color&); 108 109 109 110 template<typename Functor> decltype(auto) callOnUnderlyingType(Functor&&) const; … … 493 494 m_colorAndFlags = encodedExtendedColor(WTFMove(color)) | encodedFlags(flags); 494 495 ASSERT(isExtended()); 495 }496 497 inline bool Color::isBlackColor(const Color& color)498 {499 return color.callOnUnderlyingType([] (const auto& underlyingColor) {500 return WebCore::isBlack(underlyingColor);501 });502 }503 504 inline bool Color::isWhiteColor(const Color& color)505 {506 return color.callOnUnderlyingType([] (const auto& underlyingColor) {507 return WebCore::isWhite(underlyingColor);508 });509 496 } 510 497 -
trunk/Source/WebCore/platform/graphics/ColorUtilities.cpp
r272436 r273683 27 27 #include "ColorUtilities.h" 28 28 29 #include "ColorConversion.h"30 31 29 namespace WebCore { 32 33 float lightness(const SRGBA<float>& color)34 {35 auto [r, g, b, a] = color;36 auto [min, max] = std::minmax({ r, g, b });37 return 0.5f * (max + min);38 }39 40 float luminance(const SRGBA<float>& color)41 {42 // NOTE: This is the equivalent of convertColor<XYZA<float, WhitePoint::D65>>(color).y43 // FIMXE: If we can generalize ColorMatrix a bit more, it might be nice to write this as:44 // return convertColor<LinearSRGBA<float>>(color) * linearSRGBToXYZMatrix.row(1);45 auto [r, g, b, a] = convertColor<LinearSRGBA<float>>(color);46 return 0.2126f * r + 0.7152f * g + 0.0722f * b;47 }48 49 float contrastRatio(const SRGBA<float>& colorA, const SRGBA<float>& colorB)50 {51 // Uses the WCAG 2.0 definition of contrast ratio.52 // https://www.w3.org/TR/WCAG20/#contrast-ratiodef53 float lighterLuminance = luminance(colorA);54 float darkerLuminance = luminance(colorB);55 56 if (lighterLuminance < darkerLuminance)57 std::swap(lighterLuminance, darkerLuminance);58 59 return (lighterLuminance + 0.05) / (darkerLuminance + 0.05);60 }61 30 62 31 SRGBA<float> premultiplied(const SRGBA<float>& color) -
trunk/Source/WebCore/platform/graphics/ColorUtilities.h
r273211 r273683 35 35 namespace WebCore { 36 36 37 float lightness(const SRGBA<float>&);38 float luminance(const SRGBA<float>&);39 float contrastRatio(const SRGBA<float>&, const SRGBA<float>&);40 41 37 SRGBA<float> premultiplied(const SRGBA<float>&); 42 38 SRGBA<float> unpremultiplied(const SRGBA<float>&); … … 56 52 template<typename ColorType> ColorType colorWithOverriddenAlpha(const ColorType&, float overrideAlpha); 57 53 58 template<typename ColorType> constexpr ColorType inverted colorWithOverriddenAlpha(const ColorType&, uint8_t overrideAlpha);59 template<typename ColorType> ColorType inverted colorWithOverriddenAlpha(const ColorType&, float overrideAlpha);54 template<typename ColorType> constexpr ColorType invertedColorWithOverriddenAlpha(const ColorType&, uint8_t overrideAlpha); 55 template<typename ColorType> ColorType invertedColorWithOverriddenAlpha(const ColorType&, float overrideAlpha); 60 56 61 57 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&); … … 122 118 } 123 119 124 template<typename ColorType> constexpr ColorType inverted colorWithOverriddenAlpha(const ColorType& color, uint8_t overrideAlpha)120 template<typename ColorType> constexpr ColorType invertedColorWithOverriddenAlpha(const ColorType& color, uint8_t overrideAlpha) 125 121 { 126 122 static_assert(ColorType::Model::isInvertible); … … 136 132 } 137 133 138 template<typename ColorType> ColorType inverted colorWithOverriddenAlpha(const ColorType& color, float overrideAlpha)134 template<typename ColorType> ColorType invertedColorWithOverriddenAlpha(const ColorType& color, float overrideAlpha) 139 135 { 140 136 static_assert(ColorType::Model::isInvertible); -
trunk/Source/WebCore/rendering/RenderTheme.cpp
r272881 r273683 1408 1408 // just leave the text color alone. We don't want to change a good contrast color scheme so that it has really bad contrast. 1409 1409 // If the contrast was already poor, then it doesn't do any good to change it to a different poor contrast color scheme. 1410 if ( contrastRatio(disabledColor.toSRGBALossy<float>(), backgroundColor.toSRGBALossy<float>()) < minColorContrastValue)1410 if (Color::contrastRatio(disabledColor, backgroundColor) < minColorContrastValue) 1411 1411 return textColor; 1412 1412 -
trunk/Source/WebCore/rendering/TextPaintStyle.cpp
r263941 r273683 64 64 // Uses the WCAG 2.0 definition of legibility: a contrast ratio of 4.5:1 or greater. 65 65 // https://www.w3.org/TR/WCAG20/#visual-audio-contrast-contrast 66 return contrastRatio(textColor.toSRGBALossy<float>(), backgroundColor.toSRGBALossy<float>()) > 4.5;66 return Color::contrastRatio(textColor, backgroundColor) > 4.5; 67 67 } 68 68 -
trunk/Tools/ChangeLog
r273654 r273683 1 2021-03-01 Sam Weinig <weinig@apple.com> 2 3 Add experimental support for CSS Color 5 color-contrast() 4 https://bugs.webkit.org/show_bug.cgi?id=222530 5 6 Reviewed by Simon Fraser. 7 8 * TestWebKitAPI/Tests/WebCore/ColorTests.cpp: 9 (TestWebKitAPI::TEST): 10 Update luminance values to account for more accurate conversion to 11 XYZ now that we are usuing the actual matrix values from SRGBADescriptor 12 and not a truncated copy. 13 1 14 2021-03-01 Megan Gardner <megan_gardner@apple.com> 2 15 -
trunk/Tools/TestWebKitAPI/Tests/WebCore/ColorTests.cpp
r272870 r273683 215 215 216 216 auto cComponents = SRGBA<uint8_t> { 85, 90, 160 }; 217 EXPECT_FLOAT_EQ(Color(cComponents).luminance(), 0.11781 692);217 EXPECT_FLOAT_EQ(Color(cComponents).luminance(), 0.11781455); 218 218 219 219 EXPECT_EQ(cComponents.red, 85); … … 222 222 223 223 auto cLigtened = Color(cComponents).lightened().toSRGBALossy<uint8_t>(); 224 EXPECT_FLOAT_EQ(Color(cLigtened).luminance(), 0.29168 808);224 EXPECT_FLOAT_EQ(Color(cLigtened).luminance(), 0.291682); 225 225 EXPECT_EQ(cLigtened.red, 130); 226 226 EXPECT_EQ(cLigtened.green, 137); … … 228 228 229 229 auto cDarkened = Color(cComponents).darkened().toSRGBALossy<uint8_t>(); 230 EXPECT_FLOAT_EQ(Color(cDarkened).luminance(), 0.027006 727);230 EXPECT_FLOAT_EQ(Color(cDarkened).luminance(), 0.027006242); 231 231 EXPECT_EQ(cDarkened.red, 40); 232 232 EXPECT_EQ(cDarkened.green, 43);
Note: See TracChangeset
for help on using the changeset viewer.