Skip to content

Commit

Permalink
Fix intrinsic sizing of block container containing a BFC root after f…
Browse files Browse the repository at this point in the history
…loats (#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.
  • Loading branch information
Loirooriol committed Jul 19, 2023
1 parent cf9ec70 commit a2d38dc
Showing 1 changed file with 16 additions and 17 deletions.
33 changes: 16 additions & 17 deletions components/layout_2020/flow/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -260,14 +260,14 @@ fn calculate_inline_content_size_for_block_level_boxes(
let size = sizing::outer_inline(&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,
// so don't bother retrieving it from the style.
Some((size, Float::None, Clear::None))
// A block in the same BFC can overlap floats, it's not moved next to them,
// so we shouldn't add its size to the size of the floats.
// Instead, we treat it like an independent block with 'clear: both'.
Some((size, Float::None, Clear::Both))
},
BlockLevelBox::Independent(ref mut independent) => {
let size = independent.outer_inline_content_sizes(layout_context, writing_mode);
// TODO: do the right thing instead of copying SameFormattingContextBlock.
Some((size, Float::None, Clear::None))
Some((size, Float::None, independent.style().get_box().clear))
},
}
};
Expand Down Expand Up @@ -308,18 +308,17 @@ fn calculate_inline_content_size_for_block_level_boxes(
}

let accumulate = |mut data: AccumulatedData, (size, float, clear)| {
if float == Float::None {
// TODO: The first BFC root after a sequence of floats should appear next to them
// (if it doesn't have clearance).
data.clear_floats(Clear::Both);
data.max_size = data.max_size.max(size);
} else {
data.clear_floats(clear);
match float {
Float::Left => data.left_floats = data.left_floats.add(&size),
Float::Right => data.right_floats = data.right_floats.add(&size),
Float::None => unreachable!(),
}
data.clear_floats(clear);
match float {
Float::Left => data.left_floats = data.left_floats.add(&size),
Float::Right => data.right_floats = data.right_floats.add(&size),
Float::None => {
data.max_size = data
.max_size
.max(data.left_floats.add(&data.right_floats).add(&size));
data.left_floats = ContentSizes::zero();
data.right_floats = ContentSizes::zero();
},
}
data
};
Expand Down

0 comments on commit a2d38dc

Please sign in to comment.