Parse color() function
authordino@apple.com <dino@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Sat, 29 Oct 2016 22:34:43 +0000 (22:34 +0000)
committerdino@apple.com <dino@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Sat, 29 Oct 2016 22:34:43 +0000 (22:34 +0000)
commit322fd9608a37fc58bb75df802d0ff7825b88b975
tree8ce5c96a6d810a3d966cae29944a7cf2c022eceb
parent2d0ecac2e1d839ec0eafdb255a0b15a887d11a55
Parse color() function
https://bugs.webkit.org/show_bug.cgi?id=164146
<rdar://problems/29007218>

Reviewed by Darin Adler.

Source/WebCore:

Support the new CSS color() function:
https://drafts.csswg.org/css-color/#color-function

There are separate code paths for the old and new CSS parser.

Tests: css3/color/color-function-computed-style.html
       css3/color/color-function-parsing.html

* css/CSSComputedStyleDeclaration.cpp: Use Color directly, not via rgb().
(WebCore::ComputedStyleExtractor::currentColorOrValidColor):
(WebCore::ComputedStyleExtractor::valueForShadow):
(WebCore::ComputedStyleExtractor::propertyValue):

* css/CSSValueKeywords.in: Note that there is a color function, but the
keyword is already defined. Also add keywords for the color spaces.
* css/SVGCSSValueKeywords.in: sRGB is used outside of SVG now.

* css/parser/CSSParser.cpp: Old CSS parser code to handle color().
(WebCore::isPercent): Helper to tell if a ValueWithCalculation is a percentage or not.
(WebCore::CSSParser::parseColorInt): Renamed.
(WebCore::CSSParser::parseColorDouble): Helper to get a Number/Percentage into a double
(WebCore::CSSParser::parseRGBParameters):
(WebCore::CSSParser::parseColorFunctionParameters):
(WebCore::CSSParser::parseHSLParameters):
(WebCore::CSSParser::parseColorFromValue):
(WebCore::CSSParser::colorIntFromValue): Deleted.
* css/parser/CSSParser.h:

* css/parser/CSSPropertyParserHelpers.cpp: New CSS parser code to handle color().
(WebCore::CSSPropertyParserHelpers::parseColorFunctionParameters):
(WebCore::CSSPropertyParserHelpers::parseColorFunction):

* platform/graphics/Color.h:
(WebCore::Color::isValid): An extended color is valid.
(WebCore::Color::rgb): Move the code to a standalone inline
so that I could add a longer comment.

* platform/graphics/ExtendedColor.cpp:
(WebCore::ExtendedColor::cssText): Alpha output is only needed if != 1.

* platform/graphics/cg/ColorCG.cpp: Handle ExtendedColor -> CGColor.
(WebCore::leakCGColor):
(WebCore::cachedCGColor):

LayoutTests:

Test that exercises the new color() function in CSS. It checks
all valid and invalid input, with the exception of fallback content.

* css3/color/color-function-computed-style-expected.txt: Added.
* css3/color/color-function-computed-style.html: Added.
* css3/color/color-function-parsing-expected.txt: Added.
* css3/color/color-function-parsing.html: Added.

git-svn-id: https://svn.webkit.org/repository/webkit/trunk@208116 268f45cc-cd09-0410-ab3c-d52691b4dbfc
15 files changed:
LayoutTests/ChangeLog
LayoutTests/css3/color/color-function-computed-style-expected.txt [new file with mode: 0644]
LayoutTests/css3/color/color-function-computed-style.html [new file with mode: 0644]
LayoutTests/css3/color/color-function-parsing-expected.txt [new file with mode: 0644]
LayoutTests/css3/color/color-function-parsing.html [new file with mode: 0644]
Source/WebCore/ChangeLog
Source/WebCore/css/CSSComputedStyleDeclaration.cpp
Source/WebCore/css/CSSValueKeywords.in
Source/WebCore/css/SVGCSSValueKeywords.in
Source/WebCore/css/parser/CSSParser.cpp
Source/WebCore/css/parser/CSSParser.h
Source/WebCore/css/parser/CSSPropertyParserHelpers.cpp
Source/WebCore/platform/graphics/Color.h
Source/WebCore/platform/graphics/ExtendedColor.cpp
Source/WebCore/platform/graphics/cg/ColorCG.cpp