Преглед изворни кода

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_font(style, nullptr);
     compute_defaulted_values(style, nullptr);
     compute_defaulted_values(style, nullptr);
     absolutize_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;
     return style;
 }
 }