LibWeb: Implement intrinsic width calculation for TFC
This commit is contained in:
parent
dbf76e8ae1
commit
2f38f8c84a
Notes:
sideshowbarker
2024-07-17 22:41:14 +09:00
Author: https://github.com/kalenikaliaksandr Commit: https://github.com/SerenityOS/serenity/commit/2f38f8c84a Pull-request: https://github.com/SerenityOS/serenity/pull/16285
1 changed files with 27 additions and 0 deletions
|
@ -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);
|
||||
|
|
Loading…
Add table
Reference in a new issue