Skip to content

Commit

Permalink
[@container] Don't create ContainerQueryEvaluator without flag enabled
Browse files Browse the repository at this point in the history
Bug: 1145970
Change-Id: Ib4e579859e3168365851da5b7b270eaba19e0dd5
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/3263939
Reviewed-by: Anders Hartvoll Ruud <[email protected]>
Reviewed-by: Rune Lillesveen <[email protected]>
Commit-Queue: Rune Lillesveen <[email protected]>
Cr-Commit-Position: refs/heads/main@{#939791}
  • Loading branch information
lilles authored and Chromium LUCI CQ committed Nov 9, 2021
1 parent 9d7e301 commit 041f683
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 6 deletions.
23 changes: 23 additions & 0 deletions third_party/blink/renderer/core/css/container_query_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1018,4 +1018,27 @@ TEST_F(ContainerQueryTest, CQDependentContentVisibilityHidden) {
EXPECT_TRUE(locker->firstChild()->GetComputedStyle());
}

TEST_F(ContainerQueryTest, NoContainerQueryEvaluatorWhenDisabled) {
ScopedCSSContainerQueriesForTest scope(false);

SetBodyInnerHTML(R"HTML(
<style>
#container {
container-type: size;
contain: size style layout;
}
@container (min-width: 200px) {
span { color: pink; }
}
</style>
<div id="container">
<span></span>
</div>
)HTML");

UpdateAllLifecyclePhasesForTest();
EXPECT_FALSE(
GetDocument().getElementById("container")->GetContainerQueryEvaluator());
}

} // namespace blink
14 changes: 8 additions & 6 deletions third_party/blink/renderer/core/dom/element.cc
Original file line number Diff line number Diff line change
Expand Up @@ -3286,12 +3286,14 @@ StyleRecalcChange Element::RecalcOwnStyle(
if (UpdateForceLegacyLayout(*new_style, old_style.get()))
child_change = child_change.ForceReattachLayoutTree();
}
auto* evaluator =
ComputeContainerQueryEvaluator(*this, old_style.get(), *new_style);
if (evaluator != GetContainerQueryEvaluator()) {
EnsureElementRareData()
.EnsureContainerQueryData()
.SetContainerQueryEvaluator(evaluator);
if (RuntimeEnabledFeatures::CSSContainerQueriesEnabled()) {
auto* evaluator =
ComputeContainerQueryEvaluator(*this, old_style.get(), *new_style);
if (evaluator != GetContainerQueryEvaluator()) {
EnsureElementRareData()
.EnsureContainerQueryData()
.SetContainerQueryEvaluator(evaluator);
}
}
}

Expand Down
1 change: 1 addition & 0 deletions third_party/blink/renderer/core/dom/element_rare_data.h
Original file line number Diff line number Diff line change
Expand Up @@ -223,6 +223,7 @@ class ElementRareData final : public NodeRareData {
}

ContainerQueryData& EnsureContainerQueryData() {
DCHECK(RuntimeEnabledFeatures::CSSContainerQueriesEnabled());
if (!container_query_data_)
container_query_data_ = MakeGarbageCollected<ContainerQueryData>();
return *container_query_data_;
Expand Down

0 comments on commit 041f683

Please sign in to comment.