mirror of
https://github.com/servo/servo.git
synced 2025-08-14 18:05:36 +01:00
Move Animatable::get_zero_value to ToAnimatedZero::to_animated_zero
This commit is contained in:
parent
99592cc3d1
commit
98bf832169
13 changed files with 293 additions and 127 deletions
|
@ -11,7 +11,7 @@ use properties::longhands::text_shadow::computed_value::T as ComputedTextShadowL
|
|||
use std::cmp;
|
||||
#[cfg(not(feature = "gecko"))]
|
||||
use values::Impossible;
|
||||
use values::animated::ToAnimatedValue;
|
||||
use values::animated::{ToAnimatedValue, ToAnimatedZero};
|
||||
use values::computed::{Angle, Number};
|
||||
use values::computed::length::Length;
|
||||
use values::generics::effects::BoxShadow as GenericBoxShadow;
|
||||
|
@ -66,7 +66,7 @@ impl ToAnimatedValue for ComputedBoxShadowList {
|
|||
|
||||
impl<S> Animatable for ShadowList<S>
|
||||
where
|
||||
S: Animatable + Clone,
|
||||
S: Animatable + Clone + ToAnimatedZero,
|
||||
{
|
||||
#[inline]
|
||||
fn add_weighted(
|
||||
|
@ -83,10 +83,10 @@ where
|
|||
shadow.add_weighted(other, self_portion, other_portion)?
|
||||
},
|
||||
(Some(shadow), None) => {
|
||||
shadow.add_weighted(&shadow.get_zero_value()?, self_portion, other_portion)?
|
||||
shadow.add_weighted(&shadow.to_animated_zero()?, self_portion, other_portion)?
|
||||
},
|
||||
(None, Some(shadow)) => {
|
||||
shadow.get_zero_value()?.add_weighted(&shadow, self_portion, other_portion)?
|
||||
shadow.to_animated_zero()?.add_weighted(&shadow, self_portion, other_portion)?
|
||||
},
|
||||
(None, None) => unreachable!(),
|
||||
});
|
||||
|
@ -102,6 +102,13 @@ where
|
|||
}
|
||||
}
|
||||
|
||||
impl<S> ToAnimatedZero for ShadowList<S> {
|
||||
#[inline]
|
||||
fn to_animated_zero(&self) -> Result<Self, ()> {
|
||||
Ok(ShadowList(vec![]))
|
||||
}
|
||||
}
|
||||
|
||||
impl ToAnimatedValue for ComputedTextShadowList {
|
||||
type AnimatedValue = TextShadowList;
|
||||
|
||||
|
@ -134,15 +141,6 @@ impl Animatable for BoxShadow {
|
|||
})
|
||||
}
|
||||
|
||||
#[inline]
|
||||
fn get_zero_value(&self) -> Result<Self, ()> {
|
||||
Ok(BoxShadow {
|
||||
base: self.base.get_zero_value()?,
|
||||
spread: self.spread.get_zero_value()?,
|
||||
inset: self.inset,
|
||||
})
|
||||
}
|
||||
|
||||
#[inline]
|
||||
fn compute_distance(&self, other: &Self) -> Result<f64, ()> {
|
||||
self.compute_squared_distance(other).map(|sd| sd.sqrt())
|
||||
|
@ -160,6 +158,17 @@ impl Animatable for BoxShadow {
|
|||
}
|
||||
}
|
||||
|
||||
impl ToAnimatedZero for BoxShadow {
|
||||
#[inline]
|
||||
fn to_animated_zero(&self) -> Result<Self, ()> {
|
||||
Ok(BoxShadow {
|
||||
base: self.base.to_animated_zero()?,
|
||||
spread: self.spread.to_animated_zero()?,
|
||||
inset: self.inset,
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
impl ToAnimatedValue for ComputedFilterList {
|
||||
type AnimatedValue = FilterList;
|
||||
|
||||
|
@ -188,6 +197,13 @@ impl ToAnimatedValue for ComputedFilterList {
|
|||
}
|
||||
}
|
||||
|
||||
impl ToAnimatedZero for FilterList {
|
||||
#[inline]
|
||||
fn to_animated_zero(&self) -> Result<Self, ()> {
|
||||
Ok(FilterList(vec![]))
|
||||
}
|
||||
}
|
||||
|
||||
impl Animatable for SimpleShadow {
|
||||
#[inline]
|
||||
fn add_weighted(&self, other: &Self, self_portion: f64, other_portion: f64) -> Result<Self, ()> {
|
||||
|
@ -204,16 +220,6 @@ impl Animatable for SimpleShadow {
|
|||
})
|
||||
}
|
||||
|
||||
#[inline]
|
||||
fn get_zero_value(&self) -> Result<Self, ()> {
|
||||
Ok(SimpleShadow {
|
||||
color: IntermediateColor::transparent(),
|
||||
horizontal: self.horizontal.get_zero_value()?,
|
||||
vertical: self.vertical.get_zero_value()?,
|
||||
blur: self.blur.get_zero_value()?,
|
||||
})
|
||||
}
|
||||
|
||||
#[inline]
|
||||
fn compute_distance(&self, other: &Self) -> Result<f64, ()> {
|
||||
self.compute_squared_distance(other).map(|sd| sd.sqrt())
|
||||
|
@ -229,3 +235,15 @@ impl Animatable for SimpleShadow {
|
|||
)
|
||||
}
|
||||
}
|
||||
|
||||
impl ToAnimatedZero for SimpleShadow {
|
||||
#[inline]
|
||||
fn to_animated_zero(&self) -> Result<Self, ()> {
|
||||
Ok(SimpleShadow {
|
||||
color: IntermediateColor::transparent(),
|
||||
horizontal: self.horizontal.to_animated_zero()?,
|
||||
vertical: self.vertical.to_animated_zero()?,
|
||||
blur: self.blur.to_animated_zero()?,
|
||||
})
|
||||
}
|
||||
}
|
||||
|
|
|
@ -88,3 +88,34 @@ where
|
|||
}
|
||||
}
|
||||
|
||||
/// Returns a value similar to `self` that represents zero.
|
||||
pub trait ToAnimatedZero: Sized {
|
||||
/// Returns a value that, when added with an underlying value, will produce the underlying
|
||||
/// value. This is used for SMIL animation's "by-animation" where SMIL first interpolates from
|
||||
/// the zero value to the 'by' value, and then adds the result to the underlying value.
|
||||
///
|
||||
/// This is not the necessarily the same as the initial value of a property. For example, the
|
||||
/// initial value of 'stroke-width' is 1, but the zero value is 0, since adding 1 to the
|
||||
/// underlying value will not produce the underlying value.
|
||||
fn to_animated_zero(&self) -> Result<Self, ()>;
|
||||
}
|
||||
|
||||
impl ToAnimatedZero for Au {
|
||||
#[inline]
|
||||
fn to_animated_zero(&self) -> Result<Self, ()> { Ok(Au(0)) }
|
||||
}
|
||||
|
||||
impl ToAnimatedZero for f32 {
|
||||
#[inline]
|
||||
fn to_animated_zero(&self) -> Result<Self, ()> { Ok(0.) }
|
||||
}
|
||||
|
||||
impl ToAnimatedZero for f64 {
|
||||
#[inline]
|
||||
fn to_animated_zero(&self) -> Result<Self, ()> { Ok(0.) }
|
||||
}
|
||||
|
||||
impl ToAnimatedZero for i32 {
|
||||
#[inline]
|
||||
fn to_animated_zero(&self) -> Result<Self, ()> { Ok(0) }
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue