From df3cd2fd569a880d918bb52dd850846f8fca539a Mon Sep 17 00:00:00 2001 From: Andreas Kling Date: Thu, 28 Oct 2021 14:41:01 +0200 Subject: [PATCH] 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. --- .../Libraries/LibWeb/Layout/TableFormattingContext.cpp | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/Userland/Libraries/LibWeb/Layout/TableFormattingContext.cpp b/Userland/Libraries/LibWeb/Layout/TableFormattingContext.cpp index b577eb4459..85d4396bcd 100644 --- a/Userland/Libraries/LibWeb/Layout/TableFormattingContext.cpp +++ b/Userland/Libraries/LibWeb/Layout/TableFormattingContext.cpp @@ -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([&](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([&](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); }