Commit a021e41c authored by Eriko Kurimoto's avatar Eriko Kurimoto Committed by Commit Bot

Include shadow host in elements invalidated by type ruleset invalidations.

When we do a ruleset invalidation for a shadow scope, we schedule an
invalidation set for type selectors on the shadow root node.
This set might also contain tag names for type selectors in :host().
In order to invalidate host elements properly, check if the host's tag name is
contained in any of the type invalidation sets and mark it for style recalc.

Bug: 754191
Change-Id: I92b5a5dfacb86e65ff52247db34fbc9fa0b2101d
Reviewed-on: https://chromium-review.googlesource.com/618069
Commit-Queue: Eriko Kurimoto <elkurin@google.com>
Reviewed-by: default avatarRune Lillesveen <rune@opera.com>
Reviewed-by: default avatarTakayoshi Kochi <kochi@chromium.org>
Cr-Commit-Position: refs/heads/master@{#496561}
parent ab1d634a
...@@ -108,6 +108,17 @@ bool InvalidationSet::InvalidatesElement(Element& element) const { ...@@ -108,6 +108,17 @@ bool InvalidationSet::InvalidatesElement(Element& element) const {
return false; return false;
} }
bool InvalidationSet::InvalidatesTagName(Element& element) const {
if (tag_names_ && tag_names_->Contains(element.TagQName().LocalName())) {
TRACE_STYLE_INVALIDATOR_INVALIDATION_SELECTORPART_IF_ENABLED(
element, kInvalidationSetMatchedTagName, *this,
element.TagQName().LocalName());
return true;
}
return false;
}
void InvalidationSet::Combine(const InvalidationSet& other) { void InvalidationSet::Combine(const InvalidationSet& other) {
CHECK(is_alive_); CHECK(is_alive_);
CHECK(other.is_alive_); CHECK(other.is_alive_);
......
...@@ -99,6 +99,7 @@ class CORE_EXPORT InvalidationSet { ...@@ -99,6 +99,7 @@ class CORE_EXPORT InvalidationSet {
static void CacheTracingFlag(); static void CacheTracingFlag();
bool InvalidatesElement(Element&) const; bool InvalidatesElement(Element&) const;
bool InvalidatesTagName(Element&) const;
void AddClass(const AtomicString& class_name); void AddClass(const AtomicString& class_name);
void AddId(const AtomicString& id); void AddId(const AtomicString& id);
......
...@@ -890,6 +890,22 @@ void StyleEngine::ScheduleTypeRuleSetInvalidations( ...@@ -890,6 +890,22 @@ void StyleEngine::ScheduleTypeRuleSetInvalidations(
node); node);
DCHECK(invalidation_lists.siblings.IsEmpty()); DCHECK(invalidation_lists.siblings.IsEmpty());
style_invalidator_.ScheduleInvalidationSetsForNode(invalidation_lists, node); style_invalidator_.ScheduleInvalidationSetsForNode(invalidation_lists, node);
if (!node.IsShadowRoot())
return;
Element& host = ToShadowRoot(node).host();
if (host.NeedsStyleRecalc())
return;
for (auto& invalidation_set : invalidation_lists.descendants) {
if (invalidation_set->InvalidatesTagName(host)) {
host.SetNeedsStyleRecalc(kLocalStyleChange,
StyleChangeReasonForTracing::Create(
StyleChangeReason::kStyleSheetChange));
return;
}
}
} }
void StyleEngine::InvalidateSlottedElements(HTMLSlotElement& slot) { void StyleEngine::InvalidateSlottedElements(HTMLSlotElement& slot) {
......
...@@ -266,6 +266,9 @@ TEST_F(StyleEngineTest, RuleSetInvalidationHost) { ...@@ -266,6 +266,9 @@ TEST_F(StyleEngineTest, RuleSetInvalidationHost) {
GetDocument().View()->UpdateAllLifecyclePhases(); GetDocument().View()->UpdateAllLifecyclePhases();
after_count = GetStyleEngine().StyleForElementCount(); after_count = GetStyleEngine().StyleForElementCount();
EXPECT_EQ(1u, after_count - before_count); EXPECT_EQ(1u, after_count - before_count);
EXPECT_EQ(ScheduleInvalidationsForRules(*shadow_root,
":host(div) { background: green}"),
kRuleSetInvalidationsScheduled);
EXPECT_EQ(ScheduleInvalidationsForRules(*shadow_root, EXPECT_EQ(ScheduleInvalidationsForRules(*shadow_root,
":host(*) { background: green}"), ":host(*) { background: green}"),
......
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