aboutsummaryrefslogtreecommitdiffstats
path: root/components/layout_2020/flow
diff options
context:
space:
mode:
Diffstat (limited to 'components/layout_2020/flow')
-rw-r--r--components/layout_2020/flow/construct.rs10
-rw-r--r--components/layout_2020/flow/float.rs53
-rw-r--r--components/layout_2020/flow/inline.rs61
-rw-r--r--components/layout_2020/flow/line.rs2
-rw-r--r--components/layout_2020/flow/mod.rs37
-rw-r--r--components/layout_2020/flow/root.rs4
6 files changed, 82 insertions, 85 deletions
diff --git a/components/layout_2020/flow/construct.rs b/components/layout_2020/flow/construct.rs
index 6f017461aaa..4c7b712fade 100644
--- a/components/layout_2020/flow/construct.rs
+++ b/components/layout_2020/flow/construct.rs
@@ -71,11 +71,11 @@ impl BlockFormattingContext {
ends_with_whitespace: false,
};
let contents = BlockContainer::InlineFormattingContext(ifc);
- let bfc = Self {
+
+ Self {
contents,
contains_floats: false,
- };
- bfc
+ }
}
}
@@ -442,8 +442,8 @@ fn preserve_segment_break() -> bool {
///
/// Returns the transformed text as a [String] and also whether or not the input had
/// any uncollapsible content.
-fn collapse_and_transform_whitespace<'text>(
- input: &'text str,
+fn collapse_and_transform_whitespace(
+ input: &str,
white_space: WhiteSpace,
trim_beginning_white_space: bool,
) -> (String, bool) {
diff --git a/components/layout_2020/flow/float.rs b/components/layout_2020/flow/float.rs
index 18856db5fd2..fbe436511dc 100644
--- a/components/layout_2020/flow/float.rs
+++ b/components/layout_2020/flow/float.rs
@@ -181,7 +181,7 @@ impl<'a> PlacementAmongFloats<'a> {
min_inline_end = min_inline_end.min(right);
}
}
- return (max_inline_start, min_inline_end);
+ (max_inline_start, min_inline_end)
}
/// Find the total inline size provided by the current set of bands under consideration.
@@ -389,7 +389,7 @@ impl FloatContext {
// Find the first band this float fits in.
let mut first_band = self.bands.find(ceiling).unwrap();
- while !first_band.object_fits(&object, &self.containing_block_info) {
+ while !first_band.object_fits(object, &self.containing_block_info) {
let next_band = self.bands.find_next(first_band.top).unwrap();
if next_band.top == MAX_AU {
break;
@@ -426,7 +426,7 @@ impl FloatContext {
pub fn add_float(&mut self, new_float: &PlacementInfo) -> LogicalVec2<Au> {
// Place the float.
let ceiling = self.ceiling();
- let new_float_origin = self.place_object(&new_float, ceiling);
+ let new_float_origin = self.place_object(new_float, ceiling);
let new_float_extent = match new_float.side {
FloatSide::Left => new_float_origin.inline + new_float.size.inline,
FloatSide::Right => new_float_origin.inline,
@@ -668,6 +668,12 @@ impl FloatBandTree {
}
}
+impl Default for FloatBandTree {
+ fn default() -> Self {
+ Self::new()
+ }
+}
+
impl FloatBandNode {
fn new(band: FloatBand) -> FloatBandNode {
FloatBandNode {
@@ -681,7 +687,7 @@ impl FloatBandNode {
/// Sets the side values of all bands within the given half-open range to be at least
/// `new_value`.
fn set_range(&self, range: &Range<Au>, side: FloatSide, new_value: Au) -> Arc<FloatBandNode> {
- let mut new_band = self.band.clone();
+ let mut new_band = self.band;
if self.band.top >= range.start && self.band.top < range.end {
match side {
FloatSide::Left => {
@@ -742,7 +748,7 @@ impl FloatBandLink {
return Some(band);
}
- Some(this.band.clone())
+ Some(this.band)
}
/// Returns the first band whose top is strictly greater than the given `block_position`.
@@ -762,7 +768,7 @@ impl FloatBandLink {
return Some(band);
}
- Some(this.band.clone())
+ Some(this.band)
}
/// Inserts a new band into the tree. If the band has the same level as a pre-existing one,
@@ -801,11 +807,11 @@ impl FloatBandLink {
return FloatBandLink(Some(Arc::new(FloatBandNode {
level: this.level,
left: left.left.clone(),
- band: left.band.clone(),
+ band: left.band,
right: FloatBandLink(Some(Arc::new(FloatBandNode {
level: this.level,
left: left.right.clone(),
- band: this.band.clone(),
+ band: this.band,
right: this.right.clone(),
}))),
})));
@@ -834,10 +840,10 @@ impl FloatBandLink {
left: FloatBandLink(Some(Arc::new(FloatBandNode {
level: this.level,
left: this.left.clone(),
- band: this.band.clone(),
+ band: this.band,
right: right.left.clone(),
}))),
- band: right.band.clone(),
+ band: right.band,
right: right.right.clone(),
})));
}
@@ -889,7 +895,7 @@ impl FloatBox {
layout_context,
containing_block,
&style,
- |mut positioning_context| {
+ |positioning_context| {
// Margin is computed this way regardless of whether the element is replaced
// or non-replaced.
let pbm = style.padding_border_margin(containing_block);
@@ -901,13 +907,13 @@ impl FloatBox {
IndependentFormattingContext::NonReplaced(ref mut non_replaced) => {
// Calculate inline size.
// https://drafts.csswg.org/css2/#float-width
- let box_size = non_replaced.style.content_box_size(&containing_block, &pbm);
+ let box_size = non_replaced.style.content_box_size(containing_block, &pbm);
let max_box_size = non_replaced
.style
- .content_max_box_size(&containing_block, &pbm);
+ .content_max_box_size(containing_block, &pbm);
let min_box_size = non_replaced
.style
- .content_min_box_size(&containing_block, &pbm)
+ .content_min_box_size(containing_block, &pbm)
.auto_is(Length::zero);
let tentative_inline_size = box_size.inline.auto_is(|| {
@@ -931,7 +937,7 @@ impl FloatBox {
};
let independent_layout = non_replaced.layout(
layout_context,
- &mut positioning_context,
+ positioning_context,
&containing_block_for_children,
);
content_size = LogicalVec2 {
@@ -946,7 +952,7 @@ impl FloatBox {
// https://drafts.csswg.org/css2/#float-replaced-width
// https://drafts.csswg.org/css2/#inline-replaced-height
content_size = replaced.contents.used_size_as_if_inline_element(
- &containing_block,
+ containing_block,
&replaced.style,
None,
&pbm,
@@ -1060,7 +1066,7 @@ impl SequentialLayoutState {
// Adjoin `current_margin` and `block_start_margin` since there is no clearance.
self.bfc_relative_block_position +
self.current_margin
- .adjoin(&block_start_margin)
+ .adjoin(block_start_margin)
.solve()
.into()
}
@@ -1088,7 +1094,7 @@ impl SequentialLayoutState {
// Calculate the hypothetical position where the element's top border edge
// would have been if the element's `clear` property had been `none`.
- let hypothetical_block_position = self.position_without_clearance(&block_start_margin);
+ let hypothetical_block_position = self.position_without_clearance(block_start_margin);
// Check if the hypothetical position is past the relevant floats,
// in that case we don't need to add clearance.
@@ -1121,9 +1127,8 @@ impl SequentialLayoutState {
clear: Clear,
block_start_margin: &CollapsedMargin,
) -> Option<Au> {
- return self
- .calculate_clear_position(clear, &block_start_margin)
- .map(|offset| offset - self.position_with_zero_clearance(&block_start_margin));
+ self.calculate_clear_position(clear, block_start_margin)
+ .map(|offset| offset - self.position_with_zero_clearance(block_start_margin))
}
/// A block that is replaced or establishes an independent formatting context can't overlap floats,
@@ -1144,15 +1149,15 @@ impl SequentialLayoutState {
// First compute the clear position required by the 'clear' property.
// The code below may then add extra clearance when the element can't fit
// next to floats not covered by 'clear'.
- let clear_position = self.calculate_clear_position(clear, &block_start_margin);
+ let clear_position = self.calculate_clear_position(clear, block_start_margin);
let ceiling =
- clear_position.unwrap_or_else(|| self.position_without_clearance(&block_start_margin));
+ clear_position.unwrap_or_else(|| self.position_without_clearance(block_start_margin));
let mut placement = PlacementAmongFloats::new(&self.floats, ceiling, object_size, pbm);
let placement_rect = placement.place();
let position = &placement_rect.start_corner;
let has_clearance = clear_position.is_some() || position.block > ceiling;
let clearance = if has_clearance {
- Some(position.block - self.position_with_zero_clearance(&block_start_margin))
+ Some(position.block - self.position_with_zero_clearance(block_start_margin))
} else {
None
};
diff --git a/components/layout_2020/flow/inline.rs b/components/layout_2020/flow/inline.rs
index 6a2b7cf879e..03861743091 100644
--- a/components/layout_2020/flow/inline.rs
+++ b/components/layout_2020/flow/inline.rs
@@ -149,8 +149,8 @@ struct LineUnderConstruction {
impl LineUnderConstruction {
fn new(start_position: LogicalVec2<Length>) -> Self {
Self {
- inline_position: start_position.inline.clone(),
- start_position: start_position,
+ inline_position: start_position.inline,
+ start_position,
max_block_size: LineBlockSizes::zero(),
has_content: false,
has_floats_waiting_to_be_placed: false,
@@ -273,7 +273,7 @@ impl LineBlockSizes {
self.baseline_relative_size_for_line_height.as_ref(),
other.baseline_relative_size_for_line_height.as_ref(),
) {
- (Some(our_size), Some(other_size)) => Some(our_size.max(&other_size)),
+ (Some(our_size), Some(other_size)) => Some(our_size.max(other_size)),
(our_size, other_size) => our_size.or(other_size).cloned(),
};
Self {
@@ -290,9 +290,9 @@ impl LineBlockSizes {
}
fn adjust_for_baseline_offset(&mut self, baseline_offset: Au) {
- self.baseline_relative_size_for_line_height
- .as_mut()
- .map(|size| size.adjust_for_nested_baseline_offset(baseline_offset));
+ if let Some(size) = self.baseline_relative_size_for_line_height.as_mut() {
+ size.adjust_for_nested_baseline_offset(baseline_offset)
+ }
self.size_for_baseline_positioning
.adjust_for_nested_baseline_offset(baseline_offset);
}
@@ -460,11 +460,7 @@ impl UnbreakableSegmentUnderConstruction {
}
let segment_items = mem::take(&mut self.line_items);
- self.line_items = hierarchy
- .into_iter()
- .rev()
- .chain(segment_items.into_iter())
- .collect();
+ self.line_items = hierarchy.into_iter().rev().chain(segment_items).collect();
}
}
@@ -637,7 +633,7 @@ impl<'a, 'b> InlineFormattingContextState<'a, 'b> {
fn start_inline_box(&mut self, inline_box: &InlineBox) {
let mut inline_box_state = InlineBoxContainerState::new(
inline_box,
- &self.containing_block,
+ self.containing_block,
self.layout_context,
self.current_inline_container_state(),
inline_box.is_last_fragment,
@@ -737,7 +733,7 @@ impl<'a, 'b> InlineFormattingContextState<'a, 'b> {
// This amount includes both the block size of the line and any extra space
// added to move the line down in order to avoid overlapping floats.
let increment = block_end_position - self.current_line.start_position.block.into();
- sequential_layout_state.advance_block_position(increment.into());
+ sequential_layout_state.advance_block_position(increment);
}
let mut line_items = std::mem::take(&mut self.current_line.line_items);
@@ -758,7 +754,7 @@ impl<'a, 'b> InlineFormattingContextState<'a, 'b> {
parent_offset: LogicalVec2::zero(),
baseline_offset,
ifc_containing_block: self.containing_block,
- positioning_context: &mut self.positioning_context,
+ positioning_context: self.positioning_context,
justification_adjustment,
line_metrics: &LineMetrics {
block_offset: block_start_position.into(),
@@ -1002,9 +998,7 @@ impl<'a, 'b> InlineFormattingContextState<'a, 'b> {
.floats
.containing_block_info
.inline_start,
- block: sequential_layout_state
- .current_containing_block_offset()
- .into(),
+ block: sequential_layout_state.current_containing_block_offset(),
};
let ceiling = self
@@ -1012,7 +1006,7 @@ impl<'a, 'b> InlineFormattingContextState<'a, 'b> {
.line_block_start_considering_placement_among_floats();
let mut placement = PlacementAmongFloats::new(
&sequential_layout_state.floats,
- ceiling + ifc_offset_in_float_container.block.into(),
+ ceiling + ifc_offset_in_float_container.block,
LogicalVec2 {
inline: potential_line_size.inline.into(),
block: potential_line_size.block.into(),
@@ -1154,7 +1148,7 @@ impl<'a, 'b> InlineFormattingContextState<'a, 'b> {
font_key: FontInstanceKey,
) {
self.current_line_segment.justification_opportunities +=
- glyph_store.total_word_separators() as usize;
+ glyph_store.total_word_separators();
let inline_advance = Length::from(glyph_store.total_advance());
let preserve_spaces = parent_style
@@ -1194,7 +1188,7 @@ impl<'a, 'b> InlineFormattingContextState<'a, 'b> {
self.push_line_item_to_unbreakable_segment(LineItem::TextRun(TextRunLineItem {
text: vec![glyph_store],
- base_fragment_info: base_fragment_info.into(),
+ base_fragment_info,
parent_style: parent_style.clone(),
font_metrics: font_metrics.clone(),
font_key,
@@ -1531,12 +1525,12 @@ impl InlineFormattingContext {
content_block_size == Length::zero() &&
collapsible_with_parent_start_margin.0;
- return FlowLayout {
+ FlowLayout {
fragments: ifc.fragments,
content_block_size,
collapsible_margins_in_children,
last_inflow_baseline_offset: ifc.last_baseline_offset,
- };
+ }
}
/// Return true if this [InlineFormattingContext] is empty for the purposes of ignoring
@@ -1546,7 +1540,7 @@ impl InlineFormattingContext {
fn inline_level_boxes_are_empty(boxes: &[ArcRefCell<InlineLevelBox>]) -> bool {
boxes
.iter()
- .all(|inline_level_box| inline_level_box_is_empty(&*inline_level_box.borrow()))
+ .all(|inline_level_box| inline_level_box_is_empty(&inline_level_box.borrow()))
}
fn inline_level_box_is_empty(inline_level_box: &InlineLevelBox) -> bool {
@@ -1660,8 +1654,8 @@ impl InlineContainerState {
if style.get_inherited_text().line_height != LineHeight::Normal {
let half_leading =
(Au::from_f32_px(line_height.px()) - (ascent + descent)).scale_by(0.5);
- ascent = ascent + half_leading;
- descent = descent + half_leading;
+ ascent += half_leading;
+ descent += half_leading;
}
LineBlockSizes {
@@ -1675,7 +1669,7 @@ impl InlineContainerState {
Self::get_block_sizes_with_style(
&self.style,
font_metrics,
- line_height(&self.style, &font_metrics),
+ line_height(&self.style, font_metrics),
)
}
@@ -1718,9 +1712,8 @@ impl InlineContainerState {
.scale_by(0.5)
},
GenericVerticalAlign::Keyword(VerticalAlignKeyword::TextBottom) => {
- (self.font_metrics.descent -
- child_block_size.size_for_baseline_positioning.descent)
- .into()
+ self.font_metrics.descent -
+ child_block_size.size_for_baseline_positioning.descent
},
GenericVerticalAlign::Length(length_percentage) => {
Au::from_f32_px(-length_percentage.resolve(child_block_size.line_height).px())
@@ -1778,7 +1771,7 @@ impl IndependentFormattingContext {
ifc: &mut InlineFormattingContextState,
) {
let style = self.style();
- let pbm = style.padding_border_margin(&ifc.containing_block);
+ let pbm = style.padding_border_margin(ifc.containing_block);
let margin = pbm.margin.auto_is(Length::zero);
let pbm_sums = &(&pbm.padding + &pbm.border) + &margin;
let mut child_positioning_context = None;
@@ -1816,13 +1809,13 @@ impl IndependentFormattingContext {
IndependentFormattingContext::NonReplaced(non_replaced) => {
let box_size = non_replaced
.style
- .content_box_size(&ifc.containing_block, &pbm);
+ .content_box_size(ifc.containing_block, &pbm);
let max_box_size = non_replaced
.style
- .content_max_box_size(&ifc.containing_block, &pbm);
+ .content_max_box_size(ifc.containing_block, &pbm);
let min_box_size = non_replaced
.style
- .content_min_box_size(&ifc.containing_block, &pbm)
+ .content_min_box_size(ifc.containing_block, &pbm)
.auto_is(Length::zero);
// https://drafts.csswg.org/css2/visudet.html#inlineblock-width
@@ -2148,7 +2141,7 @@ impl FloatBox {
}
fn place_pending_floats(ifc: &mut InlineFormattingContextState, line_items: &mut Vec<LineItem>) {
- for item in line_items.into_iter() {
+ for item in line_items.iter_mut() {
match item {
LineItem::Float(float_line_item) => {
if float_line_item.needs_placement {
diff --git a/components/layout_2020/flow/line.rs b/components/layout_2020/flow/line.rs
index 0c0a4c026de..146f3388120 100644
--- a/components/layout_2020/flow/line.rs
+++ b/components/layout_2020/flow/line.rs
@@ -507,7 +507,7 @@ impl AtomicLineItem {
// This needs to be added to the calculated block and inline positions.
self.fragment.content_rect.start_corner.inline += state.inline_position;
self.fragment.content_rect.start_corner.block +=
- self.calculate_block_start(&state.line_metrics);
+ self.calculate_block_start(state.line_metrics);
// Make the final result relative to the parent box.
self.fragment.content_rect.start_corner =
diff --git a/components/layout_2020/flow/mod.rs b/components/layout_2020/flow/mod.rs
index 0780b4d6248..eb16f496e8f 100644
--- a/components/layout_2020/flow/mod.rs
+++ b/components/layout_2020/flow/mod.rs
@@ -97,7 +97,7 @@ impl BlockLevelBox {
containing_block: &ContainingBlock,
) -> bool {
let style = match self {
- BlockLevelBox::SameFormattingContextBlock { ref style, .. } => &style,
+ BlockLevelBox::SameFormattingContextBlock { ref style, .. } => style,
BlockLevelBox::OutOfFlowAbsolutelyPositionedBox(_) |
BlockLevelBox::OutOfFlowFloatBox(_) => return true,
BlockLevelBox::Independent(ref context) => {
@@ -156,7 +156,7 @@ impl BlockLevelBox {
};
if !Self::find_block_margin_collapsing_with_parent_from_slice(
- &child_boxes,
+ child_boxes,
collected_margin,
&containing_block_for_children,
) {
@@ -276,7 +276,7 @@ fn calculate_inline_content_size_for_block_level_boxes(
BlockLevelBox::SameFormattingContextBlock {
style, contents, ..
} => {
- let size = sizing::outer_inline(&style, writing_mode, || {
+ let size = sizing::outer_inline(style, writing_mode, || {
contents.inline_content_sizes(layout_context, style.writing_mode)
})
.max(ContentSizes::zero());
@@ -674,7 +674,7 @@ fn layout_in_flow_non_replaced_block_level_same_formatting_context(
if !collapsible_with_parent_start_margin && start_margin_can_collapse_with_children {
if let BlockContainer::BlockLevelBoxes(child_boxes) = contents {
BlockLevelBox::find_block_margin_collapsing_with_parent_from_slice(
- &child_boxes,
+ child_boxes,
&mut block_start_margin,
containing_block,
);
@@ -729,7 +729,7 @@ fn layout_in_flow_non_replaced_block_level_same_formatting_context(
layout_context,
positioning_context,
&containing_block_for_children,
- sequential_layout_state.as_mut().map(|x| &mut **x),
+ sequential_layout_state.as_deref_mut(),
CollapsibleWithParentStartMargin(start_margin_can_collapse_with_children),
);
let mut content_block_size = flow_layout.content_block_size;
@@ -798,8 +798,7 @@ fn layout_in_flow_non_replaced_block_level_same_formatting_context(
start_corner: LogicalVec2 {
block: (pbm.padding.block_start +
pbm.border.block_start +
- clearance.unwrap_or_else(Au::zero).into())
- .into(),
+ clearance.unwrap_or_else(Au::zero).into()),
inline: pbm.padding.inline_start + pbm.border.inline_start + margin.inline_start,
},
size: LogicalVec2 {
@@ -965,8 +964,8 @@ impl NonReplacedFormattingContext {
(clearance, (margin_inline_start, margin_inline_end)) =
solve_clearance_and_inline_margins_avoiding_floats(
- &sequential_layout_state,
- &containing_block,
+ sequential_layout_state,
+ containing_block,
&collapsed_margin_block_start,
&pbm,
&content_size + &pbm.padding_border_sums,
@@ -1062,8 +1061,8 @@ impl NonReplacedFormattingContext {
};
(margin_inline_start, margin_inline_end) = solve_inline_margins_avoiding_floats(
- &sequential_layout_state,
- &containing_block,
+ sequential_layout_state,
+ containing_block,
&pbm,
content_size.inline + pbm.padding_border_sums.inline,
placement_rect.into(),
@@ -1153,12 +1152,12 @@ fn layout_in_flow_replaced_block_level<'a>(
let size = &content_size + &pbm.padding_border_sums;
(clearance, (margin_inline_start, margin_inline_end)) =
solve_clearance_and_inline_margins_avoiding_floats(
- &sequential_layout_state,
- &containing_block,
+ sequential_layout_state,
+ containing_block,
&collapsed_margin_block_start,
&pbm,
size.clone(),
- &style,
+ style,
);
// Clearance prevents margin collapse between this block and previous ones,
@@ -1305,14 +1304,14 @@ fn solve_clearance_and_inline_margins_avoiding_floats(
let (clearance, placement_rect) = sequential_layout_state
.calculate_clearance_and_inline_adjustment(
style.get_box().clear,
- &block_start_margin,
- &pbm,
+ block_start_margin,
+ pbm,
size.clone().into(),
);
let inline_margins = solve_inline_margins_avoiding_floats(
- &sequential_layout_state,
- &containing_block,
- &pbm,
+ sequential_layout_state,
+ containing_block,
+ pbm,
size.inline,
placement_rect.into(),
);
diff --git a/components/layout_2020/flow/root.rs b/components/layout_2020/flow/root.rs
index 21a84d656c0..2dfd34fbfe7 100644
--- a/components/layout_2020/flow/root.rs
+++ b/components/layout_2020/flow/root.rs
@@ -43,7 +43,7 @@ impl BoxTree {
where
Node: 'dom + Copy + LayoutNode<'dom> + Send + Sync,
{
- let boxes = construct_for_root_element(&context, root_element);
+ let boxes = construct_for_root_element(context, root_element);
// Zero box for `:root { display: none }`, one for the root element otherwise.
assert!(boxes.len() <= 1);
@@ -291,7 +291,7 @@ impl BoxTree {
let mut root_fragments = independent_layout
.fragments
.into_iter()
- .map(|fragment| ArcRefCell::new(fragment))
+ .map(ArcRefCell::new)
.collect::<Vec<_>>();
// Zero box for `:root { display: none }`, one for the root element otherwise.