Skip to content

Commit

Permalink
[@scope] Expand :scope selectors for :has() cache
Browse files Browse the repository at this point in the history
The :scope pseudo-class can refer to different elements depending on
context. This is similar to the '&' pseudo-class, but differs
in that :scope refers to a single *element*, not a specific selector list.

This causes problems for the :has() cache, since it uses
the serialization of a selector as the key. In CL:5680906, this was
solved by expanding '&' in the cache-key, and this CL now does a similar
trick for :scope. Unlike '&', however, the :scope selector itself does
not know what it refers to; it must come from context. We can use
the pointer value of the scope node for this, since the :has() cache
only exists on the stack during style recalc.

Fixed: 383343312
Change-Id: I08e5d3caf18831d614caed474081d32caa43bd64
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/6090905
Reviewed-by: Byungwoo Lee <blee@igalia.com>
Commit-Queue: Anders Hartvoll Ruud <andruud@chromium.org>
Cr-Commit-Position: refs/heads/main@{#1397188}
  • Loading branch information
andruud authored and chromium-wpt-export-bot committed Dec 17, 2024
1 parent 2cfd560 commit b9ff3b3
Showing 1 changed file with 33 additions and 0 deletions.
33 changes: 33 additions & 0 deletions css/css-cascade/scope-overlapping-has.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
<!DOCTYPE html>
<title>@scope - Overlapping scopes with :has(..:scope..) selector</title>
<link rel="help" href="https://drafts.csswg.org/css-cascade-6/#scope-atrule">
<link rel="help" href="https://issues.chromium.org/issues/383343312">
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<style>
:where(*) {
background-color: green;
}
@scope (.a) to (.limit) {
:scope:has(.b:not(:scope .a *)) .hello {
background-color: red;
}
}
</style>
<div class=a id=outer>
<div>
<div class=limit>
<div class=a id=inner>
<div class=b></div>
<div class=hello id=first>hello</div>
</div>
</div>
</div>
<div class=hello id=second>hello</div>
</div>
<script>
test(() => {
assert_equals(getComputedStyle(first).backgroundColor, 'rgb(255, 0, 0)');
assert_equals(getComputedStyle(second).backgroundColor, 'rgb(0, 128, 0)');
}, ':has() with inner :scope works when scopes overlap');
</script>

0 comments on commit b9ff3b3

Please sign in to comment.