Title: [254406] trunk
Revision
254406
Author
[email protected]
Date
2020-01-11 16:29:34 -0800 (Sat, 11 Jan 2020)

Log Message

Support image-set() standard syntax
https://bugs.webkit.org/show_bug.cgi?id=160934
<rdar://problem/27891501>

Patch by Noam Rosenthal <[email protected]> on 2020-01-11
Source/WebCore:

Reviewed by Simon Fraser.

Inside image-set, image URLs can use regular quotes, not necessarily with url().
See https://drafts.csswg.org/css-images-4/#image-set-notation

Test: fast/hidpi/image-set-as-background-quotes.html

* css/parser/CSSPropertyParserHelpers.cpp:
        Update CSS parser to allow raw strings as URLs inside image-set.

(WebCore::CSSPropertyParserHelpers::consumeUrlOrStringAsStringView):
(WebCore::CSSPropertyParserHelpers::consumeImageSet):

LayoutTests:

Reviewed by Dean Jackson.

* fast/css/image-set-parsing-invalid.html:
* fast/css/image-set-parsing.html:
        Update parsing to include raw strings
* fast/hidpi/image-set-as-background-quotes-expected.html: Added.
* fast/hidpi/image-set-as-background-quotes.html: Added.
        Added ref-test for image-set without url().

Modified Paths

Added Paths

Diff

Modified: trunk/LayoutTests/ChangeLog (254405 => 254406)


--- trunk/LayoutTests/ChangeLog	2020-01-12 00:16:25 UTC (rev 254405)
+++ trunk/LayoutTests/ChangeLog	2020-01-12 00:29:34 UTC (rev 254406)
@@ -1,3 +1,32 @@
+2020-01-11  Noam Rosenthal  <[email protected]>
+
+        Support image-set() standard syntax
+        https://bugs.webkit.org/show_bug.cgi?id=160934
+        <rdar://problem/27891501>
+
+        Reviewed by Dean Jackson.
+
+        * fast/css/image-set-parsing-invalid.html:
+        * fast/css/image-set-parsing.html:
+                Update parsing to include raw strings
+        * fast/hidpi/image-set-as-background-quotes-expected.html: Added.
+        * fast/hidpi/image-set-as-background-quotes.html: Added.
+                Added ref-test for image-set without url().
+
+
+2020-01-09  Noam Rosenthal  <[email protected]>
+
+        Support image-set() standard syntax
+        https://bugs.webkit.org/show_bug.cgi?id=160934
+        <rdar://problem/27891501>
+
+        Reviewed by Simon Fraser.
+
+
+        * fast/hidpi/image-set-as-background-quotes-expected.html: Added.
+        * fast/hidpi/image-set-as-background-quotes.html: Added.
+                Ref-test, image with quotes should work the same as image with url()
+
 2020-01-11  Cathie Chen  <[email protected]>
 
         Import WPT test cases for 2dcontext/imagebitmap

Modified: trunk/LayoutTests/fast/css/image-set-parsing-expected.txt (254405 => 254406)


--- trunk/LayoutTests/fast/css/image-set-parsing-expected.txt	2020-01-12 00:16:25 UTC (rev 254405)
+++ trunk/LayoutTests/fast/css/image-set-parsing-expected.txt	2020-01-12 00:29:34 UTC (rev 254406)
@@ -22,6 +22,34 @@
 PASS subRule is 'b'
 PASS subRule.cssText is '2'
 
+Single value for background-image without url() function : '#a' 1x
+PASS jsWrapperClass(imageSetRule) is 'CSSValueList'
+PASS jsWrapperClass(imageSetRule.__proto__) is 'CSSValueListPrototype'
+PASS jsWrapperClass(imageSetRule.constructor) is 'Function'
+PASS imageSetRule.length is 2
+PASS subRule is 'a'
+PASS subRule.cssText is '1'
+
+Multiple values for background-image without url() function : '#a' 1x, '#b' 2x
+PASS jsWrapperClass(imageSetRule) is 'CSSValueList'
+PASS jsWrapperClass(imageSetRule.__proto__) is 'CSSValueListPrototype'
+PASS jsWrapperClass(imageSetRule.constructor) is 'Function'
+PASS imageSetRule.length is 4
+PASS subRule is 'a'
+PASS subRule.cssText is '1'
+PASS subRule is 'b'
+PASS subRule.cssText is '2'
+
+Mix values with and without url() function : '#a' 1x, url('#b') 2x
+PASS jsWrapperClass(imageSetRule) is 'CSSValueList'
+PASS jsWrapperClass(imageSetRule.__proto__) is 'CSSValueListPrototype'
+PASS jsWrapperClass(imageSetRule.constructor) is 'Function'
+PASS imageSetRule.length is 4
+PASS subRule is 'a'
+PASS subRule.cssText is '1'
+PASS subRule is 'b'
+PASS subRule.cssText is '2'
+
 Multiple values for background-image, out of order : url('#c') 3x, url('#b') 2x, url('#a') 1x
 PASS jsWrapperClass(imageSetRule) is 'CSSValueList'
 PASS jsWrapperClass(imageSetRule.__proto__) is 'CSSValueListPrototype'

Modified: trunk/LayoutTests/fast/css/image-set-parsing-invalid-expected.txt (254405 => 254406)


--- trunk/LayoutTests/fast/css/image-set-parsing-invalid-expected.txt	2020-01-12 00:16:25 UTC (rev 254405)
+++ trunk/LayoutTests/fast/css/image-set-parsing-invalid-expected.txt	2020-01-12 00:29:34 UTC (rev 254406)
@@ -18,9 +18,6 @@
 
 Scale factor is 0 : url('#a') 0x
 PASS cssRule is null
-
-No url function : '#a' 1x
-PASS cssRule is null
 PASS successfullyParsed is true
 
 TEST COMPLETE

Modified: trunk/LayoutTests/fast/css/image-set-parsing-invalid.html (254405 => 254406)


--- trunk/LayoutTests/fast/css/image-set-parsing-invalid.html	2020-01-12 00:16:25 UTC (rev 254405)
+++ trunk/LayoutTests/fast/css/image-set-parsing-invalid.html	2020-01-12 00:29:34 UTC (rev 254406)
@@ -32,7 +32,6 @@
 testInvalidImageSet("No comma", "background-image", "url('#a') 1x url('#b') 2x");
 testInvalidImageSet("Too many scale factor parameters", "background-image", "url('#a') 1x 2x");
 testInvalidImageSet("Scale factor is 0", "background-image", "url('#a') 0x");
-testInvalidImageSet("No url function", "background-image", "'#a' 1x");
 
 successfullyParsed = true;
 </script>

Modified: trunk/LayoutTests/fast/css/image-set-parsing.html (254405 => 254406)


--- trunk/LayoutTests/fast/css/image-set-parsing.html	2020-01-12 00:16:25 UTC (rev 254405)
+++ trunk/LayoutTests/fast/css/image-set-parsing.html	2020-01-12 00:29:34 UTC (rev 254406)
@@ -81,6 +81,21 @@
                 "url('#a') 1x, url('#b') 2x", 4,
                 ["a", "1", "b", "2"]);
 
+testImageSetRule("Single value for background-image without url() function",
+                "background-image",
+                "'#a' 1x", 2,
+                ["a", "1"]);
+
+testImageSetRule("Multiple values for background-image without url() function",
+                "background-image",
+                "'#a' 1x, '#b' 2x", 4,
+                ["a", "1", "b", "2"]);
+
+testImageSetRule("Mix values with and without url() function",
+                "background-image",
+                "'#a' 1x, url('#b') 2x", 4,
+                ["a", "1", "b", "2"]);
+
 testImageSetRule("Multiple values for background-image, out of order",
                 "background-image",
                 "url('#c') 3x, url('#b') 2x, url('#a') 1x", 6,

Added: trunk/LayoutTests/fast/hidpi/image-set-as-background-quotes-expected.html (0 => 254406)


--- trunk/LayoutTests/fast/hidpi/image-set-as-background-quotes-expected.html	                        (rev 0)
+++ trunk/LayoutTests/fast/hidpi/image-set-as-background-quotes-expected.html	2020-01-12 00:29:34 UTC (rev 254406)
@@ -0,0 +1,46 @@
+<html>
+<head>
+<script>
+    function runTest() {
+        if (!window.testRunner || !window.sessionStorage)
+            return;
+
+        if (!sessionStorage.scaleFactorIsSet) {
+            testRunner.waitUntilDone();
+            testRunner.setBackingScaleFactor(2, scaleFactorIsSet);
+        }
+        
+        if (sessionStorage.pageReloaded && sessionStorage.scaleFactorIsSet) {
+            delete sessionStorage.pageReloaded;
+            delete sessionStorage.scaleFactorIsSet;
+            testRunner.notifyDone();
+        } else {
+            // Right now there is a bug that image-set does not properly deal with dynamic changes to the scale factor,
+            // so to work around that, we must reload the page to get the 2x image.
+            // https://bugs.webkit.org/show_bug.cgi?id=119764
+            sessionStorage.pageReloaded = true;
+            document.location.reload(true);
+        }
+    }
+    
+    function scaleFactorIsSet() {
+        sessionStorage.scaleFactorIsSet = true;
+    }
+
+    window._onload_ = runTest;
+</script>
+    
+<style>
+    #foo {
+        width:100px;
+        height:100px;
+        background-image: -webkit-image-set(url('resources/blue-100-px-square.png') 1x, url('resources/green-200-px-square.png') 2x);
+    }
+</style>
+</head>
+
+<body id="body">
+    <div>This test passes if the div below is a blue 100px square when the deviceScaleFactor is 1, and if it is a 100px green square when the deviceScaleFactor is 2.</div>
+    <div id=foo></div>
+</body>
+</html>

