Repository navigation
Commit dcbe6bb
Count gaps in a flex container's min-content size (#2103)
Summary:
Why
===
A flex item does not shrink below its min-content size (css-flexbox-1 §4.5). When the item is itself a flex container, Chrome counts the gaps between its children along its main axis in that size. Yoga's min-content walk leaves them out, so the item can shrink until its children overflow it by the gaps:
```html
<div style="display: flex; width: 200px">
<div style="display: flex; flex-shrink: 1; gap: 20px"> <!-- Chrome: 130px. Yoga: 90px -->
<div style="width: 30px; flex-shrink: 0"></div>
<div style="width: 30px; flex-shrink: 0"></div>
<div style="width: 30px; flex-shrink: 0"></div>
</div>
<div style="width: 180px; flex-shrink: 0"></div>
</div>
```
How
===
The walk adds one gap between each two in-flow children when it sums them along the container's main axis. A percentage gap counts as zero, because a percentage gutter resolves against zero for an intrinsic size contribution (css-sizing-3 §5.2.1). Chrome does the same.
Test Plan
=========
`yarn gentest -f YGAutoMinSizeTest` generates the new fixtures from Chrome, and `cmake --build tests/build && tests/build/yogatests` passes.
With the change reverted, two fixtures fail:
| Fixture | Chrome | Without the change |
| --- | --- | --- |
| `counts_column_gaps` (item width) | 130 | 90 |
| `counts_row_gaps` (item height) | 80 | 60 |
`gaps_skip_cross_axis_and_absolute_children` and `percent_gap_counts_as_zero` pass with and without the change; they pin what must not count. Adding cross-axis gaps, counting an absolutely positioned child, or resolving a percentage gap against the owner's width makes one of them fail (50 becomes 70, 30 becomes 50, and 60 becomes 80).
`yarn gentest -h` leaves the tree clean, and `node ./scripts/clang-format.js --check` passes. The generated Java tests were not run, because the Gradle project has no unit-test source set, and neither were the generated JavaScript tests, which need Emscripten.
Changelog:
[General][Fixed] - Fix Yoga's automatic minimum size leaving out the gaps between a flex item's children
Reviewed By: javache
Differential Revision: D1353354631 parent 6ff2bcd commit dcbe6bb
1 file changed
Lines changed: 12 additions & 2 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1031 | 1031 | | |
1032 | 1032 | | |
1033 | 1033 | | |
| 1034 | + | |
1034 | 1035 | | |
1035 | 1036 | | |
1036 | 1037 | | |
| |||
1039 | 1040 | | |
1040 | 1041 | | |
1041 | 1042 | | |
| 1043 | + | |
1042 | 1044 | | |
1043 | 1045 | | |
1044 | 1046 | | |
| |||
1056 | 1058 | | |
1057 | 1059 | | |
1058 | 1060 | | |
| 1061 | + | |
| 1062 | + | |
| 1063 | + | |
| 1064 | + | |
| 1065 | + | |
| 1066 | + | |
| 1067 | + | |
1059 | 1068 | | |
1060 | 1069 | | |
1061 | 1070 | | |
| |||
1181 | 1190 | | |
1182 | 1191 | | |
1183 | 1192 | | |
1184 | | - | |
1185 | | - | |
| 1193 | + | |
| 1194 | + | |
| 1195 | + | |
1186 | 1196 | | |
1187 | 1197 | | |
1188 | 1198 | | |
| |||
0 commit comments