summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSimon Wanner <skyrising@pvpctutorials.de>2022-03-28 18:42:49 +0200
committerAndreas Kling <kling@serenityos.org>2022-03-29 00:39:57 +0200
commitb92cc3670b530a7c3659266b2e57dab0541ea2f7 (patch)
tree6afcffcc3fc9b391fd5f88c608e53c3a671ca7b3
parent3d0178a2f700500122be2d59f6747bbdddf39d90 (diff)
downloadserenity-b92cc3670b530a7c3659266b2e57dab0541ea2f7.zip
LibWeb: Only size `width: auto` table-cells by min-content
-rw-r--r--Userland/Libraries/LibWeb/Layout/TableFormattingContext.cpp12
-rw-r--r--Userland/Libraries/LibWeb/Layout/TableFormattingContext.h2
2 files changed, 8 insertions, 6 deletions
diff --git a/Userland/Libraries/LibWeb/Layout/TableFormattingContext.cpp b/Userland/Libraries/LibWeb/Layout/TableFormattingContext.cpp
index c52af0c050..a13f6b7c8e 100644
--- a/Userland/Libraries/LibWeb/Layout/TableFormattingContext.cpp
+++ b/Userland/Libraries/LibWeb/Layout/TableFormattingContext.cpp
@@ -28,6 +28,7 @@ void TableFormattingContext::run(Box const& box, LayoutMode)
auto& box_state = m_state.get_mutable(box);
compute_width(box);
+ auto table_width = CSS::Length::make_px(box_state.content_width);
float total_content_width = 0;
float total_content_height = 0;
@@ -41,7 +42,7 @@ void TableFormattingContext::run(Box const& box, LayoutMode)
column_widths.resize(column_count);
row_group_box.template for_each_child_of_type<TableRowBox>([&](auto& row) {
- calculate_column_widths(row, column_widths);
+ calculate_column_widths(row, table_width, column_widths);
});
float missing_width = box_state.content_width;
@@ -77,15 +78,16 @@ void TableFormattingContext::run(Box const& box, LayoutMode)
box_state.content_height = total_content_height;
}
-void TableFormattingContext::calculate_column_widths(Box const& row, Vector<float>& column_widths)
+void TableFormattingContext::calculate_column_widths(Box const& row, CSS::Length const& table_width, Vector<float>& column_widths)
{
m_state.get_mutable(row);
size_t column_index = 0;
- auto* table = row.first_ancestor_of_type<TableBox>();
- bool use_auto_layout = !table || (!table->computed_values().width().has_value() || (table->computed_values().width()->is_length() && table->computed_values().width()->length().is_auto()));
+ bool use_auto_layout = table_width.is_auto();
row.for_each_child_of_type<TableCellBox>([&](auto& cell) {
auto& cell_state = m_state.get_mutable(cell);
- compute_width(cell, LayoutMode::MinContent);
+ auto const& computed_values = cell.computed_values();
+ auto specified_width = computed_values.width().has_value() ? computed_values.width()->resolved(cell, table_width).resolved(cell) : CSS::Length::make_auto();
+ compute_width(cell, specified_width.is_auto() ? LayoutMode::MinContent : LayoutMode::Normal);
if (use_auto_layout) {
(void)layout_inside(cell, LayoutMode::MaxContent);
} else {
diff --git a/Userland/Libraries/LibWeb/Layout/TableFormattingContext.h b/Userland/Libraries/LibWeb/Layout/TableFormattingContext.h
index 39955ad0b9..7d22e99b1d 100644
--- a/Userland/Libraries/LibWeb/Layout/TableFormattingContext.h
+++ b/Userland/Libraries/LibWeb/Layout/TableFormattingContext.h
@@ -19,7 +19,7 @@ public:
virtual void run(Box const&, LayoutMode) override;
private:
- void calculate_column_widths(Box const& row, Vector<float>& column_widths);
+ void calculate_column_widths(Box const& row, CSS::Length const& table_width, Vector<float>& column_widths);
void layout_row(Box const& row, Vector<float>& column_widths);
};