layout: Box block_margins_collapsed_with_children member of BoxFragment (#36474)

This reduces the size of `BoxFragment` by around 20 bytes.

Testing: This just changes the layout of a data structure, so is
covered by existing WPT tests.

Signed-off-by: Martin Robinson <mrobinson@igalia.com>
Co-authored-by: Oriol Brufau <obrufau@igalia.com>
This commit is contained in:
Martin Robinson 2025-04-12 10:52:30 +02:00 committed by GitHub
parent 3c4ec17180
commit a4a308e434
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
7 changed files with 29 additions and 42 deletions

View file

@ -76,7 +76,7 @@ pub(crate) struct BoxFragment {
/// to things such as tables and inline formatting contexts.
baselines: Baselines,
pub block_margins_collapsed_with_children: CollapsedBlockMargins,
block_margins_collapsed_with_children: Option<Box<CollapsedBlockMargins>>,
/// The scrollable overflow of this box fragment.
pub scrollable_overflow_from_children: PhysicalRect<Au>,
@ -103,7 +103,6 @@ impl BoxFragment {
border: PhysicalSides<Au>,
margin: PhysicalSides<Au>,
clearance: Option<Au>,
block_margins_collapsed_with_children: CollapsedBlockMargins,
) -> BoxFragment {
let scrollable_overflow_from_children =
children.iter().fold(PhysicalRect::zero(), |acc, child| {
@ -120,7 +119,7 @@ impl BoxFragment {
margin,
clearance,
baselines: Baselines::default(),
block_margins_collapsed_with_children,
block_margins_collapsed_with_children: None,
scrollable_overflow_from_children,
resolved_sticky_insets: AtomicRefCell::default(),
background_mode: BackgroundMode::Normal,
@ -182,6 +181,14 @@ impl BoxFragment {
self
}
pub fn with_block_margins_collapsed_with_children(
mut self,
collapsed_margins: CollapsedBlockMargins,
) -> Self {
self.block_margins_collapsed_with_children = Some(collapsed_margins.into());
self
}
pub fn scrollable_overflow(&self) -> PhysicalRect<Au> {
let physical_padding_rect = self.padding_rect();
let content_origin = self.content_rect.origin.to_vector();
@ -374,4 +381,11 @@ impl BoxFragment {
_ => false,
}
}
pub(crate) fn block_margins_collapsed_with_children(&self) -> CollapsedBlockMargins {
match self.block_margins_collapsed_with_children.as_ref() {
Some(collapsed_block_margins) => *(collapsed_block_margins).clone(),
_ => CollapsedBlockMargins::zero(),
}
}
}