From 8b9bbfea75c4b2494d4dee2069029e58e5490871 Mon Sep 17 00:00:00 2001 From: Xidorn Quan Date: Tue, 7 Nov 2017 15:40:41 -0800 Subject: [PATCH] Use helpers.predefined_type for transform property. --- components/style/properties/gecko.mako.rs | 17 ++++---- .../style/properties/longhand/box.mako.rs | 42 +++---------------- .../style/properties/shorthand/box.mako.rs | 5 +-- components/style/values/computed/mod.rs | 2 +- components/style/values/generics/transform.rs | 7 ++++ components/style/values/specified/mod.rs | 2 +- .../style/values/specified/transform.rs | 21 +++++++++- 7 files changed, 45 insertions(+), 51 deletions(-) diff --git a/components/style/properties/gecko.mako.rs b/components/style/properties/gecko.mako.rs index 022507fdce0..bcc4b79fc98 100644 --- a/components/style/properties/gecko.mako.rs +++ b/components/style/properties/gecko.mako.rs @@ -2999,13 +2999,13 @@ fn static_assert() { % endfor } - fn set_single_transform_function(servo_value: &longhands::transform::computed_value::ComputedOperation, + fn set_single_transform_function(servo_value: &values::computed::TransformOperation, gecko_value: &mut structs::nsCSSValue /* output */) { - use properties::longhands::transform::computed_value::ComputedOperation; use values::computed::{Length, LengthOrNumber, LengthOrPercentage, LengthOrPercentageOrNumber}; + use values::computed::TransformOperation; use values::generics::transform::{Matrix, Matrix3D}; - let convert_to_ns_css_value = |item: &ComputedOperation| -> structs::nsCSSValue { + let convert_to_ns_css_value = |item: &TransformOperation| -> structs::nsCSSValue { let mut value = structs::nsCSSValue::null(); Self::set_single_transform_function(item, &mut value); value @@ -3035,7 +3035,7 @@ fn static_assert() { } } } - pub fn convert_transform(input: &[longhands::transform::computed_value::ComputedOperation], + pub fn convert_transform(input: &[values::computed::TransformOperation], output: &mut structs::root::RefPtr) { use gecko_bindings::sugar::refptr::RefPtr; @@ -3088,7 +3088,7 @@ fn static_assert() { pre_symbols = "(" post_symbols = ")" if keyword == "interpolatematrix" or keyword == "accumulatematrix": - # We generate this like: "ComputedOperation::InterpolateMatrix {", so the space is + # We generate this like: "TransformOperation::InterpolateMatrix {", so the space is # between "InterpolateMatrix"/"AccumulateMatrix" and '{' pre_symbols = " {" post_symbols = "}" @@ -3144,14 +3144,13 @@ fn static_assert() { }, fn clone_single_transform_function(gecko_value: &structs::nsCSSValue) - -> longhands::transform::computed_value::ComputedOperation { - use properties::longhands::transform::computed_value::ComputedOperation; - use values::computed::{Length, Percentage}; + -> values::computed::TransformOperation { + use values::computed::{Length, Percentage, TransformOperation}; use values::generics::transform::{Matrix, Matrix3D}; use values::generics::transform::Transform; let convert_shared_list_to_operations = |value: &structs::nsCSSValue| - -> Vec { + -> Vec { debug_assert!(value.mUnit == structs::nsCSSUnit::eCSSUnit_SharedList); let value_list = unsafe { value.mValue.mSharedList.as_ref() diff --git a/components/style/properties/longhand/box.mako.rs b/components/style/properties/longhand/box.mako.rs index 4d13abedf06..105db8ec1a2 100644 --- a/components/style/properties/longhand/box.mako.rs +++ b/components/style/properties/longhand/box.mako.rs @@ -567,42 +567,12 @@ ${helpers.predefined_type( allow_empty="NotInitial" )} -<%helpers:longhand name="transform" extra_prefixes="webkit" - animation_value_type="ComputedValue" - flags="CREATES_STACKING_CONTEXT FIXPOS_CB" - spec="https://drafts.csswg.org/css-transforms/#propdef-transform"> - use values::generics::transform::Transform; - - - pub mod computed_value { - pub use values::computed::transform::Transform as T; - pub use values::computed::transform::TransformOperation as ComputedOperation; - } - - pub use values::specified::transform::Transform as SpecifiedValue; - pub use values::specified::transform::TransformOperation as SpecifiedOperation; - - #[inline] - pub fn get_initial_value() -> computed_value::T { - Transform(vec![]) - } - - - /// Parses `transform` property. - #[inline] - pub fn parse<'i, 't>(context: &ParserContext, input: &mut Parser<'i, 't>) - -> Result> { - SpecifiedValue::parse_internal(context, input, false) - } - - /// Parses `-moz-transform` property. This prefixed property also accepts LengthOrPercentage - /// in the nondiagonal homogeneous components of matrix and matrix3d. - #[inline] - pub fn parse_prefixed<'i, 't>(context: &ParserContext, input: &mut Parser<'i, 't>) - -> Result> { - SpecifiedValue::parse_internal(context, input, true) - } - +${helpers.predefined_type("transform", "Transform", + "generics::transform::Transform::none()", + extra_prefixes="webkit", + animation_value_type="ComputedValue", + flags="CREATES_STACKING_CONTEXT FIXPOS_CB", + spec="https://drafts.csswg.org/css-transforms/#propdef-transform")} // CSSOM View Module // https://www.w3.org/TR/cssom-view-1/ diff --git a/components/style/properties/shorthand/box.mako.rs b/components/style/properties/shorthand/box.mako.rs index 94510e12c1f..4a058b5b7ab 100644 --- a/components/style/properties/shorthand/box.mako.rs +++ b/components/style/properties/shorthand/box.mako.rs @@ -363,12 +363,11 @@ macro_rules! try_parse_one { flags="SHORTHAND_ALIAS_PROPERTY" derive_serialize="True" spec="Non-standard: https://developer.mozilla.org/en-US/docs/Web/CSS/transform"> - use properties::longhands::transform; - pub fn parse_value<'i, 't>(context: &ParserContext, input: &mut Parser<'i, 't>) -> Result> { + use values::specified::transform::Transform; Ok(expanded! { - transform: transform::parse_prefixed(context, input)?, + transform: Transform::parse_prefixed(context, input)?, }) } diff --git a/components/style/values/computed/mod.rs b/components/style/values/computed/mod.rs index 7c6f54f58ed..bf3bbf712c5 100644 --- a/components/style/values/computed/mod.rs +++ b/components/style/values/computed/mod.rs @@ -57,7 +57,7 @@ pub use self::svg::{SVGLength, SVGOpacity, SVGPaint, SVGPaintKind, SVGStrokeDash pub use self::table::XSpan; pub use self::text::{InitialLetter, LetterSpacing, LineHeight, TextOverflow, WordSpacing}; pub use self::time::Time; -pub use self::transform::{TimingFunction, TransformOrigin}; +pub use self::transform::{TimingFunction, Transform, TransformOperation, TransformOrigin}; #[cfg(feature = "gecko")] pub mod align; diff --git a/components/style/values/generics/transform.rs b/components/style/values/generics/transform.rs index 45d19c8ab68..c4c41070065 100644 --- a/components/style/values/generics/transform.rs +++ b/components/style/values/generics/transform.rs @@ -450,3 +450,10 @@ impl ToCss for Transform { Ok(()) } } + +impl Transform { + /// `none` + pub fn none() -> Self { + Transform(vec![]) + } +} diff --git a/components/style/values/specified/mod.rs b/components/style/values/specified/mod.rs index 9a33019d98a..3827b638e4b 100644 --- a/components/style/values/specified/mod.rs +++ b/components/style/values/specified/mod.rs @@ -53,7 +53,7 @@ pub use self::svg::{SVGLength, SVGOpacity, SVGPaint, SVGPaintKind, SVGStrokeDash pub use self::table::XSpan; pub use self::text::{InitialLetter, LetterSpacing, LineHeight, TextOverflow, WordSpacing}; pub use self::time::Time; -pub use self::transform::{TimingFunction, TransformOrigin}; +pub use self::transform::{TimingFunction, Transform, TransformOrigin}; pub use super::generics::grid::GridTemplateComponent as GenericGridTemplateComponent; #[cfg(feature = "gecko")] diff --git a/components/style/values/specified/transform.rs b/components/style/values/specified/transform.rs index e01a5d996c5..ca77bd7a723 100644 --- a/components/style/values/specified/transform.rs +++ b/components/style/values/specified/transform.rs @@ -39,7 +39,7 @@ pub type TransformOrigin = GenericTransformOrigin, OriginComp impl Transform { /// Internal parse function for deciding if we wish to accept prefixed values or not // Allow unitless zero angle for rotate() and skew() to align with gecko - pub fn parse_internal<'i, 't>( + fn parse_internal<'i, 't>( context: &ParserContext, input: &mut Parser<'i, 't>, prefixed: bool, @@ -252,6 +252,25 @@ impl Transform { }) })?)) } + + /// Parses `-moz-transform` property. This prefixed property also accepts LengthOrPercentage + /// in the nondiagonal homogeneous components of matrix and matrix3d. + #[inline] + pub fn parse_prefixed<'i, 't>( + context: &ParserContext, + input: &mut Parser<'i, 't>, + ) -> Result> { + Transform::parse_internal(context, input, true) + } +} + +impl Parse for Transform { + fn parse<'i, 't>( + context: &ParserContext, + input: &mut Parser<'i, 't> + ) -> Result> { + Transform::parse_internal(context, input, false) + } } /// The specified value of a component of a CSS ``.