diff --git a/components/style/properties/helpers/animated_properties.mako.rs b/components/style/properties/helpers/animated_properties.mako.rs index c3fcef2f51e..6ed00b5d4ca 100644 --- a/components/style/properties/helpers/animated_properties.mako.rs +++ b/components/style/properties/helpers/animated_properties.mako.rs @@ -2325,6 +2325,31 @@ impl ComputeDistance for CSSParserColor { } } +impl ComputeDistance for IntermediateRGBA { + #[inline] + fn compute_distance(&self, other: &Self) -> Result { + self.compute_squared_distance(other).map(|sq| sq.sqrt()) + } + + #[inline] + fn compute_squared_distance(&self, other: &Self) -> Result { + let start = [ self.alpha, + self.red * self.alpha, + self.green * self.alpha, + self.blue * self.alpha ]; + let end = [ other.alpha, + other.red * other.alpha, + other.green * other.alpha, + other.blue * other.alpha ]; + let diff = start.iter().zip(&end) + .fold(0.0f64, |n, (&a, &b)| { + let diff = (a - b) as f64; + n + diff * diff + }); + Ok(diff) + } +} + impl ComputeDistance for CalcLengthOrPercentage { #[inline] fn compute_distance(&self, other: &Self) -> Result {