Title: [282234] trunk
Revision
282234
Author
[email protected]
Date
2021-09-09 12:12:38 -0700 (Thu, 09 Sep 2021)

Log Message

right- and bottom-relative values in background-position-x/y don't work
https://bugs.webkit.org/show_bug.cgi?id=202148

Reviewed by Antti Koivisto.

LayoutTests/imported/w3c:

More passing results.

* web-platform-tests/css/css-backgrounds/parsing/background-position-x-computed-expected.txt:
* web-platform-tests/css/css-backgrounds/parsing/background-position-x-valid-expected.txt:
* web-platform-tests/css/css-backgrounds/parsing/background-position-y-computed-expected.txt:
* web-platform-tests/css/css-backgrounds/parsing/background-position-y-valid-expected.txt:

Source/WebCore:

Test: fast/backgrounds/background-position-xy.html

background-position[1] and background-position-x/background-position-y allow authors
to specify edge-relative values, like "background-position-x: right 10px". We
failed to handle this syntax in background-position-x and background-position-y,
but we do handle it in background-position.

So fix consumePositionX()/consumePositionY(), which are used when parsing
background-position-x/y, -webkit-mask-position-x/y, perspective-origin-x/y, and
transform-origin-x.y, to handle this edge-relative form.

A failure on imported/w3c/web-platform-tests/css/css-backgrounds/parsing/background-position-x-computed.html
(which only passes in Firefox) suggets that we should convert "right 10px" to "calc(100% - 10px)"
but for now, this patch serializes with edge keywords, as we do for the shorthand.

[1] https://www.w3.org/TR/css-backgrounds-3/#background-position

Test: fast/backgrounds/background-position-xy.html

* css/CSSComputedStyleDeclaration.cpp:
(WebCore::createSingleAxisPositionValueForLayer):
(WebCore::ComputedStyleExtractor::valueForPropertyInStyle):
* css/parser/CSSPropertyParser.cpp:
(WebCore::consumePositionX):
(WebCore::consumePositionY):
(WebCore::consumePositionLonghand): Deleted.
* css/parser/CSSPropertyParserHelpers.cpp:
(WebCore::CSSPropertyParserHelpers::consumePositionCoordinates):
(WebCore::CSSPropertyParserHelpers::consumeSingleAxisPosition):
* css/parser/CSSPropertyParserHelpers.h:

LayoutTests:

Ref test for various background-position-* values. Adjust for serialization output changes.

* fast/backgrounds/background-position-xy-expected.html: Added.
* fast/backgrounds/background-position-xy.html: Added.
* fast/css/background-position-serialize-expected.txt:
* fast/css/background-position-serialize.html:
* transitions/background-position-transitions-expected.txt:
* transitions/background-position-transitions.html:

Modified Paths

Added Paths

Diff

Modified: trunk/LayoutTests/ChangeLog (282233 => 282234)


--- trunk/LayoutTests/ChangeLog	2021-09-09 19:06:01 UTC (rev 282233)
+++ trunk/LayoutTests/ChangeLog	2021-09-09 19:12:38 UTC (rev 282234)
@@ -1,3 +1,19 @@
+2021-09-09  Simon Fraser  <[email protected]>
+
+        right- and bottom-relative values in background-position-x/y don't work
+        https://bugs.webkit.org/show_bug.cgi?id=202148
+
+        Reviewed by Antti Koivisto.
+
+        Ref test for various background-position-* values. Adjust for serialization output changes.
+
+        * fast/backgrounds/background-position-xy-expected.html: Added.
+        * fast/backgrounds/background-position-xy.html: Added.
+        * fast/css/background-position-serialize-expected.txt:
+        * fast/css/background-position-serialize.html:
+        * transitions/background-position-transitions-expected.txt:
+        * transitions/background-position-transitions.html:
+
 2021-09-09  Eric Hutchison  <[email protected]>
 
         [BigSur wk2 Debug] 4 http/tests/inspector/network/ tests are flaky fails.

Added: trunk/LayoutTests/fast/backgrounds/background-position-xy-expected.html (0 => 282234)


--- trunk/LayoutTests/fast/backgrounds/background-position-xy-expected.html	                        (rev 0)
+++ trunk/LayoutTests/fast/backgrounds/background-position-xy-expected.html	2021-09-09 19:12:38 UTC (rev 282234)
@@ -0,0 +1,31 @@
+<!DOCTYPE html>
+<html>
+<head>
+    <style>
+        .box {
+            float: left;
+            margin: 5px;
+            width: 100px;
+            height: 100px;
+            outline: 1px solid black;
+            background-image: linear-gradient(green, green);
+            background-size: 20px 20px;
+            background-repeat: no-repeat;
+        }
+        
+    </style>
+    
+</head>
+<body>
+    <div class="box"></div>
+    <div class="box" style="background-position: 0 0"></div>
+    <div class="box" style="background-position: 16px 20px"></div>
+    <div class="box" style="background-position: 64px 64px"></div>
+    <div class="box" style="background-position: 20px 20px"></div>
+    <div class="box" style="background-position: 60px 60px"></div>
+    <div class="box" style="background-position: 64px 64px"></div>
+    <div class="box" style="background-position: 64px 64px"></div>
+    <div class="box" style="background-position: 20px 20px"></div>
+    <div class="box" style="background-position: 60px 60px"></div>
+</body>
+</html>

Added: trunk/LayoutTests/fast/backgrounds/background-position-xy.html (0 => 282234)


--- trunk/LayoutTests/fast/backgrounds/background-position-xy.html	                        (rev 0)
+++ trunk/LayoutTests/fast/backgrounds/background-position-xy.html	2021-09-09 19:12:38 UTC (rev 282234)
@@ -0,0 +1,31 @@
+<!DOCTYPE html>
+<html>
+<head>
+    <style>
+        .box {
+            float: left;
+            margin: 5px;
+            width: 100px;
+            height: 100px;
+            outline: 1px solid black;
+            background-image: linear-gradient(green, green);
+            background-size: 20px 20px;
+            background-repeat: no-repeat;
+        }
+        
+    </style>
+    
+</head>
+<body>
+    <div class="box"></div>
+    <div class="box" style="background-position: left top"></div>
+    <div class="box" style="background-position: 20% 25%"></div>
+    <div class="box" style="background-position: bottom 20% right 20%"></div>
+    <div class="box" style="background-position: calc(100% / 4) calc(100% / 4)"></div>
+    <div class="box" style="background-position: bottom calc(100% / 4) right calc(100% / 4)"></div>
+    <div class="box" style="background-position-x: right 20%; background-position-y: bottom 20%;"></div>
+    <div class="box" style="background-position-x: right 20%; background-position-y: bottom 20%;"></div>
+    <div class="box" style="background-position-x: calc(100% / 4); background-position-y: calc(100% / 4);"></div>
+    <div class="box" style="background-position-x: right calc(100% / 4); background-position-y:  bottom calc(100% / 4);"></div>
+</body>
+</html>

Modified: trunk/LayoutTests/fast/css/background-position-serialize-expected.txt (282233 => 282234)


--- trunk/LayoutTests/fast/css/background-position-serialize-expected.txt	2021-09-09 19:06:01 UTC (rev 282233)
+++ trunk/LayoutTests/fast/css/background-position-serialize-expected.txt	2021-09-09 19:12:38 UTC (rev 282234)
@@ -65,10 +65,10 @@
 t.setAttribute('style', 'background-position: 50% left');
 PASS: t.style.backgroundPosition should be and is.
 t.setAttribute('style', 'background-position-x: right 20px');
-PASS: window.getComputedStyle(t).backgroundPositionX should be 0% and is.
+PASS: window.getComputedStyle(t).backgroundPositionX should be right 20px and is.
 t.setAttribute('style', 'background-position: right 20px bottom 10px');
 PASS: window.getComputedStyle(t).backgroundPosition should be right 20px bottom 10px and is.
-PASS: window.getComputedStyle(t).backgroundPositionX should be 20px and is.
+PASS: window.getComputedStyle(t).backgroundPositionX should be right 20px and is.
 t.setAttribute('style', 'background: url(about:blank) 80% 80%;');
 t.style.backgroundPositionY = '50px'
 style.cssText =

Modified: trunk/LayoutTests/fast/css/background-position-serialize.html (282233 => 282234)


--- trunk/LayoutTests/fast/css/background-position-serialize.html	2021-09-09 19:06:01 UTC (rev 282233)
+++ trunk/LayoutTests/fast/css/background-position-serialize.html	2021-09-09 19:12:38 UTC (rev 282234)
@@ -122,12 +122,12 @@
 run("t.setAttribute('style', 'background-position: 50% left');"); // Invalid per spec.
 shouldBe("t.style.backgroundPosition", "");
 
-run("t.setAttribute('style', 'background-position-x: right 20px');"); // This does not parse, but perhaps it should.
-shouldBe("window.getComputedStyle(t).backgroundPositionX", "0%");
+run("t.setAttribute('style', 'background-position-x: right 20px');");
+shouldBe("window.getComputedStyle(t).backgroundPositionX", "right 20px");
 
 run("t.setAttribute('style', 'background-position: right 20px bottom 10px');");
 shouldBe("window.getComputedStyle(t).backgroundPosition", "right 20px bottom 10px");
-shouldBe("window.getComputedStyle(t).backgroundPositionX", "20px"); // This is a bug. webkit.org/b/154551
+shouldBe("window.getComputedStyle(t).backgroundPositionX", "right 20px");
 
 run("t.setAttribute('style', 'background: url(about:blank) 80% 80%;');");
 run("t.style.backgroundPositionY = '50px'");

Modified: trunk/LayoutTests/imported/w3c/ChangeLog (282233 => 282234)


--- trunk/LayoutTests/imported/w3c/ChangeLog	2021-09-09 19:06:01 UTC (rev 282233)
+++ trunk/LayoutTests/imported/w3c/ChangeLog	2021-09-09 19:12:38 UTC (rev 282234)
@@ -1,3 +1,17 @@
+2021-09-09  Simon Fraser  <[email protected]>
+
+        right- and bottom-relative values in background-position-x/y don't work
+        https://bugs.webkit.org/show_bug.cgi?id=202148
+
+        Reviewed by Antti Koivisto.
+
+        More passing results.
+
+        * web-platform-tests/css/css-backgrounds/parsing/background-position-x-computed-expected.txt:
+        * web-platform-tests/css/css-backgrounds/parsing/background-position-x-valid-expected.txt:
+        * web-platform-tests/css/css-backgrounds/parsing/background-position-y-computed-expected.txt:
+        * web-platform-tests/css/css-backgrounds/parsing/background-position-y-valid-expected.txt:
+
 2021-09-09  Youenn Fablet  <[email protected]>
 
         Update RTCPeerConnection descriptions as per specification

Modified: trunk/LayoutTests/imported/w3c/web-platform-tests/css/css-backgrounds/parsing/background-position-x-computed-expected.txt (282233 => 282234)


--- trunk/LayoutTests/imported/w3c/web-platform-tests/css/css-backgrounds/parsing/background-position-x-computed-expected.txt	2021-09-09 19:06:01 UTC (rev 282233)
+++ trunk/LayoutTests/imported/w3c/web-platform-tests/css/css-backgrounds/parsing/background-position-x-computed-expected.txt	2021-09-09 19:12:38 UTC (rev 282234)
@@ -8,11 +8,11 @@
 PASS Property background-position-x value '10px'
 PASS Property background-position-x value '0.5em'
 PASS Property background-position-x value 'calc(10px - 0.5em)'
-FAIL Property background-position-x value 'left -20%' assert_true: 'left -20%' is a supported value for background-position-x. expected true got false
-FAIL Property background-position-x value 'right -10px' assert_true: 'right -10px' is a supported value for background-position-x. expected true got false
+PASS Property background-position-x value 'left -20%'
+FAIL Property background-position-x value 'right -10px' assert_equals: expected "calc(100% + 10px)" but got "right -10px"
 PASS Property background-position-x value '-20%, 10px'
 PASS Property background-position-x value 'center, left, right'
 FAIL Property background-position-x value '0.5em, x-start, x-end' assert_true: '0.5em, x-start, x-end' is a supported value for background-position-x. expected true got false
 PASS Property background-position-x value 'calc(10px - 0.5em), -20%, 10px'
-FAIL Property background-position-x value 'calc(10px - 0.5em), left -20%, right 10px' assert_true: 'calc(10px - 0.5em), left -20%, right 10px' is a supported value for background-position-x. expected true got false
+PASS Property background-position-x value 'calc(10px - 0.5em), left -20%, right 10px'
 

Modified: trunk/LayoutTests/imported/w3c/web-platform-tests/css/css-backgrounds/parsing/background-position-x-valid-expected.txt (282233 => 282234)


