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
parent 815e77c04d
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

@@ -291,6 +291,7 @@ size_t property_maximum_value_count(PropertyID);
bool property_affects_layout(PropertyID);
bool property_affects_stacking_context(PropertyID);
bool property_needs_layout_for_getcomputedstyle(PropertyID);
constexpr PropertyID first_property_id = PropertyID::@first_property_id@;
constexpr PropertyID last_property_id = PropertyID::@last_property_id@;
@@ -700,6 +701,32 @@ bool property_affects_stacking_context(PropertyID property_id)
}
}
bool property_needs_layout_for_getcomputedstyle(PropertyID property_id)
{
switch (property_id) {
)~~~");
properties.for_each_member([&](auto& name, auto& value) {
VERIFY(value.is_object());
if (is_legacy_alias(value.as_object()))
return;
if (value.as_object().get_bool("needs-layout-for-getcomputedstyle"sv).value_or(false)) {
auto member_generator = generator.fork();
member_generator.set("name:titlecase", title_casify(name));
member_generator.append(R"~~~(
case PropertyID::@name:titlecase@:
)~~~");
}
});
generator.append(R"~~~(
return true;
default:
return false;
}
}
NonnullRefPtr<StyleValue const> property_initial_value(PropertyID property_id)
{
static Array<RefPtr<StyleValue const>, to_underlying(last_property_id) + 1> initial_values;