Bug 1391145 - stylo: Preserve the variant of rotate() values in computed transforms; r?hiro draft
authorManish Goregaokar <manishearth@gmail.com>
Mon, 18 Sep 2017 17:12:18 -0700
changeset 667200 39a0d5d56ad0f3f9ae63973f3e5bcbc1f0f0b7fb
parent 667199 b1b77889c1ffd3157986487861d2422becca854c
child 667201 b312140f85e378381a50b4825a2ea404410706f6
push id80648
push userbmo:manishearth@gmail.com
push dateTue, 19 Sep 2017 20:49:18 +0000
reviewershiro
bugs1391145
milestone57.0a1
Bug 1391145 - stylo: Preserve the variant of rotate() values in computed transforms; r?hiro MozReview-Commit-ID: 6m57wXirshe
servo/components/style/properties/gecko.mako.rs
servo/components/style/properties/helpers/animated_properties.mako.rs
servo/components/style/properties/longhand/box.mako.rs
servo/components/style/values/computed/transform.rs
--- a/servo/components/style/properties/gecko.mako.rs
+++ b/servo/components/style/properties/gecko.mako.rs
@@ -2988,16 +2988,19 @@ fn static_assert() {
                 ${transform_function_arm("TranslateX", "translatex", ["lop"])}
                 ${transform_function_arm("TranslateY", "translatey", ["lop"])}
                 ${transform_function_arm("TranslateZ", "translatez", ["length"])}
                 ${transform_function_arm("Translate", "translate3d", ["lop", "lop", "length"])}
                 ${transform_function_arm("ScaleX", "scalex", ["number"])}
                 ${transform_function_arm("ScaleY", "scaley", ["number"])}
                 ${transform_function_arm("ScaleZ", "scalez", ["number"])}
                 ${transform_function_arm("Scale", "scale3d", ["number"] * 3)}
+                ${transform_function_arm("RotateX", "rotatex", ["angle"])}
+                ${transform_function_arm("RotateY", "rotatey", ["angle"])}
+                ${transform_function_arm("RotateZ", "rotatez", ["angle"])}
                 ${transform_function_arm("Rotate", "rotate3d", ["number"] * 3 + ["angle"])}
                 ${transform_function_arm("Perspective", "perspective", ["length"])}
                 ${transform_function_arm("InterpolateMatrix", "interpolatematrix",
                                          ["list"] * 2 + ["percentage"])}
                 ${transform_function_arm("AccumulateMatrix", "accumulatematrix",
                                          ["list"] * 2 + ["integer_to_percentage"])}
             }
         }
@@ -3115,16 +3118,19 @@ fn static_assert() {
                 ${computed_operation_arm("TranslateX", "translatex", ["lop"])}
                 ${computed_operation_arm("TranslateY", "translatey", ["lop"])}
                 ${computed_operation_arm("TranslateZ", "translatez", ["length"])}
                 ${computed_operation_arm("Translate", "translate3d", ["lop", "lop", "length"])}
                 ${computed_operation_arm("ScaleX", "scalex", ["number"])}
                 ${computed_operation_arm("ScaleY", "scaley", ["number"])}
                 ${computed_operation_arm("ScaleZ", "scalez", ["number"])}
                 ${computed_operation_arm("Scale", "scale3d", ["number"] * 3)}
+                ${computed_operation_arm("RotateX", "rotatex", ["angle"])}
+                ${computed_operation_arm("RotateY", "rotatey", ["angle"])}
+                ${computed_operation_arm("RotateZ", "rotatez", ["angle"])}
                 ${computed_operation_arm("Rotate", "rotate3d", ["number"] * 3 + ["angle"])}
                 ${computed_operation_arm("Perspective", "perspective", ["length"])}
                 ${computed_operation_arm("InterpolateMatrix", "interpolatematrix",
                                          ["list"] * 2 + ["percentage"])}
                 ${computed_operation_arm("AccumulateMatrix", "accumulatematrix",
                                          ["list"] * 2 + ["percentage_to_integer"])}
                 _ => panic!("We shouldn't set any other transform function types"),
             }
--- a/servo/components/style/properties/helpers/animated_properties.mako.rs
+++ b/servo/components/style/properties/helpers/animated_properties.mako.rs
@@ -1196,16 +1196,19 @@ impl ToAnimatedZero for TransformOperati
                 ))
             },
             TransformOperation::Scale(..) => {
                 Ok(TransformOperation::Scale(1.0, 1.0, 1.0))
             },
             TransformOperation::ScaleX(_) => Ok(TransformOperation::ScaleX(1.)),
             TransformOperation::ScaleY(_) => Ok(TransformOperation::ScaleY(1.)),
             TransformOperation::ScaleZ(_) => Ok(TransformOperation::ScaleZ(1.)),
