diff --git a/Tests/LibWeb/Layout/expected/table/stretch-to-fixed-height.txt b/Tests/LibWeb/Layout/expected/table/stretch-to-fixed-height.txt new file mode 100644 index 0000000000..423d362fc4 --- /dev/null +++ b/Tests/LibWeb/Layout/expected/table/stretch-to-fixed-height.txt @@ -0,0 +1,11 @@ +Viewport <#document> at (0,0) content-size 800x600 children: not-inline + BlockContainer at (0,0) content-size 800x600 [BFC] children: not-inline + BlockContainer at (8,8) content-size 784x122 children: not-inline + TableWrapper <(anonymous)> at (8,8) content-size 0x122 [BFC] children: not-inline + Box at (19,19) content-size 0x100 table-box [TFC] children: not-inline + BlockContainer <(anonymous)> (not painted) children: inline + TextNode <#text> + Box at (19,19) content-size 0x0 table-row-group children: not-inline + Box at (21,31) content-size 0x0 table-row children: not-inline + BlockContainer <(anonymous)> (not painted) children: inline + TextNode <#text> diff --git a/Tests/LibWeb/Layout/input/table/stretch-to-fixed-height.html b/Tests/LibWeb/Layout/input/table/stretch-to-fixed-height.html new file mode 100644 index 0000000000..08a4b5e191 --- /dev/null +++ b/Tests/LibWeb/Layout/input/table/stretch-to-fixed-height.html @@ -0,0 +1,10 @@ + +
+ +
\ No newline at end of file diff --git a/Userland/Libraries/LibWeb/Layout/TableFormattingContext.cpp b/Userland/Libraries/LibWeb/Layout/TableFormattingContext.cpp index 61f7e1398e..10fcf923c0 100644 --- a/Userland/Libraries/LibWeb/Layout/TableFormattingContext.cpp +++ b/Userland/Libraries/LibWeb/Layout/TableFormattingContext.cpp @@ -699,9 +699,12 @@ void TableFormattingContext::distribute_height_to_rows() row.final_height = row.reference_height + increment; } } + + // Add undistributable space due to border spacing: https://www.w3.org/TR/css-tables-3/#computing-undistributable-space. + m_table_height += (m_rows.size() + 1) * border_spacing_vertical(); } -void TableFormattingContext::position_row_boxes(CSSPixels& total_content_height) +void TableFormattingContext::position_row_boxes() { auto const& table_state = m_state.get(table_box()); @@ -744,10 +747,11 @@ void TableFormattingContext::position_row_boxes(CSSPixels& total_content_height) row_group_top_offset += row_group_height; }); - total_content_height = max(row_top_offset, row_group_top_offset) - table_state.offset.y() - table_state.padding_top; + auto total_content_height = max(row_top_offset, row_group_top_offset) - table_state.offset.y() - table_state.padding_top; // The height of a table is the sum of the row heights plus any cell spacing or borders. // Note that we've already added one vertical border-spacing to row_top_offset, so it's sufficient to multiply it by row count here. total_content_height += m_rows.size() * border_spacing_vertical(); + m_table_height = max(total_content_height, m_table_height); } void TableFormattingContext::position_cell_boxes() @@ -966,8 +970,6 @@ void TableFormattingContext::run(Box const& box, LayoutMode layout_mode, Availab auto total_captions_height = run_caption_layout(layout_mode, CSS::CaptionSide::Top); - CSSPixels total_content_height = 0; - // Determine the number of rows/columns the table requires. calculate_row_column_grid(box); @@ -999,10 +1001,10 @@ void TableFormattingContext::run(Box const& box, LayoutMode layout_mode, Availab distribute_height_to_rows(); - position_row_boxes(total_content_height); + position_row_boxes(); position_cell_boxes(); - m_state.get_mutable(table_box()).set_content_height(total_content_height); + m_state.get_mutable(table_box()).set_content_height(m_table_height); total_captions_height += run_caption_layout(layout_mode, CSS::CaptionSide::Bottom); @@ -1011,8 +1013,7 @@ void TableFormattingContext::run(Box const& box, LayoutMode layout_mode, Availab // A visual representation of this model can be found at https://www.w3.org/TR/css-tables-3/images/table_container.png m_state.get_mutable(table_box()).margin_bottom += total_captions_height; - // FIXME: This is a total hack, we should respect the 'height' property. - m_automatic_content_height = total_content_height; + m_automatic_content_height = m_table_height; } CSSPixels TableFormattingContext::automatic_content_width() const diff --git a/Userland/Libraries/LibWeb/Layout/TableFormattingContext.h b/Userland/Libraries/LibWeb/Layout/TableFormattingContext.h index 2b558e7019..6d998e874c 100644 --- a/Userland/Libraries/LibWeb/Layout/TableFormattingContext.h +++ b/Userland/Libraries/LibWeb/Layout/TableFormattingContext.h @@ -43,7 +43,7 @@ private: void distribute_width_to_columns(); void compute_table_height(LayoutMode layout_mode); void distribute_height_to_rows(); - void position_row_boxes(CSSPixels&); + void position_row_boxes(); void position_cell_boxes(); void border_conflict_resolution(); CSSPixels border_spacing_horizontal() const;