[css-anchor-position-1] Accommodate pseudo-elements when sorting anchor elements by tree order#61306
Open
tuankiet65 wants to merge 1 commit intoWebKit:mainfrom
Conversation
…or elements by tree order rdar://173032203 https://bugs.webkit.org/show_bug.cgi?id=310398 Reviewed by NOBODY (OOPS!). When determining which element is the anchor, the last element in tree order that satistifes the anchor query wins [1]: > If an ancestor of query el satisfies the following conditions, return the nearest such element > to query el. Otherwise, return the last element el in tree order that satisfies the conditions. WebKit implemented this by sorting anchors with the same anchor name in reverse tree order, using treeOrder<ComposedTree> to determine the order. But treeOrder doesn't work with pseudo-elements (e.g ::before, ::after). Fix this by re-writing the sort comparison logic to handle pseudo-elements: * If two elements aren't pseudo-elements, use treeOrder as usual * If one is, and the other isn't, the order is the order between the pseudo-element's host and the non-pseudo element * If both are pseudo-elements of different hosts: the order is their host elements' order * Otherwise, both are pseudo-elements of the same host, and ::before is before ::after [1]: https://drafts.csswg.org/css-anchor-position-1/#target Tests: imported/w3c/web-platform-tests/css/css-anchor-position/anchor-function-chain-pseudo-elements.html imported/w3c/web-platform-tests/css/css-anchor-position/anchor-size-function-chain-pseudo-elements.html imported/w3c/web-platform-tests/css/css-anchor-position/position-area-chain-pseudo-elements.html imported/w3c/web-platform-tests/css/css-anchor-position/pseudo-element-anchor-tree-order.html * LayoutTests/imported/w3c/web-platform-tests/css/css-anchor-position/anchor-function-chain-pseudo-elements-expected.html: Added. * LayoutTests/imported/w3c/web-platform-tests/css/css-anchor-position/anchor-function-chain-pseudo-elements.html: Added. * LayoutTests/imported/w3c/web-platform-tests/css/css-anchor-position/anchor-size-function-chain-pseudo-elements-expected.html: Added. * LayoutTests/imported/w3c/web-platform-tests/css/css-anchor-position/anchor-size-function-chain-pseudo-elements-ref.html: Added. * LayoutTests/imported/w3c/web-platform-tests/css/css-anchor-position/anchor-size-function-chain-pseudo-elements.html: Added. * LayoutTests/imported/w3c/web-platform-tests/css/css-anchor-position/position-area-chain-pseudo-elements-expected.html: Added. * LayoutTests/imported/w3c/web-platform-tests/css/css-anchor-position/position-area-chain-pseudo-elements.html: Added. * LayoutTests/imported/w3c/web-platform-tests/css/css-anchor-position/pseudo-element-anchor-tree-order-expected.txt: Added. * LayoutTests/imported/w3c/web-platform-tests/css/css-anchor-position/pseudo-element-anchor-tree-order.html: Added. * LayoutTests/imported/w3c/web-platform-tests/css/css-anchor-position/reference/pseudo-element-chain-ref.html: Added. * Source/WebCore/style/AnchorPositionEvaluator.cpp: (WebCore::Style::orderInComposedTreeAccountingForPseudoElements): (WebCore::Style::collectAnchorsForAnchorName):
Collaborator
|
EWS run on current version of this PR (hash 24688fe) Details
|
anttijk
approved these changes
Mar 25, 2026
nt1m
reviewed
Mar 25, 2026
| @@ -1217,6 +1217,63 @@ static RefPtr<Element> findLastAcceptableAnchorWithName(ResolvedScopedName ancho | |||
| return { }; | |||
| } | |||
|
|
|||
| static std::partial_ordering orderInComposedTreeAccountingForPseudoElements(const Element& a, const Element& b) | |||
Member
There was a problem hiding this comment.
We should try to consolidate this with: https://searchfox.org/wubkat/source/Source/WebCore/animation/WebAnimationUtilities.cpp#68
Member
Author
There was a problem hiding this comment.
The sorting logic in WebAnimationUtilities.cpp follows the defined ordering in the CSS animation spec, while the anchor spec just says "in tree order" without specifying the order of pseudo-elements. I can certainly try to consolidate them, but that would imply that CSS animations and anchor element use the same ordering (are they?) Maybe this is worth raising an issue to CSSWG?
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
24688fe
24688fe