Branch: refs/heads/main
Home: https://github.com/WebKit/WebKit
Commit: b94432eab45deb327f7918456bf5173dccfd15c7
https://github.com/WebKit/WebKit/commit/b94432eab45deb327f7918456bf5173dccfd15c7
Author: Alan Baradlay <[email protected]>
Date: 2026-05-12 (Tue, 12 May 2026)
Changed paths:
A
LayoutTests/imported/w3c/web-platform-tests/css/css-sizing/intrinsic-percent-non-replaced-007-expected.html
A
LayoutTests/imported/w3c/web-platform-tests/css/css-sizing/intrinsic-percent-non-replaced-007-ref.html
A
LayoutTests/imported/w3c/web-platform-tests/css/css-sizing/intrinsic-percent-non-replaced-007.html
M Source/WebCore/rendering/RenderBlock.cpp
M Source/WebCore/rendering/RenderBox.cpp
M Source/WebCore/rendering/RenderBox.h
Log Message:
-----------
Non-replaced block with aspect-ratio and percentage max-width produces zero
width during intrinsic sizing
https://bugs.webkit.org/show_bug.cgi?id=314552
Reviewed by Antti Koivisto.
<div style="width: max-content">
<div style="aspect-ratio: 2/1; height: 100px; max-width: 50%"></div>
</div>
The inner box should be 200px wide during the container's intrinsic size
computation (percentage max-width is cyclic and treated as none per CSS Sizing 3
section 5.1). Then during layout, max-width: 50% of 200px = 100px clamps it.
We were getting 0px because RenderBlock::computePreferredLogicalWidths used
computeLogicalWidthFromAspectRatio() which applies min/max constraints via
constrainLogicalWidthByMinMax(). That function resolves percentage max-width
against containingBlockLogicalWidthForContent() - which is 0 during intrinsic
sizing since the containing block width is what we are trying to compute.
The fix switches to computeLogicalWidthFromAspectRatioInternal() which computes
the raw width from height x aspect-ratio without applying min/max. Percentage
max-width is correctly ignored (it's cyclic), and fixed max-width is still
applied by the shared RenderBox::computePreferredLogicalWidths() call that
runs afterward.
However, the old constrainLogicalWidthByMinMax() call also handled the automatic
content-based minimum size (CSS Sizing 4 section 5.1): for non-replaced boxes
with aspect-ratio and min-width: auto, the minimum width is the min-content
size.
This matters when the aspect-ratio width is smaller than the content (e.g.
aspect-ratio: 1/2 with a 100px child - ratio gives 50px but content needs
100px).
To avoid duplicating this logic, extract applyAutomaticContentBasedMinimumSize()
as a shared helper on RenderBox, called from both
RenderBlock::computePreferredLogicalWidths and
RenderBox::computeIntrinsicKeywordLogicalWidths (which had the same inline
pattern).
*
LayoutTests/imported/w3c/web-platform-tests/css/css-sizing/intrinsic-percent-non-replaced-007-expected.html:
Added.
*
LayoutTests/imported/w3c/web-platform-tests/css/css-sizing/intrinsic-percent-non-replaced-007-ref.html:
Added.
*
LayoutTests/imported/w3c/web-platform-tests/css/css-sizing/intrinsic-percent-non-replaced-007.html:
Added.
* Source/WebCore/rendering/RenderBlock.cpp:
(WebCore::RenderBlock::computePreferredLogicalWidths):
* Source/WebCore/rendering/RenderBox.cpp:
(WebCore::RenderBox::computeIntrinsicKeywordLogicalWidths const):
(WebCore::RenderBox::applyAutomaticContentBasedMinimumSize const):
* Source/WebCore/rendering/RenderBox.h:
Canonical link: https://commits.webkit.org/313074@main
To unsubscribe from these emails, change your notification settings at
https://github.com/WebKit/WebKit/settings/notifications