diff options
author | Andreas Kling <kling@serenityos.org> | 2021-10-13 22:07:55 +0200 |
---|---|---|
committer | Andreas Kling <kling@serenityos.org> | 2021-10-13 23:56:26 +0200 |
commit | 0fd25fcbbc0131b12ec05a85d0cdda8f7e152eb6 (patch) | |
tree | 3e9b73680305642ace14a3c0a30298ed9c4fcd55 /Userland | |
parent | fa7bbc602de6a61a55d3c82807fe389046437e1e (diff) | |
download | serenity-0fd25fcbbc0131b12ec05a85d0cdda8f7e152eb6.zip |
LibWeb: Move FFC layout algorithm step 5 to a separate function
Diffstat (limited to 'Userland')
-rw-r--r-- | Userland/Libraries/LibWeb/Layout/FlexFormattingContext.cpp | 53 | ||||
-rw-r--r-- | Userland/Libraries/LibWeb/Layout/FlexFormattingContext.h | 3 |
2 files changed, 34 insertions, 22 deletions
diff --git a/Userland/Libraries/LibWeb/Layout/FlexFormattingContext.cpp b/Userland/Libraries/LibWeb/Layout/FlexFormattingContext.cpp index 3d156d0aa6..27ed4c3193 100644 --- a/Userland/Libraries/LibWeb/Layout/FlexFormattingContext.cpp +++ b/Userland/Libraries/LibWeb/Layout/FlexFormattingContext.cpp @@ -131,28 +131,7 @@ void FlexFormattingContext::run(Box& flex_container, LayoutMode) // 5. Collect flex items into flex lines: // After this step no additional items are to be added to flex_lines or any of its items! - Vector<FlexLine> flex_lines; - // FIXME: Also support wrap-reverse - if (flex_container.computed_values().flex_wrap() == CSS::FlexWrap::Nowrap) { - FlexLine line; - for (auto& flex_item : flex_items) { - line.items.append(&flex_item); - } - flex_lines.append(line); - } else { - FlexLine line; - float line_main_size = 0; - for (auto& flex_item : flex_items) { - if ((line_main_size + flex_item.hypothetical_main_size) > main_available_size) { - flex_lines.append(line); - line = {}; - line_main_size = 0; - } - line.items.append(&flex_item); - line_main_size += flex_item.hypothetical_main_size; - } - flex_lines.append(line); - } + auto flex_lines = collect_flex_items_into_flex_lines(flex_container, flex_items, main_available_size); // 6. Resolve the flexible lengths https://www.w3.org/TR/css-flexbox-1/#resolve-flexible-lengths enum FlexFactor { @@ -921,4 +900,34 @@ void FlexFormattingContext::determine_main_size_of_flex_container(Box& flex_cont set_main_size(flex_container, main_available_size); } +// https://www.w3.org/TR/css-flexbox-1/#algo-line-break +Vector<FlexLine> FlexFormattingContext::collect_flex_items_into_flex_lines(Box const& flex_container, Vector<FlexItem>& flex_items, float main_available_size) +{ + Vector<FlexLine> flex_lines; + + // FIXME: Also support wrap-reverse + if (flex_container.computed_values().flex_wrap() == CSS::FlexWrap::Nowrap) { + FlexLine line; + for (auto& flex_item : flex_items) { + line.items.append(&flex_item); + } + flex_lines.append(line); + } else { + FlexLine line; + float line_main_size = 0; + for (auto& flex_item : flex_items) { + if ((line_main_size + flex_item.hypothetical_main_size) > main_available_size) { + flex_lines.append(line); + line = {}; + line_main_size = 0; + } + line.items.append(&flex_item); + line_main_size += flex_item.hypothetical_main_size; + } + flex_lines.append(line); + } + + return flex_lines; +} + } diff --git a/Userland/Libraries/LibWeb/Layout/FlexFormattingContext.h b/Userland/Libraries/LibWeb/Layout/FlexFormattingContext.h index c8095223fd..d8e70d42df 100644 --- a/Userland/Libraries/LibWeb/Layout/FlexFormattingContext.h +++ b/Userland/Libraries/LibWeb/Layout/FlexFormattingContext.h @@ -11,6 +11,7 @@ namespace Web::Layout { struct FlexItem; +struct FlexLine; class FlexFormattingContext final : public FormattingContext { public: @@ -61,6 +62,8 @@ private: void determine_main_size_of_flex_container(Box& flex_container, Vector<FlexItem>&, bool main_is_constrained, bool main_size_is_infinite, float& main_available_size, float main_min_size, float main_max_size); + Vector<FlexLine> collect_flex_items_into_flex_lines(Box const& flex_container, Vector<FlexItem>&, float main_available_size); + bool is_row_layout() const { return m_flex_direction == CSS::FlexDirection::Row || m_flex_direction == CSS::FlexDirection::RowReverse; } CSS::FlexDirection m_flex_direction {}; |