Skip to content

Commit

Permalink
[anchor] Search inclusive ancestors for the anchor-scoping element
Browse files Browse the repository at this point in the history
We incorrectly used exclusive ancestors, making it impossible to anchor
against elements that both name and scope some anchor name.

Fixed: 373815812
Change-Id: I5eaab2f38589f02470c5229573c199f1b3715424
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/5938970
Commit-Queue: Anders Hartvoll Ruud <andruud@chromium.org>
Reviewed-by: Rune Lillesveen <futhark@chromium.org>
Cr-Commit-Position: refs/heads/main@{#1370556}
  • Loading branch information
andruud authored and chromium-wpt-export-bot committed Oct 18, 2024
1 parent e2225ae commit cc9c2fd
Showing 1 changed file with 27 additions and 3 deletions.
30 changes: 27 additions & 3 deletions css/css-anchor-position/anchor-scope-basic.html
Original file line number Diff line number Diff line change
Expand Up @@ -37,16 +37,40 @@
</style>
<script>
function inflate(t, template_element) {
if (!template_element.hasAttribute('debug')) {
t.add_cleanup(() => main.replaceChildren());
}
t.add_cleanup(() => main.replaceChildren());
main.append(template_element.content.cloneNode(true));
}
</script>

<main id=main>
</main>

<template id=test_inclusive_subtree>
<div class="scope-a anchor-a"> <!--A-->
<div class=anchored-a></div>
</div>
</template>
<script>
test((t) => {
inflate(t, test_inclusive_subtree);
assert_equals(getComputedStyle(main.querySelector('.anchored-a')).top, '10px');
}, 'Can anchor to a name both defined and scoped by the same element');
</script>

<template id=test_skips_named_anchor_with_scope>
<div class="anchor-a"></div>
<div class="anchor-a"></div>
<div class="anchor-a"></div> <!--A-->
<div class="scope-a anchor-a"></div>
<div class=anchored-a></div>
</template>
<script>
test((t) => {
inflate(t, test_skips_named_anchor_with_scope);
assert_equals(getComputedStyle(main.querySelector('.anchored-a')).top, '30px');
}, 'Sibling can not anchor into anchor-scope, even when anchor-name present');
</script>

<template id=test_scope_all_common_ancestor>
<div class=scope-all>
<div class=anchor-a></div>
Expand Down

0 comments on commit cc9c2fd

Please sign in to comment.