diff options
author | Andreas Kling <kling@serenityos.org> | 2021-10-13 22:22:30 +0200 |
---|---|---|
committer | Andreas Kling <kling@serenityos.org> | 2021-10-13 23:56:26 +0200 |
commit | 6d433c99f40caf2527ff4ba22ebacb906790fc32 (patch) | |
tree | 8a2a4da3d365c5924efc8d2413a5426addfffabc /Userland/Libraries | |
parent | e590e17b8a665a01417923b0f0819ae0085e7d73 (diff) | |
download | serenity-6d433c99f40caf2527ff4ba22ebacb906790fc32.zip |
LibWeb: Move FFC layout algorithm step 14 to a separate function
Diffstat (limited to 'Userland/Libraries')
-rw-r--r-- | Userland/Libraries/LibWeb/Layout/FlexFormattingContext.cpp | 57 | ||||
-rw-r--r-- | Userland/Libraries/LibWeb/Layout/FlexFormattingContext.h | 2 |
2 files changed, 33 insertions, 26 deletions
diff --git a/Userland/Libraries/LibWeb/Layout/FlexFormattingContext.cpp b/Userland/Libraries/LibWeb/Layout/FlexFormattingContext.cpp index cb4279f111..be8cd3ccc0 100644 --- a/Userland/Libraries/LibWeb/Layout/FlexFormattingContext.cpp +++ b/Userland/Libraries/LibWeb/Layout/FlexFormattingContext.cpp @@ -127,32 +127,7 @@ void FlexFormattingContext::run(Box& flex_container, LayoutMode) // FIXME: This // 14. Align all flex items along the cross-axis - // FIXME: Get the alignment via "align-self" of the item (which accesses "align-items" of the parent if unset) - // FIXME: Take better care of margins - float line_cross_offset = 0; - for (auto& flex_line : flex_lines) { - for (auto* flex_item : flex_line.items) { - switch (flex_container.computed_values().align_items()) { - case CSS::AlignItems::Baseline: - // FIXME: Implement this - // Fallthrough - case CSS::AlignItems::FlexStart: - case CSS::AlignItems::Stretch: - flex_item->cross_offset = line_cross_offset + flex_item->margins.cross_before; - break; - case CSS::AlignItems::FlexEnd: - flex_item->cross_offset = line_cross_offset + flex_line.cross_size - flex_item->cross_size; - break; - case CSS::AlignItems::Center: - flex_item->cross_offset = line_cross_offset + (flex_line.cross_size / 2.0f) - (flex_item->cross_size / 2.0f); - break; - default: - break; - } - } - - line_cross_offset += flex_line.cross_size; - } + 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)) { @@ -950,4 +925,34 @@ void FlexFormattingContext::distribute_any_remaining_free_space(Box const& flex_ } } +void FlexFormattingContext::align_all_flex_items_along_the_cross_axis(Box const& flex_container, Vector<FlexLine>& flex_lines) +{ + // FIXME: Get the alignment via "align-self" of the item (which accesses "align-items" of the parent if unset) + // FIXME: Take better care of margins + float line_cross_offset = 0; + for (auto& flex_line : flex_lines) { + for (auto* flex_item : flex_line.items) { + switch (flex_container.computed_values().align_items()) { + case CSS::AlignItems::Baseline: + // FIXME: Implement this + // Fallthrough + case CSS::AlignItems::FlexStart: + case CSS::AlignItems::Stretch: + flex_item->cross_offset = line_cross_offset + flex_item->margins.cross_before; + break; + case CSS::AlignItems::FlexEnd: + flex_item->cross_offset = line_cross_offset + flex_line.cross_size - flex_item->cross_size; + break; + case CSS::AlignItems::Center: + flex_item->cross_offset = line_cross_offset + (flex_line.cross_size / 2.0f) - (flex_item->cross_size / 2.0f); + break; + default: + break; + } + } + + line_cross_offset += flex_line.cross_size; + } +} + } diff --git a/Userland/Libraries/LibWeb/Layout/FlexFormattingContext.h b/Userland/Libraries/LibWeb/Layout/FlexFormattingContext.h index f984e05363..1a97e7bf33 100644 --- a/Userland/Libraries/LibWeb/Layout/FlexFormattingContext.h +++ b/Userland/Libraries/LibWeb/Layout/FlexFormattingContext.h @@ -74,6 +74,8 @@ private: void distribute_any_remaining_free_space(Box const& flex_container, Vector<FlexLine>&, float main_available_size); + void align_all_flex_items_along_the_cross_axis(Box const& flex_container, Vector<FlexLine>&); + bool is_row_layout() const { return m_flex_direction == CSS::FlexDirection::Row || m_flex_direction == CSS::FlexDirection::RowReverse; } CSS::FlexDirection m_flex_direction {}; |