--- trunk/LayoutTests/imported/w3c/web-platform-tests/css/css-backgrounds/parsing/background-position-x-valid-expected.txt	2021-09-09 19:06:01 UTC (rev 282233)
+++ trunk/LayoutTests/imported/w3c/web-platform-tests/css/css-backgrounds/parsing/background-position-x-valid-expected.txt	2021-09-09 19:12:38 UTC (rev 282234)
@@ -1,7 +1,7 @@
 
-FAIL e.style['background-position-x'] = "center" should set the property value assert_equals: serialization should be canonical expected "center" but got "50%"
-FAIL e.style['background-position-x'] = "left" should set the property value assert_equals: serialization should be canonical expected "left" but got "0%"
-FAIL e.style['background-position-x'] = "right" should set the property value assert_equals: serialization should be canonical expected "right" but got "100%"
+PASS e.style['background-position-x'] = "center" should set the property value
+PASS e.style['background-position-x'] = "left" should set the property value
+PASS e.style['background-position-x'] = "right" should set the property value
 FAIL e.style['background-position-x'] = "x-start" should set the property value assert_not_equals: property should be set got disallowed value ""
 FAIL e.style['background-position-x'] = "x-end" should set the property value assert_not_equals: property should be set got disallowed value ""
 PASS e.style['background-position-x'] = "-20%" should set the property value
@@ -8,10 +8,10 @@
 PASS e.style['background-position-x'] = "10px" should set the property value
 PASS e.style['background-position-x'] = "0.5em" should set the property value
 PASS e.style['background-position-x'] = "calc(10px - 0.5em)" should set the property value
-FAIL e.style['background-position-x'] = "left -20%" should set the property value assert_not_equals: property should be set got disallowed value ""
-FAIL e.style['background-position-x'] = "right 10px" should set the property value assert_not_equals: property should be set got disallowed value ""
+PASS e.style['background-position-x'] = "left -20%" should set the property value
+PASS e.style['background-position-x'] = "right 10px" should set the property value
 PASS e.style['background-position-x'] = "-20%, 10px" should set the property value
-FAIL e.style['background-position-x'] = "center, left, right" should set the property value assert_equals: serialization should be canonical expected "center, left, right" but got "50%, 0%, 100%"
+PASS e.style['background-position-x'] = "center, left, right" should set the property value
 FAIL e.style['background-position-x'] = "0.5em, x-start, x-end" should set the property value assert_not_equals: property should be set got disallowed value ""
-FAIL e.style['background-position-x'] = "calc(10px - 0.5em), left -20%, right 10px" should set the property value assert_not_equals: property should be set got disallowed value ""
+PASS e.style['background-position-x'] = "calc(10px - 0.5em), left -20%, right 10px" should set the property value
 

Modified: trunk/LayoutTests/imported/w3c/web-platform-tests/css/css-backgrounds/parsing/background-position-y-computed-expected.txt (282233 => 282234)


--- trunk/LayoutTests/imported/w3c/web-platform-tests/css/css-backgrounds/parsing/background-position-y-computed-expected.txt	2021-09-09 19:06:01 UTC (rev 282233)
+++ trunk/LayoutTests/imported/w3c/web-platform-tests/css/css-backgrounds/parsing/background-position-y-computed-expected.txt	2021-09-09 19:12:38 UTC (rev 282234)
@@ -8,11 +8,11 @@
 PASS Property background-position-y value '10px'
 PASS Property background-position-y value '0.5em'
 PASS Property background-position-y value 'calc(10px - 0.5em)'
-FAIL Property background-position-y value 'top -20%' assert_true: 'top -20%' is a supported value for background-position-y. expected true got false
-FAIL Property background-position-y value 'bottom -10px' assert_true: 'bottom -10px' is a supported value for background-position-y. expected true got false
+PASS Property background-position-y value 'top -20%'
+FAIL Property background-position-y value 'bottom -10px' assert_equals: expected "calc(100% + 10px)" but got "bottom -10px"
 PASS Property background-position-y value '-20%, 10px'
 PASS Property background-position-y value 'center, top, bottom'
 FAIL Property background-position-y value '0.5em, y-start, y-end' assert_true: '0.5em, y-start, y-end' is a supported value for background-position-y. expected true got false
 PASS Property background-position-y value 'calc(10px - 0.5em), -20%, 10px'
-FAIL Property background-position-y value 'calc(10px - 0.5em), top -20%, bottom 10px' assert_true: 'calc(10px - 0.5em), top -20%, bottom 10px' is a supported value for background-position-y. expected true got false
+PASS Property background-position-y value 'calc(10px - 0.5em), top -20%, bottom 10px'
 

Modified: trunk/LayoutTests/imported/w3c/web-platform-tests/css/css-backgrounds/parsing/background-position-y-valid-expected.txt (282233 => 282234)


--- trunk/LayoutTests/imported/w3c/web-platform-tests/css/css-backgrounds/parsing/background-position-y-valid-expected.txt	2021-09-09 19:06:01 UTC (rev 282233)
+++ trunk/LayoutTests/imported/w3c/web-platform-tests/css/css-backgrounds/parsing/background-position-y-valid-expected.txt	2021-09-09 19:12:38 UTC (rev 282234)
@@ -1,7 +1,7 @@
 
-FAIL e.style['background-position-y'] = "center" should set the property value assert_equals: serialization should be canonical expected "center" but got "50%"
-FAIL e.style['background-position-y'] = "top" should set the property value assert_equals: serialization should be canonical expected "top" but got "0%"
-FAIL e.style['background-position-y'] = "bottom" should set the property value assert_equals: serialization should be canonical expected "bottom" but got "100%"
+PASS e.style['background-position-y'] = "center" should set the property value
+PASS e.style['background-position-y'] = "top" should set the property value
+PASS e.style['background-position-y'] = "bottom" should set the property value
 FAIL e.style['background-position-y'] = "y-start" should set the property value assert_not_equals: property should be set got disallowed value ""
 FAIL e.style['background-position-y'] = "y-end" should set the property value assert_not_equals: property should be set got disallowed value ""
 PASS e.style['background-position-y'] = "-20%" should set the property value
@@ -8,10 +8,10 @@
 PASS e.style['background-position-y'] = "10px" should set the property value
 PASS e.style['background-position-y'] = "0.5em" should set the property value
 PASS e.style['background-position-y'] = "calc(10px - 0.5em)" should set the property value
-FAIL e.style['background-position-y'] = "top -20%" should set the property value assert_not_equals: property should be set got disallowed value ""
-FAIL e.style['background-position-y'] = "bottom 10px" should set the property value assert_not_equals: property should be set got disallowed value ""
+PASS e.style['background-position-y'] = "top -20%" should set the property value
+PASS e.style['background-position-y'] = "bottom 10px" should set the property value
 PASS e.style['background-position-y'] = "-20%, 10px" should set the property value
-FAIL e.style['background-position-y'] = "center, top, bottom" should set the property value assert_equals: serialization should be canonical expected "center, top, bottom" but got "50%, 0%, 100%"
+PASS e.style['background-position-y'] = "center, top, bottom" should set the property value
 FAIL e.style['background-position-y'] = "0.5em, y-start, y-end" should set the property value assert_not_equals: property should be set got disallowed value ""
-FAIL e.style['background-position-y'] = "calc(10px - 0.5em), top -20%, bottom 10px" should set the property value assert_not_equals: property should be set got disallowed value ""
+FAIL e.style['background-position-y'] = "calc(10px - 0.5em), top -20%, bottom 10px" should set the property value assert_equals: serialization should be canonical expected "calc(-0.5em + 10px), top -20%, top 10px" but got "calc(-0.5em + 10px), top -20%, bottom 10px"
 

Modified: trunk/LayoutTests/transitions/background-position-transitions-expected.txt (282233 => 282234)


--- trunk/LayoutTests/transitions/background-position-transitions-expected.txt	2021-09-09 19:06:01 UTC (rev 282233)
+++ trunk/LayoutTests/transitions/background-position-transitions-expected.txt	2021-09-09 19:12:38 UTC (rev 282234)
@@ -1,7 +1,7 @@
 PASS - "background-position-x" property for "box1" element at 0.5s saw something close to: 45px
 PASS - "background-position-y" property for "box1" element at 0.5s saw something close to: 60px
