Skip to content

Commit

Permalink
[Image Set]: Refactor CSSImageSetValue to accept optional resolution …
Browse files Browse the repository at this point in the history
…and MIME type parameters

https://bugs.webkit.org/show_bug.cgi?id=252137
rdar://105367742

Reviewed by Antti Koivisto.

The standardized image-set differs from -webkit-image-set in that each option has three arguments instead of two -
an image, an optional resolution, and an optional type() function declaring the MIME type of the image.

This refactors the CSSImageSetValue to hold an CSSImageSetOptionValue object instead of placing the image and
resolution values in a vector and using a stride of 2 to represent each option. The actual parsing of
resolution and type() will be in a follow-on patch.

* LayoutTests/TestExpectations:
    Unskip newly passing WPT ref tests.

* LayoutTests/fast/css/image-set-parsing-expected.txt:
* LayoutTests/fast/css/image-set-parsing-generated-expected.txt: Removed.
* LayoutTests/fast/css/image-set-parsing-generated.html: Removed.
* LayoutTests/fast/css/image-set-parsing.html:
* LayoutTests/imported/w3c/web-platform-tests/css/css-images/image-set/image-set-parsing-expected.txt:
* LayoutTests/imported/w3c/web-platform-tests/css/css-images/image-set/image-set-parsing.html:
    Refactor the internal parsing tests in the following ways:
      1) Move and dedup all tests of standard properties (e.g. background-image) to WPT.
      2) Move generated image tests (gradients, for example) to the main image-set-parsing test.
      3) Test that -webkit-image-set is an alias to image-set
      4) Test that the serialization is as expected (per WPT).

* Source/WebCore/css/CSSImageSetOptionValue.cpp: Added.
(WebCore::CSSImageSetOptionValue::Type::Type):
(WebCore::CSSImageSetOptionValue::Type::cssText const):
(WebCore::CSSImageSetOptionValue::CSSImageSetOptionValue):
(WebCore::CSSImageSetOptionValue::create):
(WebCore::CSSImageSetOptionValue::equals const):
(WebCore::CSSImageSetOptionValue::customCSSText const):
(WebCore::CSSImageSetOptionValue::image const):
(WebCore::CSSImageSetOptionValue::resolution const):
(WebCore::CSSImageSetOptionValue::setResolution):
(WebCore::CSSImageSetOptionValue::type const):
(WebCore::CSSImageSetOptionValue::setType):
* Source/WebCore/css/CSSImageSetOptionValue.h: Copied from Source/WebCore/css/CSSImageSetValue.h.
    Create a new CSSImageSetOptionValue class to represent the arguments to the image-set function.
    This object holds a Ref to either a CSSImageValue or a generated image (e.g. a linear-gradient),
    and optionally holds a resolution (scale factor) and a MIME type string.

* Source/WebCore/css/CSSImageSetValue.cpp:
(WebCore::CSSImageSetValue::create):
(WebCore::CSSImageSetValue::CSSImageSetValue):
(WebCore::CSSImageSetValue::customCSSText const):
(WebCore::CSSImageSetValue::createStyleImage const):
* Source/WebCore/css/CSSImageSetValue.h:
    With -webkit-image-set, the image and resolution were the only two arguments and they were both
    required. The standardized image-set makes resolution and type optional. Instead of holding all
    the arguments as individual elements in the underlying CSSListValue storage we hold the new
    CSSImageSetOptionValues in the internal vector instead. We also now filter the image set on provided
    MIME type if it's supported or not when creating the StyleImage.

* Source/WebCore/css/CSSValue.cpp:
(WebCore::CSSValue::visitDerived):
* Source/WebCore/css/CSSValue.h:
(WebCore::CSSValue::isImageSetOptionValue const):
    Updates for support for the new CSSImageSetOptionValue.

* Source/WebCore/css/calc/CSSCalcPrimitiveValueNode.cpp:
* Source/WebCore/css/parser/CSSPropertyParser.cpp:
* Source/WebCore/css/parser/CSSPropertyParserHelpers.cpp:
* Source/WebCore/css/CSSValuePair.cpp:
    Adding a new file caused build errors due to missing includes/incomplete types from forward decls.
    I added the needed includes.

(WebCore::CSSPropertyParserHelpers::consumeImageSetOptionalArguments):
(WebCore::CSSPropertyParserHelpers::consumeImageSet):
    Use the new CSSImageSetOptionValue/CSSImageSetValue API when constructing those objects. Also created
    a stub function which will eventually dispatch to parsing the resolution and type() optional parameters
    in a forthcoming patch.

* Source/WebCore/rendering/style/StyleImageSet.cpp:
(WebCore::StyleImageSet::computedStyleValue const):

* Source/WebCore/Sources.txt:
* Source/WebCore/WebCore.xcodeproj/project.pbxproj:

Canonical link: https://commits.webkit.org/260760@main
  • Loading branch information
rreno committed Feb 23, 2023
1 parent 875f1ea commit f9b1ad4
Show file tree
Hide file tree
Showing 19 changed files with 368 additions and 411 deletions.
4 changes: 2 additions & 2 deletions LayoutTests/TestExpectations
Expand Up @@ -3543,8 +3543,6 @@ webkit.org/b/200207 imported/w3c/web-platform-tests/css/css-images/css-image-fal
webkit.org/b/200209 imported/w3c/web-platform-tests/css/css-images/multiple-position-color-stop-radial.html [ ImageOnlyFailure ]

# wpt image-set failures
webkit.org/b/251811 imported/w3c/web-platform-tests/css/css-images/image-set/image-set-no-res-rendering-2.html [ ImageOnlyFailure ]
webkit.org/b/251811 imported/w3c/web-platform-tests/css/css-images/image-set/image-set-no-res-rendering.html [ ImageOnlyFailure ]
webkit.org/b/251811 imported/w3c/web-platform-tests/css/css-images/image-set/image-set-type-first-match-rendering.html [ ImageOnlyFailure ]
webkit.org/b/251811 imported/w3c/web-platform-tests/css/css-images/image-set/image-set-type-rendering-2.html [ ImageOnlyFailure ]
webkit.org/b/251811 imported/w3c/web-platform-tests/css/css-images/image-set/image-set-type-rendering-3.html [ ImageOnlyFailure ]
Expand Down Expand Up @@ -6270,3 +6268,5 @@ webkit.org/b/252183 imported/w3c/web-platform-tests/css/css-box/margin-trim/bloc
imported/w3c/web-platform-tests/css/css-text/text-spacing/tentative/parsing/text-spacing-computed.html [ Skip ]
imported/w3c/web-platform-tests/css/css-text/text-spacing/tentative/parsing/text-spacing-invalid.html [ Skip ]
imported/w3c/web-platform-tests/css/css-text/text-spacing/tentative/parsing/text-spacing-valid.html [ Skip ]
imported/w3c/web-platform-tests/css/css-text/text-spacing/tentative/parsing [ Skip ]

118 changes: 33 additions & 85 deletions LayoutTests/fast/css/image-set-parsing-expected.txt
@@ -1,156 +1,104 @@
Test the parsing of the -webkit-image-set function.
Test the parsing of the image-set and -webkit-image-set functions.

On success, you will see a series of "PASS" messages, followed by "TEST COMPLETE".



Single value for background-image : url('#a') 1x
Single value for -webkit-mask-box-image-source: image-set(url('#a'))
PASS jsWrapperClass(imageSetRule) is 'CSSValueList'
PASS jsWrapperClass(imageSetRule.__proto__) is 'CSSValueList'
PASS jsWrapperClass(imageSetRule.constructor) is 'Function'
PASS imageSetRule.length is 2
PASS subRule is 'a'
PASS subRule.cssText is '1x'
PASS Image Set rule serializes as expected.

Multiple values for background-image : url('#a') 1x, url('#b') 2x
Single value for -webkit-mask-box-image-source: -webkit-image-set(url('#a'))
PASS jsWrapperClass(imageSetRule) is 'CSSValueList'
PASS jsWrapperClass(imageSetRule.__proto__) is 'CSSValueList'
PASS jsWrapperClass(imageSetRule.constructor) is 'Function'
PASS imageSetRule.length is 4
PASS subRule is 'a'
PASS subRule.cssText is '1x'
PASS subRule is 'b'
PASS subRule.cssText is '2x'
PASS Image Set rule serializes as expected.

Single value for background-image without url() function : '#a' 1x
Multiple values for -webkit-mask-box-image-source: image-set(url('#a'), url('#b') 2x)
PASS jsWrapperClass(imageSetRule) is 'CSSValueList'
PASS jsWrapperClass(imageSetRule.__proto__) is 'CSSValueList'
PASS jsWrapperClass(imageSetRule.constructor) is 'Function'
PASS imageSetRule.length is 2
PASS subRule is 'a'
PASS subRule.cssText is '1x'
PASS Image Set rule serializes as expected.

