1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-05-31 11:28:12 +00:00

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.
This commit is contained in:
Andreas Kling 2022-02-19 17:34:05 +01:00
parent c9c55d86a4
commit 9c05639d35

View file

@ -937,6 +937,11 @@ NonnullRefPtr<StyleProperties> 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;
}