1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-25 23:07:35 +00:00

LibWeb: Treat width:auto on tables as fit-content

Tables, unlike other block-level elements, should not stretch to fit
their containing block by default.
This commit is contained in:
Andreas Kling 2021-10-28 14:41:01 +02:00
parent 52a1be5eae
commit df3cd2fd56

View file

@ -29,6 +29,7 @@ void TableFormattingContext::run(Box& box, LayoutMode)
{
compute_width(box);
float total_content_width = 0;
float total_content_height = 0;
box.for_each_child_of_type<TableRowGroupBox>([&](auto& row_group_box) {
@ -41,20 +42,28 @@ void TableFormattingContext::run(Box& box, LayoutMode)
calculate_column_widths(row, column_widths);
});
float content_width = 0;
float content_height = 0;
row_group_box.template for_each_child_of_type<TableRowBox>([&](auto& row) {
row.set_offset(0, content_height);
layout_row(row, column_widths);
content_width = max(content_width, row.width());
content_height += row.height();
});
if (row_group_box.computed_values().width().is_auto())
row_group_box.set_width(content_width);
row_group_box.set_height(content_height);
row_group_box.set_offset(0, total_content_height);
total_content_height += content_height;
total_content_width = max(total_content_width, row_group_box.width());
});
if (box.computed_values().width().is_auto())
box.set_width(total_content_width);
// FIXME: This is a total hack, we should respect the 'height' property.
box.set_height(total_content_height);
}