Lint layout_2020 with clippy (#31169)

cargo clippy --fix -p layout_2020 --allow-dirty --broken-code
This commit is contained in:
Oriol Brufau 2024-01-25 10:03:31 +01:00 committed by GitHub
parent 886f6c58d4
commit 50f56affe3
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
30 changed files with 224 additions and 244 deletions

View file

@ -110,7 +110,7 @@ impl<'a> LayoutContext<'a> {
.read()
.get(&(url.clone(), use_placeholder))
{
return Some((*existing_webrender_image).clone());
return Some(*existing_webrender_image);
}
match self.get_or_request_image_or_meta(node, url.clone(), use_placeholder) {

View file

@ -29,7 +29,7 @@ pub(super) fn build(
} else {
wr::ExtendMode::Clamp
},
&layer,
layer,
builder,
),
Gradient::Radial {
@ -48,7 +48,7 @@ pub(super) fn build(
} else {
wr::ExtendMode::Clamp
},
&layer,
layer,
builder,
),
Gradient::Conic { .. } => unimplemented!(),

View file

@ -123,9 +123,9 @@ pub(crate) struct DisplayListBuilder<'a> {
}
impl DisplayList {
pub fn build<'a>(
pub fn build(
&mut self,
context: &'a LayoutContext,
context: &LayoutContext,
fragment_tree: &FragmentTree,
root_stacking_context: &StackingContext,
) -> (FnvHashMap<BrowsingContextId, Size2D<f32, CSSPixel>>, bool) {
@ -280,7 +280,7 @@ impl Fragment {
.rect
.to_physical(fragment.parent_style.writing_mode, containing_block)
.translate(containing_block.origin.to_vector());
let mut baseline_origin = rect.origin.clone();
let mut baseline_origin = rect.origin;
baseline_origin.y += Length::from(fragment.font_metrics.ascent);
let glyphs = glyphs(
&fragment.glyphs,
@ -317,8 +317,7 @@ impl Fragment {
.contains(TextDecorationLine::UNDERLINE)
{
let mut rect = rect;
rect.origin.y =
rect.origin.y + Length::from(font_metrics.ascent - font_metrics.underline_offset);
rect.origin.y += Length::from(font_metrics.ascent - font_metrics.underline_offset);
rect.size.height = Length::new(font_metrics.underline_size.to_nearest_pixel(dppx));
self.build_display_list_for_text_decoration(fragment, builder, &rect, &color);
}
@ -350,8 +349,7 @@ impl Fragment {
.contains(TextDecorationLine::LINE_THROUGH)
{
let mut rect = rect;
rect.origin.y =
rect.origin.y + Length::from(font_metrics.ascent - font_metrics.strikeout_offset);
rect.origin.y += Length::from(font_metrics.ascent - font_metrics.strikeout_offset);
// XXX(ferjm) This does not work on MacOS #942
rect.size.height = Length::new(font_metrics.strikeout_size.to_nearest_pixel(dppx));
self.build_display_list_for_text_decoration(fragment, builder, &rect, &color);
@ -590,7 +588,7 @@ impl<'a> BuilderForBoxFragment<'a> {
if let Some(layer) =
&background::layout_layer(self, &source, builder, index, intrinsic)
{
gradient::build(&style, &gradient, layer, builder)
gradient::build(style, gradient, layer, builder)
}
},
Image::Url(ref image_url) => {
@ -898,7 +896,7 @@ fn clip_for_radii(
if radii.is_zero() {
None
} else {
let clip_chain_id = builder.current_clip_chain_id.clone();
let clip_chain_id = builder.current_clip_chain_id;
let parent_space_and_clip = wr::SpaceAndClipInfo {
spatial_id: builder.current_scroll_node_id.spatial_id,
clip_id: ClipId::ClipChain(clip_chain_id),

View file

@ -198,7 +198,7 @@ impl DisplayList {
.spatial_id;
let new_scroll_node_id = self.compositor_info.scroll_tree.add_scroll_tree_node(
Some(&parent_scroll_node_id),
Some(parent_scroll_node_id),
new_spatial_id,
Some(ScrollableNodeInfo {
external_id,
@ -374,7 +374,7 @@ impl StackingContext {
) -> Self {
Self {
spatial_id,
clip_chain_id: clip_chain_id,
clip_chain_id,
initializing_fragment_style: Some(initializing_fragment_style),
context_type,
contents: vec![],
@ -423,9 +423,9 @@ impl StackingContext {
}
pub(crate) fn sort(&mut self) {
self.contents.sort_by(|a, b| a.section().cmp(&b.section()));
self.contents.sort_by_key(|a| a.section());
self.real_stacking_contexts_and_positioned_stacking_containers
.sort_by(|a, b| a.z_index().cmp(&b.z_index()));
.sort_by_key(|a| a.z_index());
debug_assert!(self
.real_stacking_contexts_and_positioned_stacking_containers
@ -502,8 +502,8 @@ impl StackingContext {
style.get_used_transform_style().to_webrender(),
effects.mix_blend_mode.to_webrender(),
&filters,
&vec![], // filter_datas
&vec![], // filter_primitives
&[], // filter_datas
&[], // filter_primitives
wr::RasterSpace::Screen,
wr::StackingContextFlags::empty(),
);
@ -541,7 +541,7 @@ impl StackingContext {
let background_color = style.resolve_color(style.get_background().background_color.clone());
if background_color.alpha > 0.0 {
let common = builder.common_properties(painting_area, &style);
let common = builder.common_properties(painting_area, style);
let color = super::rgba(background_color);
builder
.display_list
@ -1212,7 +1212,7 @@ impl BoxFragment {
let border_rect = self
.border_rect()
.to_physical(self.style.writing_mode, &containing_block_rect);
.to_physical(self.style.writing_mode, containing_block_rect);
let clip_rect = clip_rect
.for_border_rect(border_rect)
.translate(containing_block_rect.origin.to_vector())
@ -1225,7 +1225,7 @@ impl BoxFragment {
let clip_id = display_list
.wr
.define_clip_rect(&parent_space_and_clip, clip_rect);
.define_clip_rect(parent_space_and_clip, clip_rect);
Some(
display_list
.wr
@ -1261,7 +1261,7 @@ impl BoxFragment {
let padding_rect = self
.padding_rect()
.to_physical(self.style.writing_mode, &containing_block_rect)
.to_physical(self.style.writing_mode, containing_block_rect)
.translate(containing_block_rect.origin.to_vector())
.to_webrender();
@ -1269,7 +1269,7 @@ impl BoxFragment {
parent_scroll_node_id,
parent_clip_id,
external_id,
self.scrollable_overflow(&containing_block_rect)
self.scrollable_overflow(containing_block_rect)
.to_webrender(),
padding_rect,
sensitivity,
@ -1331,7 +1331,7 @@ impl BoxFragment {
let frame_rect = self
.border_rect()
.to_physical(self.style.writing_mode, &containing_block_rect)
.to_physical(self.style.writing_mode, containing_block_rect)
.translate(containing_block_rect.origin.to_vector())
.to_webrender();
@ -1379,7 +1379,7 @@ impl BoxFragment {
let relative_border_rect = self
.border_rect()
.to_physical(self.style.writing_mode, &containing_block_rect);
.to_physical(self.style.writing_mode, containing_block_rect);
let border_rect = relative_border_rect.translate(containing_block_rect.origin.to_vector());
let untyped_border_rect = border_rect.to_untyped();
@ -1431,7 +1431,7 @@ impl BoxFragment {
) -> Option<LayoutTransform> {
let list = &self.style.get_box().transform;
let transform =
LayoutTransform::from_untyped(&list.to_transform_3d_matrix(Some(&border_rect)).ok()?.0);
LayoutTransform::from_untyped(&list.to_transform_3d_matrix(Some(border_rect)).ok()?.0);
// WebRender will end up dividing by the scale value of this transform, so we
// want to ensure we don't feed it a divisor of 0.
assert_ne!(transform.m11, 0.);

View file

@ -119,8 +119,8 @@ where
.unwrap_or((0, 0));
let (mut width, mut height) = (width as f64, height as f64);
if let Some(density) = node.image_density().filter(|density| *density != 1.) {
width = width / density;
height = height / density;
width /= density;
height /= density;
}
Some((resource, PhysicalSize::new(width, height)))
}

View file

@ -58,7 +58,7 @@ impl<Node: Clone> NodeAndStyleInfo<Node> {
pub(crate) fn new_replacing_style(&self, style: ServoArc<ComputedValues>) -> Self {
Self {
node: self.node.clone(),
pseudo_element_type: self.pseudo_element_type.clone(),
pseudo_element_type: self.pseudo_element_type,
style,
}
}
@ -221,7 +221,7 @@ fn traverse_pseudo_element_contents<'dom, Node>(
let mut anonymous_style = None;
for item in items {
match item {
PseudoElementContentItem::Text(text) => handler.handle_text(&info, text.into()),
PseudoElementContentItem::Text(text) => handler.handle_text(info, text.into()),
PseudoElementContentItem::Replaced(contents) => {
let item_style = anonymous_style.get_or_insert_with(|| {
context

View file

@ -373,8 +373,7 @@ impl FlexContainer {
fragment.content_rect.start_corner += &flow_relative_line_position
}
line.item_fragments
})
.into_iter();
});
let fragments = absolutely_positioned_items_with_original_order
.into_iter()
@ -458,7 +457,7 @@ impl<'a> FlexItem<'a> {
) {
(Some(ratio), LengthOrAuto::LengthPercentage(block_size)) => {
let block_size = block_size.clamp_between_extremums(
min_size.block.auto_is(|| Length::zero()),
min_size.block.auto_is(Length::zero),
max_size.block,
);
Some(block_size * ratio)
@ -469,7 +468,7 @@ impl<'a> FlexItem<'a> {
};
let inline_content_size = box_
.inline_content_sizes(&flex_context.layout_context)
.inline_content_sizes(flex_context.layout_context)
.min_content;
let content_size_suggestion = match box_ {
IndependentFormattingContext::NonReplaced(_) => inline_content_size,
@ -479,7 +478,7 @@ impl<'a> FlexItem<'a> {
.inline_size_over_block_size_intrinsic_ratio(box_.style())
{
inline_content_size.clamp_between_extremums(
(min_size.block.auto_is(|| Length::zero()) * ratio).into(),
(min_size.block.auto_is(Length::zero) * ratio).into(),
max_size.block.map(|l| (l * ratio).into()),
)
} else {
@ -507,7 +506,7 @@ impl<'a> FlexItem<'a> {
let min_size = LogicalVec2 {
inline: min_size.inline.auto_is(automatic_min_size),
block: min_size.block.auto_is(|| Length::zero()),
block: min_size.block.auto_is(Length::zero),
};
let margin_auto_is_zero = pbm.margin.auto_is(Length::zero);
@ -653,7 +652,7 @@ fn collect_flex_lines<'items, LineResult>(
.sum(),
items,
};
return vec![each(flex_context, line)];
vec![each(flex_context, line)]
} else {
let mut lines = Vec::new();
let mut line_size_so_far = Length::zero();
@ -709,7 +708,7 @@ impl FlexLine<'_> {
.collect::<Vec<_>>();
// https://drafts.csswg.org/css-flexbox/#algo-cross-line
let line_cross_size = self.cross_size(&item_layout_results, &flex_context);
let line_cross_size = self.cross_size(&item_layout_results, flex_context);
let line_size = FlexRelativeVec2 {
main: container_main_size,
cross: line_cross_size,
@ -791,7 +790,7 @@ impl FlexLine<'_> {
let item_cross_margins = self.items.iter().zip(&item_used_cross_sizes).map(
|(item, &item_cross_content_size)| {
item.resolve_auto_cross_margins(
&flex_context,
flex_context,
line_cross_size,
item_cross_content_size,
)

View file

@ -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) {

View file

@ -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
};

View file

@ -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 {

View file

@ -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 =

View file

@ -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(),
);

View file

@ -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.

View file

@ -174,7 +174,7 @@ impl IndependentFormattingContext {
let style = &non_replaced.style;
let content_sizes = &mut non_replaced.content_sizes;
let contents = &mut non_replaced.contents;
sizing::outer_inline(&style, containing_block_writing_mode, || {
sizing::outer_inline(style, containing_block_writing_mode, || {
content_sizes
.get_or_insert_with(|| {
contents.inline_content_sizes(layout_context, style.writing_mode)

View file

@ -114,6 +114,6 @@ impl Tag {
Some(PseudoElement::After) => FragmentType::AfterPseudoContent,
_ => FragmentType::FragmentBody,
};
combine_id_with_fragment_type(self.node.id() as usize, fragment_type) as u64
combine_id_with_fragment_type(self.node.id(), fragment_type) as u64
}
}

View file

@ -135,10 +135,7 @@ impl BoxFragment {
BoxFragment {
base: base_fragment_info.into(),
style,
children: children
.into_iter()
.map(|fragment| ArcRefCell::new(fragment))
.collect(),
children: children.into_iter().map(ArcRefCell::new).collect(),
content_rect,
padding,
border,
@ -221,7 +218,7 @@ impl BoxFragment {
// https://www.w3.org/TR/css-overflow-3/#scrollable
// Only include the scrollable overflow of a child box if it has overflow: visible.
let scrollable_overflow = self.scrollable_overflow(&containing_block);
let scrollable_overflow = self.scrollable_overflow(containing_block);
let bottom_right = PhysicalPoint::new(
overflow.max_x().max(scrollable_overflow.max_x()),
overflow.max_y().max(scrollable_overflow.max_y()),
@ -254,7 +251,7 @@ impl BoxFragment {
let (cb_width, cb_height) = (containing_block.width(), containing_block.height());
let content_rect = self
.content_rect
.to_physical(self.style.writing_mode, &containing_block);
.to_physical(self.style.writing_mode, containing_block);
if let Some(resolved_sticky_insets) = self.resolved_sticky_insets {
return resolved_sticky_insets;

View file

@ -67,11 +67,11 @@ impl<'a, T> ContainingBlockManager<'a, T> {
&self,
for_non_absolute_descendants: &'a T,
) -> Self {
return ContainingBlockManager {
ContainingBlockManager {
for_non_absolute_descendants,
for_absolute_descendants: self.for_absolute_descendants,
for_absolute_and_fixed_descendants: self.for_absolute_and_fixed_descendants,
};
}
}
pub(crate) fn new_for_absolute_descendants(
@ -79,11 +79,11 @@ impl<'a, T> ContainingBlockManager<'a, T> {
for_non_absolute_descendants: &'a T,
for_absolute_descendants: &'a T,
) -> Self {
return ContainingBlockManager {
ContainingBlockManager {
for_non_absolute_descendants,
for_absolute_descendants: Some(for_absolute_descendants),
for_absolute_and_fixed_descendants: self.for_absolute_and_fixed_descendants,
};
}
}
pub(crate) fn new_for_absolute_and_fixed_descendants(
@ -91,10 +91,10 @@ impl<'a, T> ContainingBlockManager<'a, T> {
for_non_absolute_descendants: &'a T,
for_absolute_and_fixed_descendants: &'a T,
) -> Self {
return ContainingBlockManager {
ContainingBlockManager {
for_non_absolute_descendants,
for_absolute_descendants: None,
for_absolute_and_fixed_descendants,
};
}
}
}

View file

@ -134,7 +134,7 @@ impl Fragment {
match self {
Fragment::Box(fragment) => fragment.print(tree),
Fragment::Float(fragment) => {
tree.new_level(format!("Float"));
tree.new_level("Float".to_string());
fragment.print(tree);
tree.end_level();
},
@ -163,19 +163,19 @@ impl Fragment {
) -> PhysicalRect<Length> {
match self {
Fragment::Box(fragment) | Fragment::Float(fragment) => {
fragment.scrollable_overflow_for_parent(&containing_block)
fragment.scrollable_overflow_for_parent(containing_block)
},
Fragment::AbsoluteOrFixedPositioned(_) => PhysicalRect::zero(),
Fragment::Anonymous(fragment) => fragment.scrollable_overflow.clone(),
Fragment::Anonymous(fragment) => fragment.scrollable_overflow,
Fragment::Text(fragment) => fragment
.rect
.to_physical(fragment.parent_style.writing_mode, &containing_block),
.to_physical(fragment.parent_style.writing_mode, containing_block),
Fragment::Image(fragment) => fragment
.rect
.to_physical(fragment.style.writing_mode, &containing_block),
.to_physical(fragment.style.writing_mode, containing_block),
Fragment::IFrame(fragment) => fragment
.rect
.to_physical(fragment.style.writing_mode, &containing_block),
.to_physical(fragment.style.writing_mode, containing_block),
}
}
@ -251,10 +251,7 @@ impl AnonymousFragment {
AnonymousFragment {
base: BaseFragment::anonymous(),
rect,
children: children
.into_iter()
.map(|fragment| ArcRefCell::new(fragment))
.collect(),
children: children.into_iter().map(ArcRefCell::new).collect(),
mode,
scrollable_overflow,
}

View file

@ -104,10 +104,10 @@ impl FragmentTree {
let fragment_relative_rect = match fragment {
Fragment::Box(fragment) | Fragment::Float(fragment) => fragment
.border_rect()
.to_physical(fragment.style.writing_mode, &containing_block),
.to_physical(fragment.style.writing_mode, containing_block),
Fragment::Text(fragment) => fragment
.rect
.to_physical(fragment.parent_style.writing_mode, &containing_block),
.to_physical(fragment.parent_style.writing_mode, containing_block),
Fragment::AbsoluteOrFixedPositioned(_) |
Fragment::Image(_) |
Fragment::IFrame(_) |
@ -156,7 +156,7 @@ impl FragmentTree {
return Some(Rect::zero());
}
let padding_rect = padding_rect.to_physical(style.writing_mode, &containing_block);
let padding_rect = padding_rect.to_physical(style.writing_mode, containing_block);
let border = style.get_border();
Some(Rect::new(
Point2D::new(
@ -187,7 +187,7 @@ impl FragmentTree {
let tag_to_find = Tag::new(requested_node);
let scroll_area = self.find(|fragment, _, containing_block| {
if fragment.tag() == Some(tag_to_find) {
Some(fragment.scrolling_area(&containing_block))
Some(fragment.scrolling_area(containing_block))
} else {
None
}

View file

@ -57,8 +57,8 @@ pub(crate) enum AbsoluteBoxOffsets {
impl AbsoluteBoxOffsets {
pub(crate) fn both_specified(&self) -> bool {
match self {
AbsoluteBoxOffsets::Both { .. } => return true,
_ => return false,
AbsoluteBoxOffsets::Both { .. } => true,
_ => false,
}
}

View file

@ -48,7 +48,7 @@ struct ScopeData {
name: String,
pre: TreeValues,
post: TreeValues,
children: Vec<Box<ScopeData>>,
children: Vec<ScopeData>,
}
impl ScopeData {
@ -71,19 +71,19 @@ impl ScopeData {
struct State {
fragment_tree: Arc<FragmentTree>,
box_tree: Arc<BoxTree>,
scope_stack: Vec<Box<ScopeData>>,
scope_stack: Vec<ScopeData>,
}
/// A layout debugging scope. The entire state of the box and fragment trees
/// will be output at the beginning and end of this scope.
impl Scope {
pub fn new(name: String) -> Scope {
STATE_KEY.with(|ref r| {
STATE_KEY.with(|r| {
if let Some(ref mut state) = *r.borrow_mut() {
let box_tree = to_value(&state.box_tree).unwrap();
let fragment_tree = to_value(&state.fragment_tree).unwrap();
let data = Box::new(ScopeData::new(name.clone(), box_tree, fragment_tree));
state.scope_stack.push(data);
state.scope_stack.push(*data);
}
});
Scope
@ -93,7 +93,7 @@ impl Scope {
#[cfg(debug_assertions)]
impl Drop for Scope {
fn drop(&mut self) {
STATE_KEY.with(|ref r| {
STATE_KEY.with(|r| {
if let Some(ref mut state) = *r.borrow_mut() {
let mut current_scope = state.scope_stack.pop().unwrap();
current_scope.post = TreeValues {
@ -110,13 +110,13 @@ impl Drop for Scope {
/// Begin a layout debug trace. If this has not been called,
/// creating debug scopes has no effect.
pub fn begin_trace(box_tree: Arc<BoxTree>, fragment_tree: Arc<FragmentTree>) {
assert!(STATE_KEY.with(|ref r| r.borrow().is_none()));
assert!(STATE_KEY.with(|r| r.borrow().is_none()));
STATE_KEY.with(|ref r| {
STATE_KEY.with(|r| {
let box_tree_value = to_value(&box_tree).unwrap();
let fragment_tree_value = to_value(&fragment_tree).unwrap();
let state = State {
scope_stack: vec![Box::new(ScopeData::new(
scope_stack: vec![*Box::new(ScopeData::new(
"root".to_owned(),
box_tree_value,
fragment_tree_value,
@ -132,7 +132,7 @@ pub fn begin_trace(box_tree: Arc<BoxTree>, fragment_tree: Arc<FragmentTree>) {
/// trace to disk in the current directory. The output
/// file can then be viewed with an external tool.
pub fn end_trace(generation: u32) {
let mut thread_state = STATE_KEY.with(|ref r| r.borrow_mut().take().unwrap());
let mut thread_state = STATE_KEY.with(|r| r.borrow_mut().take().unwrap());
assert_eq!(thread_state.scope_stack.len(), 1);
let mut root_scope = thread_state.scope_stack.pop().unwrap();
root_scope.post = TreeValues {
@ -170,6 +170,12 @@ impl DebugId {
}
}
impl Default for DebugId {
fn default() -> Self {
Self::new()
}
}
#[cfg(not(debug_assertions))]
impl Serialize for DebugId {
fn serialize<S: Serializer>(&self, serializer: S) -> Result<S::Ok, S::Error> {

View file

@ -195,14 +195,12 @@ impl PositioningContext {
}
};
self.for_nearest_positioned_ancestor
.as_mut()
.map(|hoisted_boxes| {
hoisted_boxes
.iter_mut()
.skip(index.for_nearest_positioned_ancestor)
.for_each(update_fragment_if_needed);
});
if let Some(hoisted_boxes) = self.for_nearest_positioned_ancestor.as_mut() {
hoisted_boxes
.iter_mut()
.skip(index.for_nearest_positioned_ancestor)
.for_each(update_fragment_if_needed);
}
self.for_nearest_containing_block_for_all_descendants
.iter_mut()
.skip(index.for_nearest_containing_block_for_all_descendants)
@ -367,9 +365,9 @@ impl PositioningContext {
pub(crate) fn clear(&mut self) {
self.for_nearest_containing_block_for_all_descendants
.clear();
self.for_nearest_positioned_ancestor
.as_mut()
.map(|v| v.clear());
if let Some(v) = self.for_nearest_positioned_ancestor.as_mut() {
v.clear()
}
}
/// Get the length of this [PositioningContext].
@ -546,7 +544,7 @@ impl HoistedAbsolutelyPositionedBox {
let min_size = non_replaced
.style
.content_min_box_size(&containing_block.into(), &pbm)
.auto_is(|| Length::zero());
.auto_is(Length::zero);
let max_size = non_replaced
.style
.content_max_box_size(&containing_block.into(), &pbm);

View file

@ -89,26 +89,26 @@ impl LayoutRPC for LayoutRPCImpl {
// The neat thing here is that in order to answer the following two queries we only
// need to compare nodes for equality. Thus we can safely work only with `OpaqueNode`.
fn content_box(&self) -> ContentBoxResponse {
let &LayoutRPCImpl(ref rw_data) = self;
let LayoutRPCImpl(rw_data) = self;
let rw_data = rw_data.lock().unwrap();
ContentBoxResponse(rw_data.content_box_response)
}
/// Requests the dimensions of all the content boxes, as in the `getClientRects()` call.
fn content_boxes(&self) -> ContentBoxesResponse {
let &LayoutRPCImpl(ref rw_data) = self;
let LayoutRPCImpl(rw_data) = self;
let rw_data = rw_data.lock().unwrap();
ContentBoxesResponse(rw_data.content_boxes_response.clone())
}
fn nodes_from_point_response(&self) -> Vec<UntrustedNodeAddress> {
let &LayoutRPCImpl(ref rw_data) = self;
let LayoutRPCImpl(rw_data) = self;
let rw_data = rw_data.lock().unwrap();
rw_data.nodes_from_point_response.clone()
}
fn node_geometry(&self) -> NodeGeometryResponse {
let &LayoutRPCImpl(ref rw_data) = self;
let LayoutRPCImpl(rw_data) = self;
let rw_data = rw_data.lock().unwrap();
NodeGeometryResponse {
client_rect: rw_data.client_rect_response,
@ -133,39 +133,39 @@ impl LayoutRPC for LayoutRPCImpl {
/// Retrieves the resolved value for a CSS style property.
fn resolved_style(&self) -> ResolvedStyleResponse {
let &LayoutRPCImpl(ref rw_data) = self;
let LayoutRPCImpl(rw_data) = self;
let rw_data = rw_data.lock().unwrap();
ResolvedStyleResponse(rw_data.resolved_style_response.clone())
}
fn resolved_font_style(&self) -> Option<ServoArc<Font>> {
let &LayoutRPCImpl(ref rw_data) = self;
let LayoutRPCImpl(rw_data) = self;
let rw_data = rw_data.lock().unwrap();
rw_data.resolved_font_style_response.clone()
}
fn offset_parent(&self) -> OffsetParentResponse {
let &LayoutRPCImpl(ref rw_data) = self;
let LayoutRPCImpl(rw_data) = self;
let rw_data = rw_data.lock().unwrap();
rw_data.offset_parent_response.clone()
}
fn text_index(&self) -> TextIndexResponse {
let &LayoutRPCImpl(ref rw_data) = self;
let LayoutRPCImpl(rw_data) = self;
let rw_data = rw_data.lock().unwrap();
rw_data.text_index_response.clone()
}
fn element_inner_text(&self) -> String {
let &LayoutRPCImpl(ref rw_data) = self;
let LayoutRPCImpl(rw_data) = self;
let rw_data = rw_data.lock().unwrap();
rw_data.element_inner_text_response.clone()
}
fn inner_window_dimensions(&self) -> Option<Size2D<f32, CSSPixel>> {
let &LayoutRPCImpl(ref rw_data) = self;
let LayoutRPCImpl(rw_data) = self;
let rw_data = rw_data.lock().unwrap();
rw_data.inner_window_dimensions_response.clone()
rw_data.inner_window_dimensions_response
}
}
@ -323,7 +323,7 @@ pub fn process_resolved_style_request<'dom>(
let content_rect = box_fragment
.content_rect
.to_physical(box_fragment.style.writing_mode, &containing_block);
.to_physical(box_fragment.style.writing_mode, containing_block);
let margins = box_fragment
.margin
.to_physical(box_fragment.style.writing_mode);
@ -436,10 +436,10 @@ fn process_offset_parent_query_inner(
let fragment_relative_rect = match fragment {
Fragment::Box(fragment) | Fragment::Float(fragment) => fragment
.border_rect()
.to_physical(fragment.style.writing_mode, &containing_block),
.to_physical(fragment.style.writing_mode, containing_block),
Fragment::Text(fragment) => fragment
.rect
.to_physical(fragment.parent_style.writing_mode, &containing_block),
.to_physical(fragment.parent_style.writing_mode, containing_block),
Fragment::AbsoluteOrFixedPositioned(_) |
Fragment::Image(_) |
Fragment::IFrame(_) |
@ -555,7 +555,7 @@ fn process_offset_parent_query_inner(
// Again, take the *first* associated CSS layout box.
let padding_box_corner = fragment
.padding_rect()
.to_physical(fragment.style.writing_mode, &containing_block)
.to_physical(fragment.style.writing_mode, containing_block)
.origin
.to_vector() +
containing_block.origin.to_vector();

View file

@ -150,9 +150,8 @@ impl ReplacedContent {
}
};
let intrinsic = intrinsic_size_in_dots.map_or_else(
|| IntrinsicSizes::empty(),
|intrinsic_size_in_dots| {
let intrinsic =
intrinsic_size_in_dots.map_or_else(IntrinsicSizes::empty, |intrinsic_size_in_dots| {
// FIXME: should 'image-resolution' (when implemented) be used *instead* of
// `script::dom::htmlimageelement::ImageRequest::current_pixel_density`?
// https://drafts.csswg.org/css-images-4/#the-image-resolution
@ -160,15 +159,14 @@ impl ReplacedContent {
let width = (intrinsic_size_in_dots.width as CSSFloat) / dppx;
let height = (intrinsic_size_in_dots.height as CSSFloat) / dppx;
IntrinsicSizes::from_width_and_height(width, height)
},
);
});
let base_fragment_info = BaseFragmentInfo::new_for_node(element.opaque());
return Some(Self {
Some(Self {
kind,
intrinsic,
base_fragment_info,
});
})
}
pub fn from_image_url<'dom>(
@ -246,8 +244,8 @@ impl ReplacedContent {
}
}
pub fn make_fragments<'a>(
&'a self,
pub fn make_fragments(
&self,
style: &ServoArc<ComputedValues>,
size: LogicalVec2<Length>,
) -> Vec<Fragment> {
@ -334,10 +332,10 @@ impl ReplacedContent {
let intrinsic_size = self.flow_relative_intrinsic_size(style);
let intrinsic_ratio = self.inline_size_over_block_size_intrinsic_ratio(style);
let box_size = box_size.unwrap_or(style.content_box_size(containing_block, &pbm));
let max_box_size = style.content_max_box_size(containing_block, &pbm);
let box_size = box_size.unwrap_or(style.content_box_size(containing_block, pbm));
let max_box_size = style.content_max_box_size(containing_block, pbm);
let min_box_size = style
.content_min_box_size(containing_block, &pbm)
.content_min_box_size(containing_block, pbm)
.auto_is(Length::zero);
let default_object_size = || {

View file

@ -113,14 +113,14 @@ pub(crate) fn outer_inline(
BoxSizing::BorderBox => clamped,
};
ContentSizes {
min_content: border_box_size.into(),
max_content: border_box_size.into(),
min_content: border_box_size,
max_content: border_box_size,
}
},
None => get_content_size().map(|content_box_size| {
match box_sizing {
// Clamp to 'min-width' and 'max-width', which are sizing the…
BoxSizing::ContentBox => clamp(content_box_size.into()) + pb_lengths.into(),
BoxSizing::ContentBox => clamp(content_box_size) + pb_lengths.into(),
BoxSizing::BorderBox => clamp(content_box_size + pb_lengths.into()),
}
}),

View file

@ -133,20 +133,16 @@ impl Table {
/// the target and returns a [`ResolvedSlotAndLocation`] for each of them. If there is
/// no slot at the given coordinates or that slot is an empty space, an empty vector
/// is returned.
pub(super) fn resolve_slot_at<'a>(
&'a self,
pub(super) fn resolve_slot_at(
&self,
coords: TableSlotCoordinates,
) -> Vec<ResolvedSlotAndLocation<'a>> {
) -> Vec<ResolvedSlotAndLocation<'_>> {
let slot = self.get_slot(coords);
match slot {
Some(TableSlot::Cell(cell)) => vec![ResolvedSlotAndLocation {
cell: &cell,
coords,
}],
Some(TableSlot::Cell(cell)) => vec![ResolvedSlotAndLocation { cell, coords }],
Some(TableSlot::Spanned(ref offsets)) => offsets
.iter()
.map(|offset| self.resolve_slot_at(coords - *offset))
.flatten()
.flat_map(|offset| self.resolve_slot_at(coords - *offset))
.collect(),
Some(TableSlot::Empty) | None => {
warn!("Tried to resolve an empty or nonexistant slot!");
@ -170,12 +166,12 @@ impl Table {
let coords_of_slots_that_cover_target: Vec<_> = slots_covering_slot_above
.into_iter()
.filter(|ref slot| slot.covers_cell_at(target_coords))
.filter(|slot| slot.covers_cell_at(target_coords))
.map(|slot| target_coords - slot.coords)
.collect();
if coords_of_slots_that_cover_target.is_empty() {
return None;
None
} else {
Some(TableSlot::Spanned(coords_of_slots_that_cover_target))
}
@ -245,7 +241,7 @@ impl TableBuilder {
TableSlotCoordinates::new(self.current_x(), self.current_y())
}
pub fn start_row<'builder>(&'builder mut self) {
pub fn start_row(&mut self) {
self.table.slots.push(Vec::new());
self.table.size.height += 1;
self.create_slots_for_cells_above_with_rowspan(true);
@ -421,7 +417,7 @@ where
return;
}
let row_content = std::mem::replace(&mut self.current_anonymous_row_content, Vec::new());
let row_content = std::mem::take(&mut self.current_anonymous_row_content);
let context = self.context;
let anonymous_style = self
.context

View file

@ -199,10 +199,10 @@ impl<'a> TableLayout<'a> {
Auto => (min_content_width, min_content_width, max_content_width),
};
min_content_sizing_guesses.push(min_content_width.into());
min_content_percentage_sizing_guesses.push(min_content_percentage_sizing_guess.into());
min_content_specified_sizing_guesses.push(min_content_specified_sizing_guess.into());
max_content_sizing_guesses.push(max_content_sizing_guess.into());
min_content_sizing_guesses.push(min_content_width);
min_content_percentage_sizing_guesses.push(min_content_percentage_sizing_guess);
min_content_specified_sizing_guesses.push(min_content_specified_sizing_guess);
max_content_sizing_guesses.push(max_content_sizing_guess);
}
// > If the assignable table width is less than or equal to the max-content sizing-guess, the
@ -493,7 +493,7 @@ impl Table {
positioning_context: &mut PositioningContext,
containing_block: &ContainingBlock,
) -> IndependentLayout {
let mut table_layout = TableLayout::new(&self);
let mut table_layout = TableLayout::new(self);
table_layout.compute_measures(layout_context, positioning_context, containing_block);
let (fragments, content_block_size) =
table_layout.layout_into_box_fragments(positioning_context);

View file

@ -50,7 +50,7 @@ impl Table {
/// Return the slot at the given coordinates, if it exists in the table, otherwise
/// return None.
fn get_slot<'a>(&'a self, coords: TableSlotCoordinates) -> Option<&'a TableSlot> {
fn get_slot(&self, coords: TableSlotCoordinates) -> Option<&TableSlot> {
self.slots.get(coords.y)?.get(coords.x)
}
@ -60,8 +60,8 @@ impl Table {
) -> Option<TableSlotCoordinates> {
match self.get_slot(coords) {
Some(&TableSlot::Cell(_)) => Some(coords),
Some(&TableSlot::Spanned(ref offsets)) => Some(coords - offsets[0]),
_ => return None,
Some(TableSlot::Spanned(offsets)) => Some(coords - offsets[0]),
_ => None,
}
}
@ -73,7 +73,7 @@ impl Table {
let slot = self.get_slot(resolved_coords);
match slot {
Some(&TableSlot::Cell(ref cell)) => Some(cell),
Some(TableSlot::Cell(cell)) => Some(cell),
_ => unreachable!(
"Spanned slot should not point to an empty cell or another spanned slot."
),

View file

@ -260,8 +260,8 @@ fn test_tree_find() {
right: None,
});
let mut tree = FloatBandTree::new();
for ref band in &bands {
tree = tree.insert((*band).clone());
for band in &bands {
tree = tree.insert(*band);
}
bands.sort_by(|a, b| a.top.partial_cmp(&b.top).unwrap());
for lookup in lookups {
@ -290,8 +290,8 @@ fn test_tree_find_next() {
bands.sort_by(|a, b| a.top.partial_cmp(&b.top).unwrap());
bands.dedup_by(|a, b| a.top == b.top);
let mut tree = FloatBandTree::new();
for ref band in &bands {
tree = tree.insert((*band).clone());
for band in &bands {
tree = tree.insert(*band);
}
for lookup in lookups {
check_tree_find_next(&tree, Au::from_f32_px(lookup as f32), &bands);
@ -307,7 +307,7 @@ fn test_tree_range_setting() {
fn check(bands: Vec<FloatBandWrapper>, ranges: Vec<FloatRangeInput>) {
let mut tree = FloatBandTree::new();
for FloatBandWrapper(ref band) in &bands {
tree = tree.insert((*band).clone());
tree = tree.insert(*band);
}
let mut tops: Vec<Au> = bands.iter().map(|band| band.0.top).collect();
@ -648,7 +648,7 @@ fn check_floats_rule_7(placement: &FloatPlacement) {
fn check_floats_rule_8(floats_and_perturbations: Vec<(FloatInput, u32)>) {
let floats = floats_and_perturbations
.iter()
.map(|&(ref float, _)| (*float).clone())
.map(|(float, _)| (*float).clone())
.collect();
let placement = FloatPlacement::place(floats);
@ -658,9 +658,7 @@ fn check_floats_rule_8(floats_and_perturbations: Vec<(FloatInput, u32)>) {
}
let mut placement = placement.clone();
placement.placed_floats[float_index].origin.block =
placement.placed_floats[float_index].origin.block -
Au::from_f32_px(perturbation as f32);
placement.placed_floats[float_index].origin.block -= Au::from_f32_px(perturbation as f32);
let result = {
let mutex_guard = PANIC_HOOK_MUTEX.lock().unwrap();
@ -677,7 +675,7 @@ fn check_floats_rule_8(floats_and_perturbations: Vec<(FloatInput, u32)>) {
fn check_floats_rule_9(floats_and_perturbations: Vec<(FloatInput, u32)>) {
let floats = floats_and_perturbations
.iter()
.map(|&(ref float, _)| (*float).clone())
.map(|(float, _)| (*float).clone())
.collect();
let placement = FloatPlacement::place(floats);
@ -691,12 +689,8 @@ fn check_floats_rule_9(floats_and_perturbations: Vec<(FloatInput, u32)>) {
let placed_float = &mut placement.placed_floats[float_index];
let perturbation = Au::from_f32_px(perturbation as f32);
match placed_float.info.side {
FloatSide::Left => {
placed_float.origin.inline = placed_float.origin.inline - perturbation
},
FloatSide::Right => {
placed_float.origin.inline = placed_float.origin.inline + perturbation
},
FloatSide::Left => placed_float.origin.inline -= perturbation,
FloatSide::Right => placed_float.origin.inline += perturbation,
}
}

View file

@ -17,7 +17,7 @@ pub struct RecalcStyle<'a> {
impl<'a> RecalcStyle<'a> {
pub fn new(context: LayoutContext<'a>) -> Self {
RecalcStyle { context: context }
RecalcStyle { context }
}
pub fn context(&self) -> &LayoutContext<'a> {