diff --git a/components/style/cbindgen.toml b/components/style/cbindgen.toml index 104893701c5..0b8719c4dbf 100644 --- a/components/style/cbindgen.toml +++ b/components/style/cbindgen.toml @@ -91,6 +91,7 @@ include = [ "NonNegativeLengthOrNumberRect", "Perspective", "ZIndex", + "TransformOrigin", ] item_types = ["enums", "structs", "typedefs"] @@ -103,6 +104,7 @@ item_types = ["enums", "structs", "typedefs"] // Defined in nsStyleCoord.h static constexpr inline StyleLengthPercentage Zero(); static inline StyleLengthPercentage FromAppUnits(nscoord); + static inline StyleLengthPercentage FromPixels(CSSCoord); static inline StyleLengthPercentage FromPercentage(float); inline CSSCoord LengthInCSSPixels() const; inline float Percentage() const; diff --git a/components/style/properties/gecko.mako.rs b/components/style/properties/gecko.mako.rs index ca1a75df321..b1be315e7a0 100644 --- a/components/style/properties/gecko.mako.rs +++ b/components/style/properties/gecko.mako.rs @@ -1188,55 +1188,6 @@ pub fn clone_transform_from_list( } -<%def name="impl_transform_origin(ident, gecko_ffi_name)"> - #[allow(non_snake_case)] - pub fn set_${ident}(&mut self, v: values::computed::TransformOrigin) { - self.gecko.${gecko_ffi_name}[0].set(v.horizontal); - self.gecko.${gecko_ffi_name}[1].set(v.vertical); - // transform-origin supports the third value for depth, while - // -moz-window-transform-origin doesn't. The following code is - // for handling this difference. If we can have more knowledge - // about the type here, we may want to check that the length is - // exactly either 2 or 3 in compile time. - if let Some(third) = self.gecko.${gecko_ffi_name}.get_mut(2) { - third.set(v.depth); - } - } - - #[allow(non_snake_case)] - pub fn copy_${ident}_from(&mut self, other: &Self) { - self.gecko.${gecko_ffi_name}[0].copy_from(&other.gecko.${gecko_ffi_name}[0]); - self.gecko.${gecko_ffi_name}[1].copy_from(&other.gecko.${gecko_ffi_name}[1]); - if let (Some(self_third), Some(other_third)) = - (self.gecko.${gecko_ffi_name}.get_mut(2), other.gecko.${gecko_ffi_name}.get(2)) - { - self_third.copy_from(other_third) - } - } - - #[allow(non_snake_case)] - pub fn reset_${ident}(&mut self, other: &Self) { - self.copy_${ident}_from(other) - } - - #[allow(non_snake_case)] - pub fn clone_${ident}(&self) -> values::computed::TransformOrigin { - use crate::values::computed::{Length, LengthPercentage, TransformOrigin}; - TransformOrigin { - horizontal: LengthPercentage::from_gecko_style_coord(&self.gecko.${gecko_ffi_name}[0]) - .expect("clone for LengthPercentage failed"), - vertical: LengthPercentage::from_gecko_style_coord(&self.gecko.${gecko_ffi_name}[1]) - .expect("clone for LengthPercentage failed"), - depth: if let Some(third) = self.gecko.${gecko_ffi_name}.get(2) { - Length::from_gecko_style_coord(third) - .expect("clone for Length failed") - } else { - Length::new(0.) - }, - } - } - - <%def name="impl_logical(name, **kwargs)"> ${helpers.logical_setter(name)} @@ -1385,7 +1336,7 @@ impl Clone for ${style_struct.gecko_struct_name} { "SVGPaint": impl_svg_paint, "SVGWidth": impl_svg_length, "Transform": impl_transform, - "TransformOrigin": impl_transform_origin, + "TransformOrigin": impl_simple, "UserSelect": impl_simple, "url::UrlOrNone": impl_css_url, "ZIndex": impl_simple, @@ -2913,10 +2864,8 @@ fn static_assert() { clear transition-duration transition-delay transition-timing-function transition-property rotate scroll-snap-points-x scroll-snap-points-y - scroll-snap-coordinate - perspective-origin -moz-binding will-change - offset-path perspective-origin -moz-binding - will-change shape-outside contain touch-action + scroll-snap-coordinate -moz-binding will-change + offset-path shape-outside contain touch-action translate scale""" %> <%self:impl_trait style_struct_name="Box" skip_longhands="${skip_box_longhands}"> #[inline] @@ -3268,31 +3217,6 @@ fn static_assert() { ${impl_animation_timing_function()} - pub fn set_perspective_origin(&mut self, v: longhands::perspective_origin::computed_value::T) { - self.gecko.mPerspectiveOrigin[0].set(v.horizontal); - self.gecko.mPerspectiveOrigin[1].set(v.vertical); - } - - pub fn copy_perspective_origin_from(&mut self, other: &Self) { - self.gecko.mPerspectiveOrigin[0].copy_from(&other.gecko.mPerspectiveOrigin[0]); - self.gecko.mPerspectiveOrigin[1].copy_from(&other.gecko.mPerspectiveOrigin[1]); - } - - pub fn reset_perspective_origin(&mut self, other: &Self) { - self.copy_perspective_origin_from(other) - } - - pub fn clone_perspective_origin(&self) -> longhands::perspective_origin::computed_value::T { - use crate::properties::longhands::perspective_origin::computed_value::T; - use crate::values::computed::LengthPercentage; - T { - horizontal: LengthPercentage::from_gecko_style_coord(&self.gecko.mPerspectiveOrigin[0]) - .expect("Expected length or percentage for horizontal value of perspective-origin"), - vertical: LengthPercentage::from_gecko_style_coord(&self.gecko.mPerspectiveOrigin[1]) - .expect("Expected length or percentage for vertical value of perspective-origin"), - } - } - ${impl_individual_transform('rotate', 'Rotate', 'mSpecifiedRotate')} ${impl_individual_transform('translate', 'Translate', 'mSpecifiedTranslate')} ${impl_individual_transform('scale', 'Scale', 'mSpecifiedScale')} diff --git a/components/style/values/computed/transform.rs b/components/style/values/computed/transform.rs index 979886aa996..a78cda03ec0 100644 --- a/components/style/values/computed/transform.rs +++ b/components/style/values/computed/transform.rs @@ -21,7 +21,7 @@ pub type TransformOperation = pub type Transform = generic::Transform; /// The computed value of a CSS `` -pub type TransformOrigin = generic::TransformOrigin; +pub type TransformOrigin = generic::GenericTransformOrigin; /// A vector to represent the direction vector (rotate axis) for Rotate3D. pub type DirectionVector = Vector3D; diff --git a/components/style/values/generics/transform.rs b/components/style/values/generics/transform.rs index 4591f3addd2..6c98a45dd6c 100644 --- a/components/style/values/generics/transform.rs +++ b/components/style/values/generics/transform.rs @@ -83,7 +83,8 @@ impl> From> for Transform3D { ToComputedValue, ToCss, )] -pub struct TransformOrigin { +#[repr(C)] +pub struct GenericTransformOrigin { /// The horizontal origin. pub horizontal: H, /// The vertical origin. @@ -92,14 +93,12 @@ pub struct TransformOrigin { pub depth: Depth, } +pub use self::GenericTransformOrigin as TransformOrigin; + impl TransformOrigin { /// Returns a new transform origin. pub fn new(horizontal: H, vertical: V, depth: D) -> Self { - Self { - horizontal: horizontal, - vertical: vertical, - depth: depth, - } + Self { horizontal, vertical, depth } } }