Don't introduce calc() when interpolating between length and percentages if either side is zero

Without this patch anim-css-strokewidth-1-by-pct-pct.svg (and possibly
others) fails because we calculate the result as 'calc(0px + 10%)' and
we don't support calc on stroke-width (yet) so the rendered result is
incorrect.

As a more thorough fix, we should make the zero-value for
LengthOrPercentageOrNumber a zero *number* (instead of a zero length)
but that won't work yet since we don't support animating between
stroke-widths with units and those that don't (see
https://bugzilla.mozilla.org/show_bug.cgi?id=1369614). Regardless of
that, we still shouldn't introduce calc in order to add a zero value
using the LengthOrPercentage type, so this change is still needed.
This commit is contained in:
Brian Birtles 2017-06-05 11:24:38 +09:00
parent 00cdced2ca
commit e48f94cbda

View file

@ -1040,6 +1040,13 @@ impl Animatable for LengthOrPercentage {
.map(LengthOrPercentage::Percentage)
}
(this, other) => {
// Special handling for zero values since these should not require calc().
if this.is_definitely_zero() {
return other.add_weighted(&other, 0., other_portion)
} else if other.is_definitely_zero() {
return this.add_weighted(self, self_portion, 0.)
}
let this: CalcLengthOrPercentage = From::from(this);
let other: CalcLengthOrPercentage = From::from(other);
this.add_weighted(&other, self_portion, other_portion)