-PASS - "background-position-x" property for "box2" element at 0.5s saw something close to: 45px
-PASS - "background-position-y" property for "box2" element at 0.5s saw something close to: 60px
+PASS - "background-position-x" property for "box2" element at 0.5s saw something close to: right 45px
+PASS - "background-position-y" property for "box2" element at 0.5s saw something close to: bottom 60px
 PASS - "background-position-x" property for "box3" element at 0.5s saw something close to: calc(50% - 35px)
 PASS - "background-position-y" property for "box3" element at 0.5s saw something close to: calc(50% - 40px)
 

Modified: trunk/LayoutTests/transitions/background-position-transitions.html (282233 => 282234)


--- trunk/LayoutTests/transitions/background-position-transitions.html	2021-09-09 19:06:01 UTC (rev 282233)
+++ trunk/LayoutTests/transitions/background-position-transitions.html	2021-09-09 19:12:38 UTC (rev 282234)
@@ -43,8 +43,8 @@
         // [time, element-id, property, expected-value, tolerance]
         [0.5, 'box1', 'background-position-x', "45px"],
         [0.5, 'box1', 'background-position-y', "60px"],
-        [0.5, 'box2', 'background-position-x', "45px"],
-        [0.5, 'box2', 'background-position-y', "60px"],
+        [0.5, 'box2', 'background-position-x', "right 45px"],
+        [0.5, 'box2', 'background-position-y', "bottom 60px"],
         [0.5, 'box3', 'background-position-x', "calc(50% - 35px)"],
         [0.5, 'box3', 'background-position-y', "calc(50% - 40px)"],
         ];

Modified: trunk/Source/WebCore/ChangeLog (282233 => 282234)


--- trunk/Source/WebCore/ChangeLog	2021-09-09 19:06:01 UTC (rev 282233)
+++ trunk/Source/WebCore/ChangeLog	2021-09-09 19:12:38 UTC (rev 282234)
@@ -1,3 +1,41 @@
+2021-09-09  Simon Fraser  <[email protected]>
+
+        right- and bottom-relative values in background-position-x/y don't work
+        https://bugs.webkit.org/show_bug.cgi?id=202148
+
+        Reviewed by Antti Koivisto.
+
+        Test: fast/backgrounds/background-position-xy.html
+
+        background-position[1] and background-position-x/background-position-y allow authors
+        to specify edge-relative values, like "background-position-x: right 10px". We
+        failed to handle this syntax in background-position-x and background-position-y,
+        but we do handle it in background-position.
+
+        So fix consumePositionX()/consumePositionY(), which are used when parsing
+        background-position-x/y, -webkit-mask-position-x/y, perspective-origin-x/y, and
+        transform-origin-x.y, to handle this edge-relative form.
+
+        A failure on imported/w3c/web-platform-tests/css/css-backgrounds/parsing/background-position-x-computed.html
+        (which only passes in Firefox) suggets that we should convert "right 10px" to "calc(100% - 10px)"
+        but for now, this patch serializes with edge keywords, as we do for the shorthand.
+
+        [1] https://www.w3.org/TR/css-backgrounds-3/#background-position
+
+        Test: fast/backgrounds/background-position-xy.html
+
+        * css/CSSComputedStyleDeclaration.cpp:
+        (WebCore::createSingleAxisPositionValueForLayer):
+        (WebCore::ComputedStyleExtractor::valueForPropertyInStyle):
+        * css/parser/CSSPropertyParser.cpp:
+        (WebCore::consumePositionX):
+        (WebCore::consumePositionY):
+        (WebCore::consumePositionLonghand): Deleted.
+        * css/parser/CSSPropertyParserHelpers.cpp:
+        (WebCore::CSSPropertyParserHelpers::consumePositionCoordinates):
+        (WebCore::CSSPropertyParserHelpers::consumeSingleAxisPosition):
+        * css/parser/CSSPropertyParserHelpers.h:
+
 2021-09-09  Antti Koivisto  <[email protected]>
 
         Cull inline culling

Modified: trunk/Source/WebCore/css/CSSComputedStyleDeclaration.cpp (282233 => 282234)


--- trunk/Source/WebCore/css/CSSComputedStyleDeclaration.cpp	2021-09-09 19:06:01 UTC (rev 282233)
+++ trunk/Source/WebCore/css/CSSComputedStyleDeclaration.cpp	2021-09-09 19:12:38 UTC (rev 282234)
@@ -301,6 +301,27 @@
     return list;
 }
 
