From bc7cdab46ffd092be2f7f829d590d4b2bb91299b Mon Sep 17 00:00:00 2001 From: Oriol Brufau Date: Wed, 29 Jan 2025 07:54:52 -0800 Subject: [PATCH] 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 --- components/layout_2020/flow/float.rs | 12 --------- components/layout_2020/flow/mod.rs | 7 +++--- tests/wpt/meta/MANIFEST.json | 13 ++++++++++ .../floats-clear/table-among-floats-001.html | 25 +++++++++++++++++++ 4 files changed, 41 insertions(+), 16 deletions(-) create mode 100644 tests/wpt/tests/css/CSS2/floats-clear/table-among-floats-001.html diff --git a/components/layout_2020/flow/float.rs b/components/layout_2020/flow/float.rs index 5ebcfbb2615..a3a978f282d 100644 --- a/components/layout_2020/flow/float.rs +++ b/components/layout_2020/flow/float.rs @@ -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 diff --git a/components/layout_2020/flow/mod.rs b/components/layout_2020/flow/mod.rs index 09519fef395..38a9356c507 100644 --- a/components/layout_2020/flow/mod.rs +++ b/components/layout_2020/flow/mod.rs @@ -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; diff --git a/tests/wpt/meta/MANIFEST.json b/tests/wpt/meta/MANIFEST.json index e5bfc980545..cbb5c50fdeb 100644 --- a/tests/wpt/meta/MANIFEST.json +++ b/tests/wpt/meta/MANIFEST.json @@ -59140,6 +59140,19 @@ ], {} ] + ], + "table-among-floats-001.html": [ + "3bc8f4514528633e92222d0e65db7118259e7049", + [ + null, + [ + [ + "/css/reference/ref-filled-green-200px-square.html", + "==" + ] + ], + {} + ] ] }, "fonts": { diff --git a/tests/wpt/tests/css/CSS2/floats-clear/table-among-floats-001.html b/tests/wpt/tests/css/CSS2/floats-clear/table-among-floats-001.html new file mode 100644 index 00000000000..3bc8f451452 --- /dev/null +++ b/tests/wpt/tests/css/CSS2/floats-clear/table-among-floats-001.html @@ -0,0 +1,25 @@ + +Table among floats + + + + + +

Test passes if there is a filled green square and no red.

+
+
+
+ + +
+
+
+
+
+