summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--Userland/Libraries/LibWeb/Layout/FlexFormattingContext.cpp53
-rw-r--r--Userland/Libraries/LibWeb/Layout/FlexFormattingContext.h3
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 {};