From c65d6964ea08485a903350b2e49389f0ec6384a1 Mon Sep 17 00:00:00 2001 From: Sam Atkins Date: Fri, 13 Oct 2023 17:44:36 +0100 Subject: [PATCH] LibWeb: Update layout if we lack a node when getting computed style As noted, there are two situations where an element will have no layout node here: 1. The element is invisible in a way that it generates no layout node. 2. We haven't built the layout yet. This protects against the second case, which would otherwise incorrectly send us down the path of looking directly at the computed style. --- .../expected/css/box-shadow-resolves-length-functions.txt | 2 +- .../Libraries/LibWeb/CSS/ResolvedCSSStyleDeclaration.cpp | 5 ++++- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/Tests/LibWeb/Text/expected/css/box-shadow-resolves-length-functions.txt b/Tests/LibWeb/Text/expected/css/box-shadow-resolves-length-functions.txt index 284f5c23fb3..c6350fa96ab 100644 --- a/Tests/LibWeb/Text/expected/css/box-shadow-resolves-length-functions.txt +++ b/Tests/LibWeb/Text/expected/css/box-shadow-resolves-length-functions.txt @@ -1 +1 @@ -0 calc(5px - 10px) 0 calc(2px + 3px) => #000000ff 0px calc(5px + (0 - 10px)) 0px calc(2px + 3px) +0 calc(5px - 10px) 0 calc(2px + 3px) => #000000ff 0px -5px 0px 5px diff --git a/Userland/Libraries/LibWeb/CSS/ResolvedCSSStyleDeclaration.cpp b/Userland/Libraries/LibWeb/CSS/ResolvedCSSStyleDeclaration.cpp index ed8f47e2721..3f99653111a 100644 --- a/Userland/Libraries/LibWeb/CSS/ResolvedCSSStyleDeclaration.cpp +++ b/Userland/Libraries/LibWeb/CSS/ResolvedCSSStyleDeclaration.cpp @@ -467,7 +467,10 @@ Optional ResolvedCSSStyleDeclaration::property(PropertyID propert if (!m_element->is_connected()) return {}; - if (property_affects_layout(property_id)) { + // 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 (!m_element->layout_node() || 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.