Repository: LadybirdBrowser/ladybird
File: Libraries/LibWeb/CSS/StyleComputer.cpp (C++)

Code before:
        VERIFY(font_size_value->is_length());

        auto inherited_line_height = ancestor.element_to_inherit_style_from().map([](auto&& parent_element) { return parent_element.computed_properties()->line_height(); }).value_or(InitialValues::line_height());

        current_size_in_px = font_size_value->as_length().length().to_px(viewport_rect(), Length::FontMetrics { current_size_in_px, monospace_font->with_size(current_size_in_px * 0.75f)->pixel_metrics(), inherited_line_height }, m_root_element_font_metrics);
    };

    return CSS::LengthStyleValue::create(CSS::Length::make_px(current_size_in_px));
}

GC::Ref<ComputedProperties> StyleComputer::compute_properties(DOM::AbstractElement abstract_element, CascadedProperties& cascaded_properties) const
{
    auto computed_style = document().heap().allocate<CSS::ComputedProperties>();

    auto new_font_size = recascade_font_size_if_needed(abstract_element, cascaded_properties);
    if (new_font_size)
        computed_style->set_property(PropertyID::FontSize, *new_font_size, ComputedProperties::Inherited::No, Important::No);

    for (auto i = to_underlying(first_longhand_property_id); i <= to_underlying(last_longhand_property_id); ++i) {
        auto property_id = static_cast<CSS::PropertyID>(i);
        auto value = cascaded_properties.property(property_id);
        auto inherited = ComputedProperties::Inherited::No;
        auto important = Important::No;

        if (value)
            important = cascaded_properties.is_property_important(property_id) ? Important::Yes : Important::No;

        // NOTE: We've already handled font-size above.
        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);

        // https://www.w3.org/TR/css-color-4/#resolving-other-colors
        // In the color property, the used value of currentcolor is the resolved inherited value.
        should_inherit |= property_id == PropertyID::Color && value && value->to_keyword() == Keyword::Currentcolor;

        // FIXME: Logical properties should inherit from their parent's equivalent unmapped logical property.
        if (should_inherit) {
            inherited = ComputedProperties::Inherited::Yes;
            value = get_non_animated_inherit_value(property_id, abstract_element);

            if (auto animated_value = get_animated_inherit_value(property_id, abstract_element); animated_value.has_value())

Review comment (suggestion):
Instead of this, could we add a `CascadedProperties` API that returns both the value and the important flag using a single lookup? :)

Code after:
        VERIFY(font_size_value->is_length());

        auto inherited_line_height = ancestor.element_to_inherit_style_from().map([](auto&& parent_element) { return parent_element.computed_properties()->line_height(); }).value_or(InitialValues::line_height());

        current_size_in_px = font_size_value->as_length().length().to_px(viewport_rect(), Length::FontMetrics { current_size_in_px, monospace_font->with_size(current_size_in_px * 0.75f)->pixel_metrics(), inherited_line_height }, m_root_element_font_metrics);
    };

    return CSS::LengthStyleValue::create(CSS::Length::make_px(current_size_in_px));
}

GC::Ref<ComputedProperties> StyleComputer::compute_properties(DOM::AbstractElement abstract_element, CascadedProperties& cascaded_properties) const
{
    auto computed_style = document().heap().allocate<CSS::ComputedProperties>();

    auto new_font_size = recascade_font_size_if_needed(abstract_element, cascaded_properties);
    if (new_font_size)
        computed_style->set_property(PropertyID::FontSize, *new_font_size, ComputedProperties::Inherited::No, Important::No);

    for (auto i = to_underlying(first_longhand_property_id); i <= to_underlying(last_longhand_property_id); ++i) {
        auto property_id = static_cast<CSS::PropertyID>(i);
        auto inherited = ComputedProperties::Inherited::No;
        RefPtr<StyleValue const> value;
        auto important = Important::No;

        if (auto cascaded_style_property = cascaded_properties.style_property(property_id); cascaded_style_property.has_value()) {
            important = cascaded_style_property->important;
            value = cascaded_style_property->value;
        }

        // NOTE: We've already handled font-size above.
        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);

        // https://www.w3.org/TR/css-color-4/#resolving-other-colors
        // In the color property, the used value of currentcolor is the resolved inherited value.
        should_inherit |= property_id == PropertyID::Color && value && value->to_keyword() == Keyword::Currentcolor;

        // FIXME: Logical properties should inherit from their parent's equivalent unmapped logical property.
        if (should_inherit) {
            inherited = ComputedProperties::Inherited::Yes;
            value = get_non_animated_inherit_value(property_id, abstract_element);