From 9c05639d35d51f17397751ce3c5b4e7999a93ba4 Mon Sep 17 00:00:00 2001 From: Andreas Kling Date: Sat, 19 Feb 2022 17:34:05 +0100 Subject: [PATCH] LibWeb: Assign correct viewport dimensions when making style for ICB The ICB (initial containing block) gets its style from StyleComputer's create_document_style(). It's basically a generic style for the root of the layout tree. With this patch, we now assign the width and height of the viewport rect as two CSS "px" lengths to the "width" and "height" properties of the ICB style. (Previously they were just defaulting to "auto" and we assigned override dimensions during layout.) This fixes an issue where position:absolute elements with relative width and/or height were not dimensioned correctly, since the values were relative to the width and/or height of the ICB style. --- Userland/Libraries/LibWeb/CSS/StyleComputer.cpp | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/Userland/Libraries/LibWeb/CSS/StyleComputer.cpp b/Userland/Libraries/LibWeb/CSS/StyleComputer.cpp index d14fac4065..4129758f8e 100644 --- a/Userland/Libraries/LibWeb/CSS/StyleComputer.cpp +++ b/Userland/Libraries/LibWeb/CSS/StyleComputer.cpp @@ -937,6 +937,11 @@ NonnullRefPtr StyleComputer::create_document_style() const compute_font(style, nullptr); compute_defaulted_values(style, nullptr); absolutize_values(style, nullptr); + if (auto* browsing_context = m_document.browsing_context()) { + auto viewport_rect = browsing_context->viewport_rect(); + style->set_property(CSS::PropertyID::Width, CSS::LengthStyleValue::create(CSS::Length::make_px(viewport_rect.width()))); + style->set_property(CSS::PropertyID::Height, CSS::LengthStyleValue::create(CSS::Length::make_px(viewport_rect.height()))); + } return style; }