From d7492927e9d48eb3593ab1ca0d645200651173e2 Mon Sep 17 00:00:00 2001 From: Andreas Kling Date: Sun, 20 Mar 2022 21:12:19 +0100 Subject: [PATCH] LibWeb: Avoid some layouts in getComputedStyle() property getter For CSS properties that are known to not affect layout, we can avoid doing a layout before returning their current resolved value. It should be enough to only update style for the target element here, but we don't currently have a mechanism for that. --- .../Libraries/LibWeb/CSS/ResolvedCSSStyleDeclaration.cpp | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/Userland/Libraries/LibWeb/CSS/ResolvedCSSStyleDeclaration.cpp b/Userland/Libraries/LibWeb/CSS/ResolvedCSSStyleDeclaration.cpp index 6caed5fd62..d22dfd120f 100644 --- a/Userland/Libraries/LibWeb/CSS/ResolvedCSSStyleDeclaration.cpp +++ b/Userland/Libraries/LibWeb/CSS/ResolvedCSSStyleDeclaration.cpp @@ -768,8 +768,12 @@ RefPtr ResolvedCSSStyleDeclaration::style_value_for_property(Layout: Optional ResolvedCSSStyleDeclaration::property(PropertyID property_id) const { - // FIXME: Only update layout if required to resolve the property we're accessing. - const_cast(m_element->document()).update_layout(); + if (CSS::property_affects_layout(property_id)) { + const_cast(m_element->document()).update_layout(); + } else { + // FIXME: If we had a way to update style for a single element, this would be a good place to use it. + const_cast(m_element->document()).update_style(); + } if (!m_element->layout_node()) { auto style = m_element->document().style_computer().compute_style(const_cast(*m_element));