LibWeb: Make non-replaced flex items make use of transferred size

Corresponds to 9beaea1f2a
This commit is contained in:
Sam Atkins 2025-03-14 19:59:06 +00:00
commit 95730c66aa
Notes: github-actions[bot] 2025-03-17 09:36:52 +00:00

View file

@ -758,25 +758,37 @@ Optional<CSSPixels> 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 its definite.
// In either case, the size is clamped by the maximum main size if its definite.
if (has_main_max_size(item.box)) {
return min(unclamped_size, specified_main_max_size(item.box));
}