style: Make LengthPercentage not copy.

This is needed to support min() / max() / clamp(), etc.

Differential Revision: https://phabricator.services.mozilla.com/D57249
This commit is contained in:
Emilio Cobos Álvarez 2019-12-15 20:15:29 +01:00
parent a541046147
commit 789ddd9dc1
5 changed files with 58 additions and 49 deletions

View file

@ -468,7 +468,7 @@ impl<T: Zero> LogicalSize<T> {
} }
} }
impl<T: Copy> LogicalSize<T> { impl<T> LogicalSize<T> {
#[inline] #[inline]
pub fn new(mode: WritingMode, inline: T, block: T) -> LogicalSize<T> { pub fn new(mode: WritingMode, inline: T, block: T) -> LogicalSize<T> {
LogicalSize { LogicalSize {
@ -486,7 +486,9 @@ impl<T: Copy> LogicalSize<T> {
LogicalSize::new(mode, size.width, size.height) LogicalSize::new(mode, size.width, size.height)
} }
} }
}
impl<T: Copy> LogicalSize<T> {
#[inline] #[inline]
pub fn width(&self, mode: WritingMode) -> T { pub fn width(&self, mode: WritingMode) -> T {
self.debug_writing_mode.check(mode); self.debug_writing_mode.check(mode);
@ -860,7 +862,7 @@ impl<T: Zero> LogicalMargin<T> {
} }
} }
impl<T: Copy> LogicalMargin<T> { impl<T> LogicalMargin<T> {
#[inline] #[inline]
pub fn new( pub fn new(
mode: WritingMode, mode: WritingMode,
@ -878,11 +880,6 @@ impl<T: Copy> LogicalMargin<T> {
} }
} }
#[inline]
pub fn new_all_same(mode: WritingMode, value: T) -> LogicalMargin<T> {
LogicalMargin::new(mode, value, value, value, value)
}
#[inline] #[inline]
pub fn from_physical(mode: WritingMode, offsets: SideOffsets2D<T>) -> LogicalMargin<T> { pub fn from_physical(mode: WritingMode, offsets: SideOffsets2D<T>) -> LogicalMargin<T> {
let block_start; let block_start;
@ -917,6 +914,14 @@ impl<T: Copy> LogicalMargin<T> {
} }
LogicalMargin::new(mode, block_start, inline_end, block_end, inline_start) LogicalMargin::new(mode, block_start, inline_end, block_end, inline_start)
} }
}
impl<T: Copy> LogicalMargin<T> {
#[inline]
pub fn new_all_same(mode: WritingMode, value: T) -> LogicalMargin<T> {
LogicalMargin::new(mode, value, value, value, value)
}
#[inline] #[inline]
pub fn top(&self, mode: WritingMode) -> T { pub fn top(&self, mode: WritingMode) -> T {

View file

@ -426,7 +426,7 @@ def set_gecko_property(ffi_name, expr):
pub fn copy_${ident}_from(&mut self, other: &Self) { pub fn copy_${ident}_from(&mut self, other: &Self) {
use crate::gecko_bindings::structs::nsStyleSVG_${ident.upper()}_CONTEXT as CONTEXT_VALUE; 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 =
(self.gecko.mContextFlags & !CONTEXT_VALUE) | (self.gecko.mContextFlags & !CONTEXT_VALUE) |
(other.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 { if (self.gecko.mContextFlags & CONTEXT_VALUE) != 0 {
return SVGLength::ContextValue; return SVGLength::ContextValue;
} }
SVGLength::LengthPercentage(self.gecko.${gecko_ffi_name}) SVGLength::LengthPercentage(self.gecko.${gecko_ffi_name}.clone())
} }
</%def> </%def>
@ -563,7 +563,7 @@ def set_gecko_property(ffi_name, expr):
#[allow(non_snake_case)] #[allow(non_snake_case)]
pub fn copy_${ident}_from(&mut self, other: &Self) { pub fn copy_${ident}_from(&mut self, other: &Self) {
self.gecko.${gecko_ffi_name}.${index} = self.gecko.${gecko_ffi_name}.${index} =
other.gecko.${gecko_ffi_name}.${index}; other.gecko.${gecko_ffi_name}.${index}.clone();
} }
#[allow(non_snake_case)] #[allow(non_snake_case)]
pub fn reset_${ident}(&mut self, other: &Self) { pub fn reset_${ident}(&mut self, other: &Self) {
@ -572,7 +572,7 @@ def set_gecko_property(ffi_name, expr):
#[allow(non_snake_case)] #[allow(non_snake_case)]
pub fn clone_${ident}(&self) -> longhands::${ident}::computed_value::T { pub fn clone_${ident}(&self) -> longhands::${ident}::computed_value::T {
self.gecko.${gecko_ffi_name}.${index} self.gecko.${gecko_ffi_name}.${index}.clone()
} }
</%def> </%def>
@ -601,7 +601,7 @@ def set_gecko_property(ffi_name, expr):
#[allow(non_snake_case)] #[allow(non_snake_case)]
pub fn copy_${ident}_from(&mut self, other: &Self) { pub fn copy_${ident}_from(&mut self, other: &Self) {
self.gecko.${gecko_ffi_name}.${corner} = self.gecko.${gecko_ffi_name}.${corner} =
other.gecko.${gecko_ffi_name}.${corner}; other.gecko.${gecko_ffi_name}.${corner}.clone();
} }
#[allow(non_snake_case)] #[allow(non_snake_case)]
pub fn reset_${ident}(&mut self, other: &Self) { pub fn reset_${ident}(&mut self, other: &Self) {
@ -609,7 +609,7 @@ def set_gecko_property(ffi_name, expr):
} }
#[allow(non_snake_case)] #[allow(non_snake_case)]
pub fn clone_${ident}(&self) -> longhands::${ident}::computed_value::T { pub fn clone_${ident}(&self) -> longhands::${ident}::computed_value::T {
self.gecko.${gecko_ffi_name}.${corner} self.gecko.${gecko_ffi_name}.${corner}.clone()
} }
</%def> </%def>
@ -1852,7 +1852,7 @@ fn static_assert() {
for (layer, other) in self.gecko.${layers_field_name}.mLayers.iter_mut() for (layer, other) in self.gecko.${layers_field_name}.mLayers.iter_mut()
.zip(other.gecko.${layers_field_name}.mLayers.iter()) .zip(other.gecko.${layers_field_name}.mLayers.iter())
.take(count as usize) { .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; 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() for (layer, other) in self.gecko.${image_layers_field}.mLayers.iter_mut()
.zip(other.gecko.${image_layers_field}.mLayers.iter()) .zip(other.gecko.${image_layers_field}.mLayers.iter())
.take(count as usize) { .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; self.gecko.${image_layers_field}.mPosition${orientation.upper()}Count = count;
} }
@ -2020,7 +2020,7 @@ fn static_assert() {
longhands::${shorthand}_position_${orientation}::computed_value::List( longhands::${shorthand}_position_${orientation}::computed_value::List(
self.gecko.${image_layers_field}.mLayers.iter() self.gecko.${image_layers_field}.mLayers.iter()
.take(self.gecko.${image_layers_field}.mPosition${orientation.upper()}Count as usize) .take(self.gecko.${image_layers_field}.mPosition${orientation.upper()}Count as usize)
.map(|position| position.mPosition.${keyword}) .map(|position| position.mPosition.${keyword}.clone())
.collect() .collect()
) )
} }
@ -2054,7 +2054,7 @@ fn static_assert() {
pub fn clone_${shorthand}_size(&self) -> longhands::${shorthand}_size::computed_value::T { pub fn clone_${shorthand}_size(&self) -> longhands::${shorthand}_size::computed_value::T {
longhands::${shorthand}_size::computed_value::List( 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()
) )
} }

View file

@ -3121,59 +3121,59 @@ impl ComputedValuesInner {
/// Get the logical computed inline size. /// Get the logical computed inline size.
#[inline] #[inline]
pub fn content_inline_size(&self) -> computed::Size { pub fn content_inline_size(&self) -> &computed::Size {
let position_style = self.get_position(); let position_style = self.get_position();
if self.writing_mode.is_vertical() { if self.writing_mode.is_vertical() {
position_style.height &position_style.height
} else { } else {
position_style.width &position_style.width
} }
} }
/// Get the logical computed block size. /// Get the logical computed block size.
#[inline] #[inline]
pub fn content_block_size(&self) -> computed::Size { pub fn content_block_size(&self) -> &computed::Size {
let position_style = self.get_position(); 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. /// Get the logical computed min inline size.
#[inline] #[inline]
pub fn min_inline_size(&self) -> computed::Size { pub fn min_inline_size(&self) -> &computed::Size {
let position_style = self.get_position(); 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. /// Get the logical computed min block size.
#[inline] #[inline]
pub fn min_block_size(&self) -> computed::Size { pub fn min_block_size(&self) -> &computed::Size {
let position_style = self.get_position(); 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. /// Get the logical computed max inline size.
#[inline] #[inline]
pub fn max_inline_size(&self) -> computed::MaxSize { pub fn max_inline_size(&self) -> &computed::MaxSize {
let position_style = self.get_position(); 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. /// Get the logical computed max block size.
#[inline] #[inline]
pub fn max_block_size(&self) -> computed::MaxSize { pub fn max_block_size(&self) -> &computed::MaxSize {
let position_style = self.get_position(); 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. /// Get the logical computed padding for this writing mode.
#[inline] #[inline]
pub fn logical_padding(&self) -> LogicalMargin<computed::LengthPercentage> { pub fn logical_padding(&self) -> LogicalMargin<<&computed::LengthPercentage> {
let padding_style = self.get_padding(); let padding_style = self.get_padding();
LogicalMargin::from_physical(self.writing_mode, SideOffsets2D::new( LogicalMargin::from_physical(self.writing_mode, SideOffsets2D::new(
padding_style.padding_top.0, &padding_style.padding_top.0,
padding_style.padding_right.0, &padding_style.padding_right.0,
padding_style.padding_bottom.0, &padding_style.padding_bottom.0,
padding_style.padding_left.0, &padding_style.padding_left.0,
)) ))
} }
@ -3197,26 +3197,26 @@ impl ComputedValuesInner {
/// Gets the logical computed margin from this style. /// Gets the logical computed margin from this style.
#[inline] #[inline]
pub fn logical_margin(&self) -> LogicalMargin<computed::LengthPercentageOrAuto> { pub fn logical_margin(&self) -> LogicalMargin<<&computed::LengthPercentageOrAuto> {
let margin_style = self.get_margin(); let margin_style = self.get_margin();
LogicalMargin::from_physical(self.writing_mode, SideOffsets2D::new( LogicalMargin::from_physical(self.writing_mode, SideOffsets2D::new(
margin_style.margin_top, &margin_style.margin_top,
margin_style.margin_right, &margin_style.margin_right,
margin_style.margin_bottom, &margin_style.margin_bottom,
margin_style.margin_left, &margin_style.margin_left,
)) ))
} }
/// Gets the logical position from this style. /// Gets the logical position from this style.
#[inline] #[inline]
pub fn logical_position(&self) -> LogicalMargin<computed::LengthPercentageOrAuto> { pub fn logical_position(&self) -> LogicalMargin<<&computed::LengthPercentageOrAuto> {
// FIXME(SimonSapin): should be the writing mode of the containing block, maybe? // FIXME(SimonSapin): should be the writing mode of the containing block, maybe?
let position_style = self.get_position(); let position_style = self.get_position();
LogicalMargin::from_physical(self.writing_mode, SideOffsets2D::new( LogicalMargin::from_physical(self.writing_mode, SideOffsets2D::new(
position_style.top, &position_style.top,
position_style.right, &position_style.right,
position_style.bottom, &position_style.bottom,
position_style.left, &position_style.left,
)) ))
} }

View file

@ -1373,7 +1373,11 @@ impl ComputedTranslate {
LengthPercentage::zero(), LengthPercentage::zero(),
Length::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(),
),
} }
} }
} }

View file

@ -76,7 +76,7 @@ impl ToComputedValue for specified::Length {
/// https://drafts.csswg.org/css-values-4/#typedef-length-percentage /// https://drafts.csswg.org/css-values-4/#typedef-length-percentage
#[allow(missing_docs)] #[allow(missing_docs)]
#[derive( #[derive(
Clone, Copy, Debug, Deserialize, MallocSizeOf, Serialize, ToAnimatedZero, ToResolvedValue, Clone, Debug, Deserialize, MallocSizeOf, Serialize, ToAnimatedZero, ToResolvedValue,
)] )]
#[repr(C)] #[repr(C)]
pub struct LengthPercentage { pub struct LengthPercentage {
@ -543,14 +543,14 @@ impl ToAnimatedValue for NonNegativeLengthPercentage {
impl From<NonNegativeLength> for NonNegativeLengthPercentage { impl From<NonNegativeLength> for NonNegativeLengthPercentage {
#[inline] #[inline]
fn from(length: NonNegativeLength) -> Self { fn from(length: NonNegativeLength) -> Self {
LengthPercentage::new(length.0, None).into() NonNegative(LengthPercentage::new(length.0, None))
} }
} }
impl From<LengthPercentage> for NonNegativeLengthPercentage { impl From<LengthPercentage> for NonNegativeLengthPercentage {
#[inline] #[inline]
fn from(lp: LengthPercentage) -> Self { fn from(lp: LengthPercentage) -> Self {
NonNegative::<LengthPercentage>(lp) NonNegative(lp)
} }
} }