diff --git a/components/style/values/animated/transform.rs b/components/style/values/animated/transform.rs index a204ec2be2e..57d1900a0f9 100644 --- a/components/style/values/animated/transform.rs +++ b/components/style/values/animated/transform.rs @@ -1112,8 +1112,12 @@ impl Animate for ComputedTransformOperation { let decomposed = decompose_3d_matrix(interpolated)?; let perspective_z = decomposed.perspective.2; - let used_value = if perspective_z == 0. { - 0. + // Clamp results outside of the -1 to 0 range so that we get perspective + // function values between 1 and infinity. + let used_value = if perspective_z >= 0. { + std::f32::INFINITY + } else if perspective_z <= -1. { + 1. } else { -1. / perspective_z }; diff --git a/components/style/values/computed/transform.rs b/components/style/values/computed/transform.rs index 46c471b7e2e..431893973f5 100644 --- a/components/style/values/computed/transform.rs +++ b/components/style/values/computed/transform.rs @@ -516,8 +516,8 @@ impl ToAnimatedZero for TransformOperation { generic::TransformOperation::Rotate(_) => { Ok(generic::TransformOperation::Rotate(Angle::zero())) }, - generic::TransformOperation::Perspective(ref l) => Ok( - generic::TransformOperation::Perspective(l.to_animated_zero()?), + generic::TransformOperation::Perspective(_) => Ok( + generic::TransformOperation::Perspective(Length::new(std::f32::INFINITY)) ), generic::TransformOperation::AccumulateMatrix { .. } | generic::TransformOperation::InterpolateMatrix { .. } => { diff --git a/components/style/values/generics/transform.rs b/components/style/values/generics/transform.rs index 9669d44f1a2..1733baa2d23 100644 --- a/components/style/values/generics/transform.rs +++ b/components/style/values/generics/transform.rs @@ -583,10 +583,10 @@ impl Transform { /// Return the transform matrix from a perspective length. #[inline] pub fn create_perspective_matrix(d: CSSFloat) -> Transform3D { - if d < 0.0 { - Transform3D::identity() - } else { + if d.is_finite() { Transform3D::perspective(d.max(1.)) + } else { + Transform3D::identity() } }