Commit 468552fe authored by Rune Lillesveen's avatar Rune Lillesveen Committed by Commit Bot

Don't schedule descendant invalidations on display:none.

There's no need to schedule descendant invalidation sets on display:none
elements. If that element is displayed on the next lifecycle update,
RecalcStyle will make sure descendants will get their ComputedStyles if
necessary.

Bug: 972752
Change-Id: I60a980eecfccc43ff33bd4e050d223aced6383f5
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1783142Reviewed-by: default avatarEric Willigers <ericwilligers@chromium.org>
Commit-Queue: Rune Lillesveen <futhark@chromium.org>
Cr-Commit-Position: refs/heads/master@{#693127}
parent e086bf5f
......@@ -10,6 +10,7 @@
#include "third_party/blink/renderer/core/dom/document.h"
#include "third_party/blink/renderer/core/dom/element.h"
#include "third_party/blink/renderer/core/dom/element_traversal.h"
#include "third_party/blink/renderer/core/dom/node_computed_style.h"
#include "third_party/blink/renderer/core/dom/shadow_root.h"
#include "third_party/blink/renderer/core/html/html_slot_element.h"
#include "third_party/blink/renderer/core/inspector/inspector_trace_events.h"
......@@ -46,6 +47,11 @@ void PendingInvalidations::ScheduleInvalidationSetsForNode(
if (!invalidation_set->IsEmpty())
requires_descendant_invalidation = true;
}
// No need to schedule descendant invalidations on display:none elements.
if (requires_descendant_invalidation && !node.GetComputedStyle() &&
node.CanParticipateInFlatTree()) {
requires_descendant_invalidation = false;
}
}
if (!requires_descendant_invalidation &&
......
......@@ -64,4 +64,24 @@ TEST_F(PendingInvalidationsTest, ScheduleOnDocumentNode) {
EXPECT_EQ(2u, after_count - before_count);
}
TEST_F(PendingInvalidationsTest, DescendantInvalidationOnDisplayNone) {
GetDocument().body()->SetInnerHTMLFromString(R"HTML(
<style>
#a { display: none }
.a .b { color: green }
</style>
<div id="a">
<div class="b"></div>
<div class="b"></div>
</div>
)HTML");
GetDocument().View()->UpdateAllLifecyclePhases(
DocumentLifecycle::LifecycleUpdateReason::kTest);
// We skip scheduling descendant invalidations on display:none elements.
GetDocument().getElementById("a")->setAttribute(html_names::kClassAttr, "a");
EXPECT_FALSE(GetDocument().NeedsLayoutTreeUpdate());
}
} // 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