Fix intrinsic sizing of block container containing a BFC root after floats (#30012)

A block that establishes an independent formatting context is placed
next to previous floats, so we should add their sizes when computing
the intrinsic contribution of the parent block container.
This commit is contained in:
Oriol Brufau 2023-07-19 19:14:39 +02:00 committed by GitHub
parent cf9ec700de
commit 727d61a99d
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -260,14 +260,14 @@ fn calculate_inline_content_size_for_block_level_boxes(
let size = sizing::outer_inline(&style, writing_mode, || { let size = sizing::outer_inline(&style, writing_mode, || {
contents.inline_content_sizes(layout_context, style.writing_mode) contents.inline_content_sizes(layout_context, style.writing_mode)
}); });
// The element may in fact have clearance, but the logic below ignores it, // A block in the same BFC can overlap floats, it's not moved next to them,
// so don't bother retrieving it from the style. // so we shouldn't add its size to the size of the floats.
Some((size, Float::None, Clear::None)) // Instead, we treat it like an independent block with 'clear: both'.
Some((size, Float::None, Clear::Both))
}, },
BlockLevelBox::Independent(ref mut independent) => { BlockLevelBox::Independent(ref mut independent) => {
let size = independent.outer_inline_content_sizes(layout_context, writing_mode); let size = independent.outer_inline_content_sizes(layout_context, writing_mode);
// TODO: do the right thing instead of copying SameFormattingContextBlock. Some((size, Float::None, independent.style().get_box().clear))
Some((size, Float::None, Clear::None))
}, },
} }
}; };
@ -308,18 +308,17 @@ fn calculate_inline_content_size_for_block_level_boxes(
} }
let accumulate = |mut data: AccumulatedData, (size, float, clear)| { let accumulate = |mut data: AccumulatedData, (size, float, clear)| {
if float == Float::None { data.clear_floats(clear);
// TODO: The first BFC root after a sequence of floats should appear next to them match float {
// (if it doesn't have clearance). Float::Left => data.left_floats = data.left_floats.add(&size),
data.clear_floats(Clear::Both); Float::Right => data.right_floats = data.right_floats.add(&size),
data.max_size = data.max_size.max(size); Float::None => {
} else { data.max_size = data
data.clear_floats(clear); .max_size
match float { .max(data.left_floats.add(&data.right_floats).add(&size));
Float::Left => data.left_floats = data.left_floats.add(&size), data.left_floats = ContentSizes::zero();
Float::Right => data.right_floats = data.right_floats.add(&size), data.right_floats = ContentSizes::zero();
Float::None => unreachable!(), },
}
} }
data data
}; };