Skip to content

Commit 7752bc5

Browse files
tcl3awesomekling
authored andcommitted
LibWeb: Stretch aspect-ratio flex items only when container is definite
A flex item with a preferred aspect ratio but no natural width or height and no definite cross size is stretched to fill its container's main size as a fallback. This was applied unconditionally, but when the container itself is being measured for an intrinsic size, the container's main size is indefinite and the size evaluated to zero. This clobbered the max-content size the flex algorithm had already computed as the intrinsic contribution.
1 parent 6d84918 commit 7752bc5

3 files changed

Lines changed: 41 additions & 1 deletion

File tree

Libraries/LibWeb/Layout/FlexFormattingContext.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -801,7 +801,7 @@ void FlexFormattingContext::determine_flex_base_size(FlexItem& item)
801801
// - in response to cross size min/max constraints.
802802
auto auto_size = item.box->auto_content_box_size();
803803
if (auto_size.has_aspect_ratio()) {
804-
if (!item.used_flex_basis_is_definite && !auto_size.has_width() && !auto_size.has_height() && !has_definite_cross_size(item)) {
804+
if (!item.used_flex_basis_is_definite && !auto_size.has_width() && !auto_size.has_height() && !has_definite_cross_size(item) && has_definite_main_size(m_flex_container_state)) {
805805
item.flex_base_size = inner_main_size(m_flex_container_state);
806806
}
807807
item.flex_base_size = adjust_main_size_through_aspect_ratio_for_cross_size_min_max_constraints(child_box, item.flex_base_size, computed_cross_min_size(child_box), computed_cross_max_size(child_box));
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
<!DOCTYPE html>
2+
<title>SVG as flex item</title>
3+
<link rel="author" title="David Grogan" href="mailto:dgrogan@chromium.org">
4+
<link rel="help" href="https://drafts.csswg.org/css-flexbox/#algo-main-item" title="Part E">
5+
<link rel="help" href="https://www.w3.org/TR/CSS22/visudet.html#min-max-widths">
6+
<link rel="match" href="../../../../expected/wpt-import/css/css-flexbox/../reference/ref-filled-green-100px-square-only.html">
7+
<meta name="assert" content="Flex base size of svg item with aspect ratio + no intrinsic width or height honors transferred max-width." />
8+
9+
<p>Test passes if there is a filled green square.</p>
10+
11+
<div style="display: flex; flex-direction: column; align-items: flex-start; width: 200px;">
12+
<svg viewBox="0 0 1 1" style="max-width: 100px; background: green;"></svg>
13+
</div>
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
<!DOCTYPE html>
2+
<title>SVG root as flex item</title>
3+
<link rel="author" title="David Grogan" href="mailto:dgrogan@chromium.org">
4+
<link rel="help" href="https://drafts.csswg.org/css-flexbox/#algo-main-item" title="Part E">
5+
<link rel="help" href="https://www.w3.org/TR/css-sizing-3/#intrinsic-sizes" title="For boxes with an intrinsic aspect ratio, but no intrinsic size">
6+
<link rel="match" href="../../../../expected/wpt-import/css/css-flexbox/../reference/ref-filled-green-100px-square.xht">
7+
<meta name="assert" content="SVG's intrinsic width when used as flex base size stretches into the available size when it has no specified intrinsic sizes and is passed through the aspect ratio " />
8+
9+
<style>
10+
#reference-overlapped-red {
11+
position: absolute;
12+
background-color: red;
13+
width: 100px;
14+
height: 100px;
15+
z-index: -1;
16+
}
17+
</style>
18+
19+
<p>Test passes if there is a filled green square and <strong>no red</strong>.</p>
20+
21+
<div id="reference-overlapped-red"></div>
22+
23+
<div style="display: flex; flex-direction: column; width: 100px; align-items: flex-start;">
24+
<svg viewBox="0 0 200 200">
25+
<rect width="100%" height="100%" fill="green" />
26+
</svg>
27+
</div>

0 commit comments

Comments
 (0)