瀏覽代碼

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.
Andreas Kling 3 年之前
父節點
當前提交
9c05639d35
共有 1 個文件被更改,包括 5 次插入0 次删除
  1. 5 0
      Userland/Libraries/LibWeb/CSS/StyleComputer.cpp

+ 5 - 0
Userland/Libraries/LibWeb/CSS/StyleComputer.cpp

@@ -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;
 }