Truly independent web browser
LibWeb: Resolve initial line-height units from font metrics
Andreas Klingfe8c60fbcd47
diff --git a/Libraries/LibWeb/CSS/Length.cpp b/Libraries/LibWeb/CSS/Length.cppindex 90caee7bc16..3f7bc4078ba 100644--- a/Libraries/LibWeb/CSS/Length.cpp+++ b/Libraries/LibWeb/CSS/Length.cpp@@ -11,6 +11,7 @@#include <LibGC/Cell.h>#include <LibGfx/Font/Font.h>#include <LibGfx/Rect.h>+#include <LibWeb/CSS/ComputedStyleWorkingSet.h>#include <LibWeb/CSS/ComputedValues.h>#include <LibWeb/CSS/FontComputer.h>#include <LibWeb/CSS/Length.h>@@ -254,7 +255,10 @@ Length::ResolutionContext Length::ResolutionContext::for_document(DOM::Document{auto const& initial_font = document.font_computer().initial_font();Gfx::FontPixelMetrics const& initial_font_metrics = initial_font.pixel_metrics();- Length::FontMetrics font_metrics { CSSPixels { initial_font.pixel_size() }, initial_font_metrics, InitialValues::line_height() };+ // https://drafts.csswg.org/css-values-4/#font-relative-lengths+ // When used outside the context of an element (such as in media queries), the font-relative lengths units refer+ // to the metrics corresponding to the initial values of the font and line-height properties.+ Length::FontMetrics font_metrics { CSSPixels { initial_font.pixel_size() }, initial_font_metrics, normal_line_height(initial_font_metrics) };CSSPixelRect viewport_rect;if (document.navigable())diff --git a/Libraries/LibWeb/CSS/StyleComputer.cpp b/Libraries/LibWeb/CSS/StyleComputer.cppindex 72006b9e03f..15b62c1bfb9 100644--- a/Libraries/LibWeb/CSS/StyleComputer.cpp+++ b/Libraries/LibWeb/CSS/StyleComputer.cpp@@ -158,7 +158,7 @@ static RustDeclarationBlock const& declaration_of_rule(CSSRule const& rule)StyleComputer::StyleComputer(DOM::Document& document): m_document(document)- , m_default_font_metrics(16, Platform::FontPlugin::the().default_font(16)->pixel_metrics(), InitialValues::line_height())+ , m_default_font_metrics(16, Platform::FontPlugin::the().default_font(16)->pixel_metrics(), normal_line_height(Platform::FontPlugin::the().default_font(16)->pixel_metrics())), m_root_element_font_metrics(m_default_font_metrics), m_style_engine(this){@@ -2019,7 +2019,7 @@ ComputationContext StyleComputer::make_computation_context_for_property(Layout::auto line_height_font_metrics = Length::FontMetrics {style.font_size(),style.first_available_computed_font(document().font_computer())->pixel_metrics(),- inheritance_parent.has_value() && inheritance_parent->has_style() ? inheritance_parent->computed_style()->line_height() : InitialValues::line_height()+ inheritance_parent.has_value() && inheritance_parent->has_style() ? inheritance_parent->computed_style()->line_height() : normal_line_height(document().font_computer().initial_font().pixel_metrics())};return {diff --git a/Libraries/LibWeb/CSS/StyleEngineBridge.cpp b/Libraries/LibWeb/CSS/StyleEngineBridge.cppindex a790678650e..72068c24a31 100644--- a/Libraries/LibWeb/CSS/StyleEngineBridge.cpp+++ b/Libraries/LibWeb/CSS/StyleEngineBridge.cpp@@ -7,6 +7,7 @@#include <AK/HashTable.h>#include <AK/StdLibExtras.h>#include <AK/Time.h>+#include <LibWeb/CSS/ComputedStyleWorkingSet.h>#include <LibWeb/CSS/FontComputer.h>#include <LibWeb/CSS/FontResolution.h>#include <LibWeb/CSS/RustDeclarationBlock.h>@@ -608,7 +609,7 @@ void StyleEngine::gather_computation_inputs(LentComputationInputs& lent)}auto const& root_font_metrics = m_style_computer->root_element_font_metrics();auto const& initial_font = m_style_computer->document().font_computer().initial_font();- Length::FontMetrics const initial_font_metrics { CSSPixels { initial_font.pixel_size() }, initial_font.pixel_metrics(), InitialValues::line_height() };+ Length::FontMetrics const initial_font_metrics { CSSPixels { initial_font.pixel_size() }, initial_font.pixel_metrics(), normal_line_height(initial_font.pixel_metrics()) };lent.inputs = {.in_quirks_mode = m_style_computer->document().in_quirks_mode(),.viewport_width = viewport_rect.width().to_double(),@@ -624,6 +625,7 @@ void StyleEngine::gather_computation_inputs(LentComputationInputs& lent).initial_font_x_height = initial_font_metrics.x_height.to_double(),.initial_font_cap_height = initial_font_metrics.cap_height.to_double(),.initial_font_zero_advance = initial_font_metrics.zero_advance.to_double(),+ .initial_line_height = initial_font_metrics.line_height.to_double(),.initial_font_size_raw = InitialValues::font_size().raw_value(),.default_font_size_raw = StyleComputer::default_user_font_size().raw_value(),.device_pixels_per_css_pixel = m_style_computer->document().page().client().device_pixels_per_css_pixel(),diff --git a/Libraries/LibWeb/Rust/src/css/style/bridge.rs b/Libraries/LibWeb/Rust/src/css/style/bridge.rsindex fd679a26279..2d4c9a9f8f3 100644--- a/Libraries/LibWeb/Rust/src/css/style/bridge.rs+++ b/Libraries/LibWeb/Rust/src/css/style/bridge.rs@@ -312,6 +312,7 @@ pub struct FfiDocumentStyleComputationInputs {pub initial_font_x_height: f64,pub initial_font_cap_height: f64,pub initial_font_zero_advance: f64,+ pub initial_line_height: f64,pub initial_font_size_raw: i32,pub default_font_size_raw: i32,pub device_pixels_per_css_pixel: f64,@@ -407,6 +408,7 @@ impl Default for FfiDocumentStyleComputationInputs {initial_font_x_height: 0.0,initial_font_cap_height: 0.0,initial_font_zero_advance: 0.0,+ initial_line_height: 0.0,initial_font_size_raw: 0,default_font_size_raw: 0,device_pixels_per_css_pixel: 0.0,diff --git a/Libraries/LibWeb/Rust/src/css/style/publication/drive.rs b/Libraries/LibWeb/Rust/src/css/style/publication/drive.rsindex 588feeda108..5e2b6623c2d 100644--- a/Libraries/LibWeb/Rust/src/css/style/publication/drive.rs+++ b/Libraries/LibWeb/Rust/src/css/style/publication/drive.rs@@ -289,12 +289,12 @@ impl RetainedState {else {return Some(MonospaceRecascade::AwaitsFont(request));};- // The ancestor's own font is the one being recascaded; its line height is the one it- // inherits, and the initial one is zero.+ // NB: The ancestor's own font is the one being recascaded; its line height is the one it+ // inherits, or the initial font's normal line height when there is no parent.let (line_height, inherited_font_metrics_depend_on_viewport_metrics) = index.checked_sub(1).and_then(|parent| views[parent].1.as_ref())- .map_or((0.0, false), |view| {+ .map_or((inputs.initial_line_height, false), |view| {let font = unsafe {view.payloads[STYLE_GROUP_INDEX_FONT].cast::<crate::css::computed_value_types::FontValues>()@@ -797,7 +797,7 @@ impl RetainedState {x_height: inputs.initial_font_x_height,cap_height: inputs.initial_font_cap_height,zero_advance: inputs.initial_font_zero_advance,- line_height: 0.0,+ line_height: inputs.initial_line_height,};let (parent_metrics, parent_font_metrics_depend_on_viewport_metrics, parent_line_height_used) =match &parent_view {@@ -819,7 +819,7 @@ impl RetainedState {parent_font.line_height_used.to_double(),)}- None => (initial_metrics, false, 0.0),+ None => (initial_metrics, false, inputs.initial_line_height),};let snapshot = match &parent_view {Some(parent_view) => {diff --git a/Tests/LibWeb/Text/expected/wpt-import/css/css-values/lh-rlh-on-root-001.txt b/Tests/LibWeb/Text/expected/wpt-import/css/css-values/lh-rlh-on-root-001.txtindex 02c5fe684c8..30544ed2b0c 100644--- a/Tests/LibWeb/Text/expected/wpt-import/css/css-values/lh-rlh-on-root-001.txt+++ b/Tests/LibWeb/Text/expected/wpt-import/css/css-values/lh-rlh-on-root-001.txt@@ -2,12 +2,12 @@ Harness status: OKFound 8 tests-8 Fail-Fail lh in line-height on root-Fail rlh in line-height on root-Fail lh in font-size on root-Fail rlh in font-size on root-Fail 2lh in line-height on root-Fail 2rlh in line-height on root-Fail 2lh in font-size on root-Fail 2rlh in font-size on root\ No newline at end of file+8 Pass+Pass lh in line-height on root+Pass rlh in line-height on root+Pass lh in font-size on root+Pass rlh in font-size on root+Pass 2lh in line-height on root+Pass 2rlh in line-height on root+Pass 2lh in font-size on root+Pass 2rlh in font-size on root\ No newline at end of file