Ver código fonte

LibWeb: Expose size calculation of BlockFormattingContext

This is a hack for the FlexFormattingContext
Tobias Christiansen 4 anos atrás
pai
commit
c51dbb4372

+ 16 - 9
Userland/Libraries/LibWeb/Layout/BlockFormattingContext.cpp

@@ -296,19 +296,11 @@ static float compute_auto_height_for_block_level_element(const Box& box)
     return bottom.value_or(0) - top.value_or(0);
 }
 
-void BlockFormattingContext::compute_height(Box& box)
+float BlockFormattingContext::compute_theoretical_height(const Box& box)
 {
     auto& computed_values = box.computed_values();
     auto& containing_block = *box.containing_block();
 
-    // First, resolve the top/bottom parts of the surrounding box model.
-    box.box_model().margin.top = computed_values.margin().top.resolved_or_zero(box, containing_block.width()).to_px(box);
-    box.box_model().margin.bottom = computed_values.margin().bottom.resolved_or_zero(box, containing_block.width()).to_px(box);
-    box.box_model().border.top = computed_values.border_top().width;
-    box.box_model().border.bottom = computed_values.border_bottom().width;
-    box.box_model().padding.top = computed_values.padding().top.resolved_or_zero(box, containing_block.width()).to_px(box);
-    box.box_model().padding.bottom = computed_values.padding().bottom.resolved_or_zero(box, containing_block.width()).to_px(box);
-
     // Then work out what the height is, based on box type and CSS properties.
     float height = 0;
     if (is<ReplacedBox>(box)) {
@@ -330,7 +322,22 @@ void BlockFormattingContext::compute_height(Box& box)
     if (!specified_min_height.is_auto()
         && !(computed_values.min_height().is_percentage() && !containing_block.computed_values().height().is_absolute()))
         height = max(height, specified_min_height.to_px(box));
+    return height;
+}
+
+void BlockFormattingContext::compute_height(Box& box)
+{
+    auto& computed_values = box.computed_values();
+    auto& containing_block = *box.containing_block();
+    // First, resolve the top/bottom parts of the surrounding box model.
+    box.box_model().margin.top = computed_values.margin().top.resolved_or_zero(box, containing_block.width()).to_px(box);
+    box.box_model().margin.bottom = computed_values.margin().bottom.resolved_or_zero(box, containing_block.width()).to_px(box);
+    box.box_model().border.top = computed_values.border_top().width;
+    box.box_model().border.bottom = computed_values.border_bottom().width;
+    box.box_model().padding.top = computed_values.padding().top.resolved_or_zero(box, containing_block.width()).to_px(box);
+    box.box_model().padding.bottom = computed_values.padding().bottom.resolved_or_zero(box, containing_block.width()).to_px(box);
 
+    auto height = compute_theoretical_height(box);
     box.set_height(height);
 }
 

+ 4 - 2
Userland/Libraries/LibWeb/Layout/BlockFormattingContext.h

@@ -24,9 +24,11 @@ public:
     const Vector<Box*>& left_floating_boxes() const { return m_left_floating_boxes; }
     const Vector<Box*>& right_floating_boxes() const { return m_right_floating_boxes; }
 
-protected:
+    static float compute_theoretical_height(const Box&);
     void compute_width(Box&);
-    void compute_height(Box&);
+
+protected:
+    static void compute_height(Box&);
     void compute_position(Box&);
 
 private: