From 95730c66aa34f5b159f595b5a374f20250c451f0 Mon Sep 17 00:00:00 2001 From: Sam Atkins Date: Fri, 14 Mar 2025 19:59:06 +0000 Subject: [PATCH] LibWeb: Make non-replaced flex items make use of transferred size Corresponds to https://github.com/w3c/csswg-drafts/commit/9beaea1f2a23d935a28aef8882bfea5519e1cfde --- .../LibWeb/Layout/FlexFormattingContext.cpp | 36 ++++++++++++------- 1 file changed, 24 insertions(+), 12 deletions(-) diff --git a/Libraries/LibWeb/Layout/FlexFormattingContext.cpp b/Libraries/LibWeb/Layout/FlexFormattingContext.cpp index 6a1a67bf974..ae8a73cba60 100644 --- a/Libraries/LibWeb/Layout/FlexFormattingContext.cpp +++ b/Libraries/LibWeb/Layout/FlexFormattingContext.cpp @@ -758,25 +758,37 @@ Optional FlexFormattingContext::transferred_size_suggestion(FlexItem CSSPixels FlexFormattingContext::content_based_minimum_size(FlexItem const& item) const { auto unclamped_size = [&] { - // The content-based minimum size of a flex item is the smaller of its specified size suggestion - // and its content size suggestion if its specified size suggestion exists; - if (auto specified_size_suggestion = this->specified_size_suggestion(item); specified_size_suggestion.has_value()) { - return min(specified_size_suggestion.value(), content_size_suggestion(item)); - } - - // otherwise, the smaller of its transferred size suggestion and its content size suggestion - // if the element is replaced and its transferred size suggestion exists; + // The content-based minimum size of a flex item differs depending on whether the flex item is replaced or not: + // -> For replaced elements if (item.box->is_replaced_box()) { + // Use the smaller of the content size suggestion and the transferred size suggestion (if one exists), + // capped by the specified size suggestion (if one exists). + auto size = content_size_suggestion(item); if (auto transferred_size_suggestion = this->transferred_size_suggestion(item); transferred_size_suggestion.has_value()) { - return min(transferred_size_suggestion.value(), content_size_suggestion(item)); + size = min(size, transferred_size_suggestion.value()); } + if (auto specified_size_suggestion = this->specified_size_suggestion(item); specified_size_suggestion.has_value()) { + size = min(size, specified_size_suggestion.value()); + } + return size; } - // otherwise its content size suggestion. - return content_size_suggestion(item); + // -> For non-replaced elements + { + // Use the larger of the content size suggestion and the transferred size suggestion (if one exists), + // capped by the specified size suggestion (if one exists). + auto size = content_size_suggestion(item); + if (auto transferred_size_suggestion = this->transferred_size_suggestion(item); transferred_size_suggestion.has_value()) { + size = max(size, transferred_size_suggestion.value()); + } + if (auto specified_size_suggestion = this->specified_size_suggestion(item); specified_size_suggestion.has_value()) { + size = min(size, specified_size_suggestion.value()); + } + return size; + } }(); - // In all cases, the size is clamped by the maximum main size if it’s definite. + // In either case, the size is clamped by the maximum main size if it’s definite. if (has_main_max_size(item.box)) { return min(unclamped_size, specified_main_max_size(item.box)); }