LibWeb: Require layout update for less properties in getComputedStyle()

Some properties like `justify-items`, `grid`, or `display` do affect
layout, but their used values can be obtained without performing a
layout calculation.

This change introduces a new helper,
`property_needs_layout_for_getcomputedstyle()`, specifically for use by
`CSSStyleProperties::property()`. It returns true only for properties
such as `width`, `height`, `margin`, `padding`, `top`, and `left`, where
an up-to-date layout is required to return the correct used value.
This commit is contained in:
Aliaksandr Kalenik 2025-09-11 00:51:00 +02:00 committed by Andreas Kling
commit db5fd614ac
Notes: github-actions[bot] 2025-09-12 09:07:24 +00:00
4 changed files with 135 additions and 54 deletions

View file

@ -169,7 +169,7 @@ Optional<StyleProperty> CSSStyleProperties::property(PropertyID property_id) con
// 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)) {
if (!layout_node || property_needs_layout_for_getcomputedstyle(property_id)) {
abstract_element.document().update_layout(DOM::UpdateLayoutReason::ResolvedCSSStyleDeclarationProperty);
layout_node = abstract_element.layout_node();
} else {