summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAndreas Kling <kling@serenityos.org>2022-10-08 13:37:44 +0200
committerAndreas Kling <kling@serenityos.org>2022-10-10 20:22:50 +0200
commit4a17e8713b0a82a8feddf1add49d4220b69f1851 (patch)
treecbc0b951d06c3c071d89cdcff7a821e75c55279e
parent986940580201bfe582fe111e690c3993d28a9822 (diff)
downloadserenity-4a17e8713b0a82a8feddf1add49d4220b69f1851.zip
LibWeb: Update FFC for spec change to intrinsic min-content cross size
We now know exactly how to calculate the min-content cross size for multi-line flex containers, which is great. The other three intrinsic constraints still fall back to the old ad-hoc code path. https://github.com/w3c/csswg-drafts/commit/5630e7b064addc6f2f9f57e68935e3cb3e778b65
-rw-r--r--Userland/Libraries/LibWeb/Layout/FlexFormattingContext.cpp39
1 files changed, 34 insertions, 5 deletions
diff --git a/Userland/Libraries/LibWeb/Layout/FlexFormattingContext.cpp b/Userland/Libraries/LibWeb/Layout/FlexFormattingContext.cpp
index d8cc945090..ad287c77d0 100644
--- a/Userland/Libraries/LibWeb/Layout/FlexFormattingContext.cpp
+++ b/Userland/Libraries/LibWeb/Layout/FlexFormattingContext.cpp
@@ -1583,11 +1583,40 @@ float FlexFormattingContext::calculate_intrinsic_cross_size_of_flex_container()
return second_pass_largest_contribution;
}
- // FIXME: For a multi-line flex container, the min-content/max-content cross size is the sum of the flex line cross sizes
- // resulting from sizing the flex container under a cross-axis min-content constraint/max-content constraint (respectively).
- // FIXME: However, if the flex container is flex-flow: column wrap;, then it’s sized by first finding the largest
- // min-content/max-content cross-size contribution among the flex items (respectively), then using that size
- // as the available space in the cross axis for each of the flex items during layout.
+ if (is_row_layout()) {
+ // row multi-line flex container cross-size
+
+ // The min-content/max-content cross size is the sum of the flex line cross sizes resulting from
+ // sizing the flex container under a cross-axis min-content constraint/max-content constraint (respectively).
+
+ // NOTE: We fall through to the ad-hoc section below.
+ } else {
+ // column multi-line flex container cross-size
+
+ // The min-content cross size is the largest min-content contribution among all of its flex items.
+ if (m_available_space_for_items->cross.is_min_content()) {
+ auto calculate_largest_contribution = [&](bool resolve_percentage_min_max_sizes) {
+ float largest_contribution = 0;
+ for (auto& flex_item : m_flex_items) {
+ float contribution = calculate_cross_min_content_contribution(flex_item, resolve_percentage_min_max_sizes);
+ largest_contribution = max(largest_contribution, contribution);
+ }
+ return largest_contribution;
+ };
+
+ auto first_pass_largest_contribution = calculate_largest_contribution(false);
+ set_cross_size(flex_container(), first_pass_largest_contribution);
+ auto second_pass_largest_contribution = calculate_largest_contribution(true);
+ return second_pass_largest_contribution;
+ }
+
+ // The max-content cross size is the sum of the flex line cross sizes resulting from
+ // sizing the flex container under a cross-axis max-content constraint,
+ // using the largest max-content cross-size contribution among the flex items
+ // as the available space in the cross axis for each of the flex items during layout.
+
+ // NOTE: We fall through to the ad-hoc section below.
+ }
// HACK: We run steps 5, 7, 9 and 11 from the main algorithm. This gives us *some* cross size information to work with.
m_flex_lines.clear();