LibWeb: Propagate CSSStyleSheet owning documents and shadow roots

Previously these were only stored on the root style sheet and were
accessed by imported stylesheets via their owner rule.

Propagating these to imported style sheets allows us to more easily know
when they change for said imported style sheets.
This commit is contained in:
Callum Law 2025-10-15 23:45:38 +13:00 committed by Tim Ledbetter
parent 3708fc6aa7
commit 9651969708
Notes: github-actions[bot] 2025-10-16 09:28:43 +00:00
3 changed files with 25 additions and 7 deletions

View file

@ -321,11 +321,21 @@ void CSSStyleSheet::add_owning_document_or_shadow_root(DOM::Node& document_or_sh
{
VERIFY(document_or_shadow_root.is_document() || document_or_shadow_root.is_shadow_root());
m_owning_documents_or_shadow_roots.set(document_or_shadow_root);
for (auto const& import_rule : m_import_rules) {
if (import_rule->loaded_style_sheet())
import_rule->loaded_style_sheet()->add_owning_document_or_shadow_root(document_or_shadow_root);
}
}
void CSSStyleSheet::remove_owning_document_or_shadow_root(DOM::Node& document_or_shadow_root)
{
m_owning_documents_or_shadow_roots.remove(document_or_shadow_root);
for (auto const& import_rule : m_import_rules) {
if (import_rule->loaded_style_sheet())
import_rule->loaded_style_sheet()->remove_owning_document_or_shadow_root(document_or_shadow_root);
}
}
void CSSStyleSheet::invalidate_owners(DOM::StyleInvalidationReason reason)
@ -342,11 +352,6 @@ GC::Ptr<DOM::Document> CSSStyleSheet::owning_document() const
if (!m_owning_documents_or_shadow_roots.is_empty())
return (*m_owning_documents_or_shadow_roots.begin())->document();
if (m_owner_css_rule && m_owner_css_rule->parent_style_sheet()) {
if (auto document = m_owner_css_rule->parent_style_sheet()->owning_document())
return document;
}
if (auto* element = const_cast<CSSStyleSheet*>(this)->owner_node())
return element->document();