LibWeb: Only invalidate shadow root when style sheet inside changes

We don't have to invalidate style for the entire document when a style
sheet changes inside of a shadow root.

To make this possible, StyleSheetList now keeps track of which
Document-or-ShadowRoot it corresponds to, instead of just tracking the
containing Document.

This avoids a lot of style recomputation on pages with lots of shadow
DOM content (like GitHub).
This commit is contained in:
Andreas Kling 2024-08-20 14:55:28 +02:00 committed by Andreas Kling
commit 4bc3055c0f
Notes: github-actions[bot] 2024-08-20 14:11:28 +00:00
5 changed files with 37 additions and 25 deletions

View file

@ -108,9 +108,8 @@ void CSSStyleRule::set_selector_text(StringView selector_text)
m_selectors = parsed_selectors.release_value();
if (auto* sheet = parent_style_sheet()) {
if (auto style_sheet_list = sheet->style_sheet_list()) {
auto& document = style_sheet_list->document();
document.style_computer().invalidate_rule_cache();
document.invalidate_style();
style_sheet_list->document().style_computer().invalidate_rule_cache();
style_sheet_list->document_or_shadow_root().invalidate_style();
}
}
}