Skip to content

Commit 5f316b6

Browse files
alanbaradlayannevk
authored andcommitted
aspect-ratio is ignored on out-of-flow boxes with height: fit-content / min-content / max-content
Intrinsic sizing keywords behave as auto in the block axis, but computeOutOfFlowPositionedLogicalHeightUsing() resolved them against the content before reaching the aspect ratio branch. Check the aspect ratio first, like the in-flow path does. WebKit-Bug: https://bugs.webkit.org/show_bug.cgi?id=325418 WebKit-Canonical-Link: https://commits.webkit.org/322178@main
1 parent b0edf8a commit 5f316b6

1 file changed

Lines changed: 116 additions & 0 deletions

File tree

Lines changed: 116 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,116 @@
1+
<!DOCTYPE html>
2+
<meta charset="utf-8">
3+
<title>CSS aspect-ratio: min-content, max-content and fit-content block sizes behave as auto on absolutely positioned boxes</title>
4+
<link rel="help" href="https://drafts.csswg.org/css-sizing-3/#sizing-values">
5+
<link rel="help" href="https://drafts.csswg.org/css-sizing-4/#aspect-ratio">
6+
<link rel="help" href="https://drafts.csswg.org/css-sizing-4/#aspect-ratio-minimum">
7+
<script src="/resources/testharness.js"></script>
8+
<script src="/resources/testharnessreport.js"></script>
9+
10+
<style>
11+
.cb {
12+
position: relative;
13+
display: inline-block;
14+
margin: 0 8px 8px 0;
15+
background: red;
16+
}
17+
.cb.vertical { writing-mode: vertical-rl; }
18+
.abspos {
19+
position: absolute;
20+
top: 0;
21+
left: 0;
22+
background: green;
23+
}
24+
</style>
25+
26+
<p>Test passes if there are green rectangles and <strong>no red</strong>.</p>
27+
<div id="container"></div>
28+
<div id="log"></div>
29+
30+
<script>
31+
// In the block axis min-content, max-content and fit-content behave as the automatic size, and a box with
32+
// a preferred aspect ratio gets its automatic block size from the ratio. Each keyword has to produce what auto does.
33+
// Every box sits on a red containing block that has the size the box is expected to have.
34+
const keywords = ["auto", "min-content", "max-content", "fit-content"];
35+
36+
const cases = [
37+
{
38+
css: "width: 160px; aspect-ratio: 16 / 9",
39+
content: "height: 20px",
40+
size: [160, 90],
41+
note: "the block size comes from the ratio",
42+
},
43+
{
44+
css: "width: 160px; aspect-ratio: 16 / 9; bottom: -90px",
45+
content: "height: 20px",
46+
size: [160, 90],
47+
note: "the ratio wins over the insets",
48+
},
49+
{
50+
css: "width: 160px; aspect-ratio: 16 / 9",
51+
content: "height: 120px",
52+
size: [160, 120],
53+
note: "the automatic minimum size keeps the content from overflowing",
54+
},
55+
{
56+
css: "width: 160px; aspect-ratio: 16 / 9; min-height: 0",
57+
content: "height: 120px",
58+
size: [160, 90],
59+
note: "no automatic minimum size, the content overflows",
60+
},
61+
{
62+
css: "width: 160px; aspect-ratio: 16 / 9; padding: 10px",
63+
content: "height: 20px",
64+
size: [180, 110],
65+
note: "the ratio applies to the content box",
66+
},
67+
{
68+
css: "width: 160px; aspect-ratio: 16 / 9; padding: 10px; box-sizing: border-box",
69+
content: "height: 20px",
70+
size: [160, 90],
71+
note: "the ratio applies to the border box",
72+
},
73+
{
74+
css: "width: 160px; aspect-ratio: 16 / 9; display: flex",
75+
content: "width: 20px; height: 20px",
76+
size: [160, 90],
77+
note: "flex container",
78+
},
79+
{
80+
vertical: true,
81+
css: "height: 90px; aspect-ratio: 16 / 9",
82+
content: "width: 20px",
83+
size: [160, 90],
84+
note: "vertical writing mode",
85+
},
86+
];
87+
88+
const container = document.getElementById("container");
89+
90+
for (const testCase of cases) {
91+
const row = document.createElement("div");
92+
testCase.boxes = keywords.map(keyword => {
93+
const containingBlock = document.createElement("div");
94+
containingBlock.className = testCase.vertical ? "cb vertical" : "cb";
95+
containingBlock.style.width = testCase.size[0] + "px";
96+
containingBlock.style.height = testCase.size[1] + "px";
97+
containingBlock.innerHTML = '<div class="abspos"><div></div></div>';
98+
const box = containingBlock.firstChild;
99+
box.style.cssText = testCase.css + "; " + (testCase.vertical ? "width: " : "height: ") + keyword;
100+
box.firstChild.style.cssText = testCase.content;
101+
row.appendChild(containingBlock);
102+
return { keyword, box };
103+
});
104+
container.appendChild(row);
105+
}
106+
107+
for (const testCase of cases) {
108+
for (const { keyword, box } of testCase.boxes) {
109+
test(() => {
110+
const rect = box.getBoundingClientRect();
111+
assert_equals(rect.width, testCase.size[0], "width");
112+
assert_equals(rect.height, testCase.size[1], "height");
113+
}, (testCase.vertical ? "width: " : "height: ") + keyword + "; " + testCase.css + " — " + testCase.note);
114+
}
115+
}
116+
</script>

0 commit comments

Comments
 (0)