diff --git a/Libraries/LibWeb/CSS/CSSStyleRule.cpp b/Libraries/LibWeb/CSS/CSSStyleRule.cpp index eb9051ff635..e3e1b919e23 100644 --- a/Libraries/LibWeb/CSS/CSSStyleRule.cpp +++ b/Libraries/LibWeb/CSS/CSSStyleRule.cpp @@ -1,6 +1,6 @@ /* * Copyright (c) 2018-2020, Andreas Kling - * Copyright (c) 2021-2024, Sam Atkins + * Copyright (c) 2021-2025, Sam Atkins * * SPDX-License-Identifier: BSD-2-Clause */ @@ -12,6 +12,7 @@ #include #include #include +#include namespace Web::CSS { @@ -40,6 +41,7 @@ void CSSStyleRule::visit_edges(Cell::Visitor& visitor) { Base::visit_edges(visitor); visitor.visit(m_declaration); + visitor.visit(m_style_map); } // https://drafts.csswg.org/cssom-1/#dom-cssstylerule-style @@ -48,6 +50,14 @@ GC::Ref CSSStyleRule::style() return m_declaration; } +// https://drafts.css-houdini.org/css-typed-om-1/#dom-cssstylerule-stylemap +GC::Ref CSSStyleRule::style_map() +{ + if (!m_style_map) + m_style_map = StylePropertyMap::create(realm(), m_declaration); + return *m_style_map; +} + // https://drafts.csswg.org/cssom-1/#serialize-a-css-rule String CSSStyleRule::serialized() const { diff --git a/Libraries/LibWeb/CSS/CSSStyleRule.h b/Libraries/LibWeb/CSS/CSSStyleRule.h index 0be243aa834..56257502598 100644 --- a/Libraries/LibWeb/CSS/CSSStyleRule.h +++ b/Libraries/LibWeb/CSS/CSSStyleRule.h @@ -31,6 +31,7 @@ public: void set_selector_text(StringView); GC::Ref style(); + GC::Ref style_map(); [[nodiscard]] FlyString const& qualified_layer_name() const { return parent_layer_internal_qualified_name(); } @@ -49,6 +50,7 @@ private: SelectorList m_selectors; mutable Optional m_cached_absolutized_selectors; GC::Ref m_declaration; + GC::Ptr m_style_map; }; template<> diff --git a/Libraries/LibWeb/CSS/CSSStyleRule.idl b/Libraries/LibWeb/CSS/CSSStyleRule.idl index f7df36c9824..5b1054c7f90 100644 --- a/Libraries/LibWeb/CSS/CSSStyleRule.idl +++ b/Libraries/LibWeb/CSS/CSSStyleRule.idl @@ -1,5 +1,6 @@ #import #import +#import // https://drafts.csswg.org/cssom/#the-cssstylerule-interface [Exposed=Window] diff --git a/Libraries/LibWeb/CSS/StylePropertyMap.idl b/Libraries/LibWeb/CSS/StylePropertyMap.idl index 20d5bbd76d9..ae286d6e086 100644 --- a/Libraries/LibWeb/CSS/StylePropertyMap.idl +++ b/Libraries/LibWeb/CSS/StylePropertyMap.idl @@ -8,3 +8,8 @@ interface StylePropertyMap : StylePropertyMapReadOnly { undefined delete(USVString property); undefined clear(); }; + +// https://drafts.css-houdini.org/css-typed-om-1/#declared-stylepropertymap-objects +partial interface CSSStyleRule { + [SameObject] readonly attribute StylePropertyMap styleMap; +}; diff --git a/Tests/LibWeb/Text/expected/wpt-import/css/css-typed-om/the-stylepropertymap/declared/declared.tentative.txt b/Tests/LibWeb/Text/expected/wpt-import/css/css-typed-om/the-stylepropertymap/declared/declared.tentative.txt index dbc92eaebdf..3d56a5fafcd 100644 --- a/Tests/LibWeb/Text/expected/wpt-import/css/css-typed-om/the-stylepropertymap/declared/declared.tentative.txt +++ b/Tests/LibWeb/Text/expected/wpt-import/css/css-typed-om/the-stylepropertymap/declared/declared.tentative.txt @@ -2,11 +2,12 @@ Harness status: OK Found 7 tests -7 Fail +2 Pass +5 Fail Fail Declared StylePropertyMap only contains properties in the style rule Fail Declared StylePropertyMap contains CSS property declarations in style rules -Fail Declared StylePropertyMap does not contain inline styles +Pass Declared StylePropertyMap does not contain inline styles Fail Declared StylePropertyMap contains custom property declarations -Fail Declared StylePropertyMap does not contain properties with invalid values +Pass Declared StylePropertyMap does not contain properties with invalid values Fail Declared StylePropertyMap contains properties with their last valid value Fail Declared StylePropertyMap is live \ No newline at end of file diff --git a/Tests/LibWeb/Text/expected/wpt-import/css/css-typed-om/the-stylepropertymap/declared/delete-shorthand.txt b/Tests/LibWeb/Text/expected/wpt-import/css/css-typed-om/the-stylepropertymap/declared/delete-shorthand.txt index 86c36ce6ef9..096933cd136 100644 --- a/Tests/LibWeb/Text/expected/wpt-import/css/css-typed-om/the-stylepropertymap/declared/delete-shorthand.txt +++ b/Tests/LibWeb/Text/expected/wpt-import/css/css-typed-om/the-stylepropertymap/declared/delete-shorthand.txt @@ -2,7 +2,8 @@ Harness status: OK Found 3 tests -3 Fail -Fail Deleting a shorthand property not in the css rule is a no-op +1 Pass +2 Fail +Pass Deleting a shorthand property not in the css rule is a no-op Fail Deleting a shorthand property in the css rule removes both it and its longhands Fail Deleting a longhand property in the css rule removes both it and its shorthand \ No newline at end of file diff --git a/Tests/LibWeb/Text/expected/wpt-import/css/css-typed-om/the-stylepropertymap/declared/delete.txt b/Tests/LibWeb/Text/expected/wpt-import/css/css-typed-om/the-stylepropertymap/declared/delete.txt index 881a30777a9..53863bd3c51 100644 --- a/Tests/LibWeb/Text/expected/wpt-import/css/css-typed-om/the-stylepropertymap/declared/delete.txt +++ b/Tests/LibWeb/Text/expected/wpt-import/css/css-typed-om/the-stylepropertymap/declared/delete.txt @@ -2,8 +2,9 @@ Harness status: OK Found 5 tests -5 Fail -Fail Deleting a property not in the css rule is a no-op +1 Pass +4 Fail +Pass Deleting a property not in the css rule is a no-op Fail Deleting a property in the css rule removes it from the css rule Fail Deleting a custom property in the css rule removes it from the css rule Fail Deleting a list-valued property in the css rule removes it from the css rule diff --git a/Tests/LibWeb/Text/expected/wpt-import/css/css-typed-om/the-stylepropertymap/declared/get-shorthand.txt b/Tests/LibWeb/Text/expected/wpt-import/css/css-typed-om/the-stylepropertymap/declared/get-shorthand.txt index 8d2f9190de3..b9d8f036b8e 100644 --- a/Tests/LibWeb/Text/expected/wpt-import/css/css-typed-om/the-stylepropertymap/declared/get-shorthand.txt +++ b/Tests/LibWeb/Text/expected/wpt-import/css/css-typed-om/the-stylepropertymap/declared/get-shorthand.txt @@ -2,6 +2,7 @@ Harness status: OK Found 2 tests -2 Fail +1 Pass +1 Fail Fail Getting a shorthand property set explicitly in css rule returns a base CSSStyleValue -Fail Getting a shorthand property that is partially set in css rule returns undefined \ No newline at end of file +Pass Getting a shorthand property that is partially set in css rule returns undefined \ No newline at end of file diff --git a/Tests/LibWeb/Text/expected/wpt-import/css/css-typed-om/the-stylepropertymap/declared/get.txt b/Tests/LibWeb/Text/expected/wpt-import/css/css-typed-om/the-stylepropertymap/declared/get.txt index a5fb975e09e..af1e233a684 100644 --- a/Tests/LibWeb/Text/expected/wpt-import/css/css-typed-om/the-stylepropertymap/declared/get.txt +++ b/Tests/LibWeb/Text/expected/wpt-import/css/css-typed-om/the-stylepropertymap/declared/get.txt @@ -2,9 +2,10 @@ Harness status: OK Found 7 tests -7 Fail -Fail Getting a custom property not in the CSS rule returns undefined -Fail Getting a valid property not in the CSS rule returns undefined +2 Pass +5 Fail +Pass Getting a custom property not in the CSS rule returns undefined +Pass Getting a valid property not in the CSS rule returns undefined Fail Getting a valid property from CSS rule returns the correct entry Fail Getting a valid custom property from CSS rule returns the correct entry Fail Getting a list-valued property from CSS rule returns only the first value diff --git a/Tests/LibWeb/Text/expected/wpt-import/css/css-typed-om/the-stylepropertymap/declared/getAll-shorthand.txt b/Tests/LibWeb/Text/expected/wpt-import/css/css-typed-om/the-stylepropertymap/declared/getAll-shorthand.txt index 865f2eb2d69..6a8ab8d12d3 100644 --- a/Tests/LibWeb/Text/expected/wpt-import/css/css-typed-om/the-stylepropertymap/declared/getAll-shorthand.txt +++ b/Tests/LibWeb/Text/expected/wpt-import/css/css-typed-om/the-stylepropertymap/declared/getAll-shorthand.txt @@ -2,6 +2,7 @@ Harness status: OK Found 2 tests -2 Fail +1 Pass +1 Fail Fail StylePropertyMap.getAll() with a shorthand property set explicitly in css rule returns a base CSSStyleValue -Fail StylePropertyMap.getAll() with a shorthand property that is partially in css rule returns empty list \ No newline at end of file +Pass StylePropertyMap.getAll() with a shorthand property that is partially in css rule returns empty list \ No newline at end of file diff --git a/Tests/LibWeb/Text/expected/wpt-import/css/css-typed-om/the-stylepropertymap/declared/getAll.tentative.txt b/Tests/LibWeb/Text/expected/wpt-import/css/css-typed-om/the-stylepropertymap/declared/getAll.tentative.txt index d50ed00e172..3cd6f1618dc 100644 --- a/Tests/LibWeb/Text/expected/wpt-import/css/css-typed-om/the-stylepropertymap/declared/getAll.tentative.txt +++ b/Tests/LibWeb/Text/expected/wpt-import/css/css-typed-om/the-stylepropertymap/declared/getAll.tentative.txt @@ -2,11 +2,11 @@ Harness status: OK Found 7 tests -1 Pass -6 Fail +3 Pass +4 Fail Pass Calling StylePropertyMap.getAll with an unsupported property throws a TypeError -Fail Calling StylePropertyMap.getAll with a property not in the property model returns an empty list -Fail Calling StylePropertyMap.getAll with a custom property not in the property model returns an empty list +Pass Calling StylePropertyMap.getAll with a property not in the property model returns an empty list +Pass Calling StylePropertyMap.getAll with a custom property not in the property model returns an empty list Fail Calling StylePropertyMap.getAll with a valid property returns a single element list with the correct entry Fail StylePropertyMap.getAll is case-insensitive Fail Calling StylePropertyMap.getAll with a valid custom property returns a single element list with the correct entry diff --git a/Tests/LibWeb/Text/expected/wpt-import/css/css-typed-om/the-stylepropertymap/declared/has.tentative.txt b/Tests/LibWeb/Text/expected/wpt-import/css/css-typed-om/the-stylepropertymap/declared/has.tentative.txt index 44279fbdd0c..5911c5af484 100644 --- a/Tests/LibWeb/Text/expected/wpt-import/css/css-typed-om/the-stylepropertymap/declared/has.tentative.txt +++ b/Tests/LibWeb/Text/expected/wpt-import/css/css-typed-om/the-stylepropertymap/declared/has.tentative.txt @@ -2,14 +2,14 @@ Harness status: OK Found 9 tests -1 Pass -8 Fail +4 Pass +5 Fail Pass Calling StylePropertyMap.has with an unsupported property throws a TypeError -Fail Calling StylePropertyMap.has with a property not in the property model returns false -Fail Calling StylePropertyMap.has with a custom property not in the property model returns false +Pass Calling StylePropertyMap.has with a property not in the property model returns false +Pass Calling StylePropertyMap.has with a custom property not in the property model returns false Fail Calling StylePropertyMap.has with a valid property returns true Fail Calling StylePropertyMap.has with a valid property in mixed case returns true Fail Calling StylePropertyMap.has with a valid shorthand specified explicitly returns true -Fail Calling StylePropertyMap.has with a valid shorthand only partially specified returns false +Pass Calling StylePropertyMap.has with a valid shorthand only partially specified returns false Fail Calling StylePropertyMap.has with a valid custom property returns true Fail Calling StylePropertyMap.has with a valid list-valued property returns true \ No newline at end of file