+static Ref<CSSValue> createSingleAxisPositionValueForLayer(CSSPropertyID propertyID, const FillLayer& layer, const RenderStyle& style)
+{
+    if (propertyID == CSSPropertyBackgroundPositionX || propertyID == CSSPropertyWebkitMaskPositionX) {
+        if (!layer.isBackgroundXOriginSet() || layer.backgroundXOrigin() == Edge::Left)
+            return zoomAdjustedPixelValueForLength(layer.xPosition(), style);
+
+        auto list = CSSValueList::createSpaceSeparated();
+        list->append(CSSValuePool::singleton().createValue(layer.backgroundXOrigin()));
+        list->append(zoomAdjustedPixelValueForLength(layer.xPosition(), style));
+        return list;
+    }
+
+    if (!layer.isBackgroundYOriginSet() || layer.backgroundYOrigin() == Edge::Top)
+        return zoomAdjustedPixelValueForLength(layer.yPosition(), style);
+
+    auto list = CSSValueList::createSpaceSeparated();
+    list->append(CSSValuePool::singleton().createValue(layer.backgroundYOrigin()));
+    list->append(zoomAdjustedPixelValueForLength(layer.yPosition(), style));
+    return list;
+}
+
 static Length getOffsetComputedLength(const RenderStyle& style, CSSPropertyID propertyID)
 {
     // If specified as a length, the corresponding absolute length; if specified as
@@ -2699,11 +2720,11 @@
         case CSSPropertyWebkitMaskPositionX: {
             auto& layers = propertyID == CSSPropertyWebkitMaskPositionX ? style.maskLayers() : style.backgroundLayers();
             if (!layers.next())
-                return cssValuePool.createValue(layers.xPosition(), style);
+                return createSingleAxisPositionValueForLayer(propertyID, layers, style);
 
             auto list = CSSValueList::createCommaSeparated();
             for (auto* currLayer = &layers; currLayer; currLayer = currLayer->next())
-                list->append(cssValuePool.createValue(currLayer->xPosition(), style));
+                list->append(createSingleAxisPositionValueForLayer(propertyID, *currLayer, style));
 
             return list;
         }
@@ -2711,11 +2732,11 @@
         case CSSPropertyWebkitMaskPositionY: {
             auto& layers = propertyID == CSSPropertyWebkitMaskPositionY ? style.maskLayers() : style.backgroundLayers();
             if (!layers.next())
-                return cssValuePool.createValue(layers.yPosition(), style);
+                return createSingleAxisPositionValueForLayer(propertyID, layers, style);
 
             auto list = CSSValueList::createCommaSeparated();
             for (auto* currLayer = &layers; currLayer; currLayer = currLayer->next())
-                list->append(cssValuePool.createValue(currLayer->yPosition(), style));
+                list->append(createSingleAxisPositionValueForLayer(propertyID, *currLayer, style));
 
             return list;
         }

Modified: trunk/Source/WebCore/css/parser/CSSPropertyParser.cpp (282233 => 282234)


--- trunk/Source/WebCore/css/parser/CSSPropertyParser.cpp	2021-09-09 19:06:01 UTC (rev 282233)
+++ trunk/Source/WebCore/css/parser/CSSPropertyParser.cpp	2021-09-09 19:12:38 UTC (rev 282234)
@@ -2132,34 +2132,14 @@
     return list;
 }
 
-template <CSSValueID start, CSSValueID end>
-static RefPtr<CSSPrimitiveValue> consumePositionLonghand(CSSParserTokenRange& range, CSSParserMode cssParserMode)
-{
-    if (range.peek().type() == IdentToken) {
-        CSSValueID id = range.peek().id();
-        int percent;
-        if (id == start)
-            percent = 0;
-        else if (id == CSSValueCenter)
-            percent = 50;
-        else if (id == end)
-            percent = 100;
-        else
-            return nullptr;
-        range.consumeIncludingWhitespace();
-        return CSSPrimitiveValue::create(percent, CSSUnitType::CSS_PERCENTAGE);
-    }
-    return consumeLengthOrPercent(range, cssParserMode, ValueRange::All);
-}
-
 static RefPtr<CSSPrimitiveValue> consumePositionX(CSSParserTokenRange& range, CSSParserMode cssParserMode)
 {
-    return consumePositionLonghand<CSSValueLeft, CSSValueRight>(range, cssParserMode);
+    return consumeSingleAxisPosition(range, cssParserMode, BoxOrient::Horizontal);
 }
 
 static RefPtr<CSSPrimitiveValue> consumePositionY(CSSParserTokenRange& range, CSSParserMode cssParserMode)
 {
-    return consumePositionLonghand<CSSValueTop, CSSValueBottom>(range, cssParserMode);
+    return consumeSingleAxisPosition(range, cssParserMode, BoxOrient::Vertical);
 }
 
 static RefPtr<CSSValue> consumePaintStroke(CSSParserTokenRange& range, const CSSParserContext& context)

