diff --git a/components/layout_2020/flexbox/layout.rs b/components/layout_2020/flexbox/layout.rs index 77c1111bb468..71488d833814 100644 --- a/components/layout_2020/flexbox/layout.rs +++ b/components/layout_2020/flexbox/layout.rs @@ -847,7 +847,7 @@ impl FlexLine<'_> { .zip(&item_margins) .map(|(((item, item_result), content_rect), margin)| { 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); ( // TODO: We should likely propagate baselines from `display: flex`. @@ -858,7 +858,7 @@ impl FlexLine<'_> { content_rect, flex_context.sides_to_flow_relative(item.padding), flex_context.sides_to_flow_relative(item.border), - margin.into(), + margin, None, /* clearance */ collapsed_margin, ), diff --git a/components/layout_2020/flow/float.rs b/components/layout_2020/flow/float.rs index 4b620feba8bd..85f405558ce6 100644 --- a/components/layout_2020/flow/float.rs +++ b/components/layout_2020/flow/float.rs @@ -1062,7 +1062,7 @@ impl SequentialLayoutState { /// Return the current block position in the float containing block formatting /// context and any uncollapsed block margins. 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` @@ -1071,7 +1071,7 @@ impl SequentialLayoutState { /// 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. 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(); } @@ -1079,11 +1079,7 @@ impl SequentialLayoutState { /// with the provided `block_start_margin`, assuming no clearance. pub(crate) fn position_without_clearance(&self, block_start_margin: &CollapsedMargin) -> Au { // Adjoin `current_margin` and `block_start_margin` since there is no clearance. - self.bfc_relative_block_position + - self.current_margin - .adjoin(block_start_margin) - .solve() - .into() + self.bfc_relative_block_position + self.current_margin.adjoin(block_start_margin).solve() } /// 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 { // Clearance prevents `current_margin` and `block_start_margin` from being // adjoining, so we need to solve them separately and then sum. - self.bfc_relative_block_position + - self.current_margin.solve().into() + - block_start_margin.solve().into() + self.bfc_relative_block_position + self.current_margin.solve() + block_start_margin.solve() } /// 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 .block_start_margins_not_collapsed .solve() - .into() } /// This function places a Fragment that has been created for a FloatBox. @@ -1206,8 +1199,7 @@ impl SequentialLayoutState { .containing_block_info .block_start_margins_not_collapsed .adjoin(&margins_collapsing_with_parent_containing_block) - .solve() - .into(); + .solve(); self.floats.set_ceiling_from_non_floats( block_start_of_containing_block_in_bfc + block_offset_from_containing_block_top, diff --git a/components/layout_2020/flow/mod.rs b/components/layout_2020/flow/mod.rs index b9f2bd8fec21..e242a2239682 100644 --- a/components/layout_2020/flow/mod.rs +++ b/components/layout_2020/flow/mod.rs @@ -117,7 +117,7 @@ impl BlockLevelBox { let pbm = style.padding_border_margin(containing_block); 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 { BlockLevelBox::SameFormattingContextBlock { ref contents, .. } => match contents { @@ -176,7 +176,7 @@ impl BlockLevelBox { } 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 } @@ -242,10 +242,9 @@ impl BlockFormattingContext { IndependentLayout { 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() + - clearance.unwrap_or_else(Au::zero).into()) - .into(), + clearance.unwrap_or_default(), content_inline_size_for_table: None, baselines: flow_layout.baselines, } @@ -638,7 +637,7 @@ fn layout_in_flow_non_replaced_block_level_same_formatting_context( } = solve_margins( containing_block, &pbm, - containing_block_for_children.inline_size.into(), + containing_block_for_children.inline_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 + pbm.padding.inline_start + pbm.border.inline_start + - effective_margin_inline_start.into(); + effective_margin_inline_start; let new_cb_offsets = ContainingBlockPositionInfo { block_start: sequential_layout_state.bfc_relative_block_position, 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 .adjoin_assign(&collapsible_margins_in_children.end); } 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(); @@ -801,7 +800,7 @@ fn layout_in_flow_non_replaced_block_level_same_formatting_context( clearance.unwrap_or_else(Au::zero)), inline: pbm.padding.inline_start + pbm.border.inline_start + - effective_margin_inline_start.into(), + effective_margin_inline_start, }, size: LogicalVec2 { block: block_size, @@ -816,7 +815,7 @@ fn layout_in_flow_non_replaced_block_level_same_formatting_context( content_rect.into(), pbm.padding, pbm.border, - margin.into(), + margin, clearance, block_margins_collapsed_with_children, ) @@ -878,14 +877,14 @@ impl NonReplacedFormattingContext { let ResolvedMargins { margin, effective_margin_inline_start, - } = solve_margins(containing_block, &pbm, inline_size.into()); + } = solve_margins(containing_block, &pbm, inline_size); let content_rect = LogicalRect { start_corner: LogicalVec2 { block: pbm.padding.block_start + pbm.border.block_start, inline: pbm.padding.inline_start + pbm.border.inline_start + - effective_margin_inline_start.into(), + effective_margin_inline_start, }, size: LogicalVec2 { block: block_size, @@ -902,7 +901,7 @@ impl NonReplacedFormattingContext { content_rect.into(), pbm.padding, pbm.border, - margin.into(), + margin, None, /* clearance */ block_margins_collapsed_with_children, ) @@ -935,7 +934,7 @@ impl NonReplacedFormattingContext { let effective_margin_inline_start; let (margin_block_start, margin_block_end) = 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: // "The border box of a table, a block-level replaced element, or an element in @@ -1112,10 +1111,10 @@ impl NonReplacedFormattingContext { } let margin = LogicalSides { - inline_start: margin_inline_start.into(), - inline_end: margin_inline_end.into(), - block_start: margin_block_start.into(), - block_end: margin_block_end.into(), + inline_start: margin_inline_start, + inline_end: margin_inline_end, + block_start: margin_block_start, + block_end: margin_block_end, }; // Clearance prevents margin collapse between this block and previous ones, @@ -1154,7 +1153,7 @@ impl NonReplacedFormattingContext { content_rect.into(), pbm.padding, pbm.border, - margin.into(), + margin, clearance, 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 // 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." - 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(); ( clearance, @@ -1219,7 +1218,7 @@ fn layout_in_flow_replaced_block_level( sequential_layout_state.collapse_margins(); sequential_layout_state .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 { clearance = None; ( @@ -1228,15 +1227,15 @@ fn layout_in_flow_replaced_block_level( ) = solve_inline_margins_for_in_flow_block_level( containing_block, &pbm, - content_size.inline.into(), + content_size.inline, ); }; let margin = LogicalSides { - inline_start: margin_inline_start.into(), - inline_end: margin_inline_end.into(), - block_start: margin_block_start.into(), - block_end: margin_block_end.into(), + inline_start: margin_inline_start, + inline_end: margin_inline_end, + block_start: margin_block_start, + block_end: margin_block_end, }; let start_corner = LogicalVec2 { @@ -1259,7 +1258,7 @@ fn layout_in_flow_replaced_block_level( content_rect.into(), pbm.padding, pbm.border, - margin.into(), + margin, clearance, block_margins_collapsed_with_children, ) @@ -1274,7 +1273,7 @@ struct ContainingBlockPaddingAndBorder<'a> { struct ResolvedMargins { /// Used value for the margin properties, as exposed in getComputedStyle(). - margin: LogicalSides, + margin: LogicalSides, /// 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 @@ -1282,7 +1281,7 @@ struct ResolvedMargins { /// The reason we aren't just adjusting the used margin-inline-start is that /// this shouldn't be observable via getComputedStyle(). /// - 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 @@ -1348,19 +1347,19 @@ fn solve_containing_block_padding_and_border_for_in_flow_box<'a>( fn solve_margins( containing_block: &ContainingBlock<'_>, pbm: &PaddingBorderMargin, - inline_size: Length, + inline_size: Au, ) -> ResolvedMargins { let (inline_margins, effective_margin_inline_start) = 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); ResolvedMargins { margin: LogicalSides { - inline_start: inline_margins.0.into(), - inline_end: inline_margins.1.into(), - block_start: block_margins.0.into(), - block_end: block_margins.1.into(), + inline_start: inline_margins.0, + inline_end: inline_margins.1, + block_start: block_margins.0, + 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( containing_block: &ContainingBlock, pbm: &PaddingBorderMargin, - inline_size: Length, + inline_size: Au, ) -> ((Au, Au), Au) { - let free_space = - containing_block.inline_size - pbm.padding_border_sums.inline - inline_size.into(); + let free_space = containing_block.inline_size - pbm.padding_border_sums.inline - inline_size; let mut justification = Au::zero(); let inline_margins = match (pbm.margin.inline_start, pbm.margin.inline_end) { (AuOrAuto::Auto, AuOrAuto::Auto) => { @@ -1598,7 +1596,7 @@ impl PlacementState { // Setting `next_in_flow_margin_collapses_with_parent_start_margin` to false // prevents collapsing with the start margin of the parent, and will set // `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.next_in_flow_margin_collapses_with_parent_start_margin = false; if fragment_block_margins.collapsed_through { @@ -1609,7 +1607,7 @@ impl PlacementState { } 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 .adjoin_assign(&fragment_block_margins.start); if fragment_block_margins.collapsed_through { @@ -1621,9 +1619,9 @@ impl PlacementState { self.current_margin .adjoin_assign(&fragment_block_margins.start); } - 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 { // `fragment_block_size` is typically zero when collapsing through, @@ -1633,13 +1631,14 @@ impl PlacementState { .adjoin_assign(&fragment_block_margins.end); } else { 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; } }, Fragment::AbsoluteOrFixedPositioned(fragment) => { 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.), }; fragment.borrow_mut().adjust_offsets(offset); @@ -1648,7 +1647,7 @@ impl PlacementState { let sequential_layout_state = sequential_layout_state .expect("Found float fragment without SequentialLayoutState"); 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( box_fragment, self.start_margin, @@ -1662,7 +1661,7 @@ impl PlacementState { fn finish(mut self) -> (Length, CollapsedBlockMargins, Baselines) { 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(); } ( diff --git a/components/layout_2020/fragment_tree/fragment.rs b/components/layout_2020/fragment_tree/fragment.rs index b13fab0ddd4c..1fdff5040725 100644 --- a/components/layout_2020/fragment_tree/fragment.rs +++ b/components/layout_2020/fragment_tree/fragment.rs @@ -4,6 +4,7 @@ use std::sync::Arc; +use app_units::Au; use gfx::font::FontMetrics; use gfx::text::glyph::GlyphStore; use gfx_traits::print_tree::PrintTree; @@ -61,8 +62,8 @@ pub(crate) struct CollapsedBlockMargins { #[derive(Clone, Copy, Debug, Serialize)] pub(crate) struct CollapsedMargin { - max_positive: Length, - min_negative: Length, + max_positive: Au, + min_negative: Au, } #[derive(Serialize)] @@ -259,7 +260,7 @@ impl IFrameFragment { } impl CollapsedBlockMargins { - pub fn from_margin(margin: &LogicalSides) -> Self { + pub fn from_margin(margin: &LogicalSides) -> Self { Self { collapsed_through: false, start: CollapsedMargin::new(margin.block_start), @@ -279,15 +280,15 @@ impl CollapsedBlockMargins { impl CollapsedMargin { pub fn zero() -> Self { Self { - max_positive: Length::zero(), - min_negative: Length::zero(), + max_positive: Au::zero(), + min_negative: Au::zero(), } } - pub fn new(margin: Length) -> Self { + pub fn new(margin: Au) -> Self { Self { - max_positive: margin.max(Length::zero()), - min_negative: margin.min(Length::zero()), + max_positive: margin.max(Au::zero()), + min_negative: margin.min(Au::zero()), } } @@ -302,7 +303,7 @@ impl CollapsedMargin { *self = self.adjoin(other); } - pub fn solve(&self) -> Length { + pub fn solve(&self) -> Au { self.max_positive + self.min_negative } }