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

This appears to match other engines.

(cherry picked from commit ae906ca4974da309c362e61ce7b6b393b8c4aed1)
This commit is contained in:
Andreas Kling 2024-06-23 16:00:20 +02:00 committed by Nico Weber
parent 97edca4e4e
commit 19e4b138af
3 changed files with 24 additions and 2 deletions

View file

@ -0,0 +1,12 @@
Viewport <#document> at (0,0) content-size 800x600 children: not-inline
BlockContainer <html> at (0,0) content-size 800x800 [BFC] children: not-inline
BlockContainer <body> at (8,8) content-size 784x784 children: inline
frag 0 from SVGSVGBox start: 0, length: 0, rect: [8,8 784x784] baseline: 784
SVGSVGBox <svg> at (8,8) content-size 784x784 [SVG] children: not-inline
SVGGeometryBox <rect> at (8,8) content-size 392x392 children: not-inline
ViewportPaintable (Viewport<#document>) [0,0 800x600] overflow: [0,0 800x800]
PaintableWithLines (BlockContainer<HTML>) [0,0 800x800]
PaintableWithLines (BlockContainer<BODY>) [8,8 784x784]
SVGSVGPaintable (SVGSVGBox<svg>) [8,8 784x784]
SVGPathPaintable (SVGGeometryBox<rect>) [8,8 392x392]

View file

@ -0,0 +1,3 @@
<!DOCTYPE html><style>
svg { width: max-content; }
</style><body><svg viewBox="0 0 24 24"><rect x=0 y=0 width=12 height=12></svg>

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;
}