mirror of
https://github.com/servo/servo.git
synced 2025-08-03 04:30:10 +01:00
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.
This commit is contained in:
parent
e9cf4d4971
commit
adc0fc984d
10 changed files with 80 additions and 102 deletions
|
@ -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 {
|
||||
|
|
|
@ -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
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
|
|
|
@ -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),
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue