Bug 1360144 - make stroke-{*} animatable for stylo.
This part includes making stroke-linecap, stroke-linejoin, stroke-miterlimit,
stroke-opacity, and stroke-dasharray animatable.
For properties that already implemented Interpolate trait and clone() for
glue code, we can just make them animatable by replacing the animation_value_type
with proper type name. So, set animation_value_type to 'discrete' for
stroke-linecap and stroke-linejoin. Set animation_value_type to 'ComputedValue'
for stroke-miterlimit and stroke-opacity.
As to stroke-dasharray, we need to implement Interpolate trait and glue codes
for it.
MozReview-Commit-ID: FHUs3Fbg2xY
--- a/servo/components/style/properties/gecko.mako.rs
+++ b/servo/components/style/properties/gecko.mako.rs
@@ -3772,16 +3772,36 @@ clip-path
}
}
pub fn copy_stroke_dasharray_from(&mut self, other: &Self) {
unsafe {
bindings::Gecko_nsStyleSVG_CopyDashArray(&mut self.gecko, &other.gecko);
}
}
+
+ pub fn clone_stroke_dasharray(&self) -> longhands::stroke_dasharray::computed_value::T {
+ use smallvec::SmallVec;
+ use values::computed::LengthOrPercentage;
+
+ let mut vec = SmallVec::new();
+ for gecko in self.gecko.mStrokeDasharray.iter() {
+ match gecko.as_value() {
+ CoordDataValue::Factor(number) => vec.push(Either::First(number)),
+ CoordDataValue::Coord(coord) =>
+ vec.push(Either::Second(LengthOrPercentage::Length(Au(coord)))),
+ CoordDataValue::Percent(p) =>
+ vec.push(Either::Second(LengthOrPercentage::Percentage(p))),
+ CoordDataValue::Calc(calc) =>
+ vec.push(Either::Second(LengthOrPercentage::Calc(calc.into()))),
+ _ => unreachable!(),
+ }
+ }
+ longhands::stroke_dasharray::computed_value::T(vec)
+ }
</%self:impl_trait>
<%self:impl_trait style_struct_name="Color"
skip_longhands="*">
pub fn set_color(&mut self, v: longhands::color::computed_value::T) {
let result = convert_rgba_to_nscolor(&v);
${set_gecko_property("mColor", "result")}
}
--- a/servo/components/style/properties/helpers/animated_properties.mako.rs
+++ b/servo/components/style/properties/helpers/animated_properties.mako.rs
@@ -616,16 +616,18 @@ impl Interpolate for AnimationValue {
pub trait Interpolate: Sized {
/// Interpolate a value with another for a given property.
fn interpolate(&self, other: &Self, progress: f64) -> Result<Self, ()>;
}
/// https://drafts.csswg.org/css-transitions/#animtype-repeatable-list
pub trait RepeatableListInterpolate: Interpolate {}
+impl RepeatableListInterpolate for Either<f32, LengthOrPercentage> {}
+
impl<T: RepeatableListInterpolate> Interpolate for SmallVec<[T; 1]> {
fn interpolate(&self, other: &Self, progress: f64) -> Result<Self, ()> {
use num_integer::lcm;
let len = lcm(self.len(), other.len());
self.iter().cycle().zip(other.iter().cycle()).take(len).map(|(me, you)| {
me.interpolate(you, progress)
}).collect()
}
--- a/servo/components/style/properties/longhand/inherited_svg.mako.rs
+++ b/servo/components/style/properties/longhand/inherited_svg.mako.rs
@@ -69,40 +69,41 @@
"stroke-width", "LengthOrPercentage",
"computed::LengthOrPercentage::one()",
"parse_numbers_are_pixels_non_negative",
products="gecko",
animation_value_type="ComputedValue",
spec="https://www.w3.org/TR/SVG2/painting.html#StrokeWidth")}
${helpers.single_keyword("stroke-linecap", "butt round square",
- products="gecko", animation_value_type="none",
+ products="gecko", animation_value_type="discrete",
spec="https://www.w3.org/TR/SVG11/painting.html#StrokeLinecapProperty")}
${helpers.single_keyword("stroke-linejoin", "miter round bevel",
- products="gecko", animation_value_type="none",
+ products="gecko", animation_value_type="discrete",
spec="https://www.w3.org/TR/SVG11/painting.html#StrokeLinejoinProperty")}
${helpers.predefined_type("stroke-miterlimit", "Number", "4.0",
"parse_at_least_one", products="gecko",
- animation_value_type="none",
+ animation_value_type="ComputedValue",
spec="https://www.w3.org/TR/SVG11/painting.html#StrokeMiterlimitProperty")}
${helpers.predefined_type("stroke-opacity", "Opacity", "1.0",
- products="gecko", animation_value_type="none",
+ products="gecko", animation_value_type="ComputedValue",
spec="https://www.w3.org/TR/SVG11/painting.html#StrokeOpacityProperty")}
${helpers.predefined_type("stroke-dasharray",
"LengthOrPercentageOrNumber",
"Either::First(0.0)",
"parse_non_negative",
vector="True",
+ delegate_animate="True",
allow_empty="True",
products="gecko",
- animation_value_type="none",
+ animation_value_type="ComputedValue",
space_separated_allowed="True",
spec="https://www.w3.org/TR/SVG2/painting.html#StrokeDashing")}
${helpers.predefined_type(
"stroke-dashoffset", "LengthOrPercentage",
"computed::LengthOrPercentage::zero()",
"parse_numbers_are_pixels",
products="gecko",