From ed947940d7030bf1143fbf78b84e07af625969ee Mon Sep 17 00:00:00 2001 From: Callum Law Date: Mon, 25 Aug 2025 15:09:12 +1200 Subject: [PATCH] LibWeb: Simplify conversion of percentage line-height to absolute length We can take advantage of the fact that we already do this in `compute_line_height`. --- Libraries/LibWeb/CSS/StyleComputer.cpp | 10 +--------- 1 file changed, 1 insertion(+), 9 deletions(-) diff --git a/Libraries/LibWeb/CSS/StyleComputer.cpp b/Libraries/LibWeb/CSS/StyleComputer.cpp index a6b48ccd78b..11e24ee11fd 100644 --- a/Libraries/LibWeb/CSS/StyleComputer.cpp +++ b/Libraries/LibWeb/CSS/StyleComputer.cpp @@ -2143,21 +2143,13 @@ void StyleComputer::absolutize_values(ComputedProperties& style) const style.first_available_computed_font().pixel_metrics() }; - // NOTE: Percentage line-height values are relative to the font-size of the element. - // We have to resolve them right away, so that the *computed* line-height is ready for inheritance. - // We can't simply absolutize *all* percentage values against the font size, - // because most percentages are relative to containing block metrics. auto& line_height_value_slot = style.m_property_values[to_underlying(CSS::PropertyID::LineHeight)]; - if (line_height_value_slot && line_height_value_slot->is_percentage()) { - line_height_value_slot = LengthStyleValue::create( - Length::make_px(CSSPixels::nearest_value_for(style.font_size() * static_cast(line_height_value_slot->as_percentage().percentage().as_fraction())))); - } auto line_height = style.compute_line_height(viewport_rect(), font_metrics, m_root_element_font_metrics); font_metrics.line_height = line_height; // NOTE: line-height might be using lh which should be resolved against the parent line height (like we did here already) - if (line_height_value_slot && line_height_value_slot->is_length()) + if (line_height_value_slot && (line_height_value_slot->is_length() || line_height_value_slot->is_percentage())) line_height_value_slot = LengthStyleValue::create(Length::make_px(line_height)); for (size_t i = 0; i < style.m_property_values.size(); ++i) {