From f81ffda69d550e041a0bb549a1e81b4c4b76507e Mon Sep 17 00:00:00 2001 From: Matt Woodrow Date: Mon, 22 May 2023 09:56:09 +0200 Subject: [PATCH] style: Clamp perspective() values to a minimum of 1px Differential Revision: https://phabricator.services.mozilla.com/D118250 --- components/style/values/animated/transform.rs | 4 ++-- components/style/values/generics/transform.rs | 11 ++--------- 2 files changed, 4 insertions(+), 11 deletions(-) diff --git a/components/style/values/animated/transform.rs b/components/style/values/animated/transform.rs index 621ae60084d..a204ec2be2e 100644 --- a/components/style/values/animated/transform.rs +++ b/components/style/values/animated/transform.rs @@ -1204,8 +1204,8 @@ impl ComputeSquaredDistance for ComputedTransformOperation { // FIXME(emilio): Is this right? Why interpolating this with // Perspective but not with anything else? let mut p_matrix = Matrix3D::identity(); - if p.px() > 0. { - p_matrix.m34 = -1. / p.px(); + if p.px() >= 0. { + p_matrix.m34 = -1. / p.px().max(1.); } p_matrix.compute_squared_distance(&m) }, diff --git a/components/style/values/generics/transform.rs b/components/style/values/generics/transform.rs index 4d1df3d58ea..9669d44f1a2 100644 --- a/components/style/values/generics/transform.rs +++ b/components/style/values/generics/transform.rs @@ -583,17 +583,10 @@ impl Transform { /// Return the transform matrix from a perspective length. #[inline] pub fn create_perspective_matrix(d: CSSFloat) -> Transform3D { - // TODO(gw): The transforms spec says that perspective length must - // be positive. However, there is some confusion between the spec - // and browser implementations as to handling the case of 0 for the - // perspective value. Until the spec bug is resolved, at least ensure - // that a provided perspective value of <= 0.0 doesn't cause panics - // and behaves as it does in other browsers. - // See https://lists.w3.org/Archives/Public/www-style/2016Jan/0020.html for more details. - if d <= 0.0 { + if d < 0.0 { Transform3D::identity() } else { - Transform3D::perspective(d) + Transform3D::perspective(d.max(1.)) } }