mirror of
https://github.com/servo/servo.git
synced 2025-08-06 14:10:11 +01:00
parent
61267cde63
commit
554a4cf9f2
5 changed files with 118 additions and 5 deletions
|
@ -28,7 +28,7 @@ use util::bezier::Bezier;
|
|||
use util::geometry::Au;
|
||||
use values::CSSFloat;
|
||||
use values::computed::{Angle, LengthOrPercentageOrAuto, LengthOrPercentageOrNone};
|
||||
use values::computed::{LengthOrPercentage, Length, Time};
|
||||
use values::computed::{LengthOrPercentage, Length, Time, Calc};
|
||||
|
||||
#[derive(Clone, Debug)]
|
||||
pub struct PropertyAnimation {
|
||||
|
@ -513,6 +513,17 @@ impl Interpolate for Color {
|
|||
}
|
||||
}
|
||||
|
||||
impl Interpolate for Calc {
|
||||
#[inline]
|
||||
fn interpolate(&self, other: &Calc, time: f64)
|
||||
-> Option<Calc> {
|
||||
Some(Calc {
|
||||
length: self.length().interpolate(&other.length(), time),
|
||||
percentage: self.percentage().interpolate(&other.percentage(), time),
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
impl Interpolate for LengthOrPercentage {
|
||||
#[inline]
|
||||
fn interpolate(&self, other: &LengthOrPercentage, time: f64)
|
||||
|
@ -530,7 +541,13 @@ impl Interpolate for LengthOrPercentage {
|
|||
Some(LengthOrPercentage::Percentage(value))
|
||||
})
|
||||
}
|
||||
(_, _) => None,
|
||||
(this, other) => {
|
||||
let this: Calc = From::from(this);
|
||||
let other: Calc = From::from(other);
|
||||
this.interpolate(&other, time).and_then(|value| {
|
||||
Some(LengthOrPercentage::Calc(value))
|
||||
})
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -555,7 +572,13 @@ impl Interpolate for LengthOrPercentageOrAuto {
|
|||
(LengthOrPercentageOrAuto::Auto, LengthOrPercentageOrAuto::Auto) => {
|
||||
Some(LengthOrPercentageOrAuto::Auto)
|
||||
}
|
||||
(_, _) => None,
|
||||
(this, other) => {
|
||||
let this: Option<Calc> = From::from(this);
|
||||
let other: Option<Calc> = From::from(other);
|
||||
this.interpolate(&other, time).unwrap_or(None).and_then(|value| {
|
||||
Some(LengthOrPercentageOrAuto::Calc(value))
|
||||
})
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1299,8 +1299,8 @@ pub mod computed {
|
|||
|
||||
#[derive(Clone, PartialEq, Copy, Debug, HeapSizeOf)]
|
||||
pub struct Calc {
|
||||
length: Option<Au>,
|
||||
percentage: Option<CSSFloat>,
|
||||
pub length: Option<Au>,
|
||||
pub percentage: Option<CSSFloat>,
|
||||
}
|
||||
|
||||
impl Calc {
|
||||
|
@ -1313,6 +1313,53 @@ pub mod computed {
|
|||
}
|
||||
}
|
||||
|
||||
impl From<LengthOrPercentage> for Calc {
|
||||
fn from(len: LengthOrPercentage) -> Calc {
|
||||
match len {
|
||||
LengthOrPercentage::Percentage(this) => {
|
||||
Calc {
|
||||
length: None,
|
||||
percentage: Some(this),
|
||||
}
|
||||
}
|
||||
LengthOrPercentage::Length(this) => {
|
||||
Calc {
|
||||
length: Some(this),
|
||||
percentage: None,
|
||||
}
|
||||
}
|
||||
LengthOrPercentage::Calc(this) => {
|
||||
this
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl From<LengthOrPercentageOrAuto> for Option<Calc> {
|
||||
fn from(len: LengthOrPercentageOrAuto) -> Option<Calc> {
|
||||
match len {
|
||||
LengthOrPercentageOrAuto::Percentage(this) => {
|
||||
Some(Calc {
|
||||
length: None,
|
||||
percentage: Some(this),
|
||||
})
|
||||
}
|
||||
LengthOrPercentageOrAuto::Length(this) => {
|
||||
Some(Calc {
|
||||
length: Some(this),
|
||||
percentage: None,
|
||||
})
|
||||
}
|
||||
LengthOrPercentageOrAuto::Calc(this) => {
|
||||
Some(this)
|
||||
}
|
||||
LengthOrPercentageOrAuto::Auto => {
|
||||
None
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl ::cssparser::ToCss for Calc {
|
||||
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