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.
This commit is contained in:
Callum Law 2025-10-15 20:46:00 +13:00 committed by Tim Ledbetter
parent c23ed104e5
commit 29fb63c928
Notes: github-actions[bot] 2025-10-16 09:28:56 +00:00

View file

@ -142,8 +142,13 @@ Length::ResolutionContext Length::ResolutionContext::for_document(DOM::Document
auto const& initial_font = document.style_computer().initial_font(); auto const& initial_font = document.style_computer().initial_font();
Gfx::FontPixelMetrics const& initial_font_metrics = initial_font.pixel_metrics(); 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() }; 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 { return Length::ResolutionContext {
.viewport_rect = document.navigable()->viewport_rect(), .viewport_rect = viewport_rect,
.font_metrics = font_metrics, .font_metrics = font_metrics,
.root_font_metrics = font_metrics, .root_font_metrics = font_metrics,
}; };