mirror of
https://github.com/servo/servo.git
synced 2025-08-03 12:40:06 +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
|
@ -112,5 +112,10 @@ macro_rules! define_keyword_type {
|
|||
impl $crate::values::computed::ComputedValueAsSpecified for $name {}
|
||||
impl $crate::values::animated::AnimatedValueAsComputed for $name {}
|
||||
no_viewport_percentage!($name);
|
||||
|
||||
impl $crate::values::animated::ToAnimatedZero for $name {
|
||||
#[inline]
|
||||
fn to_animated_zero(&self) -> Result<Self, ()> { Ok($name) }
|
||||
}
|
||||
};
|
||||
}
|
||||
|
|
|
@ -129,6 +129,8 @@
|
|||
|
||||
% if animation_value_type == "ComputedValue":
|
||||
use properties::animated_properties::Animatable;
|
||||
use values::animated::ToAnimatedZero;
|
||||
|
||||
impl Animatable for T {
|
||||
fn add_weighted(&self, other: &Self, self_portion: f64, other_portion: f64)
|
||||
-> Result<Self, ()> {
|
||||
|
@ -149,6 +151,11 @@
|
|||
self.0.compute_squared_distance(&other.0)
|
||||
}
|
||||
}
|
||||
|
||||
impl ToAnimatedZero for T {
|
||||
#[inline]
|
||||
fn to_animated_zero(&self) -> Result<Self, ()> { Err(()) }
|
||||
}
|
||||
% endif
|
||||
|
||||
pub type Iter<'a, 'cx, 'cx_a> = ComputedVecIter<'a, 'cx, 'cx_a, super::single_value::SpecifiedValue>;
|
||||
|
|
|
@ -33,7 +33,7 @@ use super::ComputedValuesInner;
|
|||
#[cfg(any(feature = "gecko", feature = "testing"))]
|
||||
use values::Auto;
|
||||
use values::{CSSFloat, CustomIdent, Either};
|
||||
use values::animated::ToAnimatedValue;
|
||||
use values::animated::{ToAnimatedValue, ToAnimatedZero};
|
||||
use values::animated::effects::BoxShadowList as AnimatedBoxShadowList;
|
||||
use values::animated::effects::Filter as AnimatedFilter;
|
||||
use values::animated::effects::FilterList as AnimatedFilterList;
|
||||
|
@ -77,16 +77,6 @@ pub trait Animatable: Sized {
|
|||
self.add_weighted(other, count as f64, 1.0)
|
||||
}
|
||||
|
||||
/// 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.
|
||||
#[inline]
|
||||
fn get_zero_value(&self) -> Result<Self, ()> { Err(()) }
|
||||
|
||||
/// Compute distance between a value and another for a given property.
|
||||
fn compute_distance(&self, _other: &Self) -> Result<f64, ()> { Err(()) }
|
||||
|
||||
|
@ -745,19 +735,6 @@ impl Animatable for AnimationValue {
|
|||
}
|
||||
}
|
||||
|
||||
fn get_zero_value(&self) -> Result<Self, ()> {
|
||||
match *self {
|
||||
% for prop in data.longhands:
|
||||
% if prop.animatable and prop.animation_value_type != "discrete":
|
||||
AnimationValue::${prop.camel_case}(ref base) => {
|
||||
Ok(AnimationValue::${prop.camel_case}(base.get_zero_value()?))
|
||||
},
|
||||
% endif
|
||||
% endfor
|
||||
_ => Err(()),
|
||||
}
|
||||
}
|
||||
|
||||
fn compute_distance(&self, other: &Self) -> Result<f64, ()> {
|
||||
match (self, other) {
|
||||
% for prop in data.longhands:
|
||||
|
@ -783,6 +760,22 @@ impl Animatable for AnimationValue {
|
|||
}
|
||||
}
|
||||
|
||||
impl ToAnimatedZero for AnimationValue {
|
||||
#[inline]
|
||||
fn to_animated_zero(&self) -> Result<Self, ()> {
|
||||
match *self {
|
||||
% for prop in data.longhands:
|
||||
% if prop.animatable and prop.animation_value_type != "discrete":
|
||||
AnimationValue::${prop.camel_case}(ref base) => {
|
||||
Ok(AnimationValue::${prop.camel_case}(base.to_animated_zero()?))
|
||||
},
|
||||
% endif
|
||||
% endfor
|
||||
_ => Err(()),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl RepeatableListAnimatable for LengthOrPercentage {}
|
||||
impl RepeatableListAnimatable for Either<f32, LengthOrPercentage> {}
|
||||
|
||||
|
@ -832,9 +825,6 @@ impl Animatable for Au {
|
|||
Ok(Au((self.0 as f64 * self_portion + other.0 as f64 * other_portion).round() as i32))
|
||||
}
|
||||
|
||||
#[inline]
|
||||
fn get_zero_value(&self) -> Result<Self, ()> { Ok(Au(0)) }
|
||||
|
||||
#[inline]
|
||||
fn compute_distance(&self, other: &Self) -> Result<f64, ()> {
|
||||
self.0.compute_distance(&other.0)
|
||||
|
@ -885,9 +875,6 @@ impl Animatable for f32 {
|
|||
Ok((*self as f64 * self_portion + *other as f64 * other_portion) as f32)
|
||||
}
|
||||
|
||||
#[inline]
|
||||
fn get_zero_value(&self) -> Result<Self, ()> { Ok(0.) }
|
||||
|
||||
#[inline]
|
||||
fn compute_distance(&self, other: &Self) -> Result<f64, ()> {
|
||||
Ok((*self - *other).abs() as f64)
|
||||
|
@ -901,9 +888,6 @@ impl Animatable for f64 {
|
|||
Ok(*self * self_portion + *other * other_portion)
|
||||
}
|
||||
|
||||
#[inline]
|
||||
fn get_zero_value(&self) -> Result<Self, ()> { Ok(0.) }
|
||||
|
||||
#[inline]
|
||||
fn compute_distance(&self, other: &Self) -> Result<f64, ()> {
|
||||
Ok((*self - *other).abs())
|
||||
|
@ -917,9 +901,6 @@ impl Animatable for i32 {
|
|||
Ok((*self as f64 * self_portion + *other as f64 * other_portion).round() as i32)
|
||||
}
|
||||
|
||||
#[inline]
|
||||
fn get_zero_value(&self) -> Result<Self, ()> { Ok(0) }
|
||||
|
||||
#[inline]
|
||||
fn compute_distance(&self, other: &Self) -> Result<f64, ()> {
|
||||
Ok((*self - *other).abs() as f64)
|
||||
|
@ -954,15 +935,19 @@ impl Animatable for Percentage {
|
|||
Ok(Percentage((self.0 as f64 * self_portion + other.0 as f64 * other_portion) as f32))
|
||||
}
|
||||
|
||||
#[inline]
|
||||
fn get_zero_value(&self) -> Result<Self, ()> { Ok(Percentage(0.)) }
|
||||
|
||||
#[inline]
|
||||
fn compute_distance(&self, other: &Self) -> Result<f64, ()> {
|
||||
Ok((self.0 as f64 - other.0 as f64).abs())
|
||||
}
|
||||
}
|
||||
|
||||
impl ToAnimatedZero for Percentage {
|
||||
#[inline]
|
||||
fn to_animated_zero(&self) -> Result<Self, ()> {
|
||||
Ok(Percentage(0.))
|
||||
}
|
||||
}
|
||||
|
||||
/// https://drafts.csswg.org/css-transitions/#animtype-visibility
|
||||
impl Animatable for Visibility {
|
||||
#[inline]
|
||||
|
@ -988,6 +973,13 @@ impl Animatable for Visibility {
|
|||
}
|
||||
}
|
||||
|
||||
impl ToAnimatedZero for Visibility {
|
||||
#[inline]
|
||||
fn to_animated_zero(&self) -> Result<Self, ()> {
|
||||
Err(())
|
||||
}
|
||||
}
|
||||
|
||||
impl<T: Animatable + Copy> Animatable for Size2D<T> {
|
||||
#[inline]
|
||||
fn add_weighted(&self, other: &Self, self_portion: f64, other_portion: f64) -> Result<Self, ()> {
|
||||
|
@ -1026,6 +1018,11 @@ impl Animatable for BorderCornerRadius {
|
|||
}
|
||||
}
|
||||
|
||||
impl ToAnimatedZero for BorderCornerRadius {
|
||||
#[inline]
|
||||
fn to_animated_zero(&self) -> Result<Self, ()> { Err(()) }
|
||||
}
|
||||
|
||||
/// https://drafts.csswg.org/css-transitions/#animtype-length
|
||||
impl Animatable for VerticalAlign {
|
||||
#[inline]
|
||||
|
@ -1053,6 +1050,11 @@ impl Animatable for VerticalAlign {
|
|||
}
|
||||
}
|
||||
|
||||
impl ToAnimatedZero for VerticalAlign {
|
||||
#[inline]
|
||||
fn to_animated_zero(&self) -> Result<Self, ()> { Err(()) }
|
||||
}
|
||||
|
||||
/// https://drafts.csswg.org/css-transitions/#animtype-lpcalc
|
||||
impl Animatable for CalcLengthOrPercentage {
|
||||
#[inline]
|
||||
|
@ -1123,11 +1125,6 @@ impl Animatable for LengthOrPercentage {
|
|||
}
|
||||
}
|
||||
|
||||
#[inline]
|
||||
fn get_zero_value(&self) -> Result<Self, ()> {
|
||||
Ok(LengthOrPercentage::zero())
|
||||
}
|
||||
|
||||
#[inline]
|
||||
fn compute_distance(&self, other: &Self) -> Result<f64, ()> {
|
||||
match (*self, *other) {
|
||||
|
@ -1171,6 +1168,13 @@ impl Animatable for LengthOrPercentage {
|
|||
}
|
||||
}
|
||||
|
||||
impl ToAnimatedZero for LengthOrPercentage {
|
||||
#[inline]
|
||||
fn to_animated_zero(&self) -> Result<Self, ()> {
|
||||
Ok(LengthOrPercentage::zero())
|
||||
}
|
||||
}
|
||||
|
||||
/// https://drafts.csswg.org/css-transitions/#animtype-lpcalc
|
||||
impl Animatable for LengthOrPercentageOrAuto {
|
||||
#[inline]
|
||||
|
@ -1200,18 +1204,6 @@ impl Animatable for LengthOrPercentageOrAuto {
|
|||
}
|
||||
}
|
||||
|
||||
#[inline]
|
||||
fn get_zero_value(&self) -> Result<Self, ()> {
|
||||
match *self {
|
||||
LengthOrPercentageOrAuto::Length(_) |
|
||||
LengthOrPercentageOrAuto::Percentage(_) |
|
||||
LengthOrPercentageOrAuto::Calc(_) => {
|
||||
Ok(LengthOrPercentageOrAuto::Length(Au(0)))
|
||||
},
|
||||
LengthOrPercentageOrAuto::Auto => Err(()),
|
||||
}
|
||||
}
|
||||
|
||||
#[inline]
|
||||
fn compute_distance(&self, other: &Self) -> Result<f64, ()> {
|
||||
match (*self, *other) {
|
||||
|
@ -1260,6 +1252,20 @@ impl Animatable for LengthOrPercentageOrAuto {
|
|||
}
|
||||
}
|
||||
|
||||
impl ToAnimatedZero for LengthOrPercentageOrAuto {
|
||||
#[inline]
|
||||
fn to_animated_zero(&self) -> Result<Self, ()> {
|
||||
match *self {
|
||||
LengthOrPercentageOrAuto::Length(_) |
|
||||
LengthOrPercentageOrAuto::Percentage(_) |
|
||||
LengthOrPercentageOrAuto::Calc(_) => {
|
||||
Ok(LengthOrPercentageOrAuto::Length(Au(0)))
|
||||
},
|
||||
LengthOrPercentageOrAuto::Auto => Err(()),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// https://drafts.csswg.org/css-transitions/#animtype-lpcalc
|
||||
impl Animatable for LengthOrPercentageOrNone {
|
||||
#[inline]
|
||||
|
@ -1289,18 +1295,6 @@ impl Animatable for LengthOrPercentageOrNone {
|
|||
}
|
||||
}
|
||||
|
||||
#[inline]
|
||||
fn get_zero_value(&self) -> Result<Self, ()> {
|
||||
match *self {
|
||||
LengthOrPercentageOrNone::Length(_) |
|
||||
LengthOrPercentageOrNone::Percentage(_) |
|
||||
LengthOrPercentageOrNone::Calc(_) => {
|
||||
Ok(LengthOrPercentageOrNone::Length(Au(0)))
|
||||
},
|
||||
LengthOrPercentageOrNone::None => Err(()),
|
||||
}
|
||||
}
|
||||
|
||||
#[inline]
|
||||
fn compute_distance(&self, other: &Self) -> Result<f64, ()> {
|
||||
match (*self, *other) {
|
||||
|
@ -1322,6 +1316,20 @@ impl Animatable for LengthOrPercentageOrNone {
|
|||
}
|
||||
}
|
||||
|
||||
impl ToAnimatedZero for LengthOrPercentageOrNone {
|
||||
#[inline]
|
||||
fn to_animated_zero(&self) -> Result<Self, ()> {
|
||||
match *self {
|
||||
LengthOrPercentageOrNone::Length(_) |
|
||||
LengthOrPercentageOrNone::Percentage(_) |
|
||||
LengthOrPercentageOrNone::Calc(_) => {
|
||||
Ok(LengthOrPercentageOrNone::Length(Au(0)))
|
||||
},
|
||||
LengthOrPercentageOrNone::None => Err(()),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// https://drafts.csswg.org/css-transitions/#animtype-lpcalc
|
||||
impl Animatable for MozLength {
|
||||
#[inline]
|
||||
|
@ -1348,6 +1356,11 @@ impl Animatable for MozLength {
|
|||
}
|
||||
}
|
||||
|
||||
impl ToAnimatedZero for MozLength {
|
||||
#[inline]
|
||||
fn to_animated_zero(&self) -> Result<Self, ()> { Err(()) }
|
||||
}
|
||||
|
||||
/// https://drafts.csswg.org/css-transitions/#animtype-lpcalc
|
||||
impl Animatable for MaxLength {
|
||||
#[inline]
|
||||
|
@ -1374,6 +1387,11 @@ impl Animatable for MaxLength {
|
|||
}
|
||||
}
|
||||
|
||||
impl ToAnimatedZero for MaxLength {
|
||||
#[inline]
|
||||
fn to_animated_zero(&self) -> Result<Self, ()> { Err(()) }
|
||||
}
|
||||
|
||||
/// http://dev.w3.org/csswg/css-transitions/#animtype-font-weight
|
||||
impl Animatable for FontWeight {
|
||||
#[inline]
|
||||
|
@ -1386,9 +1404,6 @@ impl Animatable for FontWeight {
|
|||
Ok(FontWeight(weight as u16))
|
||||
}
|
||||
|
||||
#[inline]
|
||||
fn get_zero_value(&self) -> Result<Self, ()> { Ok(FontWeight::normal()) }
|
||||
|
||||
#[inline]
|
||||
fn compute_distance(&self, other: &Self) -> Result<f64, ()> {
|
||||
let a = self.0 as f64;
|
||||
|
@ -1397,6 +1412,13 @@ impl Animatable for FontWeight {
|
|||
}
|
||||
}
|
||||
|
||||
impl ToAnimatedZero for FontWeight {
|
||||
#[inline]
|
||||
fn to_animated_zero(&self) -> Result<Self, ()> {
|
||||
Ok(FontWeight::normal())
|
||||
}
|
||||
}
|
||||
|
||||
/// https://drafts.csswg.org/css-fonts/#font-stretch-prop
|
||||
impl Animatable for FontStretch {
|
||||
#[inline]
|
||||
|
@ -1420,6 +1442,11 @@ impl Animatable for FontStretch {
|
|||
}
|
||||
}
|
||||
|
||||
impl ToAnimatedZero for FontStretch {
|
||||
#[inline]
|
||||
fn to_animated_zero(&self) -> Result<Self, ()> { Err(()) }
|
||||
}
|
||||
|
||||
/// We should treat font stretch as real number in order to interpolate this property.
|
||||
/// https://drafts.csswg.org/css-fonts-3/#font-stretch-animation
|
||||
impl From<FontStretch> for f64 {
|
||||
|
@ -1460,14 +1487,6 @@ impl<H: Animatable, V: Animatable> Animatable for generic_position::Position<H,
|
|||
})
|
||||
}
|
||||
|
||||
#[inline]
|
||||
fn get_zero_value(&self) -> Result<Self, ()> {
|
||||
Ok(generic_position::Position {
|
||||
horizontal: self.horizontal.get_zero_value()?,
|
||||
vertical: self.vertical.get_zero_value()?,
|
||||
})
|
||||
}
|
||||
|
||||
#[inline]
|
||||
fn compute_distance(&self, other: &Self) -> Result<f64, ()> {
|
||||
self.compute_squared_distance(other).map(|sd| sd.sqrt())
|
||||
|
@ -1480,6 +1499,20 @@ impl<H: Animatable, V: Animatable> Animatable for generic_position::Position<H,
|
|||
}
|
||||
}
|
||||
|
||||
impl<H, V> ToAnimatedZero for generic_position::Position<H, V>
|
||||
where
|
||||
H: ToAnimatedZero,
|
||||
V: ToAnimatedZero,
|
||||
{
|
||||
#[inline]
|
||||
fn to_animated_zero(&self) -> Result<Self, ()> {
|
||||
Ok(generic_position::Position {
|
||||
horizontal: self.horizontal.to_animated_zero()?,
|
||||
vertical: self.vertical.to_animated_zero()?,
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
impl<H, V> RepeatableListAnimatable for generic_position::Position<H, V>
|
||||
where H: RepeatableListAnimatable, V: RepeatableListAnimatable {}
|
||||
|
||||
|
@ -1513,6 +1546,11 @@ impl Animatable for ClipRect {
|
|||
}
|
||||
}
|
||||
|
||||
impl ToAnimatedZero for ClipRect {
|
||||
#[inline]
|
||||
fn to_animated_zero(&self) -> Result<Self, ()> { Err(()) }
|
||||
}
|
||||
|
||||
/// Check if it's possible to do a direct numerical interpolation
|
||||
/// between these two transform lists.
|
||||
/// http://dev.w3.org/csswg/css-transforms/#transform-transform-animation
|
||||
|
@ -2587,9 +2625,13 @@ impl Animatable for TransformList {
|
|||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl ToAnimatedZero for TransformList {
|
||||
#[inline]
|
||||
fn get_zero_value(&self) -> Result<Self, ()> { Ok(TransformList(None)) }
|
||||
fn to_animated_zero(&self) -> Result<Self, ()> {
|
||||
Ok(TransformList(None))
|
||||
}
|
||||
}
|
||||
|
||||
impl<T, U> Animatable for Either<T, U>
|
||||
|
@ -2611,18 +2653,6 @@ impl<T, U> Animatable for Either<T, U>
|
|||
}
|
||||
}
|
||||
|
||||
#[inline]
|
||||
fn get_zero_value(&self) -> Result<Self, ()> {
|
||||
match *self {
|
||||
Either::First(ref this) => {
|
||||
Ok(Either::First(this.get_zero_value()?))
|
||||
},
|
||||
Either::Second(ref this) => {
|
||||
Ok(Either::Second(this.get_zero_value()?))
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
#[inline]
|
||||
fn compute_distance(&self, other: &Self) -> Result<f64, ()> {
|
||||
match (self, other) {
|
||||
|
@ -2650,6 +2680,24 @@ impl<T, U> Animatable for Either<T, U>
|
|||
}
|
||||
}
|
||||
|
||||
impl<A, B> ToAnimatedZero for Either<A, B>
|
||||
where
|
||||
A: ToAnimatedZero,
|
||||
B: ToAnimatedZero,
|
||||
{
|
||||
#[inline]
|
||||
fn to_animated_zero(&self) -> Result<Self, ()> {
|
||||
match *self {
|
||||
Either::First(ref first) => {
|
||||
Ok(Either::First(first.to_animated_zero()?))
|
||||
},
|
||||
Either::Second(ref second) => {
|
||||
Ok(Either::Second(second.to_animated_zero()?))
|
||||
},
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Copy, Clone, Debug, PartialEq)]
|
||||
#[cfg_attr(feature = "servo", derive(HeapSizeOf))]
|
||||
/// Unlike RGBA, each component value may exceed the range [0.0, 1.0].
|
||||
|
@ -2728,11 +2776,6 @@ impl Animatable for IntermediateRGBA {
|
|||
}
|
||||
}
|
||||
|
||||
#[inline]
|
||||
fn get_zero_value(&self) -> Result<Self, ()> {
|
||||
Ok(IntermediateRGBA::transparent())
|
||||
}
|
||||
|
||||
#[inline]
|
||||
fn compute_distance(&self, other: &Self) -> Result<f64, ()> {
|
||||
self.compute_squared_distance(other).map(|sq| sq.sqrt())
|
||||
|
@ -2757,6 +2800,13 @@ impl Animatable for IntermediateRGBA {
|
|||
}
|
||||
}
|
||||
|
||||
impl ToAnimatedZero for IntermediateRGBA {
|
||||
#[inline]
|
||||
fn to_animated_zero(&self) -> Result<Self, ()> {
|
||||
Ok(IntermediateRGBA::transparent())
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Copy, Clone, Debug, PartialEq)]
|
||||
#[cfg_attr(feature = "servo", derive(HeapSizeOf))]
|
||||
#[allow(missing_docs)]
|
||||
|
@ -2895,6 +2945,11 @@ impl Animatable for IntermediateColor {
|
|||
}
|
||||
}
|
||||
|
||||
impl ToAnimatedZero for IntermediateColor {
|
||||
#[inline]
|
||||
fn to_animated_zero(&self) -> Result<Self, ()> { Err(()) }
|
||||
}
|
||||
|
||||
/// Animatable SVGPaint
|
||||
pub type IntermediateSVGPaint = SVGPaint<IntermediateRGBA>;
|
||||
|
||||
|
@ -2920,12 +2975,14 @@ impl Animatable for IntermediateSVGPaint {
|
|||
Ok(self.kind.compute_squared_distance(&other.kind)? +
|
||||
self.fallback.compute_squared_distance(&other.fallback)?)
|
||||
}
|
||||
}
|
||||
|
||||
impl ToAnimatedZero for IntermediateSVGPaint {
|
||||
#[inline]
|
||||
fn get_zero_value(&self) -> Result<Self, ()> {
|
||||
fn to_animated_zero(&self) -> Result<Self, ()> {
|
||||
Ok(IntermediateSVGPaint {
|
||||
kind: self.kind.get_zero_value()?,
|
||||
fallback: self.fallback.and_then(|v| v.get_zero_value().ok()),
|
||||
kind: self.kind.to_animated_zero()?,
|
||||
fallback: self.fallback.and_then(|v| v.to_animated_zero().ok()),
|
||||
})
|
||||
}
|
||||
}
|
||||
|
@ -2958,12 +3015,14 @@ impl Animatable for IntermediateSVGPaintKind {
|
|||
_ => Err(())
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl ToAnimatedZero for IntermediateSVGPaintKind {
|
||||
#[inline]
|
||||
fn get_zero_value(&self) -> Result<Self, ()> {
|
||||
fn to_animated_zero(&self) -> Result<Self, ()> {
|
||||
match *self {
|
||||
SVGPaintKind::Color(ref color) => {
|
||||
Ok(SVGPaintKind::Color(color.get_zero_value()?))
|
||||
Ok(SVGPaintKind::Color(color.to_animated_zero()?))
|
||||
},
|
||||
SVGPaintKind::None |
|
||||
SVGPaintKind::ContextFill |
|
||||
|
|
|
@ -1044,6 +1044,7 @@ ${helpers.single_keyword_system("font-variant-caps",
|
|||
pub mod computed_value {
|
||||
use properties::animated_properties::Animatable;
|
||||
use values::CSSFloat;
|
||||
use values::animated::ToAnimatedZero;
|
||||
|
||||
#[cfg_attr(feature = "servo", derive(HeapSizeOf))]
|
||||
#[derive(Copy, Clone, Debug, PartialEq, ToCss)]
|
||||
|
@ -1081,6 +1082,11 @@ ${helpers.single_keyword_system("font-variant-caps",
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl ToAnimatedZero for T {
|
||||
#[inline]
|
||||
fn to_animated_zero(&self) -> Result<Self, ()> { Err(()) }
|
||||
}
|
||||
}
|
||||
|
||||
#[inline]
|
||||
|
|
|
@ -28,6 +28,7 @@ ${helpers.single_keyword("caption-side", "top bottom",
|
|||
pub mod computed_value {
|
||||
use app_units::Au;
|
||||
use properties::animated_properties::Animatable;
|
||||
use values::animated::ToAnimatedZero;
|
||||
|
||||
#[cfg_attr(feature = "servo", derive(HeapSizeOf))]
|
||||
#[derive(Clone, Copy, Debug, PartialEq, ToCss)]
|
||||
|
@ -60,6 +61,11 @@ ${helpers.single_keyword("caption-side", "top bottom",
|
|||
self.vertical.compute_squared_distance(&other.vertical)?)
|
||||
}
|
||||
}
|
||||
|
||||
impl ToAnimatedZero for T {
|
||||
#[inline]
|
||||
fn to_animated_zero(&self) -> Result<Self, ()> { Err(()) }
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg_attr(feature = "servo", derive(HeapSizeOf))]
|
||||
|
|
|
@ -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) }
|
||||
}
|
||||
|
|
|
@ -5,6 +5,7 @@
|
|||
//! Computed types for CSS values related to backgrounds.
|
||||
|
||||
use properties::animated_properties::{Animatable, RepeatableListAnimatable};
|
||||
use values::animated::ToAnimatedZero;
|
||||
use values::computed::length::LengthOrPercentageOrAuto;
|
||||
use values::generics::background::BackgroundSize as GenericBackgroundSize;
|
||||
|
||||
|
@ -50,3 +51,8 @@ impl Animatable for BackgroundSize {
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl ToAnimatedZero for BackgroundSize {
|
||||
#[inline]
|
||||
fn to_animated_zero(&self) -> Result<Self, ()> { Err(()) }
|
||||
}
|
||||
|
|
|
@ -7,6 +7,7 @@
|
|||
use app_units::Au;
|
||||
use properties::animated_properties::Animatable;
|
||||
use values::{CSSInteger, CSSFloat};
|
||||
use values::animated::ToAnimatedZero;
|
||||
use values::computed::length::{Length, LengthOrPercentage};
|
||||
use values::generics::text::InitialLetter as GenericInitialLetter;
|
||||
use values::generics::text::LineHeight as GenericLineHeight;
|
||||
|
@ -61,3 +62,8 @@ impl Animatable for LineHeight {
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl ToAnimatedZero for LineHeight {
|
||||
#[inline]
|
||||
fn to_animated_zero(&self) -> Result<Self, ()> { Err(()) }
|
||||
}
|
||||
|
|
|
@ -5,6 +5,7 @@
|
|||
//! Computed types for CSS values that are related to transformations.
|
||||
|
||||
use properties::animated_properties::Animatable;
|
||||
use values::animated::ToAnimatedZero;
|
||||
use values::computed::{Length, LengthOrPercentage, Number, Percentage};
|
||||
use values::generics::transform::TimingFunction as GenericTimingFunction;
|
||||
use values::generics::transform::TransformOrigin as GenericTransformOrigin;
|
||||
|
@ -51,3 +52,14 @@ impl Animatable for TransformOrigin {
|
|||
)
|
||||
}
|
||||
}
|
||||
|
||||
impl ToAnimatedZero for TransformOrigin {
|
||||
#[inline]
|
||||
fn to_animated_zero(&self) -> Result<Self, ()> {
|
||||
Ok(Self::new(
|
||||
self.horizontal.to_animated_zero()?,
|
||||
self.vertical.to_animated_zero()?,
|
||||
self.depth.to_animated_zero()?,
|
||||
))
|
||||
}
|
||||
}
|
||||
|
|
|
@ -9,6 +9,7 @@ use cssparser::Parser;
|
|||
use parser::ParserContext;
|
||||
use properties::animated_properties::Animatable;
|
||||
use style_traits::ParseError;
|
||||
use values::animated::ToAnimatedZero;
|
||||
|
||||
/// A generic value for the `initial-letter` property.
|
||||
#[cfg_attr(feature = "servo", derive(HeapSizeOf))]
|
||||
|
@ -93,6 +94,14 @@ impl<Value> Animatable for Spacing<Value>
|
|||
}
|
||||
}
|
||||
|
||||
impl<V> ToAnimatedZero for Spacing<V>
|
||||
where
|
||||
V: From<Au>,
|
||||
{
|
||||
#[inline]
|
||||
fn to_animated_zero(&self) -> Result<Self, ()> { Err(()) }
|
||||
}
|
||||
|
||||
/// A generic value for the `line-height` property.
|
||||
#[cfg_attr(feature = "servo", derive(HeapSizeOf))]
|
||||
#[derive(Clone, Copy, Debug, HasViewportPercentage, PartialEq, ToCss)]
|
||||
|
|
|
@ -119,6 +119,7 @@ use style::traversal::{ANIMATION_ONLY, DomTraversal, FOR_CSS_RULE_CHANGES, FOR_R
|
|||
use style::traversal::{TraversalDriver, TraversalFlags, UNSTYLED_CHILDREN_ONLY};
|
||||
use style::traversal::resolve_style;
|
||||
use style::values::{CustomIdent, KeyframesName};
|
||||
use style::values::animated::ToAnimatedZero;
|
||||
use style::values::computed::Context;
|
||||
use style_traits::{PARSING_MODE_DEFAULT, ToCss};
|
||||
use super::error_reporter::ErrorReporter;
|
||||
|
@ -377,7 +378,7 @@ pub extern "C" fn Servo_AnimationValues_GetZeroValue(
|
|||
-> RawServoAnimationValueStrong
|
||||
{
|
||||
let value_to_match = AnimationValue::as_arc(&value_to_match);
|
||||
if let Ok(zero_value) = value_to_match.get_zero_value() {
|
||||
if let Ok(zero_value) = value_to_match.to_animated_zero() {
|
||||
Arc::new(zero_value).into_strong()
|
||||
} else {
|
||||
RawServoAnimationValueStrong::null()
|
||||
|
|
|
@ -4,7 +4,7 @@
|
|||
|
||||
use app_units::Au;
|
||||
use cssparser::RGBA;
|
||||
use style::properties::animated_properties::{Animatable, IntermediateRGBA};
|
||||
use style::properties::animated_properties::Animatable;
|
||||
use style::properties::longhands::transform::computed_value::ComputedOperation as TransformOperation;
|
||||
use style::properties::longhands::transform::computed_value::T as TransformList;
|
||||
use style::values::animated::ToAnimatedValue;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue