Commit 79e6e2e5 authored by Rune Lillesveen's avatar Rune Lillesveen Committed by Chromium LUCI CQ

Container Queries: Check that containment applies

Check containment on the layout object instead of ComputedStyle. If
containment does not apply according to principal box, it should not act
as a container for container queries.

Bug: 1146097
Change-Id: I361242bdd23e389a2f390930af5945301a452ad0
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2623292
Commit-Queue: Rune Lillesveen <futhark@chromium.org>
Reviewed-by: default avatarAnders Hartvoll Ruud <andruud@chromium.org>
Cr-Commit-Position: refs/heads/master@{#842543}
parent 845daaaf
...@@ -3768,10 +3768,13 @@ TEST_F(StyleEngineTest, UpdateStyleAndLayoutTreeForContainer) { ...@@ -3768,10 +3768,13 @@ TEST_F(StyleEngineTest, UpdateStyleAndLayoutTreeForContainer) {
</div> </div>
</div> </div>
<span></span> <span></span>
<div id="container3" class="container"> <div class="container">
<span class="affected"></span> <span class="affected"></span>
<span class="affected"></span> <span class="affected"></span>
</div> </div>
<span class="container" style="display:inline-block">
<span class="affected"></span>
</span>
</div> </div>
)HTML"); )HTML");
...@@ -3798,6 +3801,55 @@ TEST_F(StyleEngineTest, UpdateStyleAndLayoutTreeForContainer) { ...@@ -3798,6 +3801,55 @@ TEST_F(StyleEngineTest, UpdateStyleAndLayoutTreeForContainer) {
EXPECT_EQ(6u, GetStyleEngine().StyleForElementCount() - start_count); EXPECT_EQ(6u, GetStyleEngine().StyleForElementCount() - start_count);
} }
TEST_F(StyleEngineTest, ContainerQueriesContainmentNotApplying) {
GetDocument().body()->setInnerHTML(R"HTML(
<style>
.container {
contain: layout size;
}
</style>
<div id="container" class="container">
<div class="container" style="display:contents">
<span class="affected"></span>
</div>
<span class="container">
<span class="affected"></span>
</span>
<rt class="container">
<span class="affected"></span>
</rt>
<div class="container" style="display:table">
<span class="affected"></span>
</div>
<div class="container" style="display:table-cell">
<span class="affected"></span>
</div>
<div class="container" style="display:table-row">
<span class="affected"></span>
</div>
<div class="container" style="display:table-row-group">
<span class="affected"></span>
</div>
</div>
)HTML");
UpdateAllLifecyclePhases();
auto* container = GetDocument().getElementById("container");
auto* affected = GetDocument().getElementsByClassName("affected");
ASSERT_TRUE(container);
ASSERT_TRUE(affected);
SetDependsOnContainerQueries(*affected);
unsigned start_count = GetStyleEngine().StyleForElementCount();
GetStyleEngine().UpdateStyleAndLayoutTreeForContainer(*container);
// span.affected is updated because containment does not apply to the display
// types on the element styled with containment. All marked as affected are
// recalculated.
EXPECT_EQ(7u, GetStyleEngine().StyleForElementCount() - start_count);
}
TEST_F(StyleEngineTest, MarkStyleDirtyFromContainerRecalc) { TEST_F(StyleEngineTest, MarkStyleDirtyFromContainerRecalc) {
GetDocument().body()->setInnerHTML(R"HTML( GetDocument().body()->setInnerHTML(R"HTML(
<div id="container" style="contain: layout size"> <div id="container" style="contain: layout size">
......
...@@ -61,8 +61,9 @@ bool StyleRecalcChange::RecalcContainerQueryDependentChildren( ...@@ -61,8 +61,9 @@ bool StyleRecalcChange::RecalcContainerQueryDependentChildren(
// recalculating container queries. If the queries for this container also // recalculating container queries. If the queries for this container also
// changes, we will enter another container query recalc for this subtree from // changes, we will enter another container query recalc for this subtree from
// layout. // layout.
const ComputedStyle* style = element.GetComputedStyle(); if (LayoutObject* layout_object = element.GetLayoutObject())
return style && !style->IsContainerForContainerQueries(); return !layout_object->IsContainerForContainerQueries();
return true;
} }
} // namespace blink } // namespace blink
...@@ -625,6 +625,10 @@ class CORE_EXPORT LayoutObject : public ImageResourceObserver, ...@@ -625,6 +625,10 @@ class CORE_EXPORT LayoutObject : public ImageResourceObserver,
return ShouldApplyPaintContainment() && ShouldApplyLayoutContainment() && return ShouldApplyPaintContainment() && ShouldApplyLayoutContainment() &&
ShouldApplySizeContainment(); ShouldApplySizeContainment();
} }
inline bool IsContainerForContainerQueries() const {
NOT_DESTROYED();
return ShouldApplyLayoutContainment() && ShouldApplySizeContainment();
}
inline bool IsStackingContext() const { inline bool IsStackingContext() const {
NOT_DESTROYED(); NOT_DESTROYED();
......
...@@ -2662,10 +2662,6 @@ class ComputedStyle : public ComputedStyleBase, ...@@ -2662,10 +2662,6 @@ class ComputedStyle : public ComputedStyleBase,
return LogicalSize(LayoutUnit(ratio.Width()), LayoutUnit(ratio.Height())); return LogicalSize(LayoutUnit(ratio.Width()), LayoutUnit(ratio.Height()));
} }
bool IsContainerForContainerQueries() const {
return ContainsLayout() && ContainsSize();
}
private: private:
EClear Clear() const { return ClearInternal(); } EClear Clear() const { return ClearInternal(); }
EFloat Floating() const { return FloatingInternal(); } EFloat Floating() const { return FloatingInternal(); }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment