layout: Remove wrong optimization when placing table among floats (#35207)

When we try to place a table next to some floats, and it doesn't fit
vertically, then we try again considering more floats. And as an
optimization we were using the previous width of the table as a minimum.
However, this was wrong, because the table might accept a smaller width
when the available space is smaller than beforehand.

Signed-off-by: Oriol Brufau <obrufau@igalia.com>
This commit is contained in:
Oriol Brufau 2025-01-29 07:54:52 -08:00 committed by GitHub
parent 53fcc98585
commit bc7cdab46f
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
4 changed files with 41 additions and 16 deletions

View file

@ -251,18 +251,6 @@ impl<'a> PlacementAmongFloats<'a> {
}
}
/// After placing a table and then laying it out, it may turn out wider than what
/// we initially expected. This method takes care of updating the data so that
/// the next place() can find the right area for the new size.
/// Note that if the new size is smaller, placement won't backtrack to consider
/// areas that weren't big enough for the old size.
pub(crate) fn set_inline_size(&mut self, inline_size: Au, pbm: &PaddingBorderMargin) {
self.object_size.inline = inline_size;
self.max_inline_end = (self.float_context.containing_block_info.inline_end -
pbm.margin.inline_end.auto_is(Au::zero))
.max(self.min_inline_start + inline_size);
}
/// After placing an object with `height: auto` (and using the minimum inline and
/// block size as the object size) and then laying it out, try to fit the object into
/// the current set of bands, given block size after layout and the available inline

View file

@ -1361,11 +1361,10 @@ impl IndependentNonReplacedContents {
// up until after trying to place it. If the table doesn't fit into this
// positioning rectangle due to incompatibility in the inline axis,
// then retry at another location.
// Even if it would fit in the inline axis, we may end up having to retry
// at another location due to incompatibility in the block axis. Therefore,
// always update the size in the PlacementAmongFloats as an optimization.
// Note if we get a narrower size due to collapsed columns, we don't backtrack
// to consider areas that we thought weren't big enough.
// TODO: Should `minimum_size_of_block.inline` be zero for tables?
let outer_inline_size = inline_size + pbm.padding_border_sums.inline;
placement.set_inline_size(outer_inline_size, &pbm);
if outer_inline_size > placement_rect.size.inline {
positioning_context.truncate(&positioning_context_length);
continue;