Skip to content

Commit 1bee03c

Browse files
alanbaradlayannevk
authored andcommitted
A block-level aspect-ratio box inside a float grows when its content changes
<div style="float: left"> <div style="aspect-ratio: 1"> <div style="height: 100%; aspect-ratio: 2"> <div style="width: 20px; height: 5px"></div> </div> </div> </div> The aspect-ratio box should stay 20px wide when its content changes. Instead it doubled on every change. availableLogicalHeightForPercentageComputation() derives the box's height from logicalWidth(), which still holds the previous layout's width while the box measures its own intrinsic widths. It uses dirty bits to signal intrinsic width computation, and only for grid and shrink-to-fit boxes, so the float's measurement of this block-level box feeds the old width back in. Let's mark the box while it measures its own intrinsic widths instead, with IntrinsicLogicalWidthComputationScope (the inline-axis counterpart of IntrinsicLogicalHeightComputationScope), and bail out only inside that scope. WebKit-Bug: https://bugs.webkit.org/show_bug.cgi?id=325890 WebKit-Canonical-Link: https://commits.webkit.org/322742@main
1 parent 4882c7a commit 1bee03c

2 files changed

Lines changed: 77 additions & 0 deletions

File tree

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
<!DOCTYPE html>
2+
<meta charset="utf-8">
3+
<style>
4+
.float {
5+
float: left;
6+
}
7+
.inline-block {
8+
display: inline-block;
9+
}
10+
.table-cell {
11+
display: table-cell;
12+
}
13+
.inline-grid {
14+
display: inline-grid;
15+
}
16+
.box {
17+
width: 20px;
18+
height: 20px;
19+
}
20+
.child {
21+
width: 40px;
22+
height: 20px;
23+
background-color: green;
24+
}
25+
</style>
26+
<div class="float"><div class="box"><div class="child"></div></div></div>
27+
<div style="clear: both"></div>
28+
<div class="inline-block"><div class="box"><div class="child"></div></div></div>
29+
<div class="table-cell"><div class="box"><div class="child"></div></div></div>
30+
<div class="inline-grid"><div class="box"><div class="child"></div></div></div>
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
<!DOCTYPE html>
2+
<meta charset="utf-8">
3+
<title>Aspect-ratio block inside a shrink-to-fit ancestor keeps its size across relayouts</title>
4+
<link rel="help" href="https://drafts.csswg.org/css-sizing-4/#aspect-ratio">
5+
<link rel="help" href="https://drafts.csswg.org/css-sizing-3/#intrinsic-sizes">
6+
<link rel="match" href="block-aspect-ratio-shrink-to-fit-ancestor-relayout-ref.html">
7+
<meta name="assert" content="When a shrink-to-fit ancestor queries the intrinsic widths of a block-level aspect-ratio box between layouts, the box's percentage-height descendants must not resolve against the previous layout's width and grow the box.">
8+
<style>
9+
.float {
10+
float: left;
11+
}
12+
.inline-block {
13+
display: inline-block;
14+
}
15+
.table-cell {
16+
display: table-cell;
17+
}
18+
.inline-grid {
19+
display: inline-grid;
20+
}
21+
.aspect-ratio-box {
22+
aspect-ratio: 1 / 1;
23+
}
24+
.child {
25+
height: 100%;
26+
aspect-ratio: 2 / 1;
27+
background-color: green;
28+
}
29+
.content {
30+
width: 20px;
31+
height: 5px;
32+
}
33+
</style>
34+
<div class="float"><div class="aspect-ratio-box"><div class="child"><div class="content"></div></div></div></div>
35+
<div style="clear: both"></div>
36+
<div class="inline-block"><div class="aspect-ratio-box"><div class="child"><div class="content"></div></div></div></div>
37+
<div class="table-cell"><div class="aspect-ratio-box"><div class="child"><div class="content"></div></div></div></div>
38+
<div class="inline-grid"><div class="aspect-ratio-box"><div class="child"><div class="content"></div></div></div></div>
39+
<script>
40+
// Each min-width change invalidates the intrinsic widths up to the shrink-to-fit ancestor without changing any size.
41+
for (const content of document.querySelectorAll(".content")) {
42+
for (let i = 0; i < 4; ++i) {
43+
content.style.minWidth = (i % 2 ? 0 : 1) + "px";
44+
document.body.offsetHeight;
45+
}
46+
}
47+
</script>

0 commit comments

Comments
 (0)