Commit 9f5838c5 authored by Rune Lillesveen's avatar Rune Lillesveen Committed by Commit Bot

Don't push selector filter for pseudo elements.

Pseudo elements match the features of its originating element. We were
pushing the selector filter too early causing fast rejection glitches
when matching selectors for pseudo elements.

Change-Id: I04bc1d7e681ecd6c851bdb3820a9950003e0821d
Reviewed-on: https://chromium-review.googlesource.com/1148201
Commit-Queue: Rune Lillesveen <futhark@chromium.org>
Reviewed-by: default avatarAnders Ruud <andruud@chromium.org>
Cr-Commit-Position: refs/heads/master@{#577664}
parent 54f61462
...@@ -1472,4 +1472,32 @@ TEST_F(StyleEngineTest, GetComputedStyleOutsideFlatTreeCrash) { ...@@ -1472,4 +1472,32 @@ TEST_F(StyleEngineTest, GetComputedStyleOutsideFlatTreeCrash) {
GetDocument().View()->UpdateAllLifecyclePhases(); GetDocument().View()->UpdateAllLifecyclePhases();
} }
TEST_F(StyleEngineTest, RejectSelectorForPseudoElement) {
GetDocument().body()->SetInnerHTMLFromString(R"HTML(
<style>
div::before { content: "" }
.not-in-filter div::before { color: red }
</style>
<div class='not-in-filter'></div>
)HTML");
GetDocument().View()->UpdateAllLifecyclePhases();
StyleEngine& engine = GetDocument().GetStyleEngine();
engine.SetStatsEnabled(true);
StyleResolverStats* stats = engine.Stats();
ASSERT_TRUE(stats);
Element* div = GetDocument().QuerySelector("div");
ASSERT_TRUE(div);
div->SetInlineStyleProperty(CSSPropertyColor, "green");
GetDocument().Lifecycle().AdvanceTo(DocumentLifecycle::kInStyleRecalc);
GetDocument().documentElement()->RecalcStyle(kNoChange);
// Should fast reject ".not-in-filter div::before {}" for both the div and its
// ::before pseudo element.
EXPECT_EQ(2u, stats->rules_fast_rejected);
}
} // namespace blink } // namespace blink
...@@ -2349,14 +2349,11 @@ void Element::RecalcStyle(StyleRecalcChange change) { ...@@ -2349,14 +2349,11 @@ void Element::RecalcStyle(StyleRecalcChange change) {
} }
if (ShouldCallRecalcStyleForChildren(change)) { if (ShouldCallRecalcStyleForChildren(change)) {
// TODO(futhark@chromium.org): Pseudo elements are feature-less and match
// the same features as their originating element. Move the filter scope
// inside the if-block for shadow-including descendants below.
SelectorFilterParentScope filter_scope(*this);
UpdatePseudoElement(kPseudoIdBefore, change); UpdatePseudoElement(kPseudoIdBefore, change);
if (change > kUpdatePseudoElements || ChildNeedsStyleRecalc()) { if (change > kUpdatePseudoElements || ChildNeedsStyleRecalc()) {
SelectorFilterParentScope filter_scope(*this);
if (ShadowRoot* root = GetShadowRoot()) { if (ShadowRoot* root = GetShadowRoot()) {
if (root->ShouldCallRecalcStyle(change)) if (root->ShouldCallRecalcStyle(change))
root->RecalcStyle(change); root->RecalcStyle(change);
......
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