style: Make SVGPathData and clip-path: path() animatable.

Implement Animate trait for SVGPathData.

The basic idea is: we normalize |this| and |other| svg paths, and then
do interpolation on the normalized svg paths. The normalization is to
convert relative coordinates into absolute coordinates, so we could do
real number interpolation on each path command directly.

In this patch, we also make |clip-path:path()| animatable.

Differential Revision: https://phabricator.services.mozilla.com/D4786
This commit is contained in:
Boris Chiou 2018-09-07 22:15:50 +00:00 committed by Emilio Cobos Álvarez
parent 9c1c58a498
commit 14911b96e0
No known key found for this signature in database
GPG key ID: 056B727BB9C1027C
4 changed files with 175 additions and 4 deletions

View file

@ -54,7 +54,6 @@ pub enum ShapeSource<BasicShape, ReferenceBox, ImageOrUrl> {
Shape(BasicShape, Option<ReferenceBox>),
#[animation(error)]
Box(ReferenceBox),
#[animation(error)]
#[css(function)]
Path(Path),
#[animation(error)]
@ -152,10 +151,12 @@ pub enum FillRule {
///
/// https://drafts.csswg.org/css-shapes-2/#funcdef-path
#[css(comma)]
#[derive(Clone, Debug, MallocSizeOf, PartialEq, SpecifiedValueInfo, ToComputedValue, ToCss)]
#[derive(Animate, Clone, Debug, MallocSizeOf, PartialEq, SpecifiedValueInfo,
ToComputedValue, ToCss)]
pub struct Path {
/// The filling rule for the svg path.
#[css(skip_if = "fill_is_default")]
#[animation(constant)]
pub fill: FillRule,
/// The svg path data.
pub path: SVGPathData,
@ -177,6 +178,13 @@ where
{
this.compute_squared_distance(other)
},
(
&ShapeSource::Path(ref this),
&ShapeSource::Path(ref other),
) if this.fill == other.fill =>
{
this.path.compute_squared_distance(&other.path)
}
_ => Err(()),
}
}