diff --git a/components/style/properties/helpers/animated_properties.mako.rs b/components/style/properties/helpers/animated_properties.mako.rs index 3c55416b178..691b57845da 100644 --- a/components/style/properties/helpers/animated_properties.mako.rs +++ b/components/style/properties/helpers/animated_properties.mako.rs @@ -1033,6 +1033,7 @@ impl Animate for ComputedTransformOperation { this.animate(other, procedure)?, )) }, + // XXXManishearth handle 2D matrix ( &TransformOperation::Skew(ref fx, ref fy), &TransformOperation::Skew(ref tx, ref ty), @@ -1042,6 +1043,22 @@ impl Animate for ComputedTransformOperation { fy.animate(ty, procedure)?, )) }, + ( + &TransformOperation::SkewX(ref f), + &TransformOperation::SkewX(ref t), + ) => { + Ok(TransformOperation::SkewX( + f.animate(t, procedure)?, + )) + }, + ( + &TransformOperation::SkewY(ref f), + &TransformOperation::SkewY(ref t), + ) => { + Ok(TransformOperation::SkewY( + f.animate(t, procedure)?, + )) + }, ( &TransformOperation::Translate3D(ref fx, ref fy, ref fz), &TransformOperation::Translate3D(ref tx, ref ty, ref tz), @@ -1052,6 +1069,39 @@ impl Animate for ComputedTransformOperation { fz.animate(tz, procedure)?, )) }, + ( + &TransformOperation::Translate(ref fx, ref fy), + &TransformOperation::Translate(ref tx, ref ty), + ) => { + Ok(TransformOperation::Translate( + fx.animate(tx, procedure)?, + fy.animate(ty, procedure)? + )) + }, + ( + &TransformOperation::TranslateX(ref f), + &TransformOperation::TranslateX(ref t), + ) => { + Ok(TransformOperation::TranslateX( + f.animate(t, procedure)? + )) + }, + ( + &TransformOperation::TranslateY(ref f), + &TransformOperation::TranslateY(ref t), + ) => { + Ok(TransformOperation::TranslateY( + f.animate(t, procedure)? + )) + }, + ( + &TransformOperation::TranslateZ(ref f), + &TransformOperation::TranslateZ(ref t), + ) => { + Ok(TransformOperation::TranslateZ( + f.animate(t, procedure)? + )) + }, ( &TransformOperation::Scale3D(ref fx, ref fy, ref fz), &TransformOperation::Scale3D(ref tx, ref ty, ref tz), @@ -1062,6 +1112,30 @@ impl Animate for ComputedTransformOperation { animate_multiplicative_factor(*fz, *tz, procedure)?, )) }, + ( + &TransformOperation::ScaleX(ref f), + &TransformOperation::ScaleX(ref t), + ) => { + Ok(TransformOperation::ScaleX( + animate_multiplicative_factor(*f, *t, procedure)? + )) + }, + ( + &TransformOperation::ScaleY(ref f), + &TransformOperation::ScaleY(ref t), + ) => { + Ok(TransformOperation::ScaleY( + animate_multiplicative_factor(*f, *t, procedure)? + )) + }, + ( + &TransformOperation::ScaleZ(ref f), + &TransformOperation::ScaleZ(ref t), + ) => { + Ok(TransformOperation::ScaleZ( + animate_multiplicative_factor(*f, *t, procedure)? + )) + }, ( &TransformOperation::Rotate3D(fx, fy, fz, fa), &TransformOperation::Rotate3D(tx, ty, tz, ta), @@ -1081,6 +1155,54 @@ impl Animate for ComputedTransformOperation { )) } }, + ( + &TransformOperation::RotateX(fa), + &TransformOperation::RotateX(ta), + ) => { + Ok(TransformOperation::RotateX( + fa.animate(&ta, procedure)? + )) + }, + ( + &TransformOperation::RotateY(fa), + &TransformOperation::RotateY(ta), + ) => { + Ok(TransformOperation::RotateY( + fa.animate(&ta, procedure)? + )) + }, + ( + &TransformOperation::RotateZ(fa), + &TransformOperation::RotateZ(ta), + ) => { + Ok(TransformOperation::RotateZ( + fa.animate(&ta, procedure)? + )) + }, + ( + &TransformOperation::Rotate(fa), + &TransformOperation::Rotate(ta), + ) => { + Ok(TransformOperation::Rotate( + fa.animate(&ta, procedure)? + )) + }, + ( + &TransformOperation::Rotate(fa), + &TransformOperation::RotateZ(ta), + ) => { + Ok(TransformOperation::Rotate( + fa.animate(&ta, procedure)? + )) + }, + ( + &TransformOperation::RotateZ(fa), + &TransformOperation::Rotate(ta), + ) => { + Ok(TransformOperation::Rotate( + fa.animate(&ta, procedure)? + )) + }, ( &TransformOperation::Perspective(ref fd), &TransformOperation::Perspective(ref td), @@ -1097,6 +1219,7 @@ impl Animate for ComputedTransformOperation { fd_matrix.animate(&td_matrix, procedure)?, )) }, + // XXXManishearth handle crossover between translate and scale functions _ => Err(()), } } @@ -1106,18 +1229,29 @@ fn is_matched_operation(first: &ComputedTransformOperation, second: &ComputedTra match (first, second) { (&TransformOperation::Matrix(..), &TransformOperation::Matrix(..)) | - (&TransformOperation::PrefixedMatrix(..), - &TransformOperation::PrefixedMatrix(..)) | + (&TransformOperation::Matrix3D(..), + &TransformOperation::Matrix3D(..)) | (&TransformOperation::Skew(..), &TransformOperation::Skew(..)) | - (&TransformOperation::Translate(..), - &TransformOperation::Translate(..)) | - (&TransformOperation::Scale(..), - &TransformOperation::Scale(..)) | + (&TransformOperation::SkewX(..), + &TransformOperation::SkewX(..)) | + (&TransformOperation::SkewY(..), + &TransformOperation::SkewY(..)) | (&TransformOperation::Rotate(..), &TransformOperation::Rotate(..)) | + (&TransformOperation::Rotate3D(..), + &TransformOperation::Rotate3D(..)) | + (&TransformOperation::RotateX(..), + &TransformOperation::RotateX(..)) | + (&TransformOperation::RotateY(..), + &TransformOperation::RotateY(..)) | + (&TransformOperation::RotateZ(..), + &TransformOperation::RotateZ(..)) | (&TransformOperation::Perspective(..), &TransformOperation::Perspective(..)) => true, + // we animate scale and translate operations against each other + (a, b) if a.is_translate() && b.is_translate() => true, + (a, b) if a.is_scale() && b.is_scale() => true, // InterpolateMatrix and AccumulateMatrix are for mismatched transform. _ => false } diff --git a/components/style/values/computed/transform.rs b/components/style/values/computed/transform.rs index 6a9c7db6dc3..4c90a01b3d1 100644 --- a/components/style/values/computed/transform.rs +++ b/components/style/values/computed/transform.rs @@ -139,6 +139,42 @@ impl From for Transform3D { } } +impl TransformOperation { + /// Convert to a Translate3D. + /// + /// Must be called on a Translate function + pub fn to_translate_3d(&self) -> Self { + match *self { + GenericTransformOperation::Translate3D(..) => self.clone(), + GenericTransformOperation::TranslateX(ref x) | + GenericTransformOperation::Translate(ref x, None) => + GenericTransformOperation::Translate3D(x.clone(), LengthOrPercentage::zero(), Length::zero()), + GenericTransformOperation::Translate(ref x, Some(ref y)) => + GenericTransformOperation::Translate3D(x.clone(), y.clone(), Length::zero()), + GenericTransformOperation::TranslateY(ref y) => + GenericTransformOperation::Translate3D(LengthOrPercentage::zero(), y.clone(), Length::zero()), + GenericTransformOperation::TranslateZ(ref z) => + GenericTransformOperation::Translate3D(LengthOrPercentage::zero(), + LengthOrPercentage::zero(), z.clone()), + _ => unreachable!() + } + } + /// Convert to a Scale3D. + /// + /// Must be called on a Scale function + pub fn to_scale_3d(&self) -> Self { + match *self { + GenericTransformOperation::Scale3D(..) => self.clone(), + GenericTransformOperation::Scale(s, None) => GenericTransformOperation::Scale3D(s, s, 1.), + GenericTransformOperation::Scale(x, Some(y)) => GenericTransformOperation::Scale3D(x, y, 1.), + GenericTransformOperation::ScaleX(x) => GenericTransformOperation::Scale3D(x, 1., 1.), + GenericTransformOperation::ScaleY(y) => GenericTransformOperation::Scale3D(1., y, 1.), + GenericTransformOperation::ScaleZ(z) => GenericTransformOperation::Scale3D(1., 1., z), + _ => unreachable!() + } + } +} + /// Build an equivalent 'identity transform function list' based /// on an existing transform list. /// http://dev.w3.org/csswg/css-transforms/#none-transform-animation diff --git a/components/style/values/generics/transform.rs b/components/style/values/generics/transform.rs index f7968e72e0c..b663babf279 100644 --- a/components/style/values/generics/transform.rs +++ b/components/style/values/generics/transform.rs @@ -247,6 +247,27 @@ pub enum TransformOperation(pub Vec); +impl + TransformOperation { + + /// Check if it is any translate function + pub fn is_translate(&self) -> bool { + use self::TransformOperation::*; + match *self { + Translate(..) | Translate3D(..) | TranslateX(..) | TranslateY(..) | TranslateZ(..) => true, + _ => false + } + } + + /// Check if it is any scale function + pub fn is_scale(&self) -> bool { + use self::TransformOperation::*; + match *self { + Scale(..) | Scale3D(..) | ScaleX(..) | ScaleY(..) | ScaleZ(..) => true, + _ => false + } + } +} impl