From f401794d234aa5325755fc51e3e236233a72f33f Mon Sep 17 00:00:00 2001 From: Andreas Kling Date: Wed, 13 Oct 2021 22:24:09 +0200 Subject: [PATCH] LibWeb: Move FFC layout algorithm step 15 to a separate function --- .../LibWeb/Layout/FlexFormattingContext.cpp | 28 +++++++++++-------- .../LibWeb/Layout/FlexFormattingContext.h | 2 ++ 2 files changed, 19 insertions(+), 11 deletions(-) diff --git a/Userland/Libraries/LibWeb/Layout/FlexFormattingContext.cpp b/Userland/Libraries/LibWeb/Layout/FlexFormattingContext.cpp index be8cd3ccc08..1b26cab7ceb 100644 --- a/Userland/Libraries/LibWeb/Layout/FlexFormattingContext.cpp +++ b/Userland/Libraries/LibWeb/Layout/FlexFormattingContext.cpp @@ -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 container’s 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 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); + } +} + } diff --git a/Userland/Libraries/LibWeb/Layout/FlexFormattingContext.h b/Userland/Libraries/LibWeb/Layout/FlexFormattingContext.h index 1a97e7bf338..295218d8b0b 100644 --- a/Userland/Libraries/LibWeb/Layout/FlexFormattingContext.h +++ b/Userland/Libraries/LibWeb/Layout/FlexFormattingContext.h @@ -76,6 +76,8 @@ private: void align_all_flex_items_along_the_cross_axis(Box const& flex_container, Vector&); + void determine_flex_container_used_cross_size(Box& flex_container, Vector 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 {};