LibWeb: Treat width: {min,max,fit}-content as auto if ratio unresolvable

This appears to match other engines.
This commit is contained in:
Andreas Kling 2024-06-23 16:00:20 +02:00 committed by Andreas Kling
commit ae906ca497
Notes: sideshowbarker 2024-07-16 20:21:48 +09:00
3 changed files with 24 additions and 2 deletions

View file

@ -1767,14 +1767,21 @@ CSSPixels FormattingContext::calculate_stretch_fit_height(Box const& box, Availa
bool FormattingContext::should_treat_width_as_auto(Box const& box, AvailableSpace const& available_space)
{
if (box.computed_values().width().is_auto())
auto const& computed_width = box.computed_values().width();
if (computed_width.is_auto())
return true;
if (box.computed_values().width().contains_percentage()) {
if (computed_width.contains_percentage()) {
if (available_space.width.is_max_content())
return true;
if (available_space.width.is_indefinite())
return true;
}
// AD-HOC: If the box has a preferred aspect ratio and no natural height,
// we treat the width as auto, since it can't be resolved through the ratio.
if (computed_width.is_min_content() || computed_width.is_max_content() || computed_width.is_fit_content()) {
if (box.has_preferred_aspect_ratio() && !box.has_natural_height())
return true;
}
return false;
}