Bug 1355349 - Don't introduce calc() when interpolating between length and percentages if either side is zero; r?hiro draft
authorBrian Birtles <birtles@gmail.com>
Fri, 02 Jun 2017 14:48:49 +0900
changeset 588136 4725f59c6cd4206b006f8a048ce593c96f970936
parent 588135 ade1320a965a8d1e2f10fda5b5a92be14a2734e6
child 588137 df6177716158eefc13f0adc6d4550c9679d886d8
push id61920
push userbbirtles@mozilla.com
push dateFri, 02 Jun 2017 07:10:54 +0000
reviewershiro
bugs1355349, 1258270, 1369614
milestone55.0a1
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
servo/components/style/properties/helpers/animated_properties.mako.rs
--- 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)
             }
         }
     }