mirror of
https://github.com/servo/servo.git
synced 2025-08-24 06:45:33 +01:00
Make Position a gecko-only vector longhand
This commit is contained in:
parent
65a8a8dccb
commit
979a2798d5
8 changed files with 123 additions and 26 deletions
|
@ -155,6 +155,25 @@ pub trait Interpolate: Sized {
|
|||
fn interpolate(&self, other: &Self, time: f64) -> Result<Self, ()>;
|
||||
}
|
||||
|
||||
/// https://drafts.csswg.org/css-transitions/#animtype-repeatable-list
|
||||
pub trait RepeatableListInterpolate: Interpolate {}
|
||||
|
||||
impl<T: RepeatableListInterpolate> Interpolate for Vec<T> {
|
||||
fn interpolate(&self, other: &Self, time: f64) -> Result<Self, ()> {
|
||||
use num_integer::lcm;
|
||||
let len = lcm(self.len(), other.len());
|
||||
let ret = self.iter().cycle().zip(other.iter().cycle())
|
||||
.take(len)
|
||||
.filter_map(|(ref me, ref you)| {
|
||||
me.interpolate(you, time).ok()
|
||||
}).collect::<Self>();
|
||||
if ret.len() == len {
|
||||
Ok(ret)
|
||||
} else {
|
||||
Err(())
|
||||
}
|
||||
}
|
||||
}
|
||||
/// https://drafts.csswg.org/css-transitions/#animtype-number
|
||||
impl Interpolate for Au {
|
||||
#[inline]
|
||||
|
@ -296,6 +315,14 @@ impl Interpolate for BorderSpacing {
|
|||
}
|
||||
}
|
||||
|
||||
impl Interpolate for BackgroundSize {
|
||||
#[inline]
|
||||
fn interpolate(&self, other: &Self, time: f64) -> Result<Self, ()> {
|
||||
self.0.interpolate(&other.0, time).map(BackgroundSize)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/// https://drafts.csswg.org/css-transitions/#animtype-color
|
||||
impl Interpolate for RGBA {
|
||||
#[inline]
|
||||
|
@ -496,18 +523,12 @@ impl Interpolate for Position {
|
|||
}
|
||||
}
|
||||
|
||||
impl Interpolate for BackgroundSize {
|
||||
impl RepeatableListInterpolate for Position {}
|
||||
|
||||
impl Interpolate for BackgroundPosition {
|
||||
#[inline]
|
||||
fn interpolate(&self, other: &Self, time: f64) -> Result<Self, ()> {
|
||||
use properties::longhands::background_size::computed_value::ExplicitSize;
|
||||
match (self, other) {
|
||||
(&BackgroundSize::Explicit(ref me), &BackgroundSize::Explicit(ref other)) => {
|
||||
Ok(BackgroundSize::Explicit(ExplicitSize {
|
||||
width: try!(me.width.interpolate(&other.width, time)),
|
||||
height: try!(me.height.interpolate(&other.height, time)),
|
||||
}))
|
||||
}
|
||||
_ => Err(()),
|
||||
}
|
||||
Ok(BackgroundPosition(try!(self.0.interpolate(&other.0, time))))
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue