Layout 2020: implement clearance as Option<Length>

Clearance was implemented as a Length, where zero meant no clearance.
However, having a clearance of 0px should be different than having
no clearance, since the former can still prevent margin collapse.

This patch keeps the existing behavior, so it won't be possible to get
a clearance of Some(Length::zero()), but it prepares the terrain for
a follow-up to fix calculate_clearance to return the proper thing.
This commit is contained in:
Oriol Brufau 2023-06-23 19:56:55 +02:00
parent a725380db0
commit 6b2bbdd02d
6 changed files with 42 additions and 24 deletions

View file

@ -744,7 +744,7 @@ impl FloatBox {
margin,
// Clearance is handled internally by the float placement logic, so there's no need
// to store it explicitly in the fragment.
Length::zero(), // clearance
None, // clearance
CollapsedBlockMargins::zero(),
)
},
@ -826,9 +826,9 @@ impl SequentialLayoutState {
/// needs to have.
///
/// https://www.w3.org/TR/2011/REC-CSS2-20110607/visuren.html#flow-control
pub(crate) fn calculate_clearance(&self, clear_side: ClearSide) -> Length {
pub(crate) fn calculate_clearance(&self, clear_side: ClearSide) -> Option<Length> {
if clear_side == ClearSide::None {
return Length::zero();
return None;
}
let hypothetical_block_position = self.current_block_position_including_margins();
@ -848,7 +848,10 @@ impl SequentialLayoutState {
.max(self.floats.clear_right_position)
.max(hypothetical_block_position),
};
clear_position - hypothetical_block_position
if hypothetical_block_position >= clear_position {
return None;
}
Some(clear_position - hypothetical_block_position)
}
/// Adds a new adjoining margin.