LibWeb: Move FFC layout algorithm step 15 to a separate function

This commit is contained in:
Andreas Kling 2021-10-13 22:24:09 +02:00
parent 6d433c99f4
commit f401794d23
2 changed files with 19 additions and 11 deletions

View file

@ -130,17 +130,7 @@ void FlexFormattingContext::run(Box& flex_container, LayoutMode)
align_all_flex_items_along_the_cross_axis(flex_container, flex_lines);
// 15. Determine the flex containers used cross size:
if (has_definite_cross_size(flex_container)) {
float clamped_cross_size = clamp(specified_cross_size(flex_container), cross_min_size, cross_max_size);
set_cross_size(flex_container, clamped_cross_size);
} else {
float sum_of_flex_lines_cross_sizes = 0;
for (auto& flex_line : flex_lines) {
sum_of_flex_lines_cross_sizes += flex_line.cross_size;
}
float clamped_cross_size = clamp(sum_of_flex_lines_cross_sizes, cross_min_size, cross_max_size);
set_cross_size(flex_container, clamped_cross_size);
}
determine_flex_container_used_cross_size(flex_container, flex_lines, cross_min_size, cross_max_size);
// 16. Align all flex lines
// FIXME: Support align-content
@ -955,4 +945,20 @@ void FlexFormattingContext::align_all_flex_items_along_the_cross_axis(Box const&
}
}
// https://www.w3.org/TR/css-flexbox-1/#algo-cross-container
void FlexFormattingContext::determine_flex_container_used_cross_size(Box& flex_container, Vector<FlexLine> const& flex_lines, float cross_min_size, float cross_max_size)
{
if (has_definite_cross_size(flex_container)) {
float clamped_cross_size = clamp(specified_cross_size(flex_container), cross_min_size, cross_max_size);
set_cross_size(flex_container, clamped_cross_size);
} else {
float sum_of_flex_lines_cross_sizes = 0;
for (auto& flex_line : flex_lines) {
sum_of_flex_lines_cross_sizes += flex_line.cross_size;
}
float clamped_cross_size = clamp(sum_of_flex_lines_cross_sizes, cross_min_size, cross_max_size);
set_cross_size(flex_container, clamped_cross_size);
}
}
}

View file

@ -76,6 +76,8 @@ private:
void align_all_flex_items_along_the_cross_axis(Box const& flex_container, Vector<FlexLine>&);
void determine_flex_container_used_cross_size(Box& flex_container, Vector<FlexLine> const&, float cross_min_size, float cross_max_size);
bool is_row_layout() const { return m_flex_direction == CSS::FlexDirection::Row || m_flex_direction == CSS::FlexDirection::RowReverse; }
CSS::FlexDirection m_flex_direction {};