Fix Animatable impl for LengthOrPercentageOrNone

This commit is contained in:
Anthony Ramine 2017-06-13 10:19:06 +02:00
parent 43a5257a0c
commit f658215f12
2 changed files with 33 additions and 2 deletions

View file

@ -1246,7 +1246,14 @@ impl Animatable for LengthOrPercentageOrNone {
(LengthOrPercentageOrNone::None, LengthOrPercentageOrNone::None) => {
Ok(LengthOrPercentageOrNone::None)
}
_ => Err(())
(this, other) => {
let this = <Option<CalcLengthOrPercentage>>::from(this);
let other = <Option<CalcLengthOrPercentage>>::from(other);
match this.add_weighted(&other, self_portion, other_portion) {
Ok(Some(result)) => Ok(LengthOrPercentageOrNone::Calc(result)),
_ => Err(()),
}
},
}
}
@ -1273,7 +1280,12 @@ impl Animatable for LengthOrPercentageOrNone {
LengthOrPercentageOrNone::Percentage(ref other)) => {
this.compute_distance(other)
},
_ => Err(())
(this, other) => {
// If one of the element is Auto, Option<> will be None, and the returned distance is Err(())
let this = <Option<CalcLengthOrPercentage>>::from(this);
let other = <Option<CalcLengthOrPercentage>>::from(other);
this.compute_distance(&other)
},
}
}
}

View file

@ -157,6 +157,25 @@ impl From<LengthOrPercentageOrAuto> for Option<CalcLengthOrPercentage> {
}
}
impl From<LengthOrPercentageOrNone> for Option<CalcLengthOrPercentage> {
fn from(len: LengthOrPercentageOrNone) -> Option<CalcLengthOrPercentage> {
match len {
LengthOrPercentageOrNone::Percentage(this) => {
Some(CalcLengthOrPercentage::new(Au(0), Some(this)))
}
LengthOrPercentageOrNone::Length(this) => {
Some(CalcLengthOrPercentage::new(this, None))
}
LengthOrPercentageOrNone::Calc(this) => {
Some(this)
}
LengthOrPercentageOrNone::None => {
None
}
}
}
}
impl ToCss for CalcLengthOrPercentage {
fn to_css<W>(&self, dest: &mut W) -> fmt::Result where W: fmt::Write {
match (self.length, self.percentage) {