From 29fb63c928efa723c047b96d4c57b54d4a028fec Mon Sep 17 00:00:00 2001 From: Callum Law Date: Wed, 15 Oct 2025 20:46:00 +1300 Subject: [PATCH] LibWeb: Support length resolution context for document lacking navigable Some documents (e.g. those created by DOMParser.parseFromString()) will not be associated with a navigable. These documents effectively have a viewport of 0x0. --- Libraries/LibWeb/CSS/Length.cpp | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/Libraries/LibWeb/CSS/Length.cpp b/Libraries/LibWeb/CSS/Length.cpp index 8c341a1e37c..acddf608b56 100644 --- a/Libraries/LibWeb/CSS/Length.cpp +++ b/Libraries/LibWeb/CSS/Length.cpp @@ -142,8 +142,13 @@ Length::ResolutionContext Length::ResolutionContext::for_document(DOM::Document auto const& initial_font = document.style_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() }; + CSSPixelRect viewport_rect; + + if (document.navigable()) + viewport_rect = document.navigable()->viewport_rect(); + return Length::ResolutionContext { - .viewport_rect = document.navigable()->viewport_rect(), + .viewport_rect = viewport_rect, .font_metrics = font_metrics, .root_font_metrics = font_metrics, };