[@scope] Make '&' work like :where(scope) in @scope rules
Within @scope rules, there are currently three subtly different ways
to reference the scoping root:
A. With the :scope pseudo-class, which matches the specific element
that is the scoping root. The specificity of :scope is [0, 1, 0].
B. With the '&' selector. This is really referencing the <scope-start>
*selector* rather than a specific element [1], but it's effectively
the same in most cases. The specificity of '&' works like
the specificity of :is(), i.e. max across the held selector list.
C. Implicitly, if no '&' or :scope selector is explicitly provided.
In this case, we effectively prepend :where(scope) (+ descendant
combinator) to the selector. The specificity of that is obviously
zero.
This behavior is "all over the place", and although it was done
intentionally to begin with (for consistency with css-nesting),
the CSSWG has since decided [2] that '&' should now just mean
:where(:scope).
In other words, we are changing (B), while (A) and (C) remains the same.
We can carry out this change by simply not providing scoped '&'
with a parent rule pointer at all. This already has zero
specificity (covering the :where() part), and already behaves
like :scope in the SelectorChecker.
Also, I expect that we'll be able to clean up some of the special cases
around @scope in the parser once the flag is removed. For example,
when parsing relative selectors, we don't need to know the current
CSSNestingType to know whether to prepend '&' or ':where(:scope)';
we can just always prepend '&' now. This is for future CLs, however.
[1] This means that '@scope(div) { & + & {} }' can match (a <div> next
to another <div>), but '@scope(div) { :scope + :scope {} }' can not
(an element can not be its own sibling).
[2] https://github.com/w3c/csswg-drafts/issues/9740
Fixed: 445949406
Change-Id: I63dc55c12d875096534e69adbbd5d5298e109fa1
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/7006094
Commit-Queue: Anders Hartvoll Ruud <andruud@chromium.org>
Reviewed-by: Steinar H Gunderson <sesse@chromium.org>
Cr-Commit-Position: refs/heads/main@{#1526767}
Chromium is an open-source browser project that aims to build a safer, faster, and more stable way for all users to experience the web.
The project's web site is https://www.chromium.org.
To check out the source code locally, don't use git clone! Instead, follow the instructions on how to get the code.
Documentation in the source is rooted in docs/README.md.
Learn how to Get Around the Chromium Source Code Directory Structure.
For historical reasons, there are some small top level directories. Now the guidance is that new top level directories are for product (e.g. Chrome, Android WebView, Ash). Even if these products have multiple executables, the code should be in subdirectories of the product.
If you found a bug, please file it at https://crbug.com/new.