1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-06-01 10:08:10 +00:00

LibWeb: Traverse shadow-including subtree when adopting DOM nodes

This takes care of two FIXMEs and fixes an issue on Google Docs where
we'd mix boxes from different documents in the same layout tree.
(This happened because shadow trees remained attached to their old
document when their host was adopted.)
This commit is contained in:
Andreas Kling 2022-07-12 23:13:57 +02:00
parent 7d7d5f0b1b
commit 3ee5bdcfb7
3 changed files with 24 additions and 4 deletions

View file

@ -45,4 +45,22 @@ private:
template<>
inline bool Node::fast_is<ShadowRoot>() const { return is_shadow_root(); }
template<typename Callback>
inline IterationDecision Node::for_each_shadow_including_descendant(Callback callback)
{
if (callback(*this) == IterationDecision::Break)
return IterationDecision::Break;
for (auto* child = first_child(); child; child = child->next_sibling()) {
if (child->is_element()) {
if (RefPtr<ShadowRoot> shadow_root = static_cast<Element*>(child)->shadow_root()) {
if (shadow_root->for_each_shadow_including_descendant(callback) == IterationDecision::Break)
return IterationDecision::Break;
}
}
if (child->for_each_shadow_including_descendant(callback) == IterationDecision::Break)
return IterationDecision::Break;
}
return IterationDecision::Continue;
}
}