LibWeb: Take specified height into account for automatic table height

Track table grid height stretched to the specified height and use it to
set the final box height in TFC.

Fixes #19563.
This commit is contained in:
Andi Gallo 2023-06-22 17:22:12 +00:00 committed by Andreas Kling
parent 04a5196a5d
commit 8e52d1125d
Notes: sideshowbarker 2024-07-18 00:54:03 +09:00
4 changed files with 31 additions and 9 deletions

View file

@ -0,0 +1,11 @@
Viewport <#document> at (0,0) content-size 800x600 children: not-inline
BlockContainer <html> at (0,0) content-size 800x600 [BFC] children: not-inline
BlockContainer <body> at (8,8) content-size 784x122 children: not-inline
TableWrapper <(anonymous)> at (8,8) content-size 0x122 [BFC] children: not-inline
Box <table> at (19,19) content-size 0x100 table-box [TFC] children: not-inline
BlockContainer <(anonymous)> (not painted) children: inline
TextNode <#text>
Box <tbody> at (19,19) content-size 0x0 table-row-group children: not-inline
Box <tr> at (21,31) content-size 0x0 table-row children: not-inline
BlockContainer <(anonymous)> (not painted) children: inline
TextNode <#text>

View file

@ -0,0 +1,10 @@
<style>
table {
border: 1px solid black;
height: 100px;
padding: 10px;
}
</style>
<table>
<tr></tr>
</table>

View file

@ -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

View file

@ -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;