layout: Properly calculate free space in flexbox flexible length resolution (#34150)

Previously, when there were no more violations, the returned value for
line free space was incorrect for flexible length resolution. It was
returning the container main space minus the inner length of each item.
Free space is determined by the outer length though. Fix this by reusing
the `free_space()` function, but with an argument indicating that all
items are now frozen.

Fixes #34079.

Signed-off-by: Martin Robinson <mrobinson@igalia.com>
This commit is contained in:
Martin Robinson 2024-11-05 14:32:34 +01:00 committed by GitHub
parent fe0701e226
commit 3289e7d84d
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
16 changed files with 5 additions and 46 deletions

View file

@ -1416,12 +1416,12 @@ impl InitialFlexLineLayout<'_> {
}
let check_for_flexible_items = || frozen_count.get() < items.len();
let free_space = || {
let free_space = |all_items_frozen: bool| {
container_main_size -
items_and_main_sizes()
.map(|((item, target_main_size), frozen)| {
item.pbm_auto_is_zero.main +
if frozen.get() {
if all_items_frozen || frozen.get() {
target_main_size.get()
} else {
item.flex_base_size
@ -1430,7 +1430,7 @@ impl InitialFlexLineLayout<'_> {
.sum()
};
// https://drafts.csswg.org/css-flexbox/#initial-free-space
let initial_free_space = free_space();
let initial_free_space = free_space(false);
let unfrozen_items = || {
items_and_main_sizes().filter_map(|(item_and_target_main_size, frozen)| {
if !frozen.get() {
@ -1442,7 +1442,7 @@ impl InitialFlexLineLayout<'_> {
};
loop {
// https://drafts.csswg.org/css-flexbox/#remaining-free-space
let mut remaining_free_space = free_space();
let mut remaining_free_space = free_space(false);
if !check_for_flexible_items() {
return (target_main_sizes_vec, remaining_free_space);
}
@ -1504,8 +1504,7 @@ impl InitialFlexLineLayout<'_> {
Ordering::Equal => {
// “Freeze all items.”
// Return instead, as thats what the next loop iteration would do.
let remaining_free_space =
container_main_size - target_main_sizes_vec.iter().cloned().sum();
let remaining_free_space = free_space(true);
return (target_main_sizes_vec, remaining_free_space);
},
Ordering::Greater => {

View file

@ -5,18 +5,6 @@
[.flexbox 11]
expected: FAIL
[.flexbox 4]
expected: FAIL
[.flexbox 2]
expected: FAIL
[.flexbox 1]
expected: FAIL
[.flexbox 3]
expected: FAIL
[.flexbox 9]
expected: FAIL

View file

@ -1,2 +0,0 @@
[flexbox-basic-canvas-horiz-001.xhtml]
expected: FAIL

View file

@ -1,2 +0,0 @@
[flexbox-basic-canvas-horiz-001v.xhtml]
expected: FAIL

View file

@ -1,2 +0,0 @@
[flexbox-basic-canvas-vert-001.xhtml]
expected: FAIL

View file

@ -1,2 +0,0 @@
[flexbox-basic-canvas-vert-001v.xhtml]
expected: FAIL

View file

@ -1,2 +0,0 @@
[flexbox-basic-fieldset-horiz-001.xhtml]
expected: FAIL

View file

@ -1,2 +0,0 @@
[flexbox-basic-fieldset-vert-001.xhtml]
expected: FAIL

View file

@ -1,2 +0,0 @@
[flexbox-basic-iframe-horiz-001.xhtml]
expected: FAIL

View file

@ -1,2 +0,0 @@
[flexbox-basic-iframe-vert-001.xhtml]
expected: FAIL

View file

@ -1,2 +0,0 @@
[flexbox-basic-img-horiz-001.xhtml]
expected: FAIL

View file

@ -1,2 +0,0 @@
[flexbox-basic-img-vert-001.xhtml]
expected: FAIL

View file

@ -1,2 +0,0 @@
[flexbox-basic-textarea-horiz-001.xhtml]
expected: FAIL

View file

@ -1,2 +0,0 @@
[flexbox-basic-textarea-vert-001.xhtml]
expected: FAIL

View file

@ -1,2 +0,0 @@
[flexbox-basic-video-horiz-001.xhtml]
expected: FAIL

View file

@ -1,2 +0,0 @@
[flexbox-basic-video-vert-001.xhtml]
expected: FAIL