Commit 4ffa5792 authored by Anders Hartvoll Ruud's avatar Anders Hartvoll Ruud Committed by Chromium LUCI CQ

[@container] Mark elements that depend on container queries as such

The DependsOnContainerQueries flag was already added to ComputedStyle,
but until now nothing actually set it (outside unit tests).

This CL sets the flag whenever we match a container query-dependent
rule (regardless of the result of the query).

Note that I'm deliberately avoiding mutation of ComputedStyle
directly from ElementRuleCollector, since we're trying to get rid of
the mutable reference. Hence the flag is transported via MatchResult
instead.

Note also that this doesn't quite work correctly for pseudo-elements:
we need to mark in PseudoStyleForElements, and also handle
dynamic_pseudo matches in ElementRuleCollector, but that will be done
in a separate CL.

Bug: 1145970
Change-Id: Id48bd88d3f0580c8f58802565bc77a7ff1497d2c
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2627150
Commit-Queue: Anders Hartvoll Ruud <andruud@chromium.org>
Reviewed-by: default avatarRune Lillesveen <futhark@chromium.org>
Reviewed-by: default avatarXiaocheng Hu <xiaochengh@chromium.org>
Cr-Commit-Position: refs/heads/master@{#843888}
parent 661ed9aa
...@@ -204,6 +204,8 @@ void ElementRuleCollector::CollectMatchingRulesForList( ...@@ -204,6 +204,8 @@ void ElementRuleCollector::CollectMatchingRulesForList(
continue; continue;
} }
if (auto* container_query = rule_data->GetContainerQuery()) { if (auto* container_query = rule_data->GetContainerQuery()) {
result_.SetDependsOnContainerQueries();
// TODO(crbug.com/1145970): Propagate actual ContainerQueryEvaluator // TODO(crbug.com/1145970): Propagate actual ContainerQueryEvaluator
// instance from the container. // instance from the container.
// For now a fixed container size of 500x500 is used. // For now a fixed container size of 500x500 is used.
......
...@@ -92,6 +92,7 @@ MatchedExpansionsRange MatchResult::Expansions(const Document& document, ...@@ -92,6 +92,7 @@ MatchedExpansionsRange MatchResult::Expansions(const Document& document,
void MatchResult::Reset() { void MatchResult::Reset() {
matched_properties_.clear(); matched_properties_.clear();
is_cacheable_ = true; is_cacheable_ = true;
depends_on_container_queries_ = false;
current_origin_ = CascadeOrigin::kUserAgent; current_origin_ = CascadeOrigin::kUserAgent;
current_tree_order_ = 0; current_tree_order_ = 0;
tree_scopes_.clear(); tree_scopes_.clear();
......
...@@ -144,6 +144,10 @@ class CORE_EXPORT MatchResult { ...@@ -144,6 +144,10 @@ class CORE_EXPORT MatchResult {
void SetIsCacheable(bool cacheable) { is_cacheable_ = cacheable; } void SetIsCacheable(bool cacheable) { is_cacheable_ = cacheable; }
bool IsCacheable() const { return is_cacheable_; } bool IsCacheable() const { return is_cacheable_; }
void SetDependsOnContainerQueries() { depends_on_container_queries_ = true; }
bool DependsOnContainerQueries() const {
return depends_on_container_queries_;
}
MatchedExpansionsRange Expansions(const Document&, CascadeFilter) const; MatchedExpansionsRange Expansions(const Document&, CascadeFilter) const;
...@@ -164,6 +168,7 @@ class CORE_EXPORT MatchResult { ...@@ -164,6 +168,7 @@ class CORE_EXPORT MatchResult {
MatchedPropertiesVector matched_properties_; MatchedPropertiesVector matched_properties_;
HeapVector<Member<const TreeScope>, 4> tree_scopes_; HeapVector<Member<const TreeScope>, 4> tree_scopes_;
bool is_cacheable_{true}; bool is_cacheable_{true};
bool depends_on_container_queries_{false};
CascadeOrigin current_origin_{CascadeOrigin::kUserAgent}; CascadeOrigin current_origin_{CascadeOrigin::kUserAgent};
uint16_t current_tree_order_{0}; uint16_t current_tree_order_{0};
}; };
......
...@@ -861,6 +861,9 @@ void StyleResolver::ApplyBaseStyle( ...@@ -861,6 +861,9 @@ void StyleResolver::ApplyBaseStyle(
MatchAllRules(state, collector, MatchAllRules(state, collector,
matching_behavior != kMatchAllRulesExcludingSMIL); matching_behavior != kMatchAllRulesExcludingSMIL);
if (collector.MatchedResult().DependsOnContainerQueries())
state.Style()->SetDependsOnContainerQueries(true);
if (tracker_) if (tracker_)
AddMatchedRulesToTracker(collector); AddMatchedRulesToTracker(collector);
......
...@@ -1082,4 +1082,44 @@ TEST_F(StyleResolverTest, InheritStyleImagesFromDisplayContents) { ...@@ -1082,4 +1082,44 @@ TEST_F(StyleResolverTest, InheritStyleImagesFromDisplayContents) {
<< "-webkit-mask-image is fetched"; << "-webkit-mask-image is fetched";
} }
TEST_F(StyleResolverTest, DependsOnContainerQueries) {
ScopedCSSContainerQueriesForTest scoped_feature(true);
GetDocument().documentElement()->setInnerHTML(R"HTML(
<style>
#a { color: red; }
@container (min-width: 0px) {
#b { color: blue; }
span { color: green; }
#d { color: coral; }
}
</style>
<div id=a></div>
<span id=b></span>
<span id=c></span>
<div id=d></div>
<div id=e></div>
)HTML");
UpdateAllLifecyclePhasesForTest();
auto* a = GetDocument().getElementById("a");
auto* b = GetDocument().getElementById("b");
auto* c = GetDocument().getElementById("c");
auto* d = GetDocument().getElementById("d");
auto* e = GetDocument().getElementById("e");
ASSERT_TRUE(a);
ASSERT_TRUE(b);
ASSERT_TRUE(c);
ASSERT_TRUE(d);
ASSERT_TRUE(e);
EXPECT_FALSE(a->ComputedStyleRef().DependsOnContainerQueries());
EXPECT_TRUE(b->ComputedStyleRef().DependsOnContainerQueries());
EXPECT_TRUE(c->ComputedStyleRef().DependsOnContainerQueries());
EXPECT_TRUE(d->ComputedStyleRef().DependsOnContainerQueries());
EXPECT_FALSE(e->ComputedStyleRef().DependsOnContainerQueries());
}
} // namespace blink } // namespace blink
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