Skip to content

Commit

Permalink
[css-anchor-position-1] Add parsing support for anchor()
Browse files Browse the repository at this point in the history
https://bugs.webkit.org/show_bug.cgi?id=275063
rdar://129168625

Reviewed by Antti Koivisto.

This patch adds initial parsing support for `anchor()` and introduces
a new CSSValue subclass named CSSAnchorValue. This class is also
implemented as a CSSPrimitiveValue. Note that the parsers for inset
properties (left, top, inset-block-end, etc.) have been modified to
accept `anchor()` as a value, whereas `anchor()` is not accepted as a
<length> in other properties by default.

This patch does not support parsing `anchor()` calls in other CSS math
functions (such as `calc()` and `min()`).

Previously WebKit ignored inset property declarations using `anchor()`.
Now, because these values are properly parsed, any inset properties
using `anchor()` are assigned a default fixed length of 0 during
style resolution. (This causes many spurious test rebaselines.)

* LayoutTests/TestExpectations:
* LayoutTests/imported/w3c/web-platform-tests/css/css-anchor-position/
* LayoutTests/imported/w3c/web-platform-tests/html/dom/elements/global-attributes/the-anchor-attribute-003.tentative-expected.txt:
* LayoutTests/imported/w3c/web-platform-tests/html/semantics/popovers/popover-anchor-display-none.tentative-expected.txt:
* Source/WebCore/Headers.cmake:
* Source/WebCore/Sources.txt:
* Source/WebCore/WebCore.xcodeproj/project.pbxproj:
* Source/WebCore/css/CSSAnchorValue.cpp: Added.
(WebCore::CSSAnchorValue::create):
(WebCore::CSSAnchorValue::collectComputedStyleDependencies const):
(WebCore::CSSAnchorValue::customCSSText const):
(WebCore::CSSAnchorValue::equals const):
* Source/WebCore/css/CSSAnchorValue.h:
* Source/WebCore/css/CSSPrimitiveValue.cpp:
(WebCore::isValidCSSUnitTypeForDoubleConversion):
(WebCore::isStringType):
(WebCore::CSSPrimitiveValue::CSSPrimitiveValue):
(WebCore::CSSPrimitiveValue::~CSSPrimitiveValue):
(WebCore::CSSPrimitiveValue::create):
(WebCore::CSSPrimitiveValue::unitTypeString):
(WebCore::CSSPrimitiveValue::serializeInternal const):
(WebCore::CSSPrimitiveValue::equals const):
(WebCore::CSSPrimitiveValue::addDerivedHash const):
(WebCore::CSSPrimitiveValue::collectComputedStyleDependencies const):
* Source/WebCore/css/CSSPrimitiveValue.h:
* Source/WebCore/css/CSSProperties.json:
* Source/WebCore/css/CSSUnits.cpp:
(WebCore::unitCategory):
(WebCore::operator<<):
* Source/WebCore/css/CSSUnits.h:
* Source/WebCore/css/CSSValue.cpp:
(WebCore::CSSValue::visitDerived):
* Source/WebCore/css/CSSValue.h:
(WebCore::CSSValue::isAnchorValue const):
* Source/WebCore/css/CSSValueKeywords.in:
* Source/WebCore/css/calc/CSSCalcCategoryMapping.cpp:
(WebCore::hasDoubleValue):
* Source/WebCore/css/parser/CSSPropertyParserConsumer+Length.cpp:
(WebCore::CSSPropertyParserHelpers::consumeLengthOrPercent):
* Source/WebCore/css/parser/CSSPropertyParserConsumer+Length.h:
* Source/WebCore/css/parser/CSSPropertyParserConsumer+Primitives.h:
* Source/WebCore/css/parser/CSSPropertyParserHelpers.cpp:
(WebCore::CSSPropertyParserHelpers::consumeDashedIdent):
(WebCore::CSSPropertyParserHelpers::consumeAutoOrLengthOrPercent):
(WebCore::CSSPropertyParserHelpers::consumeSide):
(WebCore::CSSPropertyParserHelpers::consumeInsetLogicalStartEnd):
(WebCore::CSSPropertyParserHelpers::consumeAnchor):
* Source/WebCore/css/parser/CSSPropertyParserHelpers.h:
* Source/WebCore/style/StyleBuilderConverter.h:
(WebCore::Style::BuilderConverter::convertLength):

