Changeset 273078 in webkit
- Timestamp:
- Feb 18, 2021 9:02:08 AM (17 months ago)
- Location:
- trunk
- Files:
-
- 10 edited
-
LayoutTests/ChangeLog (modified) (1 diff)
-
LayoutTests/fast/css/parsing-lab-colors-expected.txt (modified) (1 diff)
-
LayoutTests/fast/css/parsing-lab-colors.html (modified) (1 diff)
-
Source/WebCore/ChangeLog (modified) (1 diff)
-
Source/WebCore/css/parser/CSSPropertyParserHelpers.cpp (modified) (1 diff)
-
Source/WebCore/platform/graphics/ColorSerialization.cpp (modified) (3 diffs)
-
Source/WebCore/platform/graphics/ColorSpace.cpp (modified) (1 diff)
-
Source/WebCore/platform/graphics/ColorSpace.h (modified) (4 diffs)
-
Source/WebCore/platform/graphics/ColorUtilities.h (modified) (3 diffs)
-
Source/WebCore/platform/graphics/cg/ColorSpaceCG.h (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
-
trunk/LayoutTests/ChangeLog
r273073 r273078 1 2021-02-17 Sam Weinig <weinig@apple.com> 2 3 lch() colors should serialize as lch(), not lab() 4 https://bugs.webkit.org/show_bug.cgi?id=222085 5 6 Reviewed by Darin Adler. 7 8 The spec was updated to require lch() to serialize to itself. 9 10 * fast/css/parsing-lab-colors-expected.txt: 11 * fast/css/parsing-lab-colors.html: 12 Update test to reflect new serialization of lch(). 13 1 14 2021-02-18 Martin Robinson <mrobinson@igalia.com> 2 15 -
trunk/LayoutTests/fast/css/parsing-lab-colors-expected.txt
r272909 r273078 21 21 22 22 lch() 23 PASS computedStyle("background-color", "lch(0% 0 0deg)") is "l ab(0% 0 0)"24 PASS computedStyle("background-color", "lch(0% 0 0deg / 1)") is "l ab(0% 0 0)"25 PASS computedStyle("background-color", "lch(0% 0 0deg / 0.5)") is "l ab(0% 0 0 / 0.5)"26 PASS computedStyle("background-color", "lch(100% 230 0deg / 0.5)") is "l ab(100% 230 0 / 0.5)"27 PASS computedStyle("background-color", "lch(20% 50 20deg/0.5)") is "l ab(20% 46.98463 17.101006/ 0.5)"28 PASS computedStyle("background-color", "lch(20% 50 20deg/50%)") is "l ab(20% 46.98463 17.101006/ 0.5)"29 PASS computedStyle("background-color", "lch(10% 20 20deg / -10%)") is "l ab(10% 18.793852 6.8404026/ 0)"30 PASS computedStyle("background-color", "lch(10% 20 20deg / 110%)") is "l ab(10% 18.793852 6.8404026)"31 PASS computedStyle("background-color", "lch(10% 20 1.28rad)") is "l ab(10% 5.7343025 19.160316)"32 PASS computedStyle("background-color", "lch(10% 20 380deg)") is "l ab(10% 18.793852 6.8404026)"33 PASS computedStyle("background-color", "lch(10% 20 -340deg)") is "l ab(10% 18.793852 6.8404026)"34 PASS computedStyle("background-color", "lch(10% 20 740deg)") is "l ab(10% 18.793852 6.8404026)"35 PASS computedStyle("background-color", "lch(10% 20 -700deg)") is "l ab(10% 18.793852 6.8404026)"36 PASS computedStyle("background-color", "lch(-40% 0 0)") is "l ab(0% 0 0)"37 PASS computedStyle("background-color", "lch(20% -20 0)") is "l ab(20% 0 0)"38 PASS computedStyle("background-color", "lch(0% 0 0 / 0.5)") is "l ab(0% 0 0 / 0.5)"39 PASS computedStyle("background-color", "lch(10% 20 20 / 110%)") is "l ab(10% 18.793852 6.8404026)"40 PASS computedStyle("background-color", "lch(10% 20 -700)") is "l ab(10% 18.793852 6.8404026)"23 PASS computedStyle("background-color", "lch(0% 0 0deg)") is "lch(0% 0 0)" 24 PASS computedStyle("background-color", "lch(0% 0 0deg / 1)") is "lch(0% 0 0)" 25 PASS computedStyle("background-color", "lch(0% 0 0deg / 0.5)") is "lch(0% 0 0 / 0.5)" 26 PASS computedStyle("background-color", "lch(100% 230 0deg / 0.5)") is "lch(100% 230 0 / 0.5)" 27 PASS computedStyle("background-color", "lch(20% 50 20deg/0.5)") is "lch(20% 50 20 / 0.5)" 28 PASS computedStyle("background-color", "lch(20% 50 20deg/50%)") is "lch(20% 50 20 / 0.5)" 29 PASS computedStyle("background-color", "lch(10% 20 20deg / -10%)") is "lch(10% 20 20 / 0)" 30 PASS computedStyle("background-color", "lch(10% 20 20deg / 110%)") is "lch(10% 20 20)" 31 PASS computedStyle("background-color", "lch(10% 20 1.28rad)") is "lch(10% 20 73.3386)" 32 PASS computedStyle("background-color", "lch(10% 20 380deg)") is "lch(10% 20 20)" 33 PASS computedStyle("background-color", "lch(10% 20 -340deg)") is "lch(10% 20 20)" 34 PASS computedStyle("background-color", "lch(10% 20 740deg)") is "lch(10% 20 20)" 35 PASS computedStyle("background-color", "lch(10% 20 -700deg)") is "lch(10% 20 20)" 36 PASS computedStyle("background-color", "lch(-40% 0 0)") is "lch(0% 0 0)" 37 PASS computedStyle("background-color", "lch(20% -20 0)") is "lch(20% 0 0)" 38 PASS computedStyle("background-color", "lch(0% 0 0 / 0.5)") is "lch(0% 0 0 / 0.5)" 39 PASS computedStyle("background-color", "lch(10% 20 20 / 110%)") is "lch(10% 20 20)" 40 PASS computedStyle("background-color", "lch(10% 20 -700)") is "lch(10% 20 20)" 41 41 42 42 color(lab ) -
trunk/LayoutTests/fast/css/parsing-lab-colors.html
r272909 r273078 53 53 debug(''); 54 54 debug('lch()'); 55 testComputed("background-color", "lch(0% 0 0deg)", "l ab(0% 0 0)");56 testComputed("background-color", "lch(0% 0 0deg / 1)", "l ab(0% 0 0)");57 testComputed("background-color", "lch(0% 0 0deg / 0.5)", "l ab(0% 0 0 / 0.5)");58 testComputed("background-color", "lch(100% 230 0deg / 0.5)", "l ab(100% 230 0 / 0.5)");59 testComputed("background-color", "lch(20% 50 20deg/0.5)", "l ab(20% 46.98463 17.101006/ 0.5)");60 testComputed("background-color", "lch(20% 50 20deg/50%)", "l ab(20% 46.98463 17.101006/ 0.5)");61 testComputed("background-color", "lch(10% 20 20deg / -10%)", "l ab(10% 18.793852 6.8404026/ 0)");62 testComputed("background-color", "lch(10% 20 20deg / 110%)", "l ab(10% 18.793852 6.8404026)");63 testComputed("background-color", "lch(10% 20 1.28rad)", "l ab(10% 5.7343025 19.160316)");64 testComputed("background-color", "lch(10% 20 380deg)", "l ab(10% 18.793852 6.8404026)");65 testComputed("background-color", "lch(10% 20 -340deg)", "l ab(10% 18.793852 6.8404026)");66 testComputed("background-color", "lch(10% 20 740deg)", "l ab(10% 18.793852 6.8404026)");67 testComputed("background-color", "lch(10% 20 -700deg)", "l ab(10% 18.793852 6.8404026)");68 testComputed("background-color", "lch(-40% 0 0)", "l ab(0% 0 0)");69 testComputed("background-color", "lch(20% -20 0)", "l ab(20% 0 0)");55 testComputed("background-color", "lch(0% 0 0deg)", "lch(0% 0 0)"); 56 testComputed("background-color", "lch(0% 0 0deg / 1)", "lch(0% 0 0)"); 57 testComputed("background-color", "lch(0% 0 0deg / 0.5)", "lch(0% 0 0 / 0.5)"); 58 testComputed("background-color", "lch(100% 230 0deg / 0.5)", "lch(100% 230 0 / 0.5)"); 59 testComputed("background-color", "lch(20% 50 20deg/0.5)", "lch(20% 50 20 / 0.5)"); 60 testComputed("background-color", "lch(20% 50 20deg/50%)", "lch(20% 50 20 / 0.5)"); 61 testComputed("background-color", "lch(10% 20 20deg / -10%)", "lch(10% 20 20 / 0)"); 62 testComputed("background-color", "lch(10% 20 20deg / 110%)", "lch(10% 20 20)"); 63 testComputed("background-color", "lch(10% 20 1.28rad)", "lch(10% 20 73.3386)"); 64 testComputed("background-color", "lch(10% 20 380deg)", "lch(10% 20 20)"); 65 testComputed("background-color", "lch(10% 20 -340deg)", "lch(10% 20 20)"); 66 testComputed("background-color", "lch(10% 20 740deg)", "lch(10% 20 20)"); 67 testComputed("background-color", "lch(10% 20 -700deg)", "lch(10% 20 20)"); 68 testComputed("background-color", "lch(-40% 0 0)", "lch(0% 0 0)"); 69 testComputed("background-color", "lch(20% -20 0)", "lch(20% 0 0)"); 70 70 // hue (the third argument) can be either an angle or number, with number interpreted as degrees. 71 testComputed("background-color", "lch(0% 0 0 / 0.5)", "l ab(0% 0 0 / 0.5)");72 testComputed("background-color", "lch(10% 20 20 / 110%)", "l ab(10% 18.793852 6.8404026)");73 testComputed("background-color", "lch(10% 20 -700)", "l ab(10% 18.793852 6.8404026)");71 testComputed("background-color", "lch(0% 0 0 / 0.5)", "lch(0% 0 0 / 0.5)"); 72 testComputed("background-color", "lch(10% 20 20 / 110%)", "lch(10% 20 20)"); 73 testComputed("background-color", "lch(10% 20 -700)", "lch(10% 20 20)"); 74 74 75 75 debug(''); -
trunk/Source/WebCore/ChangeLog
r273077 r273078 1 2021-02-17 Sam Weinig <weinig@apple.com> 2 3 lch() colors should serialize as lch(), not lab() 4 https://bugs.webkit.org/show_bug.cgi?id=222085 5 6 Reviewed by Darin Adler. 7 8 Updates fast/css/parsing-lab-colors.html 9 10 The spec was updated to require lch() to serialize to itself. 11 12 Store LCHA colors in Color to allow serialization. This just moves 13 the conversion to Lab from parse time to CGColor creation time (it 14 happens implicitly in the conversion to extended sRGB). 15 16 * css/parser/CSSPropertyParserHelpers.cpp: 17 (WebCore::CSSPropertyParserHelpers::parseLCHParameters): 18 * platform/graphics/ColorSerialization.cpp: 19 (WebCore::serialization): 20 (WebCore::serializationForCSS): 21 (WebCore::serializationForHTML): 22 (WebCore::serializationForRenderTreeAsText): 23 * platform/graphics/ColorSpace.cpp: 24 (WebCore::operator<<): 25 * platform/graphics/ColorSpace.h: 26 (WebCore::callWithColorType): 27 * platform/graphics/ColorUtilities.h: 28 (WebCore::isBlack): 29 (WebCore::isWhite): 30 * platform/graphics/cg/ColorSpaceCG.h: 31 (WebCore::cachedNullableCGColorSpace): 32 1 33 2021-02-17 Wenson Hsieh <wenson_hsieh@apple.com> 2 34 -
trunk/Source/WebCore/css/parser/CSSPropertyParserHelpers.cpp
r272909 r273078 960 960 auto normalizedHue = normalizeHue(*hue); 961 961 962 return convertColor<Lab<float>>(LCHA<float> { static_cast<float>(normalizedLightness), static_cast<float>(normalizedChroma), static_cast<float>(normalizedHue), static_cast<float>(*alpha) });962 return LCHA<float> { static_cast<float>(normalizedLightness), static_cast<float>(normalizedChroma), static_cast<float>(normalizedHue), static_cast<float>(*alpha) }; 963 963 } 964 964 -
trunk/Source/WebCore/platform/graphics/ColorSerialization.cpp
r272475 r273078 45 45 static String serializationForRenderTreeAsText(const DisplayP3<float>&); 46 46 47 static String serializationForCSS(const LCHA<float>&); 48 static String serializationForHTML(const LCHA<float>&); 49 static String serializationForRenderTreeAsText(const LCHA<float>&); 50 47 51 static String serializationForCSS(const Lab<float>&); 48 52 static String serializationForHTML(const Lab<float>&); … … 102 106 case ColorSpace::DisplayP3: 103 107 return "display-p3"_s; 108 case ColorSpace::LCH: 109 return "lch"_s; 104 110 case ColorSpace::Lab: 105 111 return "lab"_s; … … 162 168 } 163 169 170 // MARK: LCHA<float> overloads 171 172 String serializationForCSS(const LCHA<float>& color) 173 { 174 // https://www.w3.org/TR/css-color-4/#serializing-lab-lch 175 176 auto [c1, c2, c3, alpha] = color; 177 if (WTF::areEssentiallyEqual(alpha, 1.0f)) 178 return makeString("lch(", c1, "% ", c2, ' ', c3, ')'); 179 return makeString("lch(", c1, "% ", c2, ' ', c3, " / ", alpha, ')'); 180 } 181 182 String serializationForHTML(const LCHA<float>& color) 183 { 184 return serializationForCSS(color); 185 } 186 187 String serializationForRenderTreeAsText(const LCHA<float>& color) 188 { 189 return serializationForCSS(color); 190 } 191 164 192 // MARK: Lab<float> overloads 165 193 -
trunk/Source/WebCore/platform/graphics/ColorSpace.cpp
r272475 r273078 40 40 ts << "DisplayP3"; 41 41 break; 42 case ColorSpace::LCH: 43 ts << "LCH"; 44 break; 42 45 case ColorSpace::Lab: 43 46 ts << "L*a*b"; -
trunk/Source/WebCore/platform/graphics/ColorSpace.h
r272475 r273078 39 39 A98RGB, 40 40 DisplayP3, 41 LCH, 41 42 Lab, 42 43 LinearSRGB, … … 59 60 template<typename T> struct ColorSpaceMapping<A98RGB<T>> { static constexpr auto colorSpace { ColorSpace::A98RGB }; }; 60 61 template<typename T> struct ColorSpaceMapping<DisplayP3<T>> { static constexpr auto colorSpace { ColorSpace::DisplayP3 }; }; 62 template<typename T> struct ColorSpaceMapping<LCHA<T>> { static constexpr auto colorSpace { ColorSpace::LCH }; }; 61 63 template<typename T> struct ColorSpaceMapping<Lab<T>> { static constexpr auto colorSpace { ColorSpace::Lab }; }; 62 64 template<typename T> struct ColorSpaceMapping<LinearSRGBA<T>> { static constexpr auto colorSpace { ColorSpace::LinearSRGB }; }; … … 76 78 case ColorSpace::DisplayP3: 77 79 return std::invoke(std::forward<Functor>(functor), makeFromComponents<DisplayP3<T>>(components)); 80 case ColorSpace::LCH: 81 return std::invoke(std::forward<Functor>(functor), makeFromComponents<LCHA<T>>(components)); 78 82 case ColorSpace::Lab: 79 83 return std::invoke(std::forward<Functor>(functor), makeFromComponents<Lab<T>>(components)); … … 103 107 WebCore::ColorSpace::A98RGB, 104 108 WebCore::ColorSpace::DisplayP3, 109 WebCore::ColorSpace::LCH, 105 110 WebCore::ColorSpace::Lab, 106 111 WebCore::ColorSpace::LinearSRGB, -
trunk/Source/WebCore/platform/graphics/ColorUtilities.h
r272474 r273078 61 61 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&); 62 62 template<WhitePoint W> constexpr bool isBlack(const XYZA<float, W>&); 63 constexpr bool isBlack(const LCHA<float>&); 63 64 constexpr bool isBlack(const Lab<float>&); 64 65 65 66 template<typename ColorType, typename std::enable_if_t<std::is_same_v<typename ColorType::Model, RGBModel<typename ColorType::ComponentType>>>* = nullptr> constexpr bool isWhite(const ColorType&); 66 67 template<WhitePoint W> constexpr bool isWhite(const XYZA<float, W>&); 68 constexpr bool isWhite(const LCHA<float>&); 67 69 constexpr bool isWhite(const Lab<float>&); 68 70 … … 153 155 } 154 156 157 constexpr bool isBlack(const LCHA<float>& color) 158 { 159 return color.lightness == 0 && color.alpha == AlphaTraits<float>::opaque; 160 } 161 155 162 constexpr bool isBlack(const Lab<float>& color) 156 163 { … … 169 176 { 170 177 return color.y == 1 && color.alpha == AlphaTraits<float>::opaque; 178 } 179 180 constexpr bool isWhite(const LCHA<float>& color) 181 { 182 return color.lightness == 100 && color.alpha == AlphaTraits<float>::opaque; 171 183 } 172 184 -
trunk/Source/WebCore/platform/graphics/cg/ColorSpaceCG.h
r272736 r273078 81 81 return nullptr; 82 82 #endif 83 case ColorSpace::LCH: 84 return nullptr; 83 85 case ColorSpace::Lab: 84 86 #if HAVE(CORE_GRAPHICS_LAB_COLOR_SPACE)
Note: See TracChangeset
for help on using the changeset viewer.