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

Fix DCHECK for computed style root outside flat tree.

We have a DCHECK that ensures we start with initial style as the parent
style if the element is the document root element, or if we are
computing styles outside the flat tree, in which case we start at
unassigned host children. A similar case is for fallback children of
slots which are not part of the flat tree because the slot has assigned
nodes from the host.

Add that condition to the DCHECK along with a test.

Bug: 1131767
Change-Id: Ic8a44f52273cc10a3a6936bf80b3b25ac0cb85d2
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2426450Reviewed-by: default avatarXiaocheng Hu <xiaochengh@chromium.org>
Commit-Queue: Rune Lillesveen <futhark@chromium.org>
Cr-Commit-Position: refs/heads/master@{#810526}
parent 3b77fd8f
...@@ -903,9 +903,10 @@ void StyleResolver::InitStyleAndApplyInheritance(Element& element, ...@@ -903,9 +903,10 @@ void StyleResolver::InitStyleAndApplyInheritance(Element& element,
// Strictly, we should only allow the root element to inherit from // Strictly, we should only allow the root element to inherit from
// initial styles, but we allow getComputedStyle() for connected // initial styles, but we allow getComputedStyle() for connected
// elements outside the flat tree rooted at an unassigned shadow host // elements outside the flat tree rooted at an unassigned shadow host
// child, or Shadow DOM V0 insertion points. // child, a slot fallback element, or Shadow DOM V0 insertion points.
DCHECK(element.IsV0InsertionPoint() || DCHECK(element.IsV0InsertionPoint() ||
(IsShadowHost(element.parentNode()) && ((IsShadowHost(element.parentNode()) ||
IsA<HTMLSlotElement>(element.parentNode())) &&
!LayoutTreeBuilderTraversal::ParentElement(element))); !LayoutTreeBuilderTraversal::ParentElement(element)));
state.Style()->SetIsEnsuredOutsideFlatTree(); state.Style()->SetIsEnsuredOutsideFlatTree();
} }
......
...@@ -781,4 +781,35 @@ TEST_F(StyleResolverTest, CascadedValuesForPseudoElement) { ...@@ -781,4 +781,35 @@ TEST_F(StyleResolverTest, CascadedValuesForPseudoElement) {
EXPECT_EQ("1em", map.at(top)->CssText()); EXPECT_EQ("1em", map.at(top)->CssText());
} }
TEST_F(StyleResolverTest, EnsureComputedStyleSlotFallback) {
GetDocument().body()->setInnerHTML(R"HTML(
<div id="host"><span></span></div>
)HTML");
ShadowRoot& shadow_root =
GetDocument().getElementById("host")->AttachShadowRootInternal(
ShadowRootType::kOpen);
shadow_root.setInnerHTML(R"HTML(
<style>
slot { color: red }
</style>
<slot><span id="fallback"></span></slot>
)HTML");
Element* fallback = shadow_root.getElementById("fallback");
ASSERT_TRUE(fallback);
UpdateAllLifecyclePhasesForTest();
// Elements outside the flat tree does not get styles computed during the
// lifecycle update.
EXPECT_FALSE(fallback->GetComputedStyle());
// We are currently allowed to query the computed style of elements outside
// the flat tree, but slot fallback does not inherit from the slot.
const ComputedStyle* fallback_style = fallback->EnsureComputedStyle();
ASSERT_TRUE(fallback_style);
EXPECT_EQ(Color::kBlack,
fallback_style->VisitedDependentColor(GetCSSPropertyColor()));
}
} // namespace blink } // 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