+            TransformOperation::RotateX(_) => Ok(TransformOperation::RotateX(Angle::zero())),
+            TransformOperation::RotateY(_) => Ok(TransformOperation::RotateY(Angle::zero())),
+            TransformOperation::RotateZ(_) => Ok(TransformOperation::RotateZ(Angle::zero())),
             TransformOperation::Rotate(x, y, z, a) => {
                 let (x, y, z, _) = TransformList::get_normalized_vector_and_angle(x, y, z, a);
                 Ok(TransformOperation::Rotate(x, y, z, Angle::zero()))
             },
             TransformOperation::Perspective(..) |
             TransformOperation::AccumulateMatrix { .. } |
             TransformOperation::InterpolateMatrix { .. } => {
                 // Perspective: We convert a perspective function into an equivalent
--- a/servo/components/style/properties/longhand/box.mako.rs
+++ b/servo/components/style/properties/longhand/box.mako.rs
@@ -719,16 +719,19 @@
             TranslateZ(Length),
             Translate(computed::LengthOrPercentage,
                       computed::LengthOrPercentage,
                       computed::Length),
             ScaleX(CSSFloat),
             ScaleY(CSSFloat),
             ScaleZ(CSSFloat),
             Scale(CSSFloat, CSSFloat, CSSFloat),
+            RotateX(computed::Angle),
+            RotateY(computed::Angle),
+            RotateZ(computed::Angle),
             Rotate(CSSFloat, CSSFloat, CSSFloat, computed::Angle),
             Perspective(computed::Length),
             // For mismatched transform lists.
             // A vector of |ComputedOperation| could contain an |InterpolateMatrix| and other
             // |ComputedOperation|s, and multiple nested |InterpolateMatrix|s is acceptable.
             // e.g.
             // [ InterpolateMatrix { from_list: [ InterpolateMatrix { ... },
             //                                    Scale(...) ],
@@ -1346,25 +1349,25 @@
                         result.push(computed_value::ComputedOperation::Scale(sx, sy, sz));
                     }
                     SpecifiedOperation::Rotate(theta) => {
                         let theta = theta.to_computed_value(context);
                         result.push(computed_value::ComputedOperation::Rotate(0.0, 0.0, 1.0, theta));
                     }
                     SpecifiedOperation::RotateX(theta) => {
                         let theta = theta.to_computed_value(context);
-                        result.push(computed_value::ComputedOperation::Rotate(1.0, 0.0, 0.0, theta));
+                        result.push(computed_value::ComputedOperation::RotateX(theta));
                     }
                     SpecifiedOperation::RotateY(theta) => {
                         let theta = theta.to_computed_value(context);
-                        result.push(computed_value::ComputedOperation::Rotate(0.0, 1.0, 0.0, theta));
+                        result.push(computed_value::ComputedOperation::RotateY(theta));
                     }
                     SpecifiedOperation::RotateZ(theta) => {
                         let theta = theta.to_computed_value(context);
-                        result.push(computed_value::ComputedOperation::Rotate(0.0, 0.0, 1.0, theta));
+                        result.push(computed_value::ComputedOperation::RotateZ(theta));
                     }
                     SpecifiedOperation::Rotate3D(ax, ay, az, theta) => {
                         let ax = ax.to_computed_value(context);
                         let ay = ay.to_computed_value(context);
                         let az = az.to_computed_value(context);
                         let theta = theta.to_computed_value(context);
                         result.push(computed_value::ComputedOperation::Rotate(ax, ay, az, theta));
                     }
@@ -1485,16 +1488,28 @@
                                               ToComputedValue::from_computed_value(sz)));
                         }
                         computed_value::ComputedOperation::Scale(ref sx, ref sy, ref sz) => {
                             result.push(SpecifiedOperation::Scale3D(
                                     Number::from_computed_value(sx),
                                     Number::from_computed_value(sy),
                                     Number::from_computed_value(sz)));
                         }
+                        computed_value::ComputedOperation::RotateX(ref rx) => {
+                            result.push(SpecifiedOperation::RotateX(
+                                              ToComputedValue::from_computed_value(rx)));
+                        }
+                        computed_value::ComputedOperation::RotateY(ref ry) => {
+                            result.push(SpecifiedOperation::RotateY(
+                                              ToComputedValue::from_computed_value(ry)));
+                        }
+                        computed_value::ComputedOperation::RotateZ(ref rz) => {
+                            result.push(SpecifiedOperation::RotateZ(
+                                              ToComputedValue::from_computed_value(rz)));
+                        }
                         computed_value::ComputedOperation::Rotate(ref ax, ref ay, ref az, ref theta) => {
                             result.push(SpecifiedOperation::Rotate3D(
                                     Number::from_computed_value(ax),
                                     Number::from_computed_value(ay),
                                     Number::from_computed_value(az),
                                     specified::Angle::from_computed_value(theta)));
                         }
                         computed_value::ComputedOperation::Skew(ref theta_x, ref theta_y) => {
--- a/servo/components/style/values/computed/transform.rs
+++ b/servo/components/style/values/computed/transform.rs
@@ -75,16 +75,28 @@ impl TransformList {
                 LengthOrPercentage::Length(px) => px.px(),
                 LengthOrPercentage::Percentage(_) => 0.,
                 LengthOrPercentage::Calc(calc) => calc.length().px(),
             }
         };
 
         for operation in list {
             let matrix = match *operation {
+                ComputedOperation::RotateX(theta) => {
+                    let theta = Angle::from_radians(2.0f32 * f32::consts::PI - theta.radians());
+                    Transform3D::create_rotation(1., 0., 0., theta.into())
+                }
+                ComputedOperation::RotateY(theta) => {
+                    let theta = Angle::from_radians(2.0f32 * f32::consts::PI - theta.radians());
+                    Transform3D::create_rotation(0., 1., 0., theta.into())
+                }
+                ComputedOperation::RotateZ(theta) => {
+                    let theta = Angle::from_radians(2.0f32 * f32::consts::PI - theta.radians());
+                    Transform3D::create_rotation(0., 0., 1., theta.into())
+                }
                 ComputedOperation::Rotate(ax, ay, az, theta) => {
                     let theta = Angle::from_radians(2.0f32 * f32::consts::PI - theta.radians());
                     let (ax, ay, az, theta) =
                         Self::get_normalized_vector_and_angle(ax, ay, az, theta);
                     Transform3D::create_rotation(ax, ay, az, theta.into())
                 }
                 ComputedOperation::Perspective(d) => {
                     Self::create_perspective_matrix(d.px())