mirror of
https://github.com/servo/servo.git
synced 2025-08-03 12:40:06 +01:00
Fix Animatable impl for LengthOrPercentageOrNone
This commit is contained in:
parent
43a5257a0c
commit
f658215f12
2 changed files with 33 additions and 2 deletions
|
@ -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)
|
||||
},
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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) {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue