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.
This commit is contained in:
Callum Law 2025-08-20 16:42:45 +12:00 committed by Jelle Raaijmakers
commit ca9cb42ed4
Notes: github-actions[bot] 2025-08-21 11:50:50 +00:00

View file

@ -2674,23 +2674,26 @@ GC::Ref<ComputedProperties> 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 propertys 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);