From 2aa6d7636cc06acdb66ffd17e1248191ced5c4f3 Mon Sep 17 00:00:00 2001 From: Andreas Kling Date: Sat, 12 Apr 2025 11:44:41 +0200 Subject: [PATCH] LibWeb: Invalidate sheet owners after mutating cssText of its rules This fixes one source of flakiness on WPT (of many) where we wouldn't recompute style after programmatically altering the contents of a style sheet, but instead had to wait for something else to cause invalidation. --- Libraries/LibWeb/CSS/CSSStyleProperties.cpp | 7 + Libraries/LibWeb/DOM/Node.h | 1 + .../css/css-cascade/all-prop-revert-layer.txt | 203 ++++++++ .../css-cascade/all-prop-revert-layer.html | 470 ++++++++++++++++++ 4 files changed, 681 insertions(+) create mode 100644 Tests/LibWeb/Text/expected/wpt-import/css/css-cascade/all-prop-revert-layer.txt create mode 100644 Tests/LibWeb/Text/input/wpt-import/css/css-cascade/all-prop-revert-layer.html diff --git a/Libraries/LibWeb/CSS/CSSStyleProperties.cpp b/Libraries/LibWeb/CSS/CSSStyleProperties.cpp index 64f622cda43..3af27b22b93 100644 --- a/Libraries/LibWeb/CSS/CSSStyleProperties.cpp +++ b/Libraries/LibWeb/CSS/CSSStyleProperties.cpp @@ -1158,6 +1158,13 @@ WebIDL::ExceptionOr CSSStyleProperties::set_css_text(StringView css_text) // 4. Update style attribute for the CSS declaration block. 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); + } + } + return {}; } diff --git a/Libraries/LibWeb/DOM/Node.h b/Libraries/LibWeb/DOM/Node.h index 56f85c41a4a..e3ec675c27b 100644 --- a/Libraries/LibWeb/DOM/Node.h +++ b/Libraries/LibWeb/DOM/Node.h @@ -53,6 +53,7 @@ enum class ShouldComputeRole { X(AdoptedStyleSheetsList) \ X(CSSFontLoaded) \ X(CSSImportRule) \ + X(CSSStylePropertiesTextChange) \ X(CustomElementStateChange) \ X(DidLoseFocus) \ X(DidReceiveFocus) \ diff --git a/Tests/LibWeb/Text/expected/wpt-import/css/css-cascade/all-prop-revert-layer.txt b/Tests/LibWeb/Text/expected/wpt-import/css/css-cascade/all-prop-revert-layer.txt new file mode 100644 index 00000000000..535648fbe77 --- /dev/null +++ b/Tests/LibWeb/Text/expected/wpt-import/css/css-cascade/all-prop-revert-layer.txt @@ -0,0 +1,203 @@ +Harness status: OK + +Found 197 tests + +187 Pass +10 Fail +Pass accent-color +Pass border-collapse +Pass border-spacing +Pass caption-side +Pass caret-color +Pass clip-rule +Pass color +Pass color-scheme +Pass cursor +Pass direction +Pass fill +Pass fill-opacity +Pass fill-rule +Pass font-family +Pass font-feature-settings +Pass font-language-override +Pass font-size +Pass font-style +Pass font-variant-alternates +Pass font-variant-caps +Pass font-variant-east-asian +Pass font-variant-emoji +Pass font-variant-ligatures +Pass font-variant-numeric +Pass font-variant-position +Pass font-variation-settings +Pass font-weight +Pass font-width +Pass image-rendering +Pass letter-spacing +Pass line-height +Pass list-style-position +Pass list-style-type +Pass math-depth +Pass math-shift +Pass math-style +Pass pointer-events +Pass quotes +Pass stroke +Pass stroke-dasharray +Pass stroke-dashoffset +Pass stroke-linecap +Pass stroke-linejoin +Pass stroke-miterlimit +Pass stroke-opacity +Pass stroke-width +Pass tab-size +Pass text-align +Pass text-anchor +Pass text-decoration-line +Pass text-indent +Pass text-justify +Pass text-shadow +Pass text-transform +Pass visibility +Pass white-space +Pass word-break +Pass word-spacing +Pass word-wrap +Pass writing-mode +Pass align-items +Pass align-self +Pass animation-delay +Pass animation-direction +Pass animation-duration +Pass animation-fill-mode +Pass animation-iteration-count +Fail animation-name +Pass animation-play-state +Pass animation-timing-function +Pass appearance +Pass aspect-ratio +Pass backdrop-filter +Pass background-attachment +Pass background-blend-mode +Pass background-clip +Pass background-color +Pass background-origin +Pass background-repeat +Pass background-size +Fail block-size +Pass bottom +Pass box-shadow +Pass box-sizing +Pass clear +Pass clip +Pass clip-path +Pass column-count +Pass column-gap +Pass column-span +Pass column-width +Pass contain +Pass content +Pass content-visibility +Pass counter-increment +Pass counter-reset +Pass counter-set +Pass cx +Pass cy +Pass display +Pass flex-basis +Pass flex-direction +Pass flex-grow +Pass flex-shrink +Pass flex-wrap +Pass float +Pass grid-auto-columns +Pass grid-auto-flow +Pass grid-auto-rows +Pass grid-column-end +Pass grid-column-start +Pass grid-row-end +Pass grid-row-start +Pass grid-template-areas +Pass grid-template-columns +Pass grid-template-rows +Fail height +Fail inline-size +Pass inset-block-end +Pass inset-block-start +Pass inset-inline-end +Pass inset-inline-start +Pass isolation +Pass justify-content +Pass justify-items +Pass justify-self +Pass left +Pass margin-block-end +Pass margin-block-start +Pass margin-bottom +Pass margin-inline-end +Pass margin-inline-start +Pass margin-left +Pass margin-right +Pass margin-top +Pass mask-image +Pass mask-type +Fail max-block-size +Pass max-height +Fail max-inline-size +Pass max-width +Fail min-block-size +Pass min-height +Fail min-inline-size +Pass min-width +Pass mix-blend-mode +Pass object-fit +Pass object-position +Pass opacity +Pass order +Pass outline-color +Pass outline-offset +Pass outline-style +Pass outline-width +Pass overflow-x +Pass overflow-y +Pass padding-block-end +Pass padding-block-start +Pass padding-bottom +Pass padding-inline-end +Pass padding-inline-start +Pass padding-left +Pass padding-right +Pass padding-top +Pass position +Pass r +Pass right +Pass rotate +Pass row-gap +Pass rx +Pass ry +Pass scale +Pass scrollbar-gutter +Pass scrollbar-width +Pass stop-color +Pass stop-opacity +Pass table-layout +Pass text-decoration-color +Pass text-decoration-style +Pass text-decoration-thickness +Pass text-overflow +Pass top +Fail transform +Pass transform-box +Pass transition-delay +Pass transition-duration +Pass transition-property +Pass transition-timing-function +Pass translate +Pass unicode-bidi +Pass user-select +Pass vertical-align +Pass view-transition-name +Fail width +Pass x +Pass y +Pass z-index \ No newline at end of file diff --git a/Tests/LibWeb/Text/input/wpt-import/css/css-cascade/all-prop-revert-layer.html b/Tests/LibWeb/Text/input/wpt-import/css/css-cascade/all-prop-revert-layer.html new file mode 100644 index 00000000000..5d1d08dfb8c --- /dev/null +++ b/Tests/LibWeb/Text/input/wpt-import/css/css-cascade/all-prop-revert-layer.html @@ -0,0 +1,470 @@ + + +CSS Cascade: "all: revert-layer" + + + + + +
+ + + + + + +