From ce0fef7c452b4f1486b990f299138eba163007f7 Mon Sep 17 00:00:00 2001 From: Callum Law Date: Thu, 21 Aug 2025 00:18:49 +1200 Subject: [PATCH] LibWeb: Initialize properties before calling `compute_{math_depth|font}` `StyleComputer::create_document_style` was the only place this wasn't the case so we can remove the calls to `compute_defaulted_property_value`. The call to `compute_defaulted_values` in `create_document_style` is now redundant so has been removed` --- Libraries/LibWeb/CSS/StyleComputer.cpp | 28 +++++--------------------- 1 file changed, 5 insertions(+), 23 deletions(-) diff --git a/Libraries/LibWeb/CSS/StyleComputer.cpp b/Libraries/LibWeb/CSS/StyleComputer.cpp index 69c128ddbef..fe2392eb00e 100644 --- a/Libraries/LibWeb/CSS/StyleComputer.cpp +++ b/Libraries/LibWeb/CSS/StyleComputer.cpp @@ -2120,23 +2120,6 @@ RefPtr StyleComputer::compute_font_for_style_values( void StyleComputer::compute_font(ComputedProperties& style, DOM::Element const* element, Optional pseudo_element) const { - // To compute the font, first ensure that we've defaulted the relevant CSS font properties. - // FIXME: This should be more sophisticated. - compute_defaulted_property_value(style, element, CSS::PropertyID::FontFamily, pseudo_element); - compute_defaulted_property_value(style, element, CSS::PropertyID::FontSize, pseudo_element); - compute_defaulted_property_value(style, element, CSS::PropertyID::FontWidth, pseudo_element); - compute_defaulted_property_value(style, element, CSS::PropertyID::FontStyle, pseudo_element); - compute_defaulted_property_value(style, element, CSS::PropertyID::FontWeight, pseudo_element); - compute_defaulted_property_value(style, element, CSS::PropertyID::LineHeight, pseudo_element); - compute_defaulted_property_value(style, element, CSS::PropertyID::FontVariant, pseudo_element); - compute_defaulted_property_value(style, element, CSS::PropertyID::FontVariantAlternates, pseudo_element); - compute_defaulted_property_value(style, element, CSS::PropertyID::FontVariantCaps, pseudo_element); - compute_defaulted_property_value(style, element, CSS::PropertyID::FontVariantEmoji, pseudo_element); - compute_defaulted_property_value(style, element, CSS::PropertyID::FontVariantEastAsian, pseudo_element); - compute_defaulted_property_value(style, element, CSS::PropertyID::FontVariantLigatures, pseudo_element); - compute_defaulted_property_value(style, element, CSS::PropertyID::FontVariantNumeric, pseudo_element); - compute_defaulted_property_value(style, element, CSS::PropertyID::FontVariantPosition, pseudo_element); - auto const& font_family = style.property(CSS::PropertyID::FontFamily); auto const& font_size = style.property(CSS::PropertyID::FontSize); auto const& font_style = style.property(CSS::PropertyID::FontStyle); @@ -2465,9 +2448,13 @@ void StyleComputer::transform_box_type_if_needed(ComputedProperties& style, DOM: GC::Ref StyleComputer::create_document_style() const { auto style = document().heap().allocate(); + for (auto i = to_underlying(CSS::first_longhand_property_id); i <= to_underlying(CSS::last_longhand_property_id); ++i) { + auto property_id = static_cast(i); + style->set_property(property_id, property_initial_value(property_id)); + } + compute_math_depth(style, nullptr, {}); compute_font(style, nullptr, {}); - compute_defaulted_values(style, nullptr, {}); absolutize_values(style, nullptr); style->set_property(CSS::PropertyID::Width, CSS::LengthStyleValue::create(CSS::Length::make_px(viewport_rect().width()))); style->set_property(CSS::PropertyID::Height, CSS::LengthStyleValue::create(CSS::Length::make_px(viewport_rect().height()))); @@ -3237,11 +3224,6 @@ void StyleComputer::compute_math_depth(ComputedProperties& style, DOM::Element c { // https://w3c.github.io/mathml-core/#propdef-math-depth - // First, ensure that the relevant CSS properties have been defaulted. - // FIXME: This should be more sophisticated. - compute_defaulted_property_value(style, element, CSS::PropertyID::MathDepth, pseudo_element); - compute_defaulted_property_value(style, element, CSS::PropertyID::MathStyle, pseudo_element); - auto inherited_math_depth = [&]() { if (!element || !element->element_to_inherit_style_from(pseudo_element)) return InitialValues::math_depth();