Modified: trunk/Source/WebCore/css/parser/CSSPropertyParserHelpers.cpp (282233 => 282234)


--- trunk/Source/WebCore/css/parser/CSSPropertyParserHelpers.cpp	2021-09-09 19:06:01 UTC (rev 282233)
+++ trunk/Source/WebCore/css/parser/CSSPropertyParserHelpers.cpp	2021-09-09 19:12:38 UTC (rev 282234)
@@ -46,6 +46,7 @@
 #include "ColorConversion.h"
 #include "ColorLuminance.h"
 #include "Pair.h"
+#include "RenderStyleConstants.h"
 #include "RuntimeEnabledFeatures.h"
 #include "StyleColor.h"
 #include "WebKitFontFamilyNames.h"
@@ -2768,7 +2769,7 @@
     
     if (positionSyntax != PositionSyntax::BackgroundPosition)
         return std::nullopt;
-    
+
     return backgroundPositionFromThreeValues(values);
 }
 
@@ -2790,6 +2791,33 @@
     return positionFromTwoValues(*value1, *value2);
 }
 
+RefPtr<CSSPrimitiveValue> consumeSingleAxisPosition(CSSParserTokenRange& range, CSSParserMode parserMode, BoxOrient orientation)
+{
+    RefPtr<CSSPrimitiveValue> value1;
+
+    if (range.peek().type() == IdentToken) {
+        switch (orientation) {
+        case BoxOrient::Horizontal:
+            value1 = consumeIdent<CSSValueLeft, CSSValueRight, CSSValueCenter>(range);
+            break;
+        case BoxOrient::Vertical:
+            value1 = consumeIdent<CSSValueTop, CSSValueBottom, CSSValueCenter>(range);
+            break;
+        }
+        if (!value1)
+            return nullptr;
+
+        if (value1->valueID() == CSSValueCenter)
+            return value1;
+    }
+
+    auto value2 = consumeLengthOrPercent(range, parserMode, ValueRange::All, UnitlessQuirk::Forbid);
+    if (value1 && value2)
+        return CSSPropertyParserHelpersInternal::createPrimitiveValuePair(WTFMove(value1), WTFMove(value2));
+
+    return value1 ? value1 : value2;
+}
+
 // This should go away once we drop support for -webkit-gradient
 static RefPtr<CSSPrimitiveValue> consumeDeprecatedGradientPoint(CSSParserTokenRange& args, bool horizontal)
 {

Modified: trunk/Source/WebCore/css/parser/CSSPropertyParserHelpers.h (282233 => 282234)


--- trunk/Source/WebCore/css/parser/CSSPropertyParserHelpers.h	2021-09-09 19:06:01 UTC (rev 282233)
+++ trunk/Source/WebCore/css/parser/CSSPropertyParserHelpers.h	2021-09-09 19:12:38 UTC (rev 282234)
@@ -46,6 +46,8 @@
 enum class FamilyNamesIndex;
 }
 
+enum class BoxOrient : uint8_t;
+
 // When these functions are successful, they will consume all the relevant
 // tokens from the range and also consume any whitespace which follows. When
 // the start of the range doesn't match the type we're looking for, the range
@@ -126,6 +128,7 @@
 };
 
 RefPtr<CSSPrimitiveValue> consumePosition(CSSParserTokenRange&, CSSParserMode, UnitlessQuirk, PositionSyntax);
+RefPtr<CSSPrimitiveValue> consumeSingleAxisPosition(CSSParserTokenRange&, CSSParserMode, BoxOrient);
 std::optional<PositionCoordinates> consumePositionCoordinates(CSSParserTokenRange&, CSSParserMode, UnitlessQuirk, PositionSyntax);
 std::optional<PositionCoordinates> consumeOneOrTwoValuedPositionCoordinates(CSSParserTokenRange&, CSSParserMode, UnitlessQuirk);
 
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to