Skip to content

Commit

Permalink
REGRESSION (Safari 17): Named at-rule container skipped when containe…
Browse files Browse the repository at this point in the history
…r named in a :host selector

https://bugs.webkit.org/show_bug.cgi?id=267046
rdar://120428386

Reviewed by Alan Baradlay.

* LayoutTests/imported/w3c/web-platform-tests/css/css-contain/container-queries/container-name-tree-scoped-expected.txt:
* LayoutTests/imported/w3c/web-platform-tests/css/css-contain/container-queries/container-name-tree-scoped.html:
* Source/WebCore/style/ContainerQueryEvaluator.cpp:
(WebCore::Style::ContainerQueryEvaluator::selectContainer):

A container query should be allowed to match a host element with container name that defined by :host rule in the same shadow tree as the query.

Canonical link: https://commits.webkit.org/273987@main
  • Loading branch information
anttijk committed Feb 2, 2024
1 parent 2ec06d7 commit 14e1048
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 5 deletions.
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@

PASS Outer scope query should not match container-name set by :host rule in shadow tree
PASS Outer scope query should not match container-name set by ::slotted rule in shadow tree
PASS Inner scope query should match container-name set by :host rule in shadow tree

Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,21 @@
#t2 { color: red; }
}
</style>

<div id="container-name-host-inner-container-rule">
<div id="t3host">
<template shadowrootmode="open">
<style>
:host { container-name: foo; }
#t3 { color: red; }
@container foo (width > 0px) {
#t3 { color: green; }
}
</style>
<div id="t3"></div>
</template>
</div>
</div>
</div>

<script>
Expand All @@ -70,4 +85,8 @@
assert_equals(getComputedStyle(t2).color, green);
}, "Outer scope query should not match container-name set by ::slotted rule in shadow tree");

test(() => {
assert_equals(getComputedStyle(t3host.shadowRoot.querySelector('#t3')).color, green);
}, "Inner scope query should match container-name set by :host rule in shadow tree");

</script>
14 changes: 9 additions & 5 deletions Source/WebCore/style/ContainerQueryEvaluator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -117,11 +117,15 @@ const Element* ContainerQueryEvaluator::selectContainer(OptionSet<CQ::Axis> axes
if (name.isEmpty())
return true;
return style->containerNames().containsIf([&](auto& scopedName) {
// Names from the inner scopes are ignored.
// FIXME: Should names from inner scopes be allowed in some cases?
if (scopedName.scopeOrdinal > ScopeOrdinal::Element)
return false;
return scopedName.name == name;
auto isNameFromAllowedScope = [&](auto& scopedName) {
// Names from :host rules are allowed when the candidate is the host element.
auto isHost = element.shadowHost() == &candidateElement;
if (scopedName.scopeOrdinal == ScopeOrdinal::Shadow && isHost)
return true;
// Otherwise names from the inner scopes are ignored.
return scopedName.scopeOrdinal <= ScopeOrdinal::Element;
};
return isNameFromAllowedScope(scopedName) && scopedName.name == name;
});
};

Expand Down

0 comments on commit 14e1048

Please sign in to comment.