From 4c89252f6aac3b1be20b2a9aa29f275cf7f21873 Mon Sep 17 00:00:00 2001 From: Andreas Kling Date: Thu, 21 Jul 2022 01:19:10 +0200 Subject: [PATCH] LibWeb: Clamp flex items to min/max main size during intrinsic sizing We were neglecting to clamp flex items when calculating the intrinsic main size of the flex container. This was covered by a FIXME, which we can now remove. :^) --- Userland/Libraries/LibWeb/Layout/FlexFormattingContext.cpp | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/Userland/Libraries/LibWeb/Layout/FlexFormattingContext.cpp b/Userland/Libraries/LibWeb/Layout/FlexFormattingContext.cpp index f5fd358ad3..c3079dcd76 100644 --- a/Userland/Libraries/LibWeb/Layout/FlexFormattingContext.cpp +++ b/Userland/Libraries/LibWeb/Layout/FlexFormattingContext.cpp @@ -1484,7 +1484,10 @@ float FlexFormattingContext::calculate_intrinsic_main_size_of_flex_container(Lay else if (flex_item->desired_flex_fraction < 0) product = chosen_flex_fraction * flex_item->scaled_flex_shrink_factor; auto result = flex_item->flex_base_size + product; - // FIXME: Clamp result to min/max main size + + auto clamp_min = has_main_min_size(flex_item->box) ? specified_main_min_size(flex_item->box) : automatic_minimum_size(*flex_item); + auto clamp_max = has_main_max_size(flex_item->box) ? specified_main_max_size(flex_item->box) : NumericLimits::max(); + result = css_clamp(result, clamp_min, clamp_max); // NOTE: The spec doesn't mention anything about the *outer* size here, but if we don't add the margin box, // flex items with non-zero padding/border/margin in the main axis end up overflowing the container. @@ -1493,6 +1496,7 @@ float FlexFormattingContext::calculate_intrinsic_main_size_of_flex_container(Lay sum += result; } + // 5. The flex container’s max-content size is the largest sum (among all the lines) of the afore-calculated sizes of all items within a single line. largest_sum = max(largest_sum, sum); }