1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-25 04:47:35 +00:00

LibWeb: Maintain list of allocated shadow roots in Document

Doing that will allow us to get a list of style sheets for each shadow
root from StyleComputer without having to traverse the entire tree in
upcoming changes.
This commit is contained in:
Aliaksandr Kalenik 2024-03-09 00:19:05 +01:00 committed by Andreas Kling
parent c6e69d501f
commit 91ec1d6f95
4 changed files with 36 additions and 0 deletions

View file

@ -486,6 +486,9 @@ void Document::visit_edges(Cell::Visitor& visitor)
}
visitor.visit(m_adopted_style_sheets);
for (auto& shadow_root : m_shadow_roots)
visitor.visit(shadow_root);
}
// https://w3c.github.io/selection-api/#dom-document-getselection
@ -4601,4 +4604,22 @@ void Document::for_each_css_style_sheet(Function<void(CSS::CSSStyleSheet&)>&& ca
}
}
void Document::register_shadow_root(Badge<DOM::ShadowRoot>, DOM::ShadowRoot& shadow_root)
{
m_shadow_roots.append(shadow_root);
}
void Document::unregister_shadow_root(Badge<DOM::ShadowRoot>, DOM::ShadowRoot& shadow_root)
{
m_shadow_roots.remove_all_matching([&](auto& item) {
return item.ptr() == &shadow_root;
});
}
void Document::for_each_shadow_root(Function<void(DOM::ShadowRoot&)>&& callback)
{
for (auto& shadow_root : m_shadow_roots)
callback(shadow_root);
}
}