diff options
author | Martin Robinson <mrobinson@igalia.com> | 2024-06-28 10:20:50 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-06-28 08:20:50 +0000 |
commit | adc0fc984d07918ad2eac3ab641d833a3cab008c (patch) | |
tree | c0cc1352325236a355c5a7d67bff117b9eb5bb28 /components/layout_2020/flow/inline | |
parent | e9cf4d4971c0ce8ec64da7f09d6e97ae10be5b05 (diff) | |
download | servo-adc0fc984d07918ad2eac3ab641d833a3cab008c.tar.gz servo-adc0fc984d07918ad2eac3ab641d833a3cab008c.zip |
layout: Make `geom.rs` logical geoemetry types more ergonomic (#32633)
Make using the logical geometry types more ergonomic by having them all
implement `Copy` (at most 4 64-bit numbers), similar to what `euclid`
does. In addition add an implementation of `Neg` for `LogicalVec` and
`LogicalSides` as it will be used in upcoming table implementation code.
Diffstat (limited to 'components/layout_2020/flow/inline')
-rw-r--r-- | components/layout_2020/flow/inline/line.rs | 24 | ||||
-rw-r--r-- | components/layout_2020/flow/inline/mod.rs | 10 |
2 files changed, 16 insertions, 18 deletions
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<BoxFragment> { 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); } |