Multiple values for background-image without url() function : '#a' 1x, '#b' 2x
Multiple values for -webkit-mask-box-image-source: -webkit-image-set(url('#a'), url('#b') 2x)
PASS jsWrapperClass(imageSetRule) is 'CSSValueList'
PASS jsWrapperClass(imageSetRule.__proto__) is 'CSSValueList'
PASS jsWrapperClass(imageSetRule.constructor) is 'Function'
PASS imageSetRule.length is 4
PASS subRule is 'a'
PASS subRule.cssText is '1x'
PASS subRule is 'b'
PASS subRule.cssText is '2x'
PASS Image Set rule serializes as expected.

Mix values with and without url() function : '#a' 1x, url('#b') 2x
Single value for -webkit-mask-box-image-source with gradient.: image-set(linear-gradient(green, white))
PASS jsWrapperClass(imageSetRule) is 'CSSValueList'
PASS jsWrapperClass(imageSetRule.__proto__) is 'CSSValueList'
PASS jsWrapperClass(imageSetRule.constructor) is 'Function'
PASS imageSetRule.length is 4
PASS subRule is 'a'
PASS subRule.cssText is '1x'
PASS subRule is 'b'
PASS subRule.cssText is '2x'
PASS Image Set rule serializes as expected.

Multiple values for background-image, out of order : url('#c') 3x, url('#b') 2x, url('#a') 1x
Single value for -webkit-mask-box-image-source with gradient.: -webkit-image-set(linear-gradient(green, white))
PASS jsWrapperClass(imageSetRule) is 'CSSValueList'
PASS jsWrapperClass(imageSetRule.__proto__) is 'CSSValueList'
PASS jsWrapperClass(imageSetRule.constructor) is 'Function'
PASS imageSetRule.length is 6
PASS subRule is 'c'
PASS subRule.cssText is '3x'
PASS subRule is 'b'
PASS subRule.cssText is '2x'
PASS subRule is 'a'
PASS subRule.cssText is '1x'
PASS Image Set rule serializes as expected.

Single value for content : url('#a') 1x
Multiple values for -webkit-mask-box-image-source with gradients: image-set(linear-gradient(green, white) 1x, radial-gradient(blue, white) 2x)
PASS jsWrapperClass(imageSetRule) is 'CSSValueList'
PASS jsWrapperClass(imageSetRule.__proto__) is 'CSSValueList'
PASS jsWrapperClass(imageSetRule.constructor) is 'Function'
PASS imageSetRule.length is 2
PASS subRule is 'a'
PASS subRule.cssText is '1x'
PASS Image Set rule serializes as expected.

Multiple values for content : url('#a') 1x, url('#b') 2x
Multiple values for -webkit-mask-box-image-source with gradients: -webkit-image-set(linear-gradient(green, white) 1x, radial-gradient(blue, white) 2x)
PASS jsWrapperClass(imageSetRule) is 'CSSValueList'
PASS jsWrapperClass(imageSetRule.__proto__) is 'CSSValueList'
PASS jsWrapperClass(imageSetRule.constructor) is 'Function'
PASS imageSetRule.length is 4
PASS subRule is 'a'
PASS subRule.cssText is '1x'
PASS subRule is 'b'
PASS subRule.cssText is '2x'
PASS Image Set rule serializes as expected.

Single value for border-image-source : url('#a') 1x
Combined gradient and URL for -webkit-mask-box-image-source: image-set(url("#a"), linear-gradient(green, white) 2x)
PASS jsWrapperClass(imageSetRule) is 'CSSValueList'
PASS jsWrapperClass(imageSetRule.__proto__) is 'CSSValueList'
PASS jsWrapperClass(imageSetRule.constructor) is 'Function'
PASS imageSetRule.length is 2
PASS subRule is 'a'
PASS subRule.cssText is '1x'
PASS Image Set rule serializes as expected.

Multiple values for border-image-source : url('#a') 1x, url('#b') 2x
Combined gradient and URL for -webkit-mask-box-image-source: -webkit-image-set(url("#a"), linear-gradient(green, white) 2x)
PASS jsWrapperClass(imageSetRule) is 'CSSValueList'
PASS jsWrapperClass(imageSetRule.__proto__) is 'CSSValueList'
PASS jsWrapperClass(imageSetRule.constructor) is 'Function'
PASS imageSetRule.length is 4
PASS subRule is 'a'
PASS subRule.cssText is '1x'
PASS subRule is 'b'
PASS subRule.cssText is '2x'
PASS Image Set rule serializes as expected.

