浏览代码

LibWeb: Move initial containing block setup out of BFC

BFC currently has a number of architectural issues due to it being
responsible for setting the dimensions of the BFC root.

This patch moves the logic for setting up the ICB from BFC to Document.
Andreas Kling 3 年之前
父节点
当前提交
40bd2cb611

+ 5 - 0
Userland/Libraries/LibWeb/DOM/Document.cpp

@@ -405,6 +405,8 @@ void Document::update_layout()
     if (!browsing_context())
         return;
 
+    auto viewport_rect = browsing_context()->viewport_rect();
+
     update_style();
 
     if (!m_layout_root) {
@@ -413,6 +415,9 @@ void Document::update_layout()
     }
 
     Layout::BlockFormattingContext root_formatting_context(*m_layout_root, nullptr);
+    m_layout_root->build_stacking_context_tree();
+    m_layout_root->set_content_size(viewport_rect.size().to_type<float>());
+
     root_formatting_context.run(*m_layout_root, Layout::LayoutMode::Default);
 
     m_layout_root->set_needs_display();

+ 0 - 4
Userland/Libraries/LibWeb/Layout/BlockFormattingContext.cpp

@@ -532,10 +532,6 @@ void BlockFormattingContext::layout_initial_containing_block(LayoutMode layout_m
     auto viewport_rect = root().browsing_context().viewport_rect();
 
     auto& icb = verify_cast<Layout::InitialContainingBlock>(root());
-    icb.build_stacking_context_tree();
-
-    icb.set_content_width(viewport_rect.width());
-    icb.set_content_height(viewport_rect.height());
 
     VERIFY(!icb.children_are_inline());
     layout_block_level_children(root(), layout_mode);