LibWeb: Implement intrinsic width calculation for TFC

This commit is contained in:
Aliaksandr Kalenik 2022-12-04 22:47:45 +03:00 committed by Andreas Kling
parent dbf76e8ae1
commit 2f38f8c84a
Notes: sideshowbarker 2024-07-17 22:41:14 +09:00

View file

@ -176,6 +176,28 @@ void TableFormattingContext::distribute_width_to_columns(float extra_width)
column.used_width += ((column.max_width - column.min_width) / grid_max) * extra_width;
}
void TableFormattingContext::determine_intrisic_size_of_table_container(AvailableSpace const& available_space)
{
auto const& table_box = context_box();
auto& table_box_state = m_state.get_mutable(table_box);
if (available_space.width.is_min_content()) {
// The min-content width of a table is the width required to fit all of its columns min-content widths and its undistributable spaces.
float grid_min = 0.0f;
for (auto& column : m_columns)
grid_min += column.min_width;
table_box_state.set_content_width(grid_min);
}
if (available_space.width.is_max_content()) {
// The max-content width of a table is the width required to fit all of its columns max-content widths and its undistributable spaces.
float grid_max = 0.0f;
for (auto& column : m_columns)
grid_max += column.max_width;
table_box_state.set_content_width(grid_max);
}
}
void TableFormattingContext::run(Box const& box, LayoutMode, AvailableSpace const& available_space)
{
float total_content_height = 0;
@ -186,6 +208,11 @@ void TableFormattingContext::run(Box const& box, LayoutMode, AvailableSpace cons
// Compute the minimum width of each column.
compute_table_measures();
if (available_space.width.is_intrinsic_sizing_constraint()) {
determine_intrisic_size_of_table_container(available_space);
return;
}
// Compute the width of the table.
float extra_width = 0;
compute_table_width(extra_width);