mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2025-07-31 05:09:12 +00:00
LibWeb: Fix insert/delete rule invalidation for adopted style sheets
Invalidation for adopted style sheets was broken because we had an assumption that "active" style sheet is always attached to StyleSheetList which is not true for adopted style sheets. This change addresses that by keeping track of all documents/shadow roots that own a style sheet and notifying them about invalidation instead of going through the StyleSheetList.
This commit is contained in:
parent
24e374d7e1
commit
98691810b1
Notes:
github-actions[bot]
2025-01-13 22:04:04 +00:00
Author: https://github.com/kalenikaliaksandr
Commit: 98691810b1
Pull-request: https://github.com/LadybirdBrowser/ladybird/pull/3217
Reviewed-by: https://github.com/awesomekling
Reviewed-by: https://github.com/gmta
Reviewed-by: https://github.com/tcl3
9 changed files with 103 additions and 43 deletions
|
@ -10,11 +10,11 @@
|
|||
|
||||
namespace Web::DOM {
|
||||
|
||||
GC::Ref<WebIDL::ObservableArray> create_adopted_style_sheets_list(Document& document)
|
||||
GC::Ref<WebIDL::ObservableArray> create_adopted_style_sheets_list(Node& document_or_shadow_root)
|
||||
{
|
||||
auto adopted_style_sheets = WebIDL::ObservableArray::create(document.realm());
|
||||
adopted_style_sheets->set_on_set_an_indexed_value_callback([&document](JS::Value& value) -> WebIDL::ExceptionOr<void> {
|
||||
auto& vm = document.vm();
|
||||
auto adopted_style_sheets = WebIDL::ObservableArray::create(document_or_shadow_root.realm());
|
||||
adopted_style_sheets->set_on_set_an_indexed_value_callback([&document_or_shadow_root](JS::Value& value) -> WebIDL::ExceptionOr<void> {
|
||||
auto& vm = document_or_shadow_root.vm();
|
||||
if (!value.is_object())
|
||||
return vm.throw_completion<JS::TypeError>(JS::ErrorType::NotAnObjectOfType, "CSSStyleSheet");
|
||||
auto& object = value.as_object();
|
||||
|
@ -26,24 +26,26 @@ GC::Ref<WebIDL::ObservableArray> create_adopted_style_sheets_list(Document& docu
|
|||
// 1. If value’s constructed flag is not set, or its constructor document is not equal to this
|
||||
// DocumentOrShadowRoot's node document, throw a "NotAllowedError" DOMException.
|
||||
if (!style_sheet.constructed())
|
||||
return WebIDL::NotAllowedError::create(document.realm(), "StyleSheet's constructed flag is not set."_string);
|
||||
if (!style_sheet.constructed() || style_sheet.constructor_document().ptr() != &document)
|
||||
return WebIDL::NotAllowedError::create(document.realm(), "Sharing a StyleSheet between documents is not allowed."_string);
|
||||
return WebIDL::NotAllowedError::create(document_or_shadow_root.realm(), "StyleSheet's constructed flag is not set."_string);
|
||||
if (!style_sheet.constructed() || style_sheet.constructor_document().ptr() != &document_or_shadow_root.document())
|
||||
return WebIDL::NotAllowedError::create(document_or_shadow_root.realm(), "Sharing a StyleSheet between documents is not allowed."_string);
|
||||
|
||||
document.style_computer().load_fonts_from_sheet(style_sheet);
|
||||
document.style_computer().invalidate_rule_cache();
|
||||
document.invalidate_style(DOM::StyleInvalidationReason::AdoptedStyleSheetsList);
|
||||
style_sheet.add_owning_document_or_shadow_root(document_or_shadow_root);
|
||||
document_or_shadow_root.document().style_computer().load_fonts_from_sheet(style_sheet);
|
||||
document_or_shadow_root.document().style_computer().invalidate_rule_cache();
|
||||
document_or_shadow_root.invalidate_style(DOM::StyleInvalidationReason::AdoptedStyleSheetsList);
|
||||
return {};
|
||||
});
|
||||
adopted_style_sheets->set_on_delete_an_indexed_value_callback([&document](JS::Value value) -> WebIDL::ExceptionOr<void> {
|
||||
adopted_style_sheets->set_on_delete_an_indexed_value_callback([&document_or_shadow_root](JS::Value value) -> WebIDL::ExceptionOr<void> {
|
||||
VERIFY(value.is_object());
|
||||
auto& object = value.as_object();
|
||||
VERIFY(is<CSS::CSSStyleSheet>(object));
|
||||
auto& style_sheet = static_cast<CSS::CSSStyleSheet&>(object);
|
||||
|
||||
document.style_computer().unload_fonts_from_sheet(style_sheet);
|
||||
document.style_computer().invalidate_rule_cache();
|
||||
document.invalidate_style(DOM::StyleInvalidationReason::AdoptedStyleSheetsList);
|
||||
style_sheet.remove_owning_document_or_shadow_root(document_or_shadow_root);
|
||||
document_or_shadow_root.document().style_computer().unload_fonts_from_sheet(style_sheet);
|
||||
document_or_shadow_root.document().style_computer().invalidate_rule_cache();
|
||||
document_or_shadow_root.invalidate_style(DOM::StyleInvalidationReason::AdoptedStyleSheetsList);
|
||||
return {};
|
||||
});
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue