diff --git a/components/layout_2020/display_list/mod.rs b/components/layout_2020/display_list/mod.rs index 6fa4cd1ef48..0ebc9975c88 100644 --- a/components/layout_2020/display_list/mod.rs +++ b/components/layout_2020/display_list/mod.rs @@ -617,7 +617,7 @@ impl<'a> BuilderForBoxFragment<'a> { let radii = inner_radii( self.border_radius, - (&self.fragment.border + &self.fragment.padding) + (self.fragment.border + self.fragment.padding) .to_physical(self.fragment.style.writing_mode) .to_webrender(), ); diff --git a/components/layout_2020/flexbox/geom.rs b/components/layout_2020/flexbox/geom.rs index d99682729ed..65f5d66b683 100644 --- a/components/layout_2020/flexbox/geom.rs +++ b/components/layout_2020/flexbox/geom.rs @@ -266,6 +266,6 @@ where inline: flow_relative_base_rect_size.inline - flow_relative_offsets.inline_end, block: flow_relative_base_rect_size.block - flow_relative_offsets.block_end, }; - let size = &end_corner_position - &start_corner; + let size = end_corner_position - start_corner; LogicalRect { start_corner, size } } diff --git a/components/layout_2020/flexbox/layout.rs b/components/layout_2020/flexbox/layout.rs index 84ae58dd31d..001908e6fe8 100644 --- a/components/layout_2020/flexbox/layout.rs +++ b/components/layout_2020/flexbox/layout.rs @@ -428,7 +428,7 @@ impl FlexContainer { }, }; for (fragment, _) in &mut line.item_fragments { - fragment.content_rect.start_corner += &flow_relative_line_position + fragment.content_rect.start_corner += flow_relative_line_position } line.item_fragments }); diff --git a/components/layout_2020/flow/float.rs b/components/layout_2020/flow/float.rs index 8b6f8687d64..6f4d3b2d89e 100644 --- a/components/layout_2020/flow/float.rs +++ b/components/layout_2020/flow/float.rs @@ -897,7 +897,7 @@ impl FloatBox { // or non-replaced. let pbm = style.padding_border_margin(containing_block); let margin = pbm.margin.auto_is(Au::zero); - let pbm_sums = &(&pbm.padding + &pbm.border) + &margin.clone(); + let pbm_sums = pbm.padding + pbm.border + margin; let (content_size, children); match self.contents { @@ -1208,10 +1208,10 @@ impl SequentialLayoutState { block_start_of_containing_block_in_bfc + block_offset_from_containing_block_top, ); - let pbm_sums = &(&box_fragment.padding + &box_fragment.border) + &box_fragment.margin; - let content_rect = box_fragment.content_rect.clone(); + let pbm_sums = box_fragment.padding + box_fragment.border + box_fragment.margin; + let content_rect = &box_fragment.content_rect; let margin_box_start_corner = self.floats.add_float(&PlacementInfo { - size: &content_rect.size + &pbm_sums.sum(), + size: content_rect.size + pbm_sums.sum(), side: FloatSide::from_style(&box_fragment.style).expect("Float box wasn't floated!"), clear: box_fragment.style.get_box().clear, }); @@ -1219,7 +1219,7 @@ impl SequentialLayoutState { // This is the position of the float in the float-containing block formatting context. We add the // existing start corner here because we may have already gotten some relative positioning offset. let new_position_in_bfc = - &(&margin_box_start_corner + &pbm_sums.start_offset()) + &content_rect.start_corner; + margin_box_start_corner + pbm_sums.start_offset() + content_rect.start_corner; // This is the position of the float relative to the containing block start. let new_position_in_containing_block = LogicalVec2 { diff --git a/components/layout_2020/flow/inline/line.rs b/components/layout_2020/flow/inline/line.rs index ca3127565d3..bfd8209809e 100644 --- a/components/layout_2020/flow/inline/line.rs +++ b/components/layout_2020/flow/inline/line.rs @@ -223,10 +223,10 @@ impl TextRunLineItem { // The block start of the TextRun is often zero (meaning it has the same font metrics as the // inline box's strut), but for children of the inline formatting context root or for // fallback fonts that use baseline relatve alignment, it might be different. - let start_corner = &LogicalVec2 { + let start_corner = LogicalVec2 { inline: state.inline_position, block: (state.baseline_offset - self.font_metrics.ascent).into(), - } - &state.parent_offset; + } - state.parent_offset; let rect = LogicalRect { start_corner, @@ -283,8 +283,8 @@ impl InlineBoxLineItem { state: &mut LineItemLayoutState, ) -> Option { let style = self.style.clone(); - let mut padding = self.pbm.padding.clone(); - let mut border = self.pbm.border.clone(); + let mut padding = self.pbm.padding; + let mut border = self.pbm.border; let mut margin = self.pbm.margin.auto_is(Au::zero); if !self.is_first_fragment { @@ -297,7 +297,7 @@ impl InlineBoxLineItem { border.inline_end = Au::zero(); margin.inline_end = Au::zero(); } - let pbm_sums = &(&padding + &border) + &margin; + let pbm_sums = padding + border + margin; state.inline_position += pbm_sums.inline_start.into(); let space_above_baseline = self.calculate_space_above_baseline(); @@ -335,7 +335,7 @@ impl InlineBoxLineItem { border.inline_end = Au::zero(); margin.inline_end = Au::zero(); } - let pbm_sums = &(&padding + &border) + &margin.clone(); + let pbm_sums = padding + border + margin; // If the inline box didn't have any content at all, don't add a Fragment for it. let box_has_padding_border_or_margin = pbm_sums.inline_sum() > Au::zero(); @@ -361,13 +361,13 @@ impl InlineBoxLineItem { }; // Make `content_rect` relative to the parent Fragment. - content_rect.start_corner = &content_rect.start_corner - &state.parent_offset; + content_rect.start_corner -= state.parent_offset; // Relative adjustment should not affect the rest of line layout, so we can // do it right before creating the Fragment. if style.clone_position().is_relative() { content_rect.start_corner += - &relative_adjustement(&style, state.ifc_containing_block).into(); + relative_adjustement(&style, state.ifc_containing_block).into(); } let mut fragment = BoxFragment::new( @@ -466,12 +466,11 @@ impl AtomicLineItem { self.calculate_block_start(state.line_metrics).into(); // Make the final result relative to the parent box. - self.fragment.content_rect.start_corner = - &self.fragment.content_rect.start_corner - &state.parent_offset.into(); + self.fragment.content_rect.start_corner -= state.parent_offset.into(); if self.fragment.style.clone_position().is_relative() { self.fragment.content_rect.start_corner += - &relative_adjustement(&self.fragment.style, state.ifc_containing_block); + relative_adjustement(&self.fragment.style, state.ifc_containing_block); } state.inline_position += self.size.inline.into(); @@ -571,8 +570,7 @@ impl FloatLineItem { inline: state.parent_offset.inline, block: state.line_metrics.block_offset + state.parent_offset.block, }; - self.fragment.content_rect.start_corner = - &self.fragment.content_rect.start_corner - &distance_from_parent_to_ifc.into(); + self.fragment.content_rect.start_corner -= distance_from_parent_to_ifc.into(); self.fragment } } diff --git a/components/layout_2020/flow/inline/mod.rs b/components/layout_2020/flow/inline/mod.rs index 594c3c093e4..03e289deff8 100644 --- a/components/layout_2020/flow/inline/mod.rs +++ b/components/layout_2020/flow/inline/mod.rs @@ -1206,7 +1206,7 @@ impl<'a, 'b> InlineFormattingContextState<'a, 'b> { ); let mut placement_rect = placement.place(); - placement_rect.start_corner = &placement_rect.start_corner - &ifc_offset_in_float_container; + placement_rect.start_corner -= ifc_offset_in_float_container; placement_rect.into() } @@ -2026,7 +2026,7 @@ impl IndependentFormattingContext { let style = self.style(); let pbm = style.padding_border_margin(ifc.containing_block); let margin = pbm.margin.auto_is(Au::zero); - let pbm_sums = &(&pbm.padding + &pbm.border) + &margin.clone(); + let pbm_sums = pbm.padding + pbm.border + margin; let mut child_positioning_context = None; // We need to know the inline size of the atomic before deciding whether to do the line break. @@ -2156,7 +2156,7 @@ impl IndependentFormattingContext { ifc.process_soft_wrap_opportunity(); } - let size = &pbm_sums.sum() + &fragment.content_rect.size; + let size = pbm_sums.sum() + fragment.content_rect.size; let baseline_offset = self .pick_baseline(&fragment.baselines) .map(|baseline| pbm_sums.block_start + baseline) @@ -2171,7 +2171,7 @@ impl IndependentFormattingContext { ); ifc.push_line_item_to_unbreakable_segment(LineItem::Atomic(AtomicLineItem { fragment, - size: size.into(), + size, positioning_context: child_positioning_context, baseline_offset_in_parent, baseline_offset_in_item: baseline_offset, @@ -2402,7 +2402,7 @@ impl<'a> ContentSizesComputation<'a> { .percentages_relative_to(zero) .auto_is(Length::zero); - let pbm = &(&margin + &padding) + &border; + let pbm = margin + padding + border; if inline_box.is_first_fragment { self.add_length(pbm.inline_start); } diff --git a/components/layout_2020/flow/mod.rs b/components/layout_2020/flow/mod.rs index 87eb75c46c0..f47136eba24 100644 --- a/components/layout_2020/flow/mod.rs +++ b/components/layout_2020/flow/mod.rs @@ -1086,7 +1086,7 @@ impl NonReplacedFormattingContext { &collapsed_margin_block_start, containing_block, &pbm, - &content_size + &pbm.padding_border_sums.into(), + content_size + pbm.padding_border_sums.into(), &self.style, ); } else { @@ -1102,12 +1102,10 @@ impl NonReplacedFormattingContext { }); // Create a PlacementAmongFloats using the minimum size in all dimensions as the object size. - let minimum_size_of_block = &LogicalVec2 { - inline: min_box_size.inline, - block: block_size.auto_is(|| min_box_size.block), - } - .into() + - &pbm.padding_border_sums; + let minimum_size_of_block = LogicalVec2 { + inline: min_box_size.inline.into(), + block: block_size.auto_is(|| min_box_size.block).into(), + } + pbm.padding_border_sums; let mut placement = PlacementAmongFloats::new( &sequential_layout_state.floats, ceiling, @@ -1291,7 +1289,7 @@ fn layout_in_flow_replaced_block_level( // 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); - let size = &content_size + &pbm.padding_border_sums.clone(); + let size = content_size + pbm.padding_border_sums; ( clearance, (margin_inline_start, margin_inline_end), diff --git a/components/layout_2020/geom.rs b/components/layout_2020/geom.rs index f75b09e9169..bb7b26f7661 100644 --- a/components/layout_2020/geom.rs +++ b/components/layout_2020/geom.rs @@ -4,7 +4,7 @@ use std::convert::From; use std::fmt; -use std::ops::{Add, AddAssign, Sub, SubAssign}; +use std::ops::{Add, AddAssign, Neg, Sub, SubAssign}; use app_units::Au; use serde::Serialize; @@ -32,13 +32,13 @@ pub struct LogicalVec2 { pub block: T, } -#[derive(Clone, Serialize)] +#[derive(Clone, Copy, Serialize)] pub struct LogicalRect { pub start_corner: LogicalVec2, pub size: LogicalVec2, } -#[derive(Clone, Debug, Serialize)] +#[derive(Clone, Copy, Debug, Serialize)] pub struct LogicalSides { pub inline_start: T, pub inline_end: T, @@ -79,13 +79,9 @@ impl LogicalVec2 { } } -impl Add<&'_ LogicalVec2> for &'_ LogicalVec2 -where - T: Add + Copy, -{ +impl + Copy> Add> for LogicalVec2 { type Output = LogicalVec2; - - fn add(self, other: &'_ LogicalVec2) -> Self::Output { + fn add(self, other: Self) -> Self::Output { LogicalVec2 { inline: self.inline + other.inline, block: self.block + other.block, @@ -93,13 +89,9 @@ where } } -impl Sub<&'_ LogicalVec2> for &'_ LogicalVec2 -where - T: Sub + Copy, -{ +impl + Copy> Sub> for LogicalVec2 { type Output = LogicalVec2; - - fn sub(self, other: &'_ LogicalVec2) -> Self::Output { + fn sub(self, other: Self) -> Self::Output { LogicalVec2 { inline: self.inline - other.inline, block: self.block - other.block, @@ -107,41 +99,27 @@ where } } -impl AddAssign<&'_ LogicalVec2> for LogicalVec2 -where - T: AddAssign + Copy, -{ - fn add_assign(&mut self, other: &'_ LogicalVec2) { +impl + Copy> AddAssign> for LogicalVec2 { + fn add_assign(&mut self, other: LogicalVec2) { self.inline += other.inline; self.block += other.block; } } -impl AddAssign> for LogicalVec2 -where - T: AddAssign + Copy, -{ - fn add_assign(&mut self, other: LogicalVec2) { - self.add_assign(&other); - } -} - -impl SubAssign<&'_ LogicalVec2> for LogicalVec2 -where - T: SubAssign + Copy, -{ - fn sub_assign(&mut self, other: &'_ LogicalVec2) { +impl + Copy> SubAssign> for LogicalVec2 { + fn sub_assign(&mut self, other: LogicalVec2) { self.inline -= other.inline; self.block -= other.block; } } -impl SubAssign> for LogicalVec2 -where - T: SubAssign + Copy, -{ - fn sub_assign(&mut self, other: LogicalVec2) { - self.sub_assign(&other); +impl + Copy> Neg for LogicalVec2 { + type Output = LogicalVec2; + fn neg(self) -> Self::Output { + Self { + inline: -self.inline, + block: -self.block, + } } } @@ -352,10 +330,7 @@ impl LogicalSides { } } -impl LogicalSides -where - T: Copy, -{ +impl LogicalSides { pub fn start_offset(&self) -> LogicalVec2 { LogicalVec2 { inline: self.inline_start, @@ -382,13 +357,10 @@ impl LogicalSides> { } } -impl Add<&'_ LogicalSides> for &'_ LogicalSides -where - T: Add + Copy, -{ +impl + Copy> Add> for LogicalSides { type Output = LogicalSides; - fn add(self, other: &'_ LogicalSides) -> Self::Output { + fn add(self, other: Self) -> Self::Output { LogicalSides { inline_start: self.inline_start + other.inline_start, inline_end: self.inline_end + other.inline_end, @@ -398,6 +370,18 @@ where } } +impl + Copy> Neg for LogicalSides { + type Output = LogicalSides; + fn neg(self) -> Self::Output { + Self { + inline_start: -self.inline_start, + inline_end: -self.inline_end, + block_start: -self.block_start, + block_end: -self.block_end, + } + } +} + impl LogicalSides { pub(crate) fn zero() -> LogicalSides { LogicalSides { diff --git a/components/layout_2020/positioned.rs b/components/layout_2020/positioned.rs index e0ad7acfc99..d104c680785 100644 --- a/components/layout_2020/positioned.rs +++ b/components/layout_2020/positioned.rs @@ -240,8 +240,7 @@ impl PositioningContext { self.append(new_context); if style.clone_position() == Position::Relative { - new_fragment.content_rect.start_corner += - &relative_adjustement(style, containing_block); + new_fragment.content_rect.start_corner += relative_adjustement(style, containing_block); } new_fragment @@ -690,7 +689,7 @@ impl HoistedAbsolutelyPositionedBox { block_end: block_axis.margin_end, }; - let pb = &pbm.padding + &pbm.border; + let pb = pbm.padding + pbm.border; let inline_start = match inline_axis.anchor { Anchor::Start(start) => start + pb.inline_start + margin.inline_start, Anchor::End(end) => { diff --git a/components/layout_2020/table/layout.rs b/components/layout_2020/table/layout.rs index 9614de72793..83a9839d4e7 100644 --- a/components/layout_2020/table/layout.rs +++ b/components/layout_2020/table/layout.rs @@ -1079,8 +1079,8 @@ impl<'a> TableLayout<'a> { Some(CellLayout { layout, - padding: padding.clone(), - border: border.clone(), + padding, + border, positioning_context, }) }) @@ -1666,8 +1666,7 @@ impl<'a> TableLayout<'a> { cell.rowspan, cell.colspan, ); - row_relative_cell_rect.start_corner = - &row_relative_cell_rect.start_corner - &row_rect.start_corner; + row_relative_cell_rect.start_corner -= row_rect.start_corner; let mut fragment = cell.create_fragment( layout, row_relative_cell_rect, @@ -1710,7 +1709,7 @@ impl<'a> TableLayout<'a> { }) } if let Some(row) = row { - let mut rect = row_rect.clone(); + let mut rect = *row_rect; rect.start_corner = LogicalVec2::zero(); fragment.add_extra_background(ExtraBackground { style: row.style.clone(), @@ -1989,12 +1988,12 @@ impl TableAndTrackDimensions { inline: column_dimensions.first().map_or_else(Au::zero, |v| v.0), block: row_dimensions.first().map_or_else(Au::zero, |v| v.0), }; - let table_size = &LogicalVec2 { + let table_size = LogicalVec2 { inline: column_dimensions .last() .map_or(fallback_inline_size, |v| v.1), block: row_dimensions.last().map_or(fallback_block_size, |v| v.1), - } - &table_start_corner; + } - table_start_corner; let table_cells_rect = LogicalRect { start_corner: table_start_corner, size: table_size, @@ -2017,7 +2016,7 @@ impl TableAndTrackDimensions { } fn get_row_rect(&self, row_index: usize) -> LogicalRect { - let mut row_rect = self.table_cells_rect.clone(); + let mut row_rect = self.table_cells_rect; let row_dimensions = self.row_dimensions[row_index]; row_rect.start_corner.block = row_dimensions.0; row_rect.size.block = row_dimensions.1 - row_dimensions.0; @@ -2025,7 +2024,7 @@ impl TableAndTrackDimensions { } fn get_column_rect(&self, column_index: usize) -> LogicalRect { - let mut row_rect = self.table_cells_rect.clone(); + let mut row_rect = self.table_cells_rect; let column_dimensions = self.column_dimensions[column_index]; row_rect.start_corner.inline = column_dimensions.0; row_rect.size.inline = column_dimensions.1 - column_dimensions.0; @@ -2037,7 +2036,7 @@ impl TableAndTrackDimensions { return LogicalRect::zero(); } - let mut row_group_rect = self.table_cells_rect.clone(); + let mut row_group_rect = self.table_cells_rect; let block_start = self.row_dimensions[row_group.track_range.start].0; let block_end = self.row_dimensions[row_group.track_range.end - 1].1; row_group_rect.start_corner.block = block_start; @@ -2050,7 +2049,7 @@ impl TableAndTrackDimensions { return LogicalRect::zero(); } - let mut column_group_rect = self.table_cells_rect.clone(); + let mut column_group_rect = self.table_cells_rect; let inline_start = self.column_dimensions[column_group.track_range.start].0; let inline_end = self.column_dimensions[column_group.track_range.end - 1].1; column_group_rect.start_corner.inline = inline_start; @@ -2068,10 +2067,10 @@ impl TableAndTrackDimensions { inline: self.column_dimensions[coordinates.x].0, block: self.row_dimensions[coordinates.y].0, }; - let size = &LogicalVec2 { + let size = LogicalVec2 { inline: self.column_dimensions[coordinates.x + colspan - 1].1, block: self.row_dimensions[coordinates.y + rowspan - 1].1, - } - &start_corner; + } - start_corner; LogicalRect { start_corner, size } } } @@ -2213,7 +2212,7 @@ impl TableSlotCell { // This must be scoped to this function because it conflicts with euclid's Zero. use style::Zero as StyleZero; - let cell_content_rect = cell_rect.deflate(&(&layout.padding + &layout.border)); + let cell_content_rect = cell_rect.deflate(&(layout.padding + layout.border)); let content_block_size = layout.layout.content_block_size; let vertical_align_offset = match self.effective_vertical_align() { VerticalAlignKeyword::Top => Au::zero(), @@ -2237,7 +2236,7 @@ impl TableSlotCell { } // Create an `AnonymousFragment` to move the cell contents to the cell baseline. - let mut vertical_align_fragment_rect = cell_content_rect.clone(); + let mut vertical_align_fragment_rect = cell_content_rect; vertical_align_fragment_rect.start_corner = LogicalVec2 { inline: Au::zero(), block: vertical_align_offset, @@ -2317,7 +2316,7 @@ fn get_outer_sizes_from_style( ) -> (LogicalVec2, LogicalVec2, LogicalVec2) { let box_sizing = style.get_position().box_sizing; let outer_size = |size: LogicalVec2| match box_sizing { - BoxSizing::ContentBox => &size + padding_border_sums, + BoxSizing::ContentBox => size + *padding_border_sums, BoxSizing::BorderBox => LogicalVec2 { inline: size.inline.max(padding_border_sums.inline), block: size.block.max(padding_border_sums.block),