From ca9cb42ed465e96e1ec6a4bc8d953eb69e6dc396 Mon Sep 17 00:00:00 2001 From: Callum Law Date: Wed, 20 Aug 2025 16:42:45 +1200 Subject: [PATCH] LibWeb: Handle `unset` immediately in `compute_properties` Previously we would hand off to `compute_defaulted_properties` to resolve these values but there is no need as we can just resolve them immediately. --- Libraries/LibWeb/CSS/StyleComputer.cpp | 21 ++++++++++++--------- 1 file changed, 12 insertions(+), 9 deletions(-) diff --git a/Libraries/LibWeb/CSS/StyleComputer.cpp b/Libraries/LibWeb/CSS/StyleComputer.cpp index 750110b744d..9f12e29fc20 100644 --- a/Libraries/LibWeb/CSS/StyleComputer.cpp +++ b/Libraries/LibWeb/CSS/StyleComputer.cpp @@ -2674,23 +2674,26 @@ GC::Ref StyleComputer::compute_properties(DOM::Element& elem if (property_id == PropertyID::FontSize && !value && new_font_size) continue; + bool should_inherit = (!value && is_inherited_property(property_id)); + + // https://www.w3.org/TR/css-cascade-4/#inherit + // If the cascaded value of a property is the inherit keyword, the property’s specified and computed values are the inherited value. + should_inherit |= value && value->is_inherit(); + + // https://www.w3.org/TR/css-cascade-4/#inherit-initial + // If the cascaded value of a property is the unset keyword, then if it is an inherited property, this is treated as inherit, and if it is not, this is treated as initial. + should_inherit |= value && value->is_unset() && is_inherited_property(property_id); + // FIXME: Logical properties should inherit from their parent's equivalent unmapped logical property. - if ((!value && is_inherited_property(property_id)) || (value && value->is_inherit())) { + if (should_inherit) { value = get_inherit_value(property_id, &element, pseudo_element); animated_value = get_animated_inherit_value(property_id, &element, pseudo_element); inherited = ComputedProperties::Inherited::Yes; } - if (!value || value->is_initial()) + if (!value || value->is_initial() || value->is_unset()) value = property_initial_value(property_id); - if (value->is_unset()) { - if (is_inherited_property(property_id)) - value = KeywordStyleValue::create(Keyword::Inherit); - else - value = KeywordStyleValue::create(Keyword::Initial); - } - computed_style->set_property(property_id, value.release_nonnull(), inherited); if (animated_value.has_value()) computed_style->set_animated_property(property_id, animated_value.value(), inherited);