Canonical link: https://commits.webkit.org/279891@main
  • Loading branch information
RWDavid authored and nt1m committed Jun 10, 2024
1 parent e4bbed4 commit 258ed7a
Show file tree
Hide file tree
Showing 73 changed files with 3,106 additions and 2,851 deletions.
13 changes: 11 additions & 2 deletions LayoutTests/TestExpectations
Original file line number Diff line number Diff line change
Expand Up @@ -7525,13 +7525,22 @@ imported/w3c/web-platform-tests/css/css-anchor-position/position-visibility-remo
imported/w3c/web-platform-tests/css/css-anchor-position/position-visibility-remove-no-overflow.html [ ImageOnlyFailure ]
imported/w3c/web-platform-tests/css/css-anchor-position/sticky-anchor-position-invalid.html [ ImageOnlyFailure ]

# ios-wk2-wpt and mac-AS-debug-wk2 failures (leaving in the general TestExpectations for now since these are not useful failures)
# The following failures are left in the general TestExpectations for now since these are not useful failures

# ios-wk2-wpt failures
imported/w3c/web-platform-tests/css/css-anchor-position/anchor-position-borders-001.html [ Failure ]
imported/w3c/web-platform-tests/css/css-anchor-position/anchor-position-dynamic-001.html [ Failure ]

# ios-wk2-wpt AND wpe-wk2 AND gtk-wk2 failures
imported/w3c/web-platform-tests/css/css-anchor-position/anchor-invalid-fallback.html [ Failure ]

# ios-wk2-wpt AND mac-AS-debug-wk2 failures
imported/w3c/web-platform-tests/css/css-anchor-position/anchor-position-borders-002.html [ Failure ]
imported/w3c/web-platform-tests/css/css-anchor-position/anchor-scroll-position-try-007.html [ Failure ]
imported/w3c/web-platform-tests/css/css-anchor-position/anchor-scroll-position-try-008.html [ Failure ]
imported/w3c/web-platform-tests/css/css-anchor-position/anchor-scroll-position-try-010.html [ Failure ]

# wpe-wk2 AND gtk-wk2 AND wincairo failures (leaving in the general TestExpectations for now since these are not useful failures)
# wpe-wk2 AND gtk-wk2 AND wincairo failures
imported/w3c/web-platform-tests/css/css-anchor-position/anchor-center-htb-htb.html [ Failure ]
imported/w3c/web-platform-tests/css/css-anchor-position/anchor-center-htb-vrl.html [ Failure ]
imported/w3c/web-platform-tests/css/css-anchor-position/anchor-center-vrl-htb.html [ Failure ]
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@

FAIL Basic case assert_equals: expected "100px" but got "120px"
FAIL Mixed writing modes and directions assert_equals: expected "100px" but got "150px"
FAIL With containing block padding assert_equals: expected "90px" but got "110px"
FAIL Basic case assert_equals: expected "100px" but got "0px"
FAIL Mixed writing modes and directions assert_equals: expected "100px" but got "0px"
FAIL With containing block padding assert_equals: expected "90px" but got "0px"

Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,5 @@ Lorem ipsum dolor sit amet.
Lorem ipsum dolor sit amet.

