From 1667d6d4daa1becd14119281a2a2fb6009cbc5f0 Mon Sep 17 00:00:00 2001 From: Sam Atkins Date: Fri, 5 Sep 2025 14:22:00 +0100 Subject: [PATCH] LibWeb/CSS: Use AbstractElement in CSSStyleProperties::property() Avoids duplicating the "get layout node" logic. --- Libraries/LibWeb/CSS/CSSStyleProperties.cpp | 21 +++++++-------------- 1 file changed, 7 insertions(+), 14 deletions(-) diff --git a/Libraries/LibWeb/CSS/CSSStyleProperties.cpp b/Libraries/LibWeb/CSS/CSSStyleProperties.cpp index bddfb360f41..128ef065800 100644 --- a/Libraries/LibWeb/CSS/CSSStyleProperties.cpp +++ b/Libraries/LibWeb/CSS/CSSStyleProperties.cpp @@ -157,35 +157,28 @@ Optional CSSStyleProperties::property(PropertyID property_id) con if (!owner_node().has_value()) return {}; - auto& element = owner_node()->element(); - auto pseudo_element = owner_node()->pseudo_element(); + auto abstract_element = *owner_node(); // https://www.w3.org/TR/cssom-1/#dom-window-getcomputedstyle // NB: This is a partial enforcement of step 5 ("If elt is connected, ...") - if (!element.is_connected()) + if (!abstract_element.element().is_connected()) return {}; - auto get_layout_node = [&]() { - if (pseudo_element.has_value()) - return element.get_pseudo_element_node(pseudo_element.value()); - return element.layout_node(); - }; - - Layout::NodeWithStyle* layout_node = get_layout_node(); + Layout::NodeWithStyle* layout_node = abstract_element.layout_node(); // FIXME: Be smarter about updating layout if there's no layout node. // We may legitimately have no layout node if we're not visible, but this protects against situations // where we're requesting the computed style before layout has happened. if (!layout_node || property_affects_layout(property_id)) { - element.document().update_layout(DOM::UpdateLayoutReason::ResolvedCSSStyleDeclarationProperty); - layout_node = get_layout_node(); + abstract_element.document().update_layout(DOM::UpdateLayoutReason::ResolvedCSSStyleDeclarationProperty); + layout_node = abstract_element.layout_node(); } else { // FIXME: If we had a way to update style for a single element, this would be a good place to use it. - element.document().update_style(); + abstract_element.document().update_style(); } if (!layout_node) { - auto style = element.document().style_computer().compute_style(element, pseudo_element); + auto style = abstract_element.document().style_computer().compute_style(abstract_element.element(), abstract_element.pseudo_element()); return StyleProperty { .property_id = property_id,