diff --git a/components/layout/fragment.rs b/components/layout/fragment.rs index fd2d5698efd..2510b185d1c 100644 --- a/components/layout/fragment.rs +++ b/components/layout/fragment.rs @@ -2887,8 +2887,17 @@ impl Fragment { for operation in operations { let matrix = match *operation { transform::ComputedOperation::Rotate(ax, ay, az, theta) => { - let theta = 2.0f32 * f32::consts::PI - theta.radians(); - Transform3D::create_rotation(ax, ay, az, Radians::new(theta)) + // https://www.w3.org/TR/css-transforms-1/#funcdef-rotate3d + // A direction vector that cannot be normalized, such as [0, 0, 0], will cause + // the rotation to not be applied, so we use identity matrix in this case. + let len = (ax * ax + ay * ay + az * az).sqrt(); + if len > 0. { + let theta = 2.0f32 * f32::consts::PI - theta.radians(); + Transform3D::create_rotation(ax / len, ay / len, az / len, + Radians::new(theta)) + } else { + Transform3D::identity() + } } transform::ComputedOperation::Perspective(d) => { create_perspective_matrix(d) diff --git a/components/style/properties/longhand/box.mako.rs b/components/style/properties/longhand/box.mako.rs index b96e12fdc0e..37f111b42b5 100644 --- a/components/style/properties/longhand/box.mako.rs +++ b/components/style/properties/longhand/box.mako.rs @@ -1415,8 +1415,7 @@ ${helpers.predefined_type( let ay = ay.to_computed_value(context); let az = az.to_computed_value(context); let theta = theta.to_computed_value(context); - let len = (ax * ax + ay * ay + az * az).sqrt(); - result.push(computed_value::ComputedOperation::Rotate(ax / len, ay / len, az / len, theta)); + result.push(computed_value::ComputedOperation::Rotate(ax, ay, az, theta)); } SpecifiedOperation::Skew(theta_x, None) => { let theta_x = theta_x.to_computed_value(context);