- Revision
- 292592
- Author
- [email protected]
- Date
- 2022-04-07 21:59:16 -0700 (Thu, 07 Apr 2022)
Log Message
[CSS Container Queries] Evaluate against shadow-including ancestors
https://bugs.webkit.org/show_bug.cgi?id=238934
Reviewed by Tim Nguyen.
LayoutTests/imported/w3c:
* web-platform-tests/css/css-contain/container-queries/container-for-shadow-dom-expected.txt:
* web-platform-tests/css/css-contain/container-queries/container-for-shadow-dom.html:
Add declarative shadow DOM polyfill.
Source/WebCore:
"Style rules applying to its shadow-including descendants can then be conditioned by querying against it,
using the @container conditional group rule."
https://drafts.csswg.org/css-contain-3/#container-queries
* style/ContainerQueryEvaluator.cpp:
(WebCore::Style::ContainerQueryEvaluator::selectContainer):
Evaluate against shadow-including ancestors instead of flat tree ancestors if the cache is not available.
* style/StyleTreeResolver.cpp:
(WebCore::Style::TreeResolver::Scope::Scope):
Copy the container state when pushing scope. This also creates a stack of shadow-including ancestors.
* style/StyleTreeResolver.h:
Modified Paths
Diff
Modified: trunk/LayoutTests/imported/w3c/ChangeLog (292591 => 292592)
--- trunk/LayoutTests/imported/w3c/ChangeLog 2022-04-08 04:09:07 UTC (rev 292591)
+++ trunk/LayoutTests/imported/w3c/ChangeLog 2022-04-08 04:59:16 UTC (rev 292592)
@@ -1,3 +1,15 @@
+2022-04-07 Antti Koivisto <[email protected]>
+
+ [CSS Container Queries] Evaluate against shadow-including ancestors
+ https://bugs.webkit.org/show_bug.cgi?id=238934
+
+ Reviewed by Tim Nguyen.
+
+ * web-platform-tests/css/css-contain/container-queries/container-for-shadow-dom-expected.txt:
+ * web-platform-tests/css/css-contain/container-queries/container-for-shadow-dom.html:
+
+ Add declarative shadow DOM polyfill.
+
2022-04-07 Tim Nguyen <[email protected]>
[:has() pseudo-class] Support invalidation for :indeterminate pseudo class on <progress>
Modified: trunk/LayoutTests/imported/w3c/web-platform-tests/css/css-contain/container-queries/container-for-shadow-dom-expected.txt (292591 => 292592)
--- trunk/LayoutTests/imported/w3c/web-platform-tests/css/css-contain/container-queries/container-for-shadow-dom-expected.txt 2022-04-08 04:09:07 UTC (rev 292591)
+++ trunk/LayoutTests/imported/w3c/web-platform-tests/css/css-contain/container-queries/container-for-shadow-dom-expected.txt 2022-04-08 04:59:16 UTC (rev 292592)
@@ -1,12 +1,12 @@
-FAIL Match container in outer tree null is not an object (evaluating 'document.querySelector("#inclusive-ancestor-across-root > div").shadowRoot.querySelector')
+PASS Match container in outer tree
PASS Match container in same tree, not walking flat tree ancestors
FAIL Match container in ::slotted selector's originating element tree assert_equals: expected "rgb(0, 128, 0)" but got "rgb(0, 0, 0)"
-FAIL Match container in outer tree for :host assert_equals: expected "rgb(0, 128, 0)" but got "rgb(0, 0, 0)"
-FAIL Match container in ::part selector's originating element tree null is not an object (evaluating 'document.querySelector("#inclusive-ancestor-part > div").shadowRoot.querySelector')
+PASS Match container in outer tree for :host
+FAIL Match container in ::part selector's originating element tree assert_equals: expected "rgb(0, 128, 0)" but got "rgb(0, 0, 0)"
FAIL Match container for ::before in ::slotted selector's originating element tree assert_equals: expected "rgb(0, 128, 0)" but got "rgb(0, 0, 0)"
-FAIL Match container in outer tree for :host::before assert_equals: expected "rgb(0, 128, 0)" but got "rgb(0, 0, 0)"
-FAIL Match container for ::before in ::part selector's originating element tree null is not an object (evaluating 'document.querySelector("#inclusive-ancestor-part-before > div").shadowRoot.querySelector')
-FAIL Match container for ::part selector's originating element tree for exportparts null is not an object (evaluating 'outerhost.shadowRoot.querySelector')
-FAIL Match container for slot light tree child fallback null is not an object (evaluating 'document.querySelector("#inclusive-ancestor-slot-fallback > div").shadowRoot.querySelector')
+PASS Match container in outer tree for :host::before
+FAIL Match container for ::before in ::part selector's originating element tree assert_equals: expected "rgb(0, 128, 0)" but got "rgb(0, 0, 0)"
+FAIL Match container for ::part selector's originating element tree for exportparts assert_equals: expected "rgb(0, 128, 0)" but got "rgb(0, 0, 0)"
+PASS Match container for slot light tree child fallback
Modified: trunk/LayoutTests/imported/w3c/web-platform-tests/css/css-contain/container-queries/container-for-shadow-dom.html (292591 => 292592)
--- trunk/LayoutTests/imported/w3c/web-platform-tests/css/css-contain/container-queries/container-for-shadow-dom.html 2022-04-08 04:09:07 UTC (rev 292591)
+++ trunk/LayoutTests/imported/w3c/web-platform-tests/css/css-contain/container-queries/container-for-shadow-dom.html 2022-04-08 04:59:16 UTC (rev 292592)
@@ -231,6 +231,18 @@
<script>
setup(() => assert_implements_container_queries());
+ function attachShadowRoots(root) {
+ root.querySelectorAll("template[shadowroot]").forEach(template => {
+ const mode = template.getAttribute("shadowroot");
+ const shadowRoot = template.parentNode.attachShadow({ mode });
+ shadowRoot.appendChild(template.content);
+ template.remove();
+ attachShadowRoots(shadowRoot);
+ });
+ }
+ if (!document.querySelector("template[shadowroot]").parentNode.shadowRoot)
+ attachShadowRoots(document);
+
const green = "rgb(0, 128, 0)";
test(() => {
Modified: trunk/Source/WebCore/ChangeLog (292591 => 292592)
--- trunk/Source/WebCore/ChangeLog 2022-04-08 04:09:07 UTC (rev 292591)
+++ trunk/Source/WebCore/ChangeLog 2022-04-08 04:59:16 UTC (rev 292592)
@@ -1,3 +1,27 @@
+2022-04-07 Antti Koivisto <[email protected]>
+
+ [CSS Container Queries] Evaluate against shadow-including ancestors
+ https://bugs.webkit.org/show_bug.cgi?id=238934
+
+ Reviewed by Tim Nguyen.
+
+ "Style rules applying to its shadow-including descendants can then be conditioned by querying against it,
+ using the @container conditional group rule."
+
+ https://drafts.csswg.org/css-contain-3/#container-queries
+
+ * style/ContainerQueryEvaluator.cpp:
+ (WebCore::Style::ContainerQueryEvaluator::selectContainer):
+
+ Evaluate against shadow-including ancestors instead of flat tree ancestors if the cache is not available.
+
+ * style/StyleTreeResolver.cpp:
+ (WebCore::Style::TreeResolver::Scope::Scope):
+
+ Copy the container state when pushing scope. This also creates a stack of shadow-including ancestors.
+
+ * style/StyleTreeResolver.h:
+
2022-04-07 Elliott Williams <[email protected]>
[XCBuild] Enable dependency validation by default
Modified: trunk/Source/WebCore/style/ContainerQueryEvaluator.cpp (292591 => 292592)
--- trunk/Source/WebCore/style/ContainerQueryEvaluator.cpp 2022-04-08 04:09:07 UTC (rev 292591)
+++ trunk/Source/WebCore/style/ContainerQueryEvaluator.cpp 2022-04-08 04:59:16 UTC (rev 292592)
@@ -136,9 +136,9 @@
return &element;
}
- for (auto& ancestor : composedTreeAncestors(const_cast<Element&>(element))) {
- if (isContainerForQuery(ancestor))
- return &ancestor;
+ for (auto* ancestor = element.parentOrShadowHostElement(); ancestor; ancestor = ancestor->parentOrShadowHostElement()) {
+ if (isContainerForQuery(*ancestor))
+ return ancestor;
}
return { };
}
Modified: trunk/Source/WebCore/style/StyleTreeResolver.cpp (292591 => 292592)
--- trunk/Source/WebCore/style/StyleTreeResolver.cpp 2022-04-08 04:09:07 UTC (rev 292591)
+++ trunk/Source/WebCore/style/StyleTreeResolver.cpp 2022-04-08 04:59:16 UTC (rev 292592)
@@ -88,6 +88,7 @@
, shadowRoot(&shadowRoot)
, enclosingScope(&enclosingScope)
{
+ selectorMatchingState.queryContainers = enclosingScope.selectorMatchingState.queryContainers;
}
TreeResolver::Scope::~Scope()