Single value for -webkit-mask-box-image-source : url('#a') 1x
Single -webkit-cross-fade for -webkit-mask-box-image-source: image-set(-webkit-cross-fade(url("#a"), url("#b"), 70%))
PASS jsWrapperClass(imageSetRule) is 'CSSValueList'
PASS jsWrapperClass(imageSetRule.__proto__) is 'CSSValueList'
PASS jsWrapperClass(imageSetRule.constructor) is 'Function'
PASS imageSetRule.length is 2
PASS subRule is 'a'
PASS subRule.cssText is '1x'
PASS Image Set rule serializes as expected.

Multiple values for -webkit-mask-box-image-source : url('#a') 1x, url('#b') 2x
Single -webkit-cross-fade for -webkit-mask-box-image-source: -webkit-image-set(-webkit-cross-fade(url("#a"), url("#b"), 70%))
PASS jsWrapperClass(imageSetRule) is 'CSSValueList'
PASS jsWrapperClass(imageSetRule.__proto__) is 'CSSValueList'
PASS jsWrapperClass(imageSetRule.constructor) is 'Function'
PASS imageSetRule.length is 4
PASS subRule is 'a'
PASS subRule.cssText is '1x'
PASS subRule is 'b'
PASS subRule.cssText is '2x'
PASS Image Set rule serializes as expected.

Single value with dppx : url('#a') 1dppx
Combined gradient and cross-fade for -webkit-mask-box-image-source: image-set(-webkit-cross-fade(url("#a"), url("#b"), 70%), linear-gradient(green, white) 2x)
PASS jsWrapperClass(imageSetRule) is 'CSSValueList'
PASS jsWrapperClass(imageSetRule.__proto__) is 'CSSValueList'
PASS jsWrapperClass(imageSetRule.constructor) is 'Function'
PASS imageSetRule.length is 2
PASS subRule is 'a'
PASS subRule.cssText is '1dppx'
PASS Image Set rule serializes as expected.

Single value with dpi : url('#a') 192dpi
Combined gradient and cross-fade for -webkit-mask-box-image-source: -webkit-image-set(-webkit-cross-fade(url("#a"), url("#b"), 70%), linear-gradient(green, white) 2x)
PASS jsWrapperClass(imageSetRule) is 'CSSValueList'
PASS jsWrapperClass(imageSetRule.__proto__) is 'CSSValueList'
PASS jsWrapperClass(imageSetRule.constructor) is 'Function'
PASS imageSetRule.length is 2
PASS subRule is 'a'
PASS subRule.cssText is '192dpi'
PASS Image Set rule serializes as expected.

Single value with dpcm : url('#a') 102dpcm
Single value for -webkit-mask-box-image-source with gradient and dpi: image-set(linear-gradient(green, white) 192dpi)
PASS jsWrapperClass(imageSetRule) is 'CSSValueList'
PASS jsWrapperClass(imageSetRule.__proto__) is 'CSSValueList'
PASS jsWrapperClass(imageSetRule.constructor) is 'Function'
PASS imageSetRule.length is 2
PASS subRule is 'a'
PASS subRule.cssText is '102dpcm'
PASS Image Set rule serializes as expected.

Multiple values with dpi, dppx and x : url('#a') 1x, url('#b') 2dppx, url('#c') 250dpi
Single value for -webkit-mask-box-image-source with gradient and dpi: -webkit-image-set(linear-gradient(green, white) 192dpi)
PASS jsWrapperClass(imageSetRule) is 'CSSValueList'
PASS jsWrapperClass(imageSetRule.__proto__) is 'CSSValueList'
PASS jsWrapperClass(imageSetRule.constructor) is 'Function'
PASS imageSetRule.length is 6
PASS subRule is 'a'
PASS subRule.cssText is '1x'
PASS subRule is 'b'
PASS subRule.cssText is '2dppx'
PASS subRule is 'c'
PASS subRule.cssText is '250dpi'
PASS Image Set rule serializes as expected.
PASS successfullyParsed is true

TEST COMPLETE
Expand Down
73 changes: 0 additions & 73 deletions LayoutTests/fast/css/image-set-parsing-generated-expected.txt

This file was deleted.

109 changes: 0 additions & 109 deletions LayoutTests/fast/css/image-set-parsing-generated.html

This file was deleted.

0 comments on commit f9b1ad4

Please sign in to comment.