diff --git a/components/layout_2020/geom.rs b/components/layout_2020/geom.rs index 562fad5c4f6..16df6a9c0a7 100644 --- a/components/layout_2020/geom.rs +++ b/components/layout_2020/geom.rs @@ -175,13 +175,14 @@ impl flow_relative::Vec2> { containing_block: &ContainingBlock, ) -> flow_relative::Vec2> { flow_relative::Vec2 { - inline: self - .inline - .to_option() - .map(|lp| lp.percentage_relative_to(containing_block.inline_size)), - block: self.block.to_option().and_then(|olp| { - olp.maybe_percentage_relative_to(containing_block.block_size.non_auto()) - }), + inline: match self.inline { + MaxSize::None => None, + MaxSize::LengthPercentage(ref lp) => Some(lp.percentage_relative_to(containing_block.inline_size)), + }, + block: match self.block { + MaxSize::None => None, + MaxSize::LengthPercentage(ref lp) => lp.maybe_percentage_relative_to(containing_block.block_size.non_auto()), + }, } } } diff --git a/components/layout_2020/positioned.rs b/components/layout_2020/positioned.rs index c9ad2dd97c4..b10b489bc1d 100644 --- a/components/layout_2020/positioned.rs +++ b/components/layout_2020/positioned.rs @@ -40,7 +40,7 @@ pub(crate) struct HoistedAbsolutelyPositionedBox<'box_tree> { box_offsets: Vec2, } -#[derive(Clone, Copy, Debug)] +#[derive(Clone, Debug)] pub(crate) enum AbsoluteBoxOffsets { StaticStart { start: Length, @@ -113,13 +113,13 @@ impl AbsolutelyPositionedBox { box_offsets: Vec2 { inline: absolute_box_offsets( initial_start_corner.inline, - box_offsets.inline_start, - box_offsets.inline_end, + box_offsets.inline_start.clone(), + box_offsets.inline_end.clone(), ), block: absolute_box_offsets( initial_start_corner.block, - box_offsets.block_start, - box_offsets.block_end, + box_offsets.block_start.clone(), + box_offsets.block_end.clone(), ), }, } @@ -372,20 +372,20 @@ impl<'box_tree> HoistedAbsolutelyPositionedBox<'box_tree> { let inline_axis = solve_axis( cbis, pb.inline_sum(), - computed_margin.inline_start, - computed_margin.inline_end, + computed_margin.inline_start.clone(), + computed_margin.inline_end.clone(), /* avoid_negative_margin_start */ true, - self.box_offsets.inline, + self.box_offsets.inline.clone(), size.inline, ); let block_axis = solve_axis( cbis, pb.block_sum(), - computed_margin.block_start, - computed_margin.block_end, + computed_margin.block_start.clone(), + computed_margin.block_end.clone(), /* avoid_negative_margin_start */ false, - self.box_offsets.block, + self.box_offsets.block.clone(), size.block, ); diff --git a/components/layout_2020/sizing.rs b/components/layout_2020/sizing.rs index e3c74d3733f..dc7513a7859 100644 --- a/components/layout_2020/sizing.rs +++ b/components/layout_2020/sizing.rs @@ -7,6 +7,7 @@ use crate::style_ext::ComputedValuesExt; use style::properties::ComputedValues; use style::values::computed::{Length, LengthPercentage, Percentage}; +use style::values::generics::length::MaxSize; use style::Zero; /// Which min/max-content values should be computed during box construction @@ -114,11 +115,10 @@ impl BoxContentSizes { .inline .percentage_relative_to(Length::zero()) .auto_is(Length::zero); - let max_inline_size = style - .max_box_size() - .inline - .to_option() - .and_then(|lp| lp.as_length()); + let max_inline_size = match style.max_box_size().inline { + MaxSize::None => None, + MaxSize::LengthPercentage(ref lp) => lp.as_length(), + }; let clamp = |l: Length| l.clamp_between_extremums(min_inline_size, max_inline_size); // Percentages for 'width' are treated as 'auto' diff --git a/components/layout_2020/style_ext.rs b/components/layout_2020/style_ext.rs index 67d8bc78d7e..b232381add2 100644 --- a/components/layout_2020/style_ext.rs +++ b/components/layout_2020/style_ext.rs @@ -55,9 +55,9 @@ impl ComputedValuesExt for ComputedValues { fn inline_size_is_length(&self) -> bool { let position = self.get_position(); let size = if self.writing_mode.is_horizontal() { - position.width + &position.width } else { - position.height + &position.height }; matches!(size, Size::LengthPercentage(lp) if lp.0.as_length().is_some()) } @@ -65,21 +65,21 @@ impl ComputedValuesExt for ComputedValues { fn inline_box_offsets_are_both_non_auto(&self) -> bool { let position = self.get_position(); let (a, b) = if self.writing_mode.is_horizontal() { - (position.left, position.right) + (&position.left, &position.right) } else { - (position.top, position.bottom) + (&position.top, &position.bottom) }; - a != LengthPercentageOrAuto::Auto && b != LengthPercentageOrAuto::Auto + !a.is_auto() && !b.is_auto() } #[inline] fn box_offsets(&self) -> flow_relative::Sides { let position = self.get_position(); physical::Sides { - top: position.top, - left: position.left, - bottom: position.bottom, - right: position.right, + top: position.top.clone(), + left: position.left.clone(), + bottom: position.bottom.clone(), + right: position.right.clone(), } .to_flow_relative(self.writing_mode) } @@ -88,8 +88,8 @@ impl ComputedValuesExt for ComputedValues { fn box_size(&self) -> flow_relative::Vec2 { let position = self.get_position(); physical::Vec2 { - x: size_to_length(position.width), - y: size_to_length(position.height), + x: size_to_length(position.width.clone()), + y: size_to_length(position.height.clone()), } .size_to_flow_relative(self.writing_mode) } @@ -98,8 +98,8 @@ impl ComputedValuesExt for ComputedValues { fn min_box_size(&self) -> flow_relative::Vec2 { let position = self.get_position(); physical::Vec2 { - x: size_to_length(position.min_width), - y: size_to_length(position.min_height), + x: size_to_length(position.min_width.clone()), + y: size_to_length(position.min_height.clone()), } .size_to_flow_relative(self.writing_mode) } @@ -112,8 +112,8 @@ impl ComputedValuesExt for ComputedValues { }; let position = self.get_position(); physical::Vec2 { - x: unwrap(position.max_width), - y: unwrap(position.max_height), + x: unwrap(position.max_width.clone()), + y: unwrap(position.max_height.clone()), } .size_to_flow_relative(self.writing_mode) } @@ -122,10 +122,10 @@ impl ComputedValuesExt for ComputedValues { fn padding(&self) -> flow_relative::Sides { let padding = self.get_padding(); physical::Sides { - top: padding.padding_top.0, - left: padding.padding_left.0, - bottom: padding.padding_bottom.0, - right: padding.padding_right.0, + top: padding.padding_top.0.clone(), + left: padding.padding_left.0.clone(), + bottom: padding.padding_bottom.0.clone(), + right: padding.padding_right.0.clone(), } .to_flow_relative(self.writing_mode) } @@ -144,10 +144,10 @@ impl ComputedValuesExt for ComputedValues { fn margin(&self) -> flow_relative::Sides { let margin = self.get_margin(); physical::Sides { - top: margin.margin_top, - left: margin.margin_left, - bottom: margin.margin_bottom, - right: margin.margin_right, + top: margin.margin_top.clone(), + left: margin.margin_left.clone(), + bottom: margin.margin_bottom.clone(), + right: margin.margin_right.clone(), } .to_flow_relative(self.writing_mode) } @@ -180,7 +180,7 @@ impl From for Display { fn size_to_length(size: Size) -> LengthPercentageOrAuto { match size { - Size::LengthPercentage(length) => LengthPercentageOrAuto::LengthPercentage(length.0), + Size::LengthPercentage(length) => LengthPercentageOrAuto::LengthPercentage(length.0.clone()), Size::Auto => LengthPercentageOrAuto::Auto, } } diff --git a/components/style/values/generics/length.rs b/components/style/values/generics/length.rs index b2f34058283..4183f40a942 100644 --- a/components/style/values/generics/length.rs +++ b/components/style/values/generics/length.rs @@ -207,15 +207,6 @@ impl MaxSize { pub fn none() -> Self { MaxSize::None } - - /// Convert - #[cfg(not(feature = "gecko"))] - pub fn to_option(self) -> Option { - match self { - Self::LengthPercentage(lp) => Some(lp), - Self::None => None, - } - } } /// A generic `` | `` value for the `-moz-tab-size` property.