diff --git a/components/style/logical_geometry.rs b/components/style/logical_geometry.rs index cb45544146b..fc3d5c95d12 100644 --- a/components/style/logical_geometry.rs +++ b/components/style/logical_geometry.rs @@ -468,7 +468,7 @@ impl LogicalSize { } } -impl LogicalSize { +impl LogicalSize { #[inline] pub fn new(mode: WritingMode, inline: T, block: T) -> LogicalSize { LogicalSize { @@ -486,7 +486,9 @@ impl LogicalSize { LogicalSize::new(mode, size.width, size.height) } } +} +impl LogicalSize { #[inline] pub fn width(&self, mode: WritingMode) -> T { self.debug_writing_mode.check(mode); @@ -860,7 +862,7 @@ impl LogicalMargin { } } -impl LogicalMargin { +impl LogicalMargin { #[inline] pub fn new( mode: WritingMode, @@ -878,11 +880,6 @@ impl LogicalMargin { } } - #[inline] - pub fn new_all_same(mode: WritingMode, value: T) -> LogicalMargin { - LogicalMargin::new(mode, value, value, value, value) - } - #[inline] pub fn from_physical(mode: WritingMode, offsets: SideOffsets2D) -> LogicalMargin { let block_start; @@ -917,6 +914,14 @@ impl LogicalMargin { } LogicalMargin::new(mode, block_start, inline_end, block_end, inline_start) } +} + + +impl LogicalMargin { + #[inline] + pub fn new_all_same(mode: WritingMode, value: T) -> LogicalMargin { + LogicalMargin::new(mode, value, value, value, value) + } #[inline] pub fn top(&self, mode: WritingMode) -> T { diff --git a/components/style/properties/gecko.mako.rs b/components/style/properties/gecko.mako.rs index 8f6e20fd803..14262e7a074 100644 --- a/components/style/properties/gecko.mako.rs +++ b/components/style/properties/gecko.mako.rs @@ -426,7 +426,7 @@ def set_gecko_property(ffi_name, expr): pub fn copy_${ident}_from(&mut self, other: &Self) { use crate::gecko_bindings::structs::nsStyleSVG_${ident.upper()}_CONTEXT as CONTEXT_VALUE; - self.gecko.${gecko_ffi_name} = other.gecko.${gecko_ffi_name}; + self.gecko.${gecko_ffi_name} = other.gecko.${gecko_ffi_name}.clone(); self.gecko.mContextFlags = (self.gecko.mContextFlags & !CONTEXT_VALUE) | (other.gecko.mContextFlags & CONTEXT_VALUE); @@ -442,7 +442,7 @@ def set_gecko_property(ffi_name, expr): if (self.gecko.mContextFlags & CONTEXT_VALUE) != 0 { return SVGLength::ContextValue; } - SVGLength::LengthPercentage(self.gecko.${gecko_ffi_name}) + SVGLength::LengthPercentage(self.gecko.${gecko_ffi_name}.clone()) } @@ -563,7 +563,7 @@ def set_gecko_property(ffi_name, expr): #[allow(non_snake_case)] pub fn copy_${ident}_from(&mut self, other: &Self) { self.gecko.${gecko_ffi_name}.${index} = - other.gecko.${gecko_ffi_name}.${index}; + other.gecko.${gecko_ffi_name}.${index}.clone(); } #[allow(non_snake_case)] pub fn reset_${ident}(&mut self, other: &Self) { @@ -572,7 +572,7 @@ def set_gecko_property(ffi_name, expr): #[allow(non_snake_case)] pub fn clone_${ident}(&self) -> longhands::${ident}::computed_value::T { - self.gecko.${gecko_ffi_name}.${index} + self.gecko.${gecko_ffi_name}.${index}.clone() } @@ -601,7 +601,7 @@ def set_gecko_property(ffi_name, expr): #[allow(non_snake_case)] pub fn copy_${ident}_from(&mut self, other: &Self) { self.gecko.${gecko_ffi_name}.${corner} = - other.gecko.${gecko_ffi_name}.${corner}; + other.gecko.${gecko_ffi_name}.${corner}.clone(); } #[allow(non_snake_case)] pub fn reset_${ident}(&mut self, other: &Self) { @@ -609,7 +609,7 @@ def set_gecko_property(ffi_name, expr): } #[allow(non_snake_case)] pub fn clone_${ident}(&self) -> longhands::${ident}::computed_value::T { - self.gecko.${gecko_ffi_name}.${corner} + self.gecko.${gecko_ffi_name}.${corner}.clone() } @@ -1852,7 +1852,7 @@ fn static_assert() { for (layer, other) in self.gecko.${layers_field_name}.mLayers.iter_mut() .zip(other.gecko.${layers_field_name}.mLayers.iter()) .take(count as usize) { - layer.${field_name} = other.${field_name}; + layer.${field_name} = other.${field_name}.clone(); } self.gecko.${layers_field_name}.${field_name}Count = count; } @@ -2006,7 +2006,7 @@ fn static_assert() { for (layer, other) in self.gecko.${image_layers_field}.mLayers.iter_mut() .zip(other.gecko.${image_layers_field}.mLayers.iter()) .take(count as usize) { - layer.mPosition.${keyword} = other.mPosition.${keyword}; + layer.mPosition.${keyword} = other.mPosition.${keyword}.clone(); } self.gecko.${image_layers_field}.mPosition${orientation.upper()}Count = count; } @@ -2020,7 +2020,7 @@ fn static_assert() { longhands::${shorthand}_position_${orientation}::computed_value::List( self.gecko.${image_layers_field}.mLayers.iter() .take(self.gecko.${image_layers_field}.mPosition${orientation.upper()}Count as usize) - .map(|position| position.mPosition.${keyword}) + .map(|position| position.mPosition.${keyword}.clone()) .collect() ) } @@ -2054,7 +2054,7 @@ fn static_assert() { pub fn clone_${shorthand}_size(&self) -> longhands::${shorthand}_size::computed_value::T { longhands::${shorthand}_size::computed_value::List( - self.gecko.${image_layers_field}.mLayers.iter().map(|layer| layer.mSize).collect() + self.gecko.${image_layers_field}.mLayers.iter().map(|layer| layer.mSize.clone()).collect() ) } diff --git a/components/style/properties/properties.mako.rs b/components/style/properties/properties.mako.rs index 38243aa45e4..30a03f79290 100644 --- a/components/style/properties/properties.mako.rs +++ b/components/style/properties/properties.mako.rs @@ -3121,59 +3121,59 @@ impl ComputedValuesInner { /// Get the logical computed inline size. #[inline] - pub fn content_inline_size(&self) -> computed::Size { + pub fn content_inline_size(&self) -> &computed::Size { let position_style = self.get_position(); if self.writing_mode.is_vertical() { - position_style.height + &position_style.height } else { - position_style.width + &position_style.width } } /// Get the logical computed block size. #[inline] - pub fn content_block_size(&self) -> computed::Size { + pub fn content_block_size(&self) -> &computed::Size { let position_style = self.get_position(); - if self.writing_mode.is_vertical() { position_style.width } else { position_style.height } + if self.writing_mode.is_vertical() { &position_style.width } else { &position_style.height } } /// Get the logical computed min inline size. #[inline] - pub fn min_inline_size(&self) -> computed::Size { + pub fn min_inline_size(&self) -> &computed::Size { let position_style = self.get_position(); - if self.writing_mode.is_vertical() { position_style.min_height } else { position_style.min_width } + if self.writing_mode.is_vertical() { &position_style.min_height } else { &position_style.min_width } } /// Get the logical computed min block size. #[inline] - pub fn min_block_size(&self) -> computed::Size { + pub fn min_block_size(&self) -> &computed::Size { let position_style = self.get_position(); - if self.writing_mode.is_vertical() { position_style.min_width } else { position_style.min_height } + if self.writing_mode.is_vertical() { &position_style.min_width } else { &position_style.min_height } } /// Get the logical computed max inline size. #[inline] - pub fn max_inline_size(&self) -> computed::MaxSize { + pub fn max_inline_size(&self) -> &computed::MaxSize { let position_style = self.get_position(); - if self.writing_mode.is_vertical() { position_style.max_height } else { position_style.max_width } + if self.writing_mode.is_vertical() { &position_style.max_height } else { &position_style.max_width } } /// Get the logical computed max block size. #[inline] - pub fn max_block_size(&self) -> computed::MaxSize { + pub fn max_block_size(&self) -> &computed::MaxSize { let position_style = self.get_position(); - if self.writing_mode.is_vertical() { position_style.max_width } else { position_style.max_height } + if self.writing_mode.is_vertical() { &position_style.max_width } else { &position_style.max_height } } /// Get the logical computed padding for this writing mode. #[inline] - pub fn logical_padding(&self) -> LogicalMargin { + pub fn logical_padding(&self) -> LogicalMargin<<&computed::LengthPercentage> { let padding_style = self.get_padding(); LogicalMargin::from_physical(self.writing_mode, SideOffsets2D::new( - padding_style.padding_top.0, - padding_style.padding_right.0, - padding_style.padding_bottom.0, - padding_style.padding_left.0, + &padding_style.padding_top.0, + &padding_style.padding_right.0, + &padding_style.padding_bottom.0, + &padding_style.padding_left.0, )) } @@ -3197,26 +3197,26 @@ impl ComputedValuesInner { /// Gets the logical computed margin from this style. #[inline] - pub fn logical_margin(&self) -> LogicalMargin { + pub fn logical_margin(&self) -> LogicalMargin<<&computed::LengthPercentageOrAuto> { let margin_style = self.get_margin(); LogicalMargin::from_physical(self.writing_mode, SideOffsets2D::new( - margin_style.margin_top, - margin_style.margin_right, - margin_style.margin_bottom, - margin_style.margin_left, + &margin_style.margin_top, + &margin_style.margin_right, + &margin_style.margin_bottom, + &margin_style.margin_left, )) } /// Gets the logical position from this style. #[inline] - pub fn logical_position(&self) -> LogicalMargin { + pub fn logical_position(&self) -> LogicalMargin<<&computed::LengthPercentageOrAuto> { // FIXME(SimonSapin): should be the writing mode of the containing block, maybe? let position_style = self.get_position(); LogicalMargin::from_physical(self.writing_mode, SideOffsets2D::new( - position_style.top, - position_style.right, - position_style.bottom, - position_style.left, + &position_style.top, + &position_style.right, + &position_style.bottom, + &position_style.left, )) } diff --git a/components/style/values/animated/transform.rs b/components/style/values/animated/transform.rs index aceb70f6766..2285497680b 100644 --- a/components/style/values/animated/transform.rs +++ b/components/style/values/animated/transform.rs @@ -1373,7 +1373,11 @@ impl ComputedTranslate { LengthPercentage::zero(), Length::zero(), ), - Translate::Translate(tx, ty, tz) => (tx, ty, tz), + Translate::Translate(ref tx, ref ty, ref tz) => ( + tx.clone(), + ty.clone(), + tz.clone(), + ), } } } diff --git a/components/style/values/computed/length.rs b/components/style/values/computed/length.rs index cefcf213754..df93e874922 100644 --- a/components/style/values/computed/length.rs +++ b/components/style/values/computed/length.rs @@ -76,7 +76,7 @@ impl ToComputedValue for specified::Length { /// https://drafts.csswg.org/css-values-4/#typedef-length-percentage #[allow(missing_docs)] #[derive( - Clone, Copy, Debug, Deserialize, MallocSizeOf, Serialize, ToAnimatedZero, ToResolvedValue, + Clone, Debug, Deserialize, MallocSizeOf, Serialize, ToAnimatedZero, ToResolvedValue, )] #[repr(C)] pub struct LengthPercentage { @@ -543,14 +543,14 @@ impl ToAnimatedValue for NonNegativeLengthPercentage { impl From for NonNegativeLengthPercentage { #[inline] fn from(length: NonNegativeLength) -> Self { - LengthPercentage::new(length.0, None).into() + NonNegative(LengthPercentage::new(length.0, None)) } } impl From for NonNegativeLengthPercentage { #[inline] fn from(lp: LengthPercentage) -> Self { - NonNegative::(lp) + NonNegative(lp) } }