layout: Use Au in ResolvedMargins and CollapsedMargin (#31848)

* change ResolvedMargins to use Au instead of length

* made suggested changes

removed whitespace changes

made suggested changes

* Update components/layout_2020/flexbox/layout.rs

Co-authored-by: Oriol Brufau <obrufau@igalia.com>

* Update components/layout_2020/flow/mod.rs

Co-authored-by: Oriol Brufau <obrufau@igalia.com>

* fixed errors

fixed errors

fixed formatting

fixed errors

* modified changes

made suggested changes

* Update components/layout_2020/fragment_tree/fragment.rs

Co-authored-by: Oriol Brufau <obrufau@igalia.com>

updated components/layout_2020/fragment_tree/fragment.rs

* Update components/layout_2020/flow/mod.rs

Co-authored-by: Oriol Brufau <obrufau@igalia.com>

* Update components/layout_2020/flow/mod.rs

Co-authored-by: Oriol Brufau <obrufau@igalia.com>

* updated changes

updated changes

* unified all the suggested changes here

* fixed formatting

* reverted unnecessary changes

* fixed unnecessary warnings

---------

Co-authored-by: Oriol Brufau <obrufau@igalia.com>
This commit is contained in:
Ekta Siwach 2024-03-28 19:50:14 +05:30 committed by GitHub
parent 66ad795014
commit 5d518ca8dc
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
4 changed files with 62 additions and 70 deletions

View file

@ -847,7 +847,7 @@ impl FlexLine<'_> {
.zip(&item_margins) .zip(&item_margins)
.map(|(((item, item_result), content_rect), margin)| { .map(|(((item, item_result), content_rect), margin)| {
let content_rect = flex_context.rect_to_flow_relative(line_size, content_rect); let content_rect = flex_context.rect_to_flow_relative(line_size, content_rect);
let margin = flex_context.sides_to_flow_relative(*margin); let margin = flex_context.sides_to_flow_relative(*margin).into();
let collapsed_margin = CollapsedBlockMargins::from_margin(&margin); let collapsed_margin = CollapsedBlockMargins::from_margin(&margin);
( (
// TODO: We should likely propagate baselines from `display: flex`. // TODO: We should likely propagate baselines from `display: flex`.
@ -858,7 +858,7 @@ impl FlexLine<'_> {
content_rect, content_rect,
flex_context.sides_to_flow_relative(item.padding), flex_context.sides_to_flow_relative(item.padding),
flex_context.sides_to_flow_relative(item.border), flex_context.sides_to_flow_relative(item.border),
margin.into(), margin,
None, /* clearance */ None, /* clearance */
collapsed_margin, collapsed_margin,
), ),

View file

@ -1062,7 +1062,7 @@ impl SequentialLayoutState {
/// Return the current block position in the float containing block formatting /// Return the current block position in the float containing block formatting
/// context and any uncollapsed block margins. /// context and any uncollapsed block margins.
pub(crate) fn current_block_position_including_margins(&self) -> Au { pub(crate) fn current_block_position_including_margins(&self) -> Au {
self.bfc_relative_block_position + self.current_margin.solve().into() self.bfc_relative_block_position + self.current_margin.solve()
} }
/// Collapses margins, moving the block position down by the collapsed value of `current_margin` /// Collapses margins, moving the block position down by the collapsed value of `current_margin`
@ -1071,7 +1071,7 @@ impl SequentialLayoutState {
/// Call this method before laying out children when it is known that the start margin of the /// Call this method before laying out children when it is known that the start margin of the
/// current fragment can't collapse with the margins of any of its children. /// current fragment can't collapse with the margins of any of its children.
pub(crate) fn collapse_margins(&mut self) { pub(crate) fn collapse_margins(&mut self) {
self.advance_block_position(self.current_margin.solve().into()); self.advance_block_position(self.current_margin.solve());
self.current_margin = CollapsedMargin::zero(); self.current_margin = CollapsedMargin::zero();
} }
@ -1079,11 +1079,7 @@ impl SequentialLayoutState {
/// with the provided `block_start_margin`, assuming no clearance. /// with the provided `block_start_margin`, assuming no clearance.
pub(crate) fn position_without_clearance(&self, block_start_margin: &CollapsedMargin) -> Au { pub(crate) fn position_without_clearance(&self, block_start_margin: &CollapsedMargin) -> Au {
// Adjoin `current_margin` and `block_start_margin` since there is no clearance. // Adjoin `current_margin` and `block_start_margin` since there is no clearance.
self.bfc_relative_block_position + self.bfc_relative_block_position + self.current_margin.adjoin(block_start_margin).solve()
self.current_margin
.adjoin(block_start_margin)
.solve()
.into()
} }
/// Computes the position of the block-start border edge of an element /// Computes the position of the block-start border edge of an element
@ -1091,9 +1087,7 @@ impl SequentialLayoutState {
pub(crate) fn position_with_zero_clearance(&self, block_start_margin: &CollapsedMargin) -> Au { pub(crate) fn position_with_zero_clearance(&self, block_start_margin: &CollapsedMargin) -> Au {
// Clearance prevents `current_margin` and `block_start_margin` from being // Clearance prevents `current_margin` and `block_start_margin` from being
// adjoining, so we need to solve them separately and then sum. // adjoining, so we need to solve them separately and then sum.
self.bfc_relative_block_position + self.bfc_relative_block_position + self.current_margin.solve() + block_start_margin.solve()
self.current_margin.solve().into() +
block_start_margin.solve().into()
} }
/// Returns the block-end outer edge of the lowest float that is to be cleared (if any) /// Returns the block-end outer edge of the lowest float that is to be cleared (if any)
@ -1191,7 +1185,6 @@ impl SequentialLayoutState {
.containing_block_info .containing_block_info
.block_start_margins_not_collapsed .block_start_margins_not_collapsed
.solve() .solve()
.into()
} }
/// This function places a Fragment that has been created for a FloatBox. /// This function places a Fragment that has been created for a FloatBox.
@ -1206,8 +1199,7 @@ impl SequentialLayoutState {
.containing_block_info .containing_block_info
.block_start_margins_not_collapsed .block_start_margins_not_collapsed
.adjoin(&margins_collapsing_with_parent_containing_block) .adjoin(&margins_collapsing_with_parent_containing_block)
.solve() .solve();
.into();
self.floats.set_ceiling_from_non_floats( self.floats.set_ceiling_from_non_floats(
block_start_of_containing_block_in_bfc + block_offset_from_containing_block_top, block_start_of_containing_block_in_bfc + block_offset_from_containing_block_top,

View file

@ -117,7 +117,7 @@ impl BlockLevelBox {
let pbm = style.padding_border_margin(containing_block); let pbm = style.padding_border_margin(containing_block);
let start_margin = pbm.margin.block_start.auto_is(Au::zero); let start_margin = pbm.margin.block_start.auto_is(Au::zero);
collected_margin.adjoin_assign(&CollapsedMargin::new(start_margin.into())); collected_margin.adjoin_assign(&CollapsedMargin::new(start_margin));
let child_boxes = match self { let child_boxes = match self {
BlockLevelBox::SameFormattingContextBlock { ref contents, .. } => match contents { BlockLevelBox::SameFormattingContextBlock { ref contents, .. } => match contents {
@ -176,7 +176,7 @@ impl BlockLevelBox {
} }
let end_margin = pbm.margin.block_end.auto_is(Au::zero); let end_margin = pbm.margin.block_end.auto_is(Au::zero);
collected_margin.adjoin_assign(&CollapsedMargin::new(end_margin.into())); collected_margin.adjoin_assign(&CollapsedMargin::new(end_margin));
true true
} }
@ -242,10 +242,9 @@ impl BlockFormattingContext {
IndependentLayout { IndependentLayout {
fragments: flow_layout.fragments, fragments: flow_layout.fragments,
content_block_size: (flow_layout.content_block_size + content_block_size: Au::from(flow_layout.content_block_size) +
flow_layout.collapsible_margins_in_children.end.solve() + flow_layout.collapsible_margins_in_children.end.solve() +
clearance.unwrap_or_else(Au::zero).into()) clearance.unwrap_or_default(),
.into(),
content_inline_size_for_table: None, content_inline_size_for_table: None,
baselines: flow_layout.baselines, baselines: flow_layout.baselines,
} }
@ -638,7 +637,7 @@ fn layout_in_flow_non_replaced_block_level_same_formatting_context(
} = solve_margins( } = solve_margins(
containing_block, containing_block,
&pbm, &pbm,
containing_block_for_children.inline_size.into(), containing_block_for_children.inline_size,
); );
let computed_block_size = style.content_block_size(); let computed_block_size = style.content_block_size();
@ -710,7 +709,7 @@ fn layout_in_flow_non_replaced_block_level_same_formatting_context(
.inline_start + .inline_start +
pbm.padding.inline_start + pbm.padding.inline_start +
pbm.border.inline_start + pbm.border.inline_start +
effective_margin_inline_start.into(); effective_margin_inline_start;
let new_cb_offsets = ContainingBlockPositionInfo { let new_cb_offsets = ContainingBlockPositionInfo {
block_start: sequential_layout_state.bfc_relative_block_position, block_start: sequential_layout_state.bfc_relative_block_position,
block_start_margins_not_collapsed: sequential_layout_state.current_margin, block_start_margins_not_collapsed: sequential_layout_state.current_margin,
@ -753,7 +752,7 @@ fn layout_in_flow_non_replaced_block_level_same_formatting_context(
.end .end
.adjoin_assign(&collapsible_margins_in_children.end); .adjoin_assign(&collapsible_margins_in_children.end);
} else { } else {
content_block_size += collapsible_margins_in_children.end.solve(); content_block_size += collapsible_margins_in_children.end.solve().into();
} }
let computed_min_block_size = style.min_block_size(); let computed_min_block_size = style.min_block_size();
@ -801,7 +800,7 @@ fn layout_in_flow_non_replaced_block_level_same_formatting_context(
clearance.unwrap_or_else(Au::zero)), clearance.unwrap_or_else(Au::zero)),
inline: pbm.padding.inline_start + inline: pbm.padding.inline_start +
pbm.border.inline_start + pbm.border.inline_start +
effective_margin_inline_start.into(), effective_margin_inline_start,
}, },
size: LogicalVec2 { size: LogicalVec2 {
block: block_size, block: block_size,
@ -816,7 +815,7 @@ fn layout_in_flow_non_replaced_block_level_same_formatting_context(
content_rect.into(), content_rect.into(),
pbm.padding, pbm.padding,
pbm.border, pbm.border,
margin.into(), margin,
clearance, clearance,
block_margins_collapsed_with_children, block_margins_collapsed_with_children,
) )
@ -878,14 +877,14 @@ impl NonReplacedFormattingContext {
let ResolvedMargins { let ResolvedMargins {
margin, margin,
effective_margin_inline_start, effective_margin_inline_start,
} = solve_margins(containing_block, &pbm, inline_size.into()); } = solve_margins(containing_block, &pbm, inline_size);
let content_rect = LogicalRect { let content_rect = LogicalRect {
start_corner: LogicalVec2 { start_corner: LogicalVec2 {
block: pbm.padding.block_start + pbm.border.block_start, block: pbm.padding.block_start + pbm.border.block_start,
inline: pbm.padding.inline_start + inline: pbm.padding.inline_start +
pbm.border.inline_start + pbm.border.inline_start +
effective_margin_inline_start.into(), effective_margin_inline_start,
}, },
size: LogicalVec2 { size: LogicalVec2 {
block: block_size, block: block_size,
@ -902,7 +901,7 @@ impl NonReplacedFormattingContext {
content_rect.into(), content_rect.into(),
pbm.padding, pbm.padding,
pbm.border, pbm.border,
margin.into(), margin,
None, /* clearance */ None, /* clearance */
block_margins_collapsed_with_children, block_margins_collapsed_with_children,
) )
@ -935,7 +934,7 @@ impl NonReplacedFormattingContext {
let effective_margin_inline_start; let effective_margin_inline_start;
let (margin_block_start, margin_block_end) = let (margin_block_start, margin_block_end) =
solve_block_margins_for_in_flow_block_level(&pbm); solve_block_margins_for_in_flow_block_level(&pbm);
let collapsed_margin_block_start = CollapsedMargin::new(margin_block_start.into()); let collapsed_margin_block_start = CollapsedMargin::new(margin_block_start);
// From https://drafts.csswg.org/css2/#floats: // From https://drafts.csswg.org/css2/#floats:
// "The border box of a table, a block-level replaced element, or an element in // "The border box of a table, a block-level replaced element, or an element in
@ -1112,10 +1111,10 @@ impl NonReplacedFormattingContext {
} }
let margin = LogicalSides { let margin = LogicalSides {
inline_start: margin_inline_start.into(), inline_start: margin_inline_start,
inline_end: margin_inline_end.into(), inline_end: margin_inline_end,
block_start: margin_block_start.into(), block_start: margin_block_start,
block_end: margin_block_end.into(), block_end: margin_block_end,
}; };
// Clearance prevents margin collapse between this block and previous ones, // Clearance prevents margin collapse between this block and previous ones,
@ -1154,7 +1153,7 @@ impl NonReplacedFormattingContext {
content_rect.into(), content_rect.into(),
pbm.padding, pbm.padding,
pbm.border, pbm.border,
margin.into(), margin,
clearance, clearance,
block_margins_collapsed_with_children, block_margins_collapsed_with_children,
) )
@ -1193,7 +1192,7 @@ fn layout_in_flow_replaced_block_level(
// sufficient space. They may even make the border box of said element narrower // sufficient space. They may even make the border box of said element narrower
// than defined by section 10.3.3. CSS 2 does not define when a UA may put said // than defined by section 10.3.3. CSS 2 does not define when a UA may put said
// element next to the float or by how much said element may become narrower." // element next to the float or by how much said element may become narrower."
let collapsed_margin_block_start = CollapsedMargin::new(margin_block_start.into()); let collapsed_margin_block_start = CollapsedMargin::new(margin_block_start);
let size = &content_size + &pbm.padding_border_sums.clone(); let size = &content_size + &pbm.padding_border_sums.clone();
( (
clearance, clearance,
@ -1219,7 +1218,7 @@ fn layout_in_flow_replaced_block_level(
sequential_layout_state.collapse_margins(); sequential_layout_state.collapse_margins();
sequential_layout_state sequential_layout_state
.advance_block_position(size.block + clearance.unwrap_or_else(Au::zero)); .advance_block_position(size.block + clearance.unwrap_or_else(Au::zero));
sequential_layout_state.adjoin_assign(&CollapsedMargin::new(margin_block_end.into())); sequential_layout_state.adjoin_assign(&CollapsedMargin::new(margin_block_end));
} else { } else {
clearance = None; clearance = None;
( (
@ -1228,15 +1227,15 @@ fn layout_in_flow_replaced_block_level(
) = solve_inline_margins_for_in_flow_block_level( ) = solve_inline_margins_for_in_flow_block_level(
containing_block, containing_block,
&pbm, &pbm,
content_size.inline.into(), content_size.inline,
); );
}; };
let margin = LogicalSides { let margin = LogicalSides {
inline_start: margin_inline_start.into(), inline_start: margin_inline_start,
inline_end: margin_inline_end.into(), inline_end: margin_inline_end,
block_start: margin_block_start.into(), block_start: margin_block_start,
block_end: margin_block_end.into(), block_end: margin_block_end,
}; };
let start_corner = LogicalVec2 { let start_corner = LogicalVec2 {
@ -1259,7 +1258,7 @@ fn layout_in_flow_replaced_block_level(
content_rect.into(), content_rect.into(),
pbm.padding, pbm.padding,
pbm.border, pbm.border,
margin.into(), margin,
clearance, clearance,
block_margins_collapsed_with_children, block_margins_collapsed_with_children,
) )
@ -1274,7 +1273,7 @@ struct ContainingBlockPaddingAndBorder<'a> {
struct ResolvedMargins { struct ResolvedMargins {
/// Used value for the margin properties, as exposed in getComputedStyle(). /// Used value for the margin properties, as exposed in getComputedStyle().
margin: LogicalSides<Length>, margin: LogicalSides<Au>,
/// Distance between the border box and the containing block on the inline-start side. /// Distance between the border box and the containing block on the inline-start side.
/// This is typically the same as the inline-start margin, but can be greater when /// This is typically the same as the inline-start margin, but can be greater when
@ -1282,7 +1281,7 @@ struct ResolvedMargins {
/// The reason we aren't just adjusting the used margin-inline-start is that /// The reason we aren't just adjusting the used margin-inline-start is that
/// this shouldn't be observable via getComputedStyle(). /// this shouldn't be observable via getComputedStyle().
/// <https://drafts.csswg.org/css-align/#justify-self-property> /// <https://drafts.csswg.org/css-align/#justify-self-property>
effective_margin_inline_start: Length, effective_margin_inline_start: Au,
} }
/// Given the style for an in-flow box and its containing block, determine the containing /// Given the style for an in-flow box and its containing block, determine the containing
@ -1348,19 +1347,19 @@ fn solve_containing_block_padding_and_border_for_in_flow_box<'a>(
fn solve_margins( fn solve_margins(
containing_block: &ContainingBlock<'_>, containing_block: &ContainingBlock<'_>,
pbm: &PaddingBorderMargin, pbm: &PaddingBorderMargin,
inline_size: Length, inline_size: Au,
) -> ResolvedMargins { ) -> ResolvedMargins {
let (inline_margins, effective_margin_inline_start) = let (inline_margins, effective_margin_inline_start) =
solve_inline_margins_for_in_flow_block_level(containing_block, pbm, inline_size); solve_inline_margins_for_in_flow_block_level(containing_block, pbm, inline_size);
let block_margins = solve_block_margins_for_in_flow_block_level(pbm); let block_margins = solve_block_margins_for_in_flow_block_level(pbm);
ResolvedMargins { ResolvedMargins {
margin: LogicalSides { margin: LogicalSides {
inline_start: inline_margins.0.into(), inline_start: inline_margins.0,
inline_end: inline_margins.1.into(), inline_end: inline_margins.1,
block_start: block_margins.0.into(), block_start: block_margins.0,
block_end: block_margins.1.into(), block_end: block_margins.1,
}, },
effective_margin_inline_start: effective_margin_inline_start.into(), effective_margin_inline_start,
} }
} }
@ -1409,10 +1408,9 @@ fn justify_self_alignment(containing_block: &ContainingBlock, free_space: Au) ->
fn solve_inline_margins_for_in_flow_block_level( fn solve_inline_margins_for_in_flow_block_level(
containing_block: &ContainingBlock, containing_block: &ContainingBlock,
pbm: &PaddingBorderMargin, pbm: &PaddingBorderMargin,
inline_size: Length, inline_size: Au,
) -> ((Au, Au), Au) { ) -> ((Au, Au), Au) {
let free_space = let free_space = containing_block.inline_size - pbm.padding_border_sums.inline - inline_size;
containing_block.inline_size - pbm.padding_border_sums.inline - inline_size.into();
let mut justification = Au::zero(); let mut justification = Au::zero();
let inline_margins = match (pbm.margin.inline_start, pbm.margin.inline_end) { let inline_margins = match (pbm.margin.inline_start, pbm.margin.inline_end) {
(AuOrAuto::Auto, AuOrAuto::Auto) => { (AuOrAuto::Auto, AuOrAuto::Auto) => {
@ -1598,7 +1596,7 @@ impl PlacementState {
// Setting `next_in_flow_margin_collapses_with_parent_start_margin` to false // Setting `next_in_flow_margin_collapses_with_parent_start_margin` to false
// prevents collapsing with the start margin of the parent, and will set // prevents collapsing with the start margin of the parent, and will set
// `collapsed_through` to false, preventing the parent from collapsing through. // `collapsed_through` to false, preventing the parent from collapsing through.
self.current_block_direction_position += self.current_margin.solve(); self.current_block_direction_position += self.current_margin.solve().into();
self.current_margin = CollapsedMargin::zero(); self.current_margin = CollapsedMargin::zero();
self.next_in_flow_margin_collapses_with_parent_start_margin = false; self.next_in_flow_margin_collapses_with_parent_start_margin = false;
if fragment_block_margins.collapsed_through { if fragment_block_margins.collapsed_through {
@ -1609,7 +1607,7 @@ impl PlacementState {
} }
if self.next_in_flow_margin_collapses_with_parent_start_margin { if self.next_in_flow_margin_collapses_with_parent_start_margin {
debug_assert_eq!(self.current_margin.solve(), Length::zero()); debug_assert!(self.current_margin.solve().is_zero());
self.start_margin self.start_margin
.adjoin_assign(&fragment_block_margins.start); .adjoin_assign(&fragment_block_margins.start);
if fragment_block_margins.collapsed_through { if fragment_block_margins.collapsed_through {
@ -1621,9 +1619,9 @@ impl PlacementState {
self.current_margin self.current_margin
.adjoin_assign(&fragment_block_margins.start); .adjoin_assign(&fragment_block_margins.start);
} }
fragment.content_rect.start_corner.block += fragment.content_rect.start_corner.block +=
self.current_margin.solve() + self.current_block_direction_position; Length::from(self.current_margin.solve()) +
self.current_block_direction_position;
if fragment_block_margins.collapsed_through { if fragment_block_margins.collapsed_through {
// `fragment_block_size` is typically zero when collapsing through, // `fragment_block_size` is typically zero when collapsing through,
@ -1633,13 +1631,14 @@ impl PlacementState {
.adjoin_assign(&fragment_block_margins.end); .adjoin_assign(&fragment_block_margins.end);
} else { } else {
self.current_block_direction_position += self.current_block_direction_position +=
self.current_margin.solve() + fragment_block_size.into(); Length::from(self.current_margin.solve()) + fragment_block_size.into();
self.current_margin = fragment_block_margins.end; self.current_margin = fragment_block_margins.end;
} }
}, },
Fragment::AbsoluteOrFixedPositioned(fragment) => { Fragment::AbsoluteOrFixedPositioned(fragment) => {
let offset = LogicalVec2 { let offset = LogicalVec2 {
block: self.current_margin.solve() + self.current_block_direction_position, block: Length::from(self.current_margin.solve()) +
self.current_block_direction_position,
inline: Length::new(0.), inline: Length::new(0.),
}; };
fragment.borrow_mut().adjust_offsets(offset); fragment.borrow_mut().adjust_offsets(offset);
@ -1648,7 +1647,7 @@ impl PlacementState {
let sequential_layout_state = sequential_layout_state let sequential_layout_state = sequential_layout_state
.expect("Found float fragment without SequentialLayoutState"); .expect("Found float fragment without SequentialLayoutState");
let block_offset_from_containing_block_top = let block_offset_from_containing_block_top =
self.current_block_direction_position + self.current_margin.solve(); self.current_block_direction_position + self.current_margin.solve().into();
sequential_layout_state.place_float_fragment( sequential_layout_state.place_float_fragment(
box_fragment, box_fragment,
self.start_margin, self.start_margin,
@ -1662,7 +1661,7 @@ impl PlacementState {
fn finish(mut self) -> (Length, CollapsedBlockMargins, Baselines) { fn finish(mut self) -> (Length, CollapsedBlockMargins, Baselines) {
if !self.last_in_flow_margin_collapses_with_parent_end_margin { if !self.last_in_flow_margin_collapses_with_parent_end_margin {
self.current_block_direction_position += self.current_margin.solve(); self.current_block_direction_position += self.current_margin.solve().into();
self.current_margin = CollapsedMargin::zero(); self.current_margin = CollapsedMargin::zero();
} }
( (

View file

@ -4,6 +4,7 @@
use std::sync::Arc; use std::sync::Arc;
use app_units::Au;
use gfx::font::FontMetrics; use gfx::font::FontMetrics;
use gfx::text::glyph::GlyphStore; use gfx::text::glyph::GlyphStore;
use gfx_traits::print_tree::PrintTree; use gfx_traits::print_tree::PrintTree;
@ -61,8 +62,8 @@ pub(crate) struct CollapsedBlockMargins {
#[derive(Clone, Copy, Debug, Serialize)] #[derive(Clone, Copy, Debug, Serialize)]
pub(crate) struct CollapsedMargin { pub(crate) struct CollapsedMargin {
max_positive: Length, max_positive: Au,
min_negative: Length, min_negative: Au,
} }
#[derive(Serialize)] #[derive(Serialize)]
@ -259,7 +260,7 @@ impl IFrameFragment {
} }
impl CollapsedBlockMargins { impl CollapsedBlockMargins {
pub fn from_margin(margin: &LogicalSides<Length>) -> Self { pub fn from_margin(margin: &LogicalSides<Au>) -> Self {
Self { Self {
collapsed_through: false, collapsed_through: false,
start: CollapsedMargin::new(margin.block_start), start: CollapsedMargin::new(margin.block_start),
@ -279,15 +280,15 @@ impl CollapsedBlockMargins {
impl CollapsedMargin { impl CollapsedMargin {
pub fn zero() -> Self { pub fn zero() -> Self {
Self { Self {
max_positive: Length::zero(), max_positive: Au::zero(),
min_negative: Length::zero(), min_negative: Au::zero(),
} }
} }
pub fn new(margin: Length) -> Self { pub fn new(margin: Au) -> Self {
Self { Self {
max_positive: margin.max(Length::zero()), max_positive: margin.max(Au::zero()),
min_negative: margin.min(Length::zero()), min_negative: margin.min(Au::zero()),
} }
} }
@ -302,7 +303,7 @@ impl CollapsedMargin {
*self = self.adjoin(other); *self = self.adjoin(other);
} }
pub fn solve(&self) -> Length { pub fn solve(&self) -> Au {
self.max_positive + self.min_negative self.max_positive + self.min_negative
} }
} }