Added: trunk/LayoutTests/fast/hidpi/image-set-as-background-quotes.html (0 => 254406)


--- trunk/LayoutTests/fast/hidpi/image-set-as-background-quotes.html	                        (rev 0)
+++ trunk/LayoutTests/fast/hidpi/image-set-as-background-quotes.html	2020-01-12 00:29:34 UTC (rev 254406)
@@ -0,0 +1,46 @@
+<html>
+<head>
+<script>
+    function runTest() {
+        if (!window.testRunner || !window.sessionStorage)
+            return;
+
+        if (!sessionStorage.scaleFactorIsSet) {
+            testRunner.waitUntilDone();
+            testRunner.setBackingScaleFactor(2, scaleFactorIsSet);
+        }
+        
+        if (sessionStorage.pageReloaded && sessionStorage.scaleFactorIsSet) {
+            delete sessionStorage.pageReloaded;
+            delete sessionStorage.scaleFactorIsSet;
+            testRunner.notifyDone();
+        } else {
+            // Right now there is a bug that image-set does not properly deal with dynamic changes to the scale factor,
+            // so to work around that, we must reload the page to get the 2x image.
+            // https://bugs.webkit.org/show_bug.cgi?id=119764
+            sessionStorage.pageReloaded = true;
+            document.location.reload(true);
+        }
+    }
+    
+    function scaleFactorIsSet() {
+        sessionStorage.scaleFactorIsSet = true;
+    }
+
+    window._onload_ = runTest;
+</script>
+    
+<style>
+    #foo {
+        width:100px;
+        height:100px;
+        background-image: image-set("resources/blue-100-px-square.png" 1x, "resources/green-200-px-square.png" 2x);
+    }
+</style>
+</head>
+
+<body id="body">
+    <div>This test passes if the div below is a blue 100px square when the deviceScaleFactor is 1, and if it is a 100px green square when the deviceScaleFactor is 2.</div>
+    <div id=foo></div>
+</body>
+</html>

Modified: trunk/Source/WebCore/ChangeLog (254405 => 254406)


--- trunk/Source/WebCore/ChangeLog	2020-01-12 00:16:25 UTC (rev 254405)
+++ trunk/Source/WebCore/ChangeLog	2020-01-12 00:29:34 UTC (rev 254406)
@@ -1,3 +1,22 @@
+2020-01-11  Noam Rosenthal  <[email protected]>
+
+        Support image-set() standard syntax
+        https://bugs.webkit.org/show_bug.cgi?id=160934
+        <rdar://problem/27891501>
+
+        Reviewed by Simon Fraser.
+
+        Inside image-set, image URLs can use regular quotes, not necessarily with url().
+        See https://drafts.csswg.org/css-images-4/#image-set-notation
+
+        Test: fast/hidpi/image-set-as-background-quotes.html
+
+        * css/parser/CSSPropertyParserHelpers.cpp:
+                Update CSS parser to allow raw strings as URLs inside image-set.
+
+        (WebCore::CSSPropertyParserHelpers::consumeUrlOrStringAsStringView):
+        (WebCore::CSSPropertyParserHelpers::consumeImageSet):
+
 2020-01-11  Zalan Bujtas  <[email protected]>
 
         [LFC] BlockFormattingContext::verticalPositionWithMargin should take VerticalConstraints

Modified: trunk/Source/WebCore/css/parser/CSSPropertyParserHelpers.cpp (254405 => 254406)


--- trunk/Source/WebCore/css/parser/CSSPropertyParserHelpers.cpp	2020-01-12 00:16:25 UTC (rev 254405)
+++ trunk/Source/WebCore/css/parser/CSSPropertyParserHelpers.cpp	2020-01-12 00:29:34 UTC (rev 254406)
@@ -1479,6 +1479,13 @@
     return result;
 }
 
+static StringView consumeUrlOrStringAsStringView(CSSParserTokenRange& args)
+{
+    if (args.peek().type() == StringToken)
+        return args.consumeIncludingWhitespace().value();
+    return consumeUrlAsStringView(args);
+}
+
 static RefPtr<CSSValue> consumeImageSet(CSSParserTokenRange& range, const CSSParserContext& context)
 {
     CSSParserTokenRange rangeCopy = range;
@@ -1485,7 +1492,7 @@
     CSSParserTokenRange args = consumeFunction(rangeCopy);
     RefPtr<CSSImageSetValue> imageSet = CSSImageSetValue::create(context.isContentOpaque ? LoadedFromOpaqueSource::Yes : LoadedFromOpaqueSource::No);
     do {
-        AtomString urlValue = consumeUrlAsStringView(args).toAtomString();
+        AtomString urlValue = consumeUrlOrStringAsStringView(args).toAtomString();
         if (urlValue.isNull())
             return nullptr;
 
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to