diff --git a/Libraries/LibWeb/CSS/CSSStyleProperties.cpp b/Libraries/LibWeb/CSS/CSSStyleProperties.cpp index 0c60ffdac1f..b621c4990a9 100644 --- a/Libraries/LibWeb/CSS/CSSStyleProperties.cpp +++ b/Libraries/LibWeb/CSS/CSSStyleProperties.cpp @@ -44,7 +44,7 @@ GC::Ref CSSStyleProperties::create(JS::Realm& realm, Vector< return realm.create(realm, Computed::No, Readonly::No, convert_declarations_to_specified_order(properties), move(custom_properties), OptionalNone {}); } -GC::Ref CSSStyleProperties::create_resolved_style(DOM::ElementReference element_reference) +GC::Ref CSSStyleProperties::create_resolved_style(JS::Realm& realm, Optional element_reference) { // https://drafts.csswg.org/cssom/#dom-window-getcomputedstyle // 6. Return a live CSSStyleProperties object with the following properties: @@ -54,7 +54,6 @@ GC::Ref CSSStyleProperties::create_resolved_style(DOM::Eleme // parent CSS rule: Null. // owner node: obj. // AD-HOC: Rather than instantiate with a list of decls, they're generated on demand. - auto& realm = element_reference.element().realm(); return realm.create(realm, Computed::Yes, Readonly::Yes, Vector {}, HashMap {}, move(element_reference)); } diff --git a/Libraries/LibWeb/CSS/CSSStyleProperties.h b/Libraries/LibWeb/CSS/CSSStyleProperties.h index 51c6e0b1da7..f2f7da8feca 100644 --- a/Libraries/LibWeb/CSS/CSSStyleProperties.h +++ b/Libraries/LibWeb/CSS/CSSStyleProperties.h @@ -22,7 +22,7 @@ class CSSStyleProperties public: [[nodiscard]] static GC::Ref create(JS::Realm&, Vector, HashMap custom_properties); - [[nodiscard]] static GC::Ref create_resolved_style(DOM::ElementReference); + [[nodiscard]] static GC::Ref create_resolved_style(JS::Realm&, Optional); [[nodiscard]] static GC::Ref create_element_inline_style(DOM::ElementReference, Vector, HashMap custom_properties); virtual ~CSSStyleProperties() override = default; diff --git a/Libraries/LibWeb/DOM/Element.cpp b/Libraries/LibWeb/DOM/Element.cpp index 9c8f914d067..4b83bd546c0 100644 --- a/Libraries/LibWeb/DOM/Element.cpp +++ b/Libraries/LibWeb/DOM/Element.cpp @@ -775,7 +775,7 @@ CSS::RequiredInvalidationAfterStyleChange Element::recompute_inherited_style() GC::Ref Element::resolved_css_values(Optional type) { - auto element_computed_style = CSS::CSSStyleProperties::create_resolved_style({ *this, type }); + auto element_computed_style = CSS::CSSStyleProperties::create_resolved_style(realm(), ElementReference { *this, type }); auto properties = heap().allocate(); for (auto i = to_underlying(CSS::first_property_id); i <= to_underlying(CSS::last_property_id); ++i) { diff --git a/Libraries/LibWeb/Editing/Internal/Algorithms.cpp b/Libraries/LibWeb/Editing/Internal/Algorithms.cpp index da87a090e87..dd8f76ffcb3 100644 --- a/Libraries/LibWeb/Editing/Internal/Algorithms.cpp +++ b/Libraries/LibWeb/Editing/Internal/Algorithms.cpp @@ -4741,7 +4741,7 @@ Optional> resolved_value(GC::Ref(*element) }); + auto resolved_css_style_declaration = CSS::CSSStyleProperties::create_resolved_style(element->realm(), DOM::ElementReference { static_cast(*element) }); auto optional_style_property = resolved_css_style_declaration->property(property_id); if (!optional_style_property.has_value()) return {}; diff --git a/Libraries/LibWeb/HTML/Window.cpp b/Libraries/LibWeb/HTML/Window.cpp index bc4eca33973..ce4a17bf2eb 100644 --- a/Libraries/LibWeb/HTML/Window.cpp +++ b/Libraries/LibWeb/HTML/Window.cpp @@ -1273,7 +1273,7 @@ GC::Ref Window::get_computed_style(DOM::Element& eleme // 1. Let doc be elt’s node document. // 2. Let obj be elt. - DOM::ElementReference object { element }; + Optional object { element }; // 3. If pseudoElt is provided, is not the empty string, and starts with a colon, then: if (pseudo_element.has_value() && pseudo_element.value().starts_with(':')) { @@ -1281,8 +1281,8 @@ GC::Ref Window::get_computed_style(DOM::Element& eleme auto type = parse_pseudo_element_selector(CSS::Parser::ParsingParams(associated_document()), pseudo_element.value()); // 2. If type is failure, or is a ::slotted() or ::part() pseudo-element, let obj be null. - // FIXME: We can't pass a null element to CSSStyleProperties::create_resolved_style() if (!type.has_value()) { + object = {}; } // 3. Otherwise let obj be the given pseudo-element of elt. else { @@ -1311,7 +1311,7 @@ GC::Ref Window::get_computed_style(DOM::Element& eleme // Null. // owner node // obj. - return CSS::CSSStyleProperties::create_resolved_style(move(object)); + return CSS::CSSStyleProperties::create_resolved_style(element.realm(), move(object)); } // https://w3c.github.io/csswg-drafts/cssom-view/#dom-window-matchmedia