mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2025-08-17 07:50:04 +00:00
LibWeb: Invalidate owner sheet on add/remove in CSSStyleProperties
Fixes at least 2 WPT subtests.
This commit is contained in:
parent
fbb3b06462
commit
cf34a7bb32
Notes:
github-actions[bot]
2025-04-24 16:28:02 +00:00
Author: https://github.com/awesomekling
Commit: cf34a7bb32
Pull-request: https://github.com/LadybirdBrowser/ladybird/pull/4455
Reviewed-by: https://github.com/AtkinsSJ ✅
6 changed files with 87 additions and 7 deletions
|
@ -270,9 +270,13 @@ WebIDL::ExceptionOr<void> CSSStyleProperties::set_property(StringView property_n
|
|||
}
|
||||
|
||||
// 10. If updated is true, update style attribute for the CSS declaration block.
|
||||
if (updated)
|
||||
if (updated) {
|
||||
update_style_attribute();
|
||||
|
||||
// Non-standard: Invalidate style for the owners of our containing sheet, if any.
|
||||
invalidate_owners(DOM::StyleInvalidationReason::CSSStylePropertiesSetProperty);
|
||||
}
|
||||
|
||||
return {};
|
||||
}
|
||||
|
||||
|
@ -1049,9 +1053,13 @@ WebIDL::ExceptionOr<String> CSSStyleProperties::remove_property(StringView prope
|
|||
}
|
||||
|
||||
// 7. If removed is true, Update style attribute for the CSS declaration block.
|
||||
if (removed)
|
||||
if (removed) {
|
||||
update_style_attribute();
|
||||
|
||||
// Non-standard: Invalidate style for the owners of our containing sheet, if any.
|
||||
invalidate_owners(DOM::StyleInvalidationReason::CSSStylePropertiesRemoveProperty);
|
||||
}
|
||||
|
||||
// 8. Return value.
|
||||
return value;
|
||||
}
|
||||
|
@ -1164,15 +1172,20 @@ WebIDL::ExceptionOr<void> CSSStyleProperties::set_css_text(StringView css_text)
|
|||
update_style_attribute();
|
||||
|
||||
// Non-standard: Invalidate style for the owners of our containing sheet, if any.
|
||||
if (auto rule = parent_rule()) {
|
||||
if (auto sheet = rule->parent_style_sheet()) {
|
||||
sheet->invalidate_owners(DOM::StyleInvalidationReason::CSSStylePropertiesTextChange);
|
||||
}
|
||||
}
|
||||
invalidate_owners(DOM::StyleInvalidationReason::CSSStylePropertiesTextChange);
|
||||
|
||||
return {};
|
||||
}
|
||||
|
||||
void CSSStyleProperties::invalidate_owners(DOM::StyleInvalidationReason reason)
|
||||
{
|
||||
if (auto rule = parent_rule()) {
|
||||
if (auto sheet = rule->parent_style_sheet()) {
|
||||
sheet->invalidate_owners(reason);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// https://drafts.csswg.org/cssom/#set-a-css-declaration
|
||||
bool CSSStyleProperties::set_a_css_declaration(PropertyID property_id, NonnullRefPtr<CSSStyleValue const> value, Important important)
|
||||
{
|
||||
|
|
|
@ -71,6 +71,8 @@ private:
|
|||
void empty_the_declarations();
|
||||
void set_the_declarations(Vector<StyleProperty> properties, HashMap<FlyString, StyleProperty> custom_properties);
|
||||
|
||||
void invalidate_owners(DOM::StyleInvalidationReason);
|
||||
|
||||
Vector<StyleProperty> m_properties;
|
||||
HashMap<FlyString, StyleProperty> m_custom_properties;
|
||||
};
|
||||
|
|
|
@ -248,6 +248,11 @@ WebIDL::ExceptionOr<void> CSSStyleSheet::replace_sync(StringView text)
|
|||
rules_without_import.append(rule);
|
||||
}
|
||||
|
||||
// NOTE: The spec doesn't say where to set the parent style sheet, so we'll do it here.
|
||||
for (auto& rule : rules_without_import) {
|
||||
rule->set_parent_style_sheet(this);
|
||||
}
|
||||
|
||||
// 4. Set sheet’s CSS rules to rules.
|
||||
m_rules->set_rules({}, rules_without_import);
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue