From e5f8155d6c780107d5c3dc742bfa11102d247ff3 Mon Sep 17 00:00:00 2001 From: Boris Chiou Date: Fri, 21 Sep 2018 18:39:41 +0000 Subject: [PATCH] style: Flip boolean half way for path interpolation. According to the new svg 2 spec update (#543), we flip the flag half way for path interpolation. Differential Revision: https://phabricator.services.mozilla.com/D6192 --- components/style/values/specified/svg_path.rs | 32 +++++++++++++++++-- 1 file changed, 29 insertions(+), 3 deletions(-) diff --git a/components/style/values/specified/svg_path.rs b/components/style/values/specified/svg_path.rs index 5d397558d25..3f1fdc39d97 100644 --- a/components/style/values/specified/svg_path.rs +++ b/components/style/values/specified/svg_path.rs @@ -13,7 +13,7 @@ use std::slice; use style_traits::{CssWriter, ParseError, StyleParseErrorKind, ToCss}; use style_traits::values::SequenceWriter; use values::CSSFloat; -use values::animated::{Animate, Procedure}; +use values::animated::{Animate, Procedure, ToAnimatedZero}; use values::distance::{ComputeSquaredDistance, SquaredDistance}; /// The SVG path data. @@ -198,9 +198,7 @@ pub enum PathCommand { rx: CSSFloat, ry: CSSFloat, angle: CSSFloat, - #[animation(constant)] large_arc_flag: ArcFlag, - #[animation(constant)] sweep_flag: ArcFlag, point: CoordPair, absolute: IsAbsolute, @@ -538,6 +536,34 @@ impl ToCss for ArcFlag { } } +impl Animate for ArcFlag { + #[inline] + fn animate(&self, other: &Self, procedure: Procedure) -> Result { + (self.0 as i32) + .animate(&(other.0 as i32), procedure) + .map(|v| ArcFlag(v > 0)) + } +} + +impl ComputeSquaredDistance for ArcFlag { + #[inline] + fn compute_squared_distance(&self, other: &Self) -> Result { + (self.0 as i32).compute_squared_distance(&(other.0 as i32)) + } +} + +impl ToAnimatedZero for ArcFlag { + #[inline] + fn to_animated_zero(&self) -> Result { + // The 2 ArcFlags in EllipticalArc determine which one of the 4 different arcs will be + // used. (i.e. From 4 combinations). In other words, if we change the flag, we get a + // different arc. Therefore, we return *self. + // https://svgwg.org/svg2-draft/paths.html#PathDataEllipticalArcCommands + Ok(*self) + } +} + + /// SVG Path parser. struct PathParser<'a> { chars: Peekable>>,