mirror of
https://github.com/servo/servo.git
synced 2025-08-03 04:30:10 +01:00
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:
parent
3c4ec17180
commit
a4a308e434
7 changed files with 29 additions and 42 deletions
|
@ -256,8 +256,6 @@ impl FlexLineItem<'_> {
|
|||
size: item_used_size,
|
||||
},
|
||||
);
|
||||
let margin = flex_context.sides_to_flow_relative(item_margin);
|
||||
let collapsed_margin = CollapsedBlockMargins::from_margin(&margin);
|
||||
|
||||
if let Some(item_baseline) = self.layout_result.baseline_relative_to_margin_box.as_ref() {
|
||||
let item_baseline = *item_baseline + item_content_cross_start_position -
|
||||
|
@ -294,9 +292,10 @@ impl FlexLineItem<'_> {
|
|||
flex_context
|
||||
.sides_to_flow_relative(self.item.border)
|
||||
.to_physical(container_writing_mode),
|
||||
margin.to_physical(container_writing_mode),
|
||||
flex_context
|
||||
.sides_to_flow_relative(item_margin)
|
||||
.to_physical(container_writing_mode),
|
||||
None, /* clearance */
|
||||
collapsed_margin,
|
||||
);
|
||||
|
||||
// If this flex item establishes a containing block for absolutely-positioned
|
||||
|
|
|
@ -23,9 +23,7 @@ use webrender_api::FontInstanceKey;
|
|||
use super::inline_box::{InlineBoxContainerState, InlineBoxIdentifier, InlineBoxTreePathToken};
|
||||
use super::{InlineFormattingContextLayout, LineBlockSizes};
|
||||
use crate::cell::ArcRefCell;
|
||||
use crate::fragment_tree::{
|
||||
BaseFragmentInfo, BoxFragment, CollapsedBlockMargins, Fragment, TextFragment,
|
||||
};
|
||||
use crate::fragment_tree::{BaseFragmentInfo, BoxFragment, Fragment, TextFragment};
|
||||
use crate::geom::{LogicalRect, LogicalVec2, PhysicalRect, ToLogical};
|
||||
use crate::positioned::{
|
||||
AbsolutelyPositionedBox, PositioningContext, PositioningContextLength, relative_adjustement,
|
||||
|
@ -465,7 +463,6 @@ impl LineItemLayout<'_, '_> {
|
|||
border.to_physical(ifc_writing_mode),
|
||||
margin.to_physical(ifc_writing_mode),
|
||||
None, /* clearance */
|
||||
CollapsedBlockMargins::zero(),
|
||||
);
|
||||
|
||||
let offset_from_parent_ifc = LogicalVec2 {
|
||||
|
|
|
@ -355,7 +355,6 @@ impl OutsideMarker {
|
|||
PhysicalSides::zero(),
|
||||
PhysicalSides::zero(),
|
||||
None,
|
||||
CollapsedBlockMargins::zero(),
|
||||
)))
|
||||
}
|
||||
}
|
||||
|
@ -1105,9 +1104,9 @@ fn layout_in_flow_non_replaced_block_level_same_formatting_context(
|
|||
pbm.border.to_physical(containing_block_writing_mode),
|
||||
margin.to_physical(containing_block_writing_mode),
|
||||
clearance,
|
||||
block_margins_collapsed_with_children,
|
||||
)
|
||||
.with_baselines(flow_layout.baselines)
|
||||
.with_block_margins_collapsed_with_children(block_margins_collapsed_with_children)
|
||||
}
|
||||
|
||||
impl IndependentNonReplacedContents {
|
||||
|
@ -1211,10 +1210,10 @@ impl IndependentNonReplacedContents {
|
|||
pbm.border.to_physical(containing_block_writing_mode),
|
||||
margin.to_physical(containing_block_writing_mode),
|
||||
None, /* clearance */
|
||||
block_margins_collapsed_with_children,
|
||||
)
|
||||
.with_baselines(layout.baselines)
|
||||
.with_specific_layout_info(layout.specific_layout_info)
|
||||
.with_block_margins_collapsed_with_children(block_margins_collapsed_with_children)
|
||||
}
|
||||
|
||||
/// Lay out a normal in flow non-replaced block that establishes an independent
|
||||
|
@ -1516,10 +1515,10 @@ impl IndependentNonReplacedContents {
|
|||
pbm.border.to_physical(containing_block_writing_mode),
|
||||
margin.to_physical(containing_block_writing_mode),
|
||||
clearance,
|
||||
CollapsedBlockMargins::from_margin(&margin),
|
||||
)
|
||||
.with_baselines(layout.baselines)
|
||||
.with_specific_layout_info(layout.specific_layout_info)
|
||||
.with_block_margins_collapsed_with_children(CollapsedBlockMargins::from_margin(&margin))
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -1653,8 +1652,8 @@ impl ReplacedContents {
|
|||
pbm.border.to_physical(containing_block_writing_mode),
|
||||
margin.to_physical(containing_block_writing_mode),
|
||||
clearance,
|
||||
CollapsedBlockMargins::from_margin(&margin),
|
||||
)
|
||||
.with_block_margins_collapsed_with_children(CollapsedBlockMargins::from_margin(&margin))
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -2038,7 +2037,7 @@ impl<'container> PlacementState<'container> {
|
|||
return;
|
||||
}
|
||||
|
||||
let fragment_block_margins = &fragment.block_margins_collapsed_with_children;
|
||||
let fragment_block_margins = fragment.block_margins_collapsed_with_children();
|
||||
let mut fragment_block_size = fragment
|
||||
.border_rect()
|
||||
.size
|
||||
|
@ -2352,7 +2351,6 @@ impl IndependentFormattingContext {
|
|||
// so there's no need to store it explicitly in the fragment.
|
||||
// And atomic inlines don't have clearance.
|
||||
None, /* clearance */
|
||||
CollapsedBlockMargins::zero(),
|
||||
);
|
||||
|
||||
IndependentFloatOrAtomicLayoutResult {
|
||||
|
|
|
@ -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(),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -21,8 +21,7 @@ use crate::formatting_contexts::{
|
|||
IndependentFormattingContext, IndependentFormattingContextContents,
|
||||
};
|
||||
use crate::fragment_tree::{
|
||||
BoxFragment, CollapsedBlockMargins, Fragment, FragmentFlags, HoistedSharedFragment,
|
||||
SpecificLayoutInfo,
|
||||
BoxFragment, Fragment, FragmentFlags, HoistedSharedFragment, SpecificLayoutInfo,
|
||||
};
|
||||
use crate::geom::{
|
||||
AuOrAuto, LengthPercentageOrAuto, LogicalRect, LogicalSides, LogicalSides1D, LogicalVec2,
|
||||
|
@ -697,9 +696,6 @@ impl HoistedAbsolutelyPositionedBox {
|
|||
pbm.border.to_physical(containing_block_writing_mode),
|
||||
margin.to_physical(containing_block_writing_mode),
|
||||
None, /* clearance */
|
||||
// We do not set the baseline offset, because absolutely positioned
|
||||
// elements are not inflow.
|
||||
CollapsedBlockMargins::zero(),
|
||||
)
|
||||
.with_specific_layout_info(specific_layout_info)
|
||||
};
|
||||
|
|
|
@ -1785,7 +1785,6 @@ impl<'a> TableLayout<'a> {
|
|||
self.pbm.border.to_physical(table_writing_mode),
|
||||
PhysicalSides::zero(),
|
||||
None, /* clearance */
|
||||
CollapsedBlockMargins::zero(),
|
||||
)
|
||||
.with_specific_layout_info(self.specific_layout_info_for_grid());
|
||||
}
|
||||
|
@ -1911,7 +1910,6 @@ impl<'a> TableLayout<'a> {
|
|||
self.pbm.border.to_physical(table_writing_mode),
|
||||
PhysicalSides::zero(),
|
||||
None, /* clearance */
|
||||
CollapsedBlockMargins::zero(),
|
||||
)
|
||||
.with_baselines(baselines)
|
||||
.with_specific_layout_info(self.specific_layout_info_for_grid())
|
||||
|
@ -2338,7 +2336,6 @@ impl<'a> RowFragmentLayout<'a> {
|
|||
PhysicalSides::zero(), /* border */
|
||||
PhysicalSides::zero(), /* margin */
|
||||
None, /* clearance */
|
||||
CollapsedBlockMargins::zero(),
|
||||
);
|
||||
row_fragment.set_does_not_paint_background();
|
||||
|
||||
|
@ -2404,7 +2401,6 @@ impl RowGroupFragmentLayout {
|
|||
PhysicalSides::zero(), /* border */
|
||||
PhysicalSides::zero(), /* margin */
|
||||
None, /* clearance */
|
||||
CollapsedBlockMargins::zero(),
|
||||
);
|
||||
row_group_fragment.set_does_not_paint_background();
|
||||
|
||||
|
@ -2887,7 +2883,6 @@ impl TableSlotCell {
|
|||
layout.border.to_physical(table_style.writing_mode),
|
||||
PhysicalSides::zero(), /* margin */
|
||||
None, /* clearance */
|
||||
CollapsedBlockMargins::zero(),
|
||||
)
|
||||
.with_baselines(layout.layout.baselines)
|
||||
.with_specific_layout_info(specific_layout_info)
|
||||
|
|
|
@ -23,8 +23,8 @@ use crate::fragment_tree::{
|
|||
BoxFragment, CollapsedBlockMargins, Fragment, FragmentFlags, SpecificLayoutInfo,
|
||||
};
|
||||
use crate::geom::{
|
||||
LogicalSides, LogicalVec2, PhysicalPoint, PhysicalRect, PhysicalSides, PhysicalSize, Size,
|
||||
SizeConstraint, Sizes,
|
||||
LogicalVec2, PhysicalPoint, PhysicalRect, PhysicalSides, PhysicalSize, Size, SizeConstraint,
|
||||
Sizes,
|
||||
};
|
||||
use crate::layout_box_base::CacheableLayoutResult;
|
||||
use crate::positioned::{AbsolutelyPositionedBox, PositioningContext, PositioningContextLength};
|
||||
|
@ -486,15 +486,6 @@ impl TaffyContainer {
|
|||
.map(|child| (**child).borrow_mut())
|
||||
.enumerate()
|
||||
.map(|(child_id, mut child)| {
|
||||
fn rect_to_logical_sides<T>(rect: taffy::Rect<T>) -> LogicalSides<T> {
|
||||
LogicalSides {
|
||||
inline_start: rect.left,
|
||||
inline_end: rect.right,
|
||||
block_start: rect.top,
|
||||
block_end: rect.bottom,
|
||||
}
|
||||
}
|
||||
|
||||
fn rect_to_physical_sides<T>(rect: taffy::Rect<T>) -> PhysicalSides<T> {
|
||||
PhysicalSides::new(rect.top, rect.right, rect.bottom, rect.left)
|
||||
}
|
||||
|
@ -514,8 +505,6 @@ impl TaffyContainer {
|
|||
let padding = rect_to_physical_sides(layout.padding.map(Au::from_f32_px));
|
||||
let border = rect_to_physical_sides(layout.border.map(Au::from_f32_px));
|
||||
let margin = rect_to_physical_sides(layout.margin.map(Au::from_f32_px));
|
||||
let logical_margin = rect_to_logical_sides(layout.margin.map(Au::from_f32_px));
|
||||
let collapsed_margin = CollapsedBlockMargins::from_margin(&logical_margin);
|
||||
|
||||
// Compute content box size and position.
|
||||
//
|
||||
|
@ -576,7 +565,6 @@ impl TaffyContainer {
|
|||
border,
|
||||
margin,
|
||||
None, /* clearance */
|
||||
collapsed_margin,
|
||||
)
|
||||
.with_baselines(Baselines {
|
||||
first: output.first_baselines.y.map(Au::from_f32_px),
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue