diff --git a/Libraries/LibWeb/CSS/CSSStyleProperties.cpp b/Libraries/LibWeb/CSS/CSSStyleProperties.cpp index 71f193a09d8..19309dfd6cc 100644 --- a/Libraries/LibWeb/CSS/CSSStyleProperties.cpp +++ b/Libraries/LibWeb/CSS/CSSStyleProperties.cpp @@ -270,9 +270,13 @@ WebIDL::ExceptionOr 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 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 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 value, Important important) { diff --git a/Libraries/LibWeb/CSS/CSSStyleProperties.h b/Libraries/LibWeb/CSS/CSSStyleProperties.h index a6405248f4a..69326048a28 100644 --- a/Libraries/LibWeb/CSS/CSSStyleProperties.h +++ b/Libraries/LibWeb/CSS/CSSStyleProperties.h @@ -71,6 +71,8 @@ private: void empty_the_declarations(); void set_the_declarations(Vector properties, HashMap custom_properties); + void invalidate_owners(DOM::StyleInvalidationReason); + Vector m_properties; HashMap m_custom_properties; }; diff --git a/Libraries/LibWeb/CSS/CSSStyleSheet.cpp b/Libraries/LibWeb/CSS/CSSStyleSheet.cpp index eb33f279cfc..6b3b639bef1 100644 --- a/Libraries/LibWeb/CSS/CSSStyleSheet.cpp +++ b/Libraries/LibWeb/CSS/CSSStyleSheet.cpp @@ -248,6 +248,11 @@ WebIDL::ExceptionOr 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); diff --git a/Libraries/LibWeb/DOM/Node.h b/Libraries/LibWeb/DOM/Node.h index 4718ebf2a42..9426c8ad2a8 100644 --- a/Libraries/LibWeb/DOM/Node.h +++ b/Libraries/LibWeb/DOM/Node.h @@ -52,6 +52,8 @@ enum class ShouldComputeRole { X(AdoptedStyleSheetsList) \ X(CSSFontLoaded) \ X(CSSImportRule) \ + X(CSSStylePropertiesRemoveProperty) \ + X(CSSStylePropertiesSetProperty) \ X(CSSStylePropertiesTextChange) \ X(CustomElementStateChange) \ X(DidLoseFocus) \ diff --git a/Tests/LibWeb/Text/expected/wpt-import/css/cssom/CSSStyleSheet-constructable-invalidation.txt b/Tests/LibWeb/Text/expected/wpt-import/css/cssom/CSSStyleSheet-constructable-invalidation.txt new file mode 100644 index 00000000000..b8fecef6a39 --- /dev/null +++ b/Tests/LibWeb/Text/expected/wpt-import/css/cssom/CSSStyleSheet-constructable-invalidation.txt @@ -0,0 +1,9 @@ +Harness status: OK + +Found 3 tests + +2 Pass +1 Fail +Fail mutating constructed CSSStyleSheet applied to root invalidates styles +Pass mutating constructed CSSStyleSheet applied to shadowdom invalidates styles +Pass mutating dependent constructed CSSStyleSheet applied to shadowdom invalidates styles \ No newline at end of file diff --git a/Tests/LibWeb/Text/input/wpt-import/css/cssom/CSSStyleSheet-constructable-invalidation.html b/Tests/LibWeb/Text/input/wpt-import/css/cssom/CSSStyleSheet-constructable-invalidation.html new file mode 100644 index 00000000000..022ceecc1cf --- /dev/null +++ b/Tests/LibWeb/Text/input/wpt-import/css/cssom/CSSStyleSheet-constructable-invalidation.html @@ -0,0 +1,49 @@ + + +CSSStyleSheet rule mutation invalidation + + + + +Should be green. +Should be green. +