mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2025-07-04 08:01:51 +00:00
LibWeb: Make element_reference
optional in create_resolved_style
This commit is contained in:
parent
610ad25555
commit
fc46abb83f
Notes:
github-actions[bot]
2025-06-09 11:29:50 +00:00
Author: https://github.com/Calme1709
Commit: fc46abb83f
Pull-request: https://github.com/LadybirdBrowser/ladybird/pull/5034
Reviewed-by: https://github.com/AtkinsSJ
Reviewed-by: https://github.com/tcl3 ✅
5 changed files with 7 additions and 8 deletions
|
@ -44,7 +44,7 @@ GC::Ref<CSSStyleProperties> CSSStyleProperties::create(JS::Realm& realm, Vector<
|
|||
return realm.create<CSSStyleProperties>(realm, Computed::No, Readonly::No, convert_declarations_to_specified_order(properties), move(custom_properties), OptionalNone {});
|
||||
}
|
||||
|
||||
GC::Ref<CSSStyleProperties> CSSStyleProperties::create_resolved_style(DOM::ElementReference element_reference)
|
||||
GC::Ref<CSSStyleProperties> CSSStyleProperties::create_resolved_style(JS::Realm& realm, Optional<DOM::ElementReference> 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> 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<CSSStyleProperties>(realm, Computed::Yes, Readonly::Yes, Vector<StyleProperty> {}, HashMap<FlyString, StyleProperty> {}, move(element_reference));
|
||||
}
|
||||
|
||||
|
|
|
@ -22,7 +22,7 @@ class CSSStyleProperties
|
|||
public:
|
||||
[[nodiscard]] static GC::Ref<CSSStyleProperties> create(JS::Realm&, Vector<StyleProperty>, HashMap<FlyString, StyleProperty> custom_properties);
|
||||
|
||||
[[nodiscard]] static GC::Ref<CSSStyleProperties> create_resolved_style(DOM::ElementReference);
|
||||
[[nodiscard]] static GC::Ref<CSSStyleProperties> create_resolved_style(JS::Realm&, Optional<DOM::ElementReference>);
|
||||
[[nodiscard]] static GC::Ref<CSSStyleProperties> create_element_inline_style(DOM::ElementReference, Vector<StyleProperty>, HashMap<FlyString, StyleProperty> custom_properties);
|
||||
|
||||
virtual ~CSSStyleProperties() override = default;
|
||||
|
|
|
@ -775,7 +775,7 @@ CSS::RequiredInvalidationAfterStyleChange Element::recompute_inherited_style()
|
|||
|
||||
GC::Ref<CSS::ComputedProperties> Element::resolved_css_values(Optional<CSS::PseudoElement> 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<CSS::ComputedProperties>();
|
||||
|
||||
for (auto i = to_underlying(CSS::first_property_id); i <= to_underlying(CSS::last_property_id); ++i) {
|
||||
|
|
|
@ -4741,7 +4741,7 @@ Optional<NonnullRefPtr<CSS::CSSStyleValue const>> resolved_value(GC::Ref<DOM::No
|
|||
return {};
|
||||
|
||||
// Retrieve resolved style value
|
||||
auto resolved_css_style_declaration = CSS::CSSStyleProperties::create_resolved_style({ static_cast<DOM::Element&>(*element) });
|
||||
auto resolved_css_style_declaration = CSS::CSSStyleProperties::create_resolved_style(element->realm(), DOM::ElementReference { static_cast<DOM::Element&>(*element) });
|
||||
auto optional_style_property = resolved_css_style_declaration->property(property_id);
|
||||
if (!optional_style_property.has_value())
|
||||
return {};
|
||||
|
|
|
@ -1273,7 +1273,7 @@ GC::Ref<CSS::CSSStyleDeclaration> 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<DOM::ElementReference> 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<CSS::CSSStyleDeclaration> 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<CSS::CSSStyleDeclaration> 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
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue