LibWeb: Distribute the width of a table cell spanning multiple columns

This commit is contained in:
Simon Wanner 2022-03-28 14:39:37 +02:00 committed by Andreas Kling
parent 4fe154bd6a
commit 9b3229da17
Notes: sideshowbarker 2024-07-17 16:37:53 +09:00

View file

@ -91,9 +91,26 @@ void TableFormattingContext::calculate_column_widths(Box const& row, Vector<floa
} else {
(void)layout_inside(cell, LayoutMode::Normal);
}
column_widths[column_index] = max(column_widths[column_index], cell_state.border_box_width());
if (cell.colspan() == 1)
column_widths[column_index] = max(column_widths[column_index], cell_state.border_box_width());
column_index += cell.colspan();
});
column_index = 0;
row.for_each_child_of_type<TableCellBox>([&](auto& cell) {
auto& cell_state = m_state.get_mutable(cell);
size_t colspan = cell.colspan();
if (colspan != 1) {
float missing = cell_state.border_box_width();
for (size_t i = 0; i < colspan; ++i)
missing -= column_widths[column_index + i];
if (missing > 0) {
float extra = missing / (float)colspan;
for (size_t i = 0; i < colspan; ++i)
column_widths[column_index + i] += extra;
}
}
column_index += colspan;
});
}
void TableFormattingContext::layout_row(Box const& row, Vector<float>& column_widths)