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

Notify host children of flat tree change when attaching shadow.

We don't know if there will be any slots added for an attached shadow
root. If no slots are added, there will be no slot re-assignment and no
other way to inform the shadow host children that their flat tree
position changed.

LazyReattachLayoutTree will not clear ComputedStyle because it uses true
for performing_reattach in AttachContext. Instead call
RemovedFromFlatTree which detaches the layout tree and clears the
computed style.

Bug: 932871
Change-Id: I3dd8f7f3d4b4eb1fb8a745c2849840b1b4c3d89d
Reviewed-on: https://chromium-review.googlesource.com/c/1477695Reviewed-by: default avatarHayato Ito <hayato@chromium.org>
Commit-Queue: Rune Lillesveen <futhark@chromium.org>
Cr-Commit-Position: refs/heads/master@{#635571}
parent ac3496a7
......@@ -2551,15 +2551,18 @@ ShadowRoot& Element::CreateAndAttachShadowRoot(ShadowRootType type) {
ShadowRoot* shadow_root = ShadowRoot::Create(GetDocument(), type);
if (type != ShadowRootType::V0) {
if (type != ShadowRootType::V0 && InActiveDocument()) {
// Detach the host's children here for v1 (including UA shadow root),
// because we skip SetNeedsDistributionRecalc() in attaching v1 shadow root.
// See https://crrev.com/2822113002 for details.
// We need to call child.LazyReattachIfAttached() before setting a shadow
// We need to call child.RemovedFromFlatTree() before setting a shadow
// root to the element because detach must use the original flat tree
// structure before attachShadow happens.
// structure before attachShadow happens. We cannot use
// FlatTreeParentChanged() because we don't know at this point whether a
// slot will be added and the child assigned to a slot on the next slot
// assignment update.
for (Node& child : NodeTraversal::ChildrenOf(*this))
child.LazyReattachIfAttached();
child.RemovedFromFlatTree();
}
EnsureElementRareData().SetShadowRoot(*shadow_root);
shadow_root->SetParentOrShadowHostNode(this);
......
<!DOCTYPE html>
<script src="../resources/testharness.js"></script>
<script src="../resources/testharnessreport.js"></script>
<body>
<script>
test(() => {
const img = document.createElement("img");
img.setAttribute("alt", "PASS if no crash.");
document.body.appendChild(img);
const span = document.createElement("span");
img.appendChild(span);
document.body.offsetTop;
}, "Removing an img child from the flat tree because alt rendering is added should not crash.");
</script>
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