Commit ecc0ab42 authored by Rune Lillesveen's avatar Rune Lillesveen Committed by Commit Bot

Don't use cached ComputedStyle when flat-tree flag differs.

If we cache a ComputedStyle which is computed outside of the flat tree,
any pending resources will stay StylePendingImage. That means we cannot
use such a ComputedStyle for cached styles for a rendered element.

We already did this check for display:none subtree ComputedStyles, but
we need the same check for IsEnsuredOutsideFlatTree().

Bug: 1095669
Change-Id: Ide7395207a6d73b78bc793e4ee4c10cf31b9696f
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2250201Reviewed-by: default avatarAnders Hartvoll Ruud <andruud@chromium.org>
Commit-Queue: Rune Lillesveen <futhark@chromium.org>
Cr-Commit-Position: refs/heads/master@{#779530}
parent ac573d72
......@@ -92,13 +92,15 @@ bool CachedMatchedProperties::DependenciesEqual(
const StyleResolverState& state) {
if (!state.ParentStyle())
return false;
if (parent_computed_style->IsEnsuredInDisplayNone() &&
!state.ParentStyle()->IsEnsuredInDisplayNone()) {
// If we cached a ComputedStyle in a display:none subtree we would not have
// triggered fetches for external resources and have StylePendingImages in
// the ComputedStyle. Instead of having to inspect the cached ComputedStyle
// for such resources, don't use a cached ComputedStyle when it was cached
// in display:none but is now rendered.
if ((parent_computed_style->IsEnsuredInDisplayNone() ||
computed_style->IsEnsuredOutsideFlatTree()) &&
!state.ParentStyle()->IsEnsuredInDisplayNone() &&
!state.Style()->IsEnsuredOutsideFlatTree()) {
// If we cached a ComputedStyle in a display:none subtree, or outside the
// flat tree, we would not have triggered fetches for external resources
// and have StylePendingImages in the ComputedStyle. Instead of having to
// inspect the cached ComputedStyle for such resources, don't use a cached
// ComputedStyle when it was cached in display:none but is now rendered.
return false;
}
......
......@@ -547,4 +547,42 @@ TEST_F(MatchedPropertiesCacheTest, EnsuredInDisplayNone) {
EXPECT_TRUE(cache.Find(key1, *style, *ensured_parent));
}
TEST_F(MatchedPropertiesCacheTest, EnsuredOutsideFlatTree) {
TestCache cache(GetDocument());
auto style = CreateStyle();
auto parent = CreateStyle();
auto ensured_style = CreateStyle();
ensured_style->SetIsEnsuredOutsideFlatTree();
TestKey key1("display:block", 1);
cache.Add(key1, *style, *parent);
EXPECT_TRUE(cache.Find(key1, *style, *parent));
EXPECT_TRUE(cache.Find(key1, *ensured_style, *parent));
cache.Add(key1, *ensured_style, *parent);
EXPECT_FALSE(cache.Find(key1, *style, *parent));
EXPECT_TRUE(cache.Find(key1, *ensured_style, *parent));
}
TEST_F(MatchedPropertiesCacheTest, EnsuredOutsideFlatTreeAndDisplayNone) {
TestCache cache(GetDocument());
auto parent = CreateStyle();
auto parent_none = CreateStyle();
auto style = CreateStyle();
auto style_flat = CreateStyle();
parent_none->SetIsEnsuredInDisplayNone();
style_flat->SetIsEnsuredOutsideFlatTree();
TestKey key1("display:block", 1);
cache.Add(key1, *style, *parent_none);
EXPECT_TRUE(cache.Find(key1, *style_flat, *parent));
cache.Add(key1, *style_flat, *parent);
EXPECT_TRUE(cache.Find(key1, *style, *parent_none));
}
} // 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