Bug 1355349 - Don't introduce calc() when interpolating between length and percentages if either side is zero; r?hiro
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, see
bug 1258270) 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 due to
bug 1369614. Regardless of that bug, we still shouldn't
introduce calc in order to add a zero value using the LengthOrPercentage type,
so this change is still needed.
MozReview-Commit-ID: KxKKI2tjIbw
--- a/servo/components/style/properties/helpers/animated_properties.mako.rs
+++ b/servo/components/style/properties/helpers/animated_properties.mako.rs
@@ -1126,16 +1126,23 @@ impl Animatable for LengthOrPercentage {
.map(LengthOrPercentage::Length)
}
(LengthOrPercentage::Percentage(ref this),
LengthOrPercentage::Percentage(ref other)) => {
this.add_weighted(other, self_portion, other_portion)
.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)
.map(LengthOrPercentage::Calc)
}
}
}