diff --git a/Libraries/LibWeb/CSS/StylePropertyMapReadOnly.idl b/Libraries/LibWeb/CSS/StylePropertyMapReadOnly.idl index 4c43062edd7..bfbb84801b4 100644 --- a/Libraries/LibWeb/CSS/StylePropertyMapReadOnly.idl +++ b/Libraries/LibWeb/CSS/StylePropertyMapReadOnly.idl @@ -10,3 +10,8 @@ interface StylePropertyMapReadOnly { boolean has(USVString property); readonly attribute unsigned long size; }; + +// https://drafts.css-houdini.org/css-typed-om-1/#computed-stylepropertymapreadonly-objects +partial interface Element { + [SameObject] StylePropertyMapReadOnly computedStyleMap(); +}; diff --git a/Libraries/LibWeb/DOM/Element.cpp b/Libraries/LibWeb/DOM/Element.cpp index a7dba0e8ece..5b4a0cfae5a 100644 --- a/Libraries/LibWeb/DOM/Element.cpp +++ b/Libraries/LibWeb/DOM/Element.cpp @@ -122,6 +122,7 @@ void Element::visit_edges(Cell::Visitor& visitor) visitor.visit(m_custom_state_set); visitor.visit(m_cascaded_properties); visitor.visit(m_computed_properties); + visitor.visit(m_computed_style_map_cache); if (m_pseudo_element_data) { for (auto& pseudo_element : *m_pseudo_element_data) { visitor.visit(pseudo_element.value); @@ -4096,4 +4097,27 @@ void Element::set_had_duplicate_attribute_during_tokenization(Badge Element::computed_style_map() +{ + // The computedStyleMap() method must, when called on an Element this, perform the following steps: + + // 1. If this’s [[computedStyleMapCache]] internal slot is set to null, set its value to a new + // StylePropertyMapReadOnly object, whose [[declarations]] internal slot are the name and computed value of + // every longhand CSS property supported by the User Agent, every registered custom property, and every + // non-registered custom property which is not set to its initial value on this, in the standard order. + // + // The computed values in the [[declarations]] of this object must remain up-to-date, changing as style + // resolution changes the properties on this and how they’re computed. + // + // NOTE: In practice, since the values are "hidden" behind a .get() method call, UAs can delay computing anything + // until a given property is actually requested. + if (m_computed_style_map_cache == nullptr) { + m_computed_style_map_cache = CSS::StylePropertyMapReadOnly::create_computed_style(realm(), AbstractElement { *this }); + } + + // 2. Return this’s [[computedStyleMapCache]] internal slot. + return *m_computed_style_map_cache; +} + } diff --git a/Libraries/LibWeb/DOM/Element.h b/Libraries/LibWeb/DOM/Element.h index 02c298f02c6..642d224ad47 100644 --- a/Libraries/LibWeb/DOM/Element.h +++ b/Libraries/LibWeb/DOM/Element.h @@ -19,6 +19,7 @@ #include #include #include +#include #include #include #include @@ -521,6 +522,8 @@ public: void set_had_duplicate_attribute_during_tokenization(Badge); bool had_duplicate_attribute_during_tokenization() const { return m_had_duplicate_attribute_during_tokenization; } + GC::Ref computed_style_map(); + protected: Element(Document&, DOM::QualifiedName); virtual void initialize(JS::Realm&) override; @@ -603,6 +606,11 @@ private: // Element objects have an internal [[RegisteredIntersectionObservers]] slot, which is initialized to an empty list. OwnPtr> m_registered_intersection_observers; + // https://drafts.css-houdini.org/css-typed-om-1/#dom-element-computedstylemapcache-slot + // Every Element has a [[computedStyleMapCache]] internal slot, initially set to null, which caches the result of + // the computedStyleMap() method when it is first called. + GC::Ptr m_computed_style_map_cache; + CSSPixelPoint m_scroll_offset; bool m_in_top_layer : 1 { false }; diff --git a/Libraries/LibWeb/DOM/Element.idl b/Libraries/LibWeb/DOM/Element.idl index b94a50213f7..a72de6af8cf 100644 --- a/Libraries/LibWeb/DOM/Element.idl +++ b/Libraries/LibWeb/DOM/Element.idl @@ -1,5 +1,6 @@ #import #import +#import #import #import #import diff --git a/Tests/LibWeb/Text/expected/wpt-import/css/css-typed-om/the-stylepropertymap/computed/computed.tentative.txt b/Tests/LibWeb/Text/expected/wpt-import/css/css-typed-om/the-stylepropertymap/computed/computed.tentative.txt index 6055c864758..a4ccde9d274 100644 --- a/Tests/LibWeb/Text/expected/wpt-import/css/css-typed-om/the-stylepropertymap/computed/computed.tentative.txt +++ b/Tests/LibWeb/Text/expected/wpt-import/css/css-typed-om/the-stylepropertymap/computed/computed.tentative.txt @@ -1,3 +1,12 @@ -Harness status: Error +Harness status: OK -Found 0 tests +Found 7 tests + +7 Fail +Fail Computed StylePropertyMap contains every CSS property +Fail Computed StylePropertyMap contains CSS property declarations in style rules +Fail Computed StylePropertyMap contains custom property declarations in style rules +Fail Computed StylePropertyMap contains CSS property declarations in inline styles +Fail Computed StylePropertyMap contains custom property declarations in inline rules +Fail Computed StylePropertyMap contains computed values and not resolved values +Fail Computed StylePropertyMap is live \ No newline at end of file diff --git a/Tests/LibWeb/Text/expected/wpt-import/css/css-typed-om/the-stylepropertymap/computed/get-invalid.txt b/Tests/LibWeb/Text/expected/wpt-import/css/css-typed-om/the-stylepropertymap/computed/get-invalid.txt index e5f9ee2279b..f00625eeecc 100644 --- a/Tests/LibWeb/Text/expected/wpt-import/css/css-typed-om/the-stylepropertymap/computed/get-invalid.txt +++ b/Tests/LibWeb/Text/expected/wpt-import/css/css-typed-om/the-stylepropertymap/computed/get-invalid.txt @@ -2,5 +2,5 @@ Harness status: OK Found 1 tests -1 Fail -Fail Calling StylePropertyMap.get with an unsupported property throws a TypeError \ No newline at end of file +1 Pass +Pass Calling StylePropertyMap.get with an unsupported property throws a TypeError \ No newline at end of file diff --git a/Tests/LibWeb/Text/expected/wpt-import/css/css-typed-om/the-stylepropertymap/computed/get.txt b/Tests/LibWeb/Text/expected/wpt-import/css/css-typed-om/the-stylepropertymap/computed/get.txt index 1853e7752d2..d3ccc61ecf8 100644 --- a/Tests/LibWeb/Text/expected/wpt-import/css/css-typed-om/the-stylepropertymap/computed/get.txt +++ b/Tests/LibWeb/Text/expected/wpt-import/css/css-typed-om/the-stylepropertymap/computed/get.txt @@ -2,8 +2,9 @@ Harness status: OK Found 6 tests -6 Fail -Fail Getting a custom property not in the computed style returns undefined +1 Pass +5 Fail +Pass Getting a custom property not in the computed style returns undefined Fail Getting a valid property from computed style returns the correct entry Fail Getting a valid custom property from computed style returns the correct entry Fail Getting a list-valued property from computed style returns only the first value diff --git a/Tests/LibWeb/Text/expected/wpt-import/css/css-typed-om/the-stylepropertymap/computed/getAll.tentative.txt b/Tests/LibWeb/Text/expected/wpt-import/css/css-typed-om/the-stylepropertymap/computed/getAll.tentative.txt index 43ea8d818fd..9473e7be119 100644 --- a/Tests/LibWeb/Text/expected/wpt-import/css/css-typed-om/the-stylepropertymap/computed/getAll.tentative.txt +++ b/Tests/LibWeb/Text/expected/wpt-import/css/css-typed-om/the-stylepropertymap/computed/getAll.tentative.txt @@ -2,9 +2,10 @@ Harness status: OK Found 6 tests -6 Fail -Fail Calling StylePropertyMap.getAll with an unsupported property throws a TypeError -Fail Calling StylePropertyMap.getAll with a custom property not in the property model returns an empty list +2 Pass +4 Fail +Pass Calling StylePropertyMap.getAll with an unsupported property throws a TypeError +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/computed/has.tentative.txt b/Tests/LibWeb/Text/expected/wpt-import/css/css-typed-om/the-stylepropertymap/computed/has.tentative.txt index 75c8b09a693..ffad3d7d05b 100644 --- a/Tests/LibWeb/Text/expected/wpt-import/css/css-typed-om/the-stylepropertymap/computed/has.tentative.txt +++ b/Tests/LibWeb/Text/expected/wpt-import/css/css-typed-om/the-stylepropertymap/computed/has.tentative.txt @@ -2,9 +2,10 @@ Harness status: OK Found 7 tests -7 Fail -Fail Calling StylePropertyMap.has with an unsupported property throws a TypeError -Fail Calling StylePropertyMap.has with a custom property not in the property model returns false +2 Pass +5 Fail +Pass Calling StylePropertyMap.has with an unsupported property throws a TypeError +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 property returns true