Commit 3ff4a0bc authored by Rune Lillesveen's avatar Rune Lillesveen Committed by Commit Bot

Don't use recalc for ClearEnsuredDescendantStyles.

Accessibility code calls EnsureComputedStyle during layout. That is not
strictly a problem, but we lazily clear computed styles outside the flat
tree during EnsureComputedStyle when querying computed style outside the
flat tree. Since we use the style recalc code to clear ComputedStyle
objects from a subtree we got a lifecycle issue with going to style
recalc during layout.

It would be interesting to find out why we end up querying computed
style for an element outside the flat tree for accessibility, but
otherwise using style recalc traversal to clear the ComputedStyle
objects was a bit more complicated than necessary.

This CL introduces a separate traversal that just clears ComputedStyle
along with dirty bits instead of going through style recalc.

TEST=StyleEngineTest.*

Bug: 1130436
Change-Id: I22ce417c6bc133e0429ba794f555821d74d08512
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2424344Reviewed-by: default avatarAnders Hartvoll Ruud <andruud@chromium.org>
Commit-Queue: Rune Lillesveen <futhark@chromium.org>
Cr-Commit-Position: refs/heads/master@{#810020}
parent 2285197c
......@@ -2000,13 +2000,21 @@ void StyleEngine::RecalcStyle() {
PropagateWritingModeAndDirectionToHTMLRoot();
}
void StyleEngine::ClearEnsuredDescendantStyles(Element& element) {
GetDocument().Lifecycle().AdvanceTo(DocumentLifecycle::kInStyleRecalc);
SelectorFilterRootScope filter_scope(&element);
element.ClearNeedsStyleRecalc();
element.RecalcDescendantStyles(StyleRecalcChange::kClearEnsured);
element.ClearChildNeedsStyleRecalc();
GetDocument().Lifecycle().AdvanceTo(DocumentLifecycle::kStyleClean);
void StyleEngine::ClearEnsuredDescendantStyles(Element& root) {
Node* current = &root;
while (current) {
if (auto* element = DynamicTo<Element>(current)) {
if (const auto* style = element->GetComputedStyle()) {
DCHECK(style->IsEnsuredOutsideFlatTree());
element->SetComputedStyle(nullptr);
element->ClearNeedsStyleRecalc();
element->ClearChildNeedsStyleRecalc();
current = FlatTreeTraversal::Next(*current, &root);
continue;
}
}
current = FlatTreeTraversal::NextSkippingChildren(*current, &root);
}
}
void StyleEngine::RebuildLayoutTree() {
......
......@@ -2367,8 +2367,8 @@ TEST_F(StyleEngineTest, GetComputedStyleOutsideFlatTree) {
EXPECT_FALSE(innermost->GetComputedStyle());
inner->EnsureComputedStyle();
auto* outer_style = outer->GetComputedStyle();
auto* inner_style = inner->GetComputedStyle();
scoped_refptr<const ComputedStyle> outer_style = outer->GetComputedStyle();
scoped_refptr<const ComputedStyle> inner_style = inner->GetComputedStyle();
ASSERT_TRUE(outer_style);
ASSERT_TRUE(inner_style);
......
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