summaryrefslogtreecommitdiff
path: root/Userland/Libraries
diff options
context:
space:
mode:
Diffstat (limited to 'Userland/Libraries')
-rw-r--r--Userland/Libraries/LibWeb/Layout/FlexFormattingContext.cpp57
-rw-r--r--Userland/Libraries/LibWeb/Layout/FlexFormattingContext.h2
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 {};