FAIL getComputedStyle() with fragmented containing block in multicolumn layout assert_equals: expected "25px" but got "0px"
FAIL getComputedStyle() with fragmented containing block in inline layout assert_equals: expected "0px" but got "40px"
FAIL getComputedStyle() with fragmented containing block in inline layout assert_equals: expected "20px" but got "0px"

Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,10 @@ FAIL .target 2 assert_equals:
offsetLeft expected 200 but got 0
FAIL .target 3 assert_equals:
<div class="target" style="right:anchor(inside)" data-offset-x="190"></div>
offsetLeft expected 190 but got 0
offsetLeft expected 190 but got 390
FAIL .target 4 assert_equals:
<div class="target" style="right:anchor(outside)" data-offset-x="140"></div>
offsetLeft expected 140 but got 0
offsetLeft expected 140 but got 390
FAIL .target 5 assert_equals:
<div class="target" style="top:anchor(inside)" data-offset-y="250"></div>
offsetTop expected 250 but got 0
Expand All @@ -19,10 +19,10 @@ FAIL .target 6 assert_equals:
offsetTop expected 300 but got 0
FAIL .target 7 assert_equals:
<div class="target" style="bottom:anchor(inside)" data-offset-y="290"></div>
offsetTop expected 290 but got 0
offsetTop expected 290 but got 390
FAIL .target 8 assert_equals:
<div class="target" style="bottom:anchor(outside)" data-offset-y="240"></div>
offsetTop expected 240 but got 0
offsetTop expected 240 but got 390
FAIL .target 9 assert_equals:
<div class="target" style="inset-inline-start:anchor(inside)" data-offset-x="150"></div>
offsetLeft expected 150 but got 0
Expand All @@ -31,10 +31,10 @@ FAIL .target 10 assert_equals:
offsetLeft expected 200 but got 0
FAIL .target 11 assert_equals:
<div class="target" style="inset-inline-end:anchor(inside)" data-offset-x="190"></div>
offsetLeft expected 190 but got 0
offsetLeft expected 190 but got 390
FAIL .target 12 assert_equals:
<div class="target" style="inset-inline-end:anchor(outside)" data-offset-x="140"></div>
offsetLeft expected 140 but got 0
offsetLeft expected 140 but got 390
FAIL .target 13 assert_equals:
<div class="target" style="inset-block-start:anchor(inside)" data-offset-y="250"></div>
offsetTop expected 250 but got 0
Expand All @@ -43,8 +43,8 @@ FAIL .target 14 assert_equals:
offsetTop expected 300 but got 0
FAIL .target 15 assert_equals:
<div class="target" style="inset-block-end:anchor(inside)" data-offset-y="290"></div>
offsetTop expected 290 but got 0
offsetTop expected 290 but got 390
FAIL .target 16 assert_equals:
<div class="target" style="inset-block-end:anchor(outside)" data-offset-y="240"></div>
offsetTop expected 240 but got 0
offsetTop expected 240 but got 390

Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ X
FAIL Element can be anchor positioned assert_equals: expected "125px" but got "0px"
FAIL Element can use <length> fallback if present assert_equals: expected "17px" but got "0px"
PASS Invalid anchor function, left
PASS Invalid anchor function, right
PASS Invalid anchor function, bottom
FAIL Invalid anchor function, right assert_equals: left expected "0px" but got "188.4375px"
FAIL Invalid anchor function, bottom assert_equals: top expected "0px" but got "182px"
PASS Invalid anchor function, top
PASS Invalid anchor function, width
PASS Invalid anchor function, height
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@

FAIL Should be able to set anchor-name to a shadow DOM part and anchor to it assert_equals: expected 15 but got 0
PASS Should be able to set anchor-name to the shadow host and anchor to it
FAIL Should be able to set anchor-name to the shadow host and anchor to it assert_equals: expected 15 but got 0

Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@

PASS Anchor names in different tree scopes should not be confused
FAIL Anchor names in different tree scopes should not be confused assert_equals: expected 100 but got 0

Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@

PASS anchor-name should not leak out of a shadow tree
FAIL anchor() in shadow tree should not match host anchor-name assert_equals: #anchored is positioned using fallback expected 37 but got 8
FAIL anchor-name should not leak out of a shadow tree assert_equals: #anchored is positioned against #anchor expected 100 but got 0
FAIL anchor() in shadow tree should not match host anchor-name assert_equals: #anchored is positioned using fallback expected 37 but got 0

Loading

0 comments on commit 258ed7a

Please sign in to comment.