Sfoglia il codice sorgente

LibWeb: Move rows heights calculation in separate function in TFC

Aliaksandr Kalenik 2 anni fa
parent
commit
7d2a72d748

+ 34 - 29
Userland/Libraries/LibWeb/Layout/TableFormattingContext.cpp

@@ -366,35 +366,8 @@ void TableFormattingContext::determine_intrisic_size_of_table_container(Availabl
     }
 }
 
-void TableFormattingContext::run(Box const& box, LayoutMode, AvailableSpace const& available_space)
+void TableFormattingContext::calculate_row_heights()
 {
-    m_available_space = available_space;
-
-    CSSPixels total_content_height = 0;
-
-    // Determine the number of rows/columns the table requires.
-    calculate_row_column_grid(box);
-
-    // Compute the minimum width of each column.
-    compute_table_measures();
-
-    if (available_space.width.is_intrinsic_sizing_constraint()) {
-        determine_intrisic_size_of_table_container(available_space);
-        return;
-    }
-
-    // Compute the width of the table.
-    compute_table_width();
-
-    // Distribute the width of the table among columns.
-    distribute_width_to_columns();
-
-    CSSPixels left_column_offset = 0;
-    for (auto& column : m_columns) {
-        column.left_offset = left_column_offset;
-        left_column_offset += column.used_width;
-    }
-
     for (auto& cell : m_cells) {
         auto& cell_state = m_state.get_mutable(cell.box);
 
@@ -422,7 +395,7 @@ void TableFormattingContext::run(Box const& box, LayoutMode, AvailableSpace cons
         cell_state.border_right = (should_hide_borders && is_right_most_cell) ? 0 : cell.box.computed_values().border_right().width;
 
         cell_state.set_content_width((span_width - cell_state.border_box_left() - cell_state.border_box_right()));
-        auto independent_formatting_context = layout_inside(cell.box, LayoutMode::Normal, cell_state.available_inner_space_or_constraints_from(available_space));
+        auto independent_formatting_context = layout_inside(cell.box, LayoutMode::Normal, cell_state.available_inner_space_or_constraints_from(*m_available_space));
         VERIFY(independent_formatting_context);
         cell_state.set_content_height(independent_formatting_context->automatic_content_height());
         independent_formatting_context->parent_context_did_dimension_child_root_box();
@@ -433,6 +406,38 @@ void TableFormattingContext::run(Box const& box, LayoutMode, AvailableSpace cons
         row.used_width = max(row.used_width, cell_state.border_box_height());
         row.baseline = max(row.baseline, cell.baseline);
     }
+}
+
+void TableFormattingContext::run(Box const& box, LayoutMode, AvailableSpace const& available_space)
+{
+    m_available_space = available_space;
+
+    CSSPixels total_content_height = 0;
+
+    // Determine the number of rows/columns the table requires.
+    calculate_row_column_grid(box);
+
+    // Compute the minimum width of each column.
+    compute_table_measures();
+
+    if (available_space.width.is_intrinsic_sizing_constraint()) {
+        determine_intrisic_size_of_table_container(available_space);
+        return;
+    }
+
+    // Compute the width of the table.
+    compute_table_width();
+
+    // Distribute the width of the table among columns.
+    distribute_width_to_columns();
+
+    CSSPixels left_column_offset = 0;
+    for (auto& column : m_columns) {
+        column.left_offset = left_column_offset;
+        left_column_offset += column.used_width;
+    }
+
+    calculate_row_heights();
 
     CSSPixels row_top_offset = 0.0f;
     for (size_t y = 0; y < m_rows.size(); y++) {

+ 1 - 0
Userland/Libraries/LibWeb/Layout/TableFormattingContext.h

@@ -25,6 +25,7 @@ private:
     void compute_table_width();
     void distribute_width_to_columns();
     void determine_intrisic_size_of_table_container(AvailableSpace const& available_space);
+    void calculate_row_heights();
 
     CSSPixels m_automatic_content_height { 0 };