mirror of
https://github.com/servo/servo.git
synced 2025-08-09 07:25:35 +01:00
Introduce values::animated::Animate
This replaces the Animatable trait and merges its three former methods into a single one.
This commit is contained in:
parent
0cceeb9d5c
commit
aea0cd7ec7
23 changed files with 876 additions and 937 deletions
|
@ -5,10 +5,9 @@
|
|||
//! CSS handling for the [`basic-shape`](https://drafts.csswg.org/css-shapes/#typedef-basic-shape)
|
||||
//! types that are generic over their `ToCss` implementations.
|
||||
|
||||
use properties::animated_properties::Animatable;
|
||||
use std::fmt;
|
||||
use style_traits::{HasViewportPercentage, ToCss};
|
||||
use values::animated::ToAnimatedZero;
|
||||
use values::animated::{Animate, Procedure, ToAnimatedZero};
|
||||
use values::computed::ComputedValueAsSpecified;
|
||||
use values::distance::{ComputeSquaredDistance, SquaredDistance};
|
||||
use values::generics::border::BorderRadius;
|
||||
|
@ -123,24 +122,21 @@ define_css_keyword_enum!(FillRule:
|
|||
);
|
||||
add_impls_for_keyword_enum!(FillRule);
|
||||
|
||||
impl<B, T, U> Animatable for ShapeSource<B, T, U>
|
||||
impl<B, T, U> Animate for ShapeSource<B, T, U>
|
||||
where
|
||||
B: Animatable,
|
||||
B: Animate,
|
||||
T: Clone + PartialEq,
|
||||
{
|
||||
fn add_weighted(
|
||||
&self,
|
||||
other: &Self,
|
||||
self_portion: f64,
|
||||
other_portion: f64,
|
||||
) -> Result<Self, ()> {
|
||||
fn animate(&self, other: &Self, procedure: Procedure) -> Result<Self, ()> {
|
||||
match (self, other) {
|
||||
(
|
||||
&ShapeSource::Shape(ref this, ref this_box),
|
||||
&ShapeSource::Shape(ref other, ref other_box),
|
||||
) if this_box == other_box => {
|
||||
let shape = this.add_weighted(other, self_portion, other_portion)?;
|
||||
Ok(ShapeSource::Shape(shape, this_box.clone()))
|
||||
Ok(ShapeSource::Shape(
|
||||
this.animate(other, procedure)?,
|
||||
this_box.clone(),
|
||||
))
|
||||
},
|
||||
_ => Err(()),
|
||||
}
|
||||
|
@ -178,49 +174,40 @@ impl<B, T, U> HasViewportPercentage for ShapeSource<B, T, U> {
|
|||
fn has_viewport_percentage(&self) -> bool { false }
|
||||
}
|
||||
|
||||
impl<H, V, L> Animatable for BasicShape<H, V, L>
|
||||
impl<H, V, L> Animate for BasicShape<H, V, L>
|
||||
where
|
||||
H: Animatable,
|
||||
V: Animatable,
|
||||
L: Animatable + Copy,
|
||||
H: Animate,
|
||||
V: Animate,
|
||||
L: Animate + Copy,
|
||||
{
|
||||
fn add_weighted(
|
||||
&self,
|
||||
other: &Self,
|
||||
self_portion: f64,
|
||||
other_portion: f64,
|
||||
) -> Result<Self, ()> {
|
||||
fn animate(&self, other: &Self, procedure: Procedure) -> Result<Self, ()> {
|
||||
match (self, other) {
|
||||
(&BasicShape::Circle(ref this), &BasicShape::Circle(ref other)) => {
|
||||
Ok(BasicShape::Circle(this.add_weighted(other, self_portion, other_portion)?))
|
||||
Ok(BasicShape::Circle(this.animate(other, procedure)?))
|
||||
},
|
||||
(&BasicShape::Ellipse(ref this), &BasicShape::Ellipse(ref other)) => {
|
||||
Ok(BasicShape::Ellipse(this.add_weighted(other, self_portion, other_portion)?))
|
||||
Ok(BasicShape::Ellipse(this.animate(other, procedure)?))
|
||||
},
|
||||
(&BasicShape::Inset(ref this), &BasicShape::Inset(ref other)) => {
|
||||
Ok(BasicShape::Inset(this.add_weighted(other, self_portion, other_portion)?))
|
||||
Ok(BasicShape::Inset(this.animate(other, procedure)?))
|
||||
},
|
||||
(&BasicShape::Polygon(ref this), &BasicShape::Polygon(ref other)) => {
|
||||
Ok(BasicShape::Polygon(this.add_weighted(other, self_portion, other_portion)?))
|
||||
Ok(BasicShape::Polygon(this.animate(other, procedure)?))
|
||||
},
|
||||
_ => Err(()),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl<L> Animatable for InsetRect<L>
|
||||
impl<L> Animate for InsetRect<L>
|
||||
where
|
||||
L: Animatable + Copy,
|
||||
L: Animate + Copy,
|
||||
{
|
||||
fn add_weighted(
|
||||
&self,
|
||||
other: &Self,
|
||||
self_portion: f64,
|
||||
other_portion: f64,
|
||||
) -> Result<Self, ()> {
|
||||
let rect = self.rect.add_weighted(&other.rect, self_portion, other_portion)?;
|
||||
let round = self.round.add_weighted(&other.round, self_portion, other_portion)?;
|
||||
Ok(InsetRect { rect, round })
|
||||
fn animate(&self, other: &Self, procedure: Procedure) -> Result<Self, ()> {
|
||||
Ok(InsetRect {
|
||||
rect: self.rect.animate(&other.rect, procedure)?,
|
||||
round: self.round.animate(&other.round, procedure)?,
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -238,56 +225,43 @@ impl<L> ToCss for InsetRect<L>
|
|||
}
|
||||
}
|
||||
|
||||
impl<H, V, L> Animatable for Circle<H, V, L>
|
||||
impl<H, V, L> Animate for Circle<H, V, L>
|
||||
where
|
||||
H: Animatable,
|
||||
V: Animatable,
|
||||
L: Animatable,
|
||||
H: Animate,
|
||||
V: Animate,
|
||||
L: Animate,
|
||||
{
|
||||
fn add_weighted(
|
||||
&self,
|
||||
other: &Self,
|
||||
self_portion: f64,
|
||||
other_portion: f64,
|
||||
) -> Result<Self, ()> {
|
||||
let position = self.position.add_weighted(&other.position, self_portion, other_portion)?;
|
||||
let radius = self.radius.add_weighted(&other.radius, self_portion, other_portion)?;
|
||||
Ok(Circle { position, radius })
|
||||
fn animate(&self, other: &Self, procedure: Procedure) -> Result<Self, ()> {
|
||||
Ok(Circle {
|
||||
position: self.position.animate(&other.position, procedure)?,
|
||||
radius: self.radius.animate(&other.radius, procedure)?,
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
impl<H, V, L> Animatable for Ellipse<H, V, L>
|
||||
impl<H, V, L> Animate for Ellipse<H, V, L>
|
||||
where
|
||||
H: Animatable,
|
||||
V: Animatable,
|
||||
L: Animatable,
|
||||
H: Animate,
|
||||
V: Animate,
|
||||
L: Animate,
|
||||
{
|
||||
fn add_weighted(
|
||||
&self,
|
||||
other: &Self,
|
||||
self_portion: f64,
|
||||
other_portion: f64,
|
||||
) -> Result<Self, ()> {
|
||||
let position = self.position.add_weighted(&other.position, self_portion, other_portion)?;
|
||||
let semiaxis_x = self.semiaxis_x.add_weighted(&other.semiaxis_x, self_portion, other_portion)?;
|
||||
let semiaxis_y = self.semiaxis_y.add_weighted(&other.semiaxis_y, self_portion, other_portion)?;
|
||||
Ok(Ellipse { position, semiaxis_x, semiaxis_y })
|
||||
fn animate(&self, other: &Self, procedure: Procedure) -> Result<Self, ()> {
|
||||
Ok(Ellipse {
|
||||
position: self.position.animate(&other.position, procedure)?,
|
||||
semiaxis_x: self.semiaxis_x.animate(&other.semiaxis_x, procedure)?,
|
||||
semiaxis_y: self.semiaxis_y.animate(&other.semiaxis_y, procedure)?,
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
impl<L> Animatable for ShapeRadius<L>
|
||||
impl<L> Animate for ShapeRadius<L>
|
||||
where
|
||||
L: Animatable,
|
||||
L: Animate,
|
||||
{
|
||||
fn add_weighted(
|
||||
&self,
|
||||
other: &Self,
|
||||
self_portion: f64,
|
||||
other_portion: f64,
|
||||
) -> Result<Self, ()> {
|
||||
fn animate(&self, other: &Self, procedure: Procedure) -> Result<Self, ()> {
|
||||
match (self, other) {
|
||||
(&ShapeRadius::Length(ref this), &ShapeRadius::Length(ref other)) => {
|
||||
Ok(ShapeRadius::Length(this.add_weighted(other, self_portion, other_portion)?))
|
||||
Ok(ShapeRadius::Length(this.animate(other, procedure)?))
|
||||
},
|
||||
_ => Err(()),
|
||||
}
|
||||
|
@ -299,16 +273,11 @@ impl<L> Default for ShapeRadius<L> {
|
|||
fn default() -> Self { ShapeRadius::ClosestSide }
|
||||
}
|
||||
|
||||
impl<L> Animatable for Polygon<L>
|
||||
impl<L> Animate for Polygon<L>
|
||||
where
|
||||
L: Animatable,
|
||||
L: Animate,
|
||||
{
|
||||
fn add_weighted(
|
||||
&self,
|
||||
other: &Self,
|
||||
self_portion: f64,
|
||||
other_portion: f64,
|
||||
) -> Result<Self, ()> {
|
||||
fn animate(&self, other: &Self, procedure: Procedure) -> Result<Self, ()> {
|
||||
if self.fill != other.fill {
|
||||
return Err(());
|
||||
}
|
||||
|
@ -316,9 +285,10 @@ where
|
|||
return Err(());
|
||||
}
|
||||
let coordinates = self.coordinates.iter().zip(other.coordinates.iter()).map(|(this, other)| {
|
||||
let x = this.0.add_weighted(&other.0, self_portion, other_portion)?;
|
||||
let y = this.1.add_weighted(&other.1, self_portion, other_portion)?;
|
||||
Ok((x, y))
|
||||
Ok((
|
||||
this.0.animate(&other.0, procedure)?,
|
||||
this.1.animate(&other.1, procedure)?,
|
||||
))
|
||||
}).collect::<Result<Vec<_>, _>>()?;
|
||||
Ok(Polygon { fill: self.fill, coordinates })
|
||||
}
|
||||
|
|
|
@ -5,9 +5,9 @@
|
|||
//! Generic types for CSS values related to borders.
|
||||
|
||||
use euclid::Size2D;
|
||||
use properties::animated_properties::Animatable;
|
||||
use std::fmt;
|
||||
use style_traits::ToCss;
|
||||
use values::animated::{Animate, Procedure};
|
||||
use values::generics::rect::Rect;
|
||||
|
||||
/// A generic value for a single side of a `border-image-width` property.
|
||||
|
@ -113,21 +113,17 @@ impl<L> BorderRadius<L>
|
|||
}
|
||||
}
|
||||
|
||||
impl<L> Animatable for BorderRadius<L>
|
||||
impl<L> Animate for BorderRadius<L>
|
||||
where
|
||||
L: Animatable + Copy,
|
||||
L: Animate + Copy,
|
||||
{
|
||||
fn add_weighted(
|
||||
&self,
|
||||
other: &Self,
|
||||
self_portion: f64,
|
||||
other_portion: f64,
|
||||
) -> Result<Self, ()> {
|
||||
let tl = self.top_left.add_weighted(&other.top_left, self_portion, other_portion)?;
|
||||
let tr = self.top_right.add_weighted(&other.top_right, self_portion, other_portion)?;
|
||||
let br = self.bottom_right.add_weighted(&other.bottom_right, self_portion, other_portion)?;
|
||||
let bl = self.bottom_left.add_weighted(&other.bottom_left, self_portion, other_portion)?;
|
||||
Ok(BorderRadius::new(tl, tr, br, bl))
|
||||
fn animate(&self, other: &Self, procedure: Procedure) -> Result<Self, ()> {
|
||||
Ok(BorderRadius::new(
|
||||
self.top_left.animate(&other.top_left, procedure)?,
|
||||
self.top_right.animate(&other.top_right, procedure)?,
|
||||
self.bottom_right.animate(&other.bottom_right, procedure)?,
|
||||
self.bottom_left.animate(&other.bottom_left, procedure)?,
|
||||
))
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -163,18 +159,13 @@ impl<L: Clone> From<L> for BorderCornerRadius<L> {
|
|||
}
|
||||
}
|
||||
|
||||
impl<L> Animatable for BorderCornerRadius<L>
|
||||
impl<L> Animate for BorderCornerRadius<L>
|
||||
where
|
||||
L: Animatable + Copy,
|
||||
L: Animate + Copy,
|
||||
{
|
||||
#[inline]
|
||||
fn add_weighted(
|
||||
&self,
|
||||
other: &Self,
|
||||
self_portion: f64,
|
||||
other_portion: f64,
|
||||
) -> Result<Self, ()> {
|
||||
Ok(BorderCornerRadius(self.0.add_weighted(&other.0, self_portion, other_portion)?))
|
||||
fn animate(&self, other: &Self, procedure: Procedure) -> Result<Self, ()> {
|
||||
Ok(BorderCornerRadius(self.0.animate(&other.0, procedure)?))
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -6,9 +6,9 @@
|
|||
|
||||
use cssparser::Parser;
|
||||
use parser::{Parse, ParserContext};
|
||||
use properties::animated_properties::Animatable;
|
||||
use std::fmt;
|
||||
use style_traits::{ToCss, ParseError};
|
||||
use values::animated::{Animate, Procedure};
|
||||
|
||||
/// A CSS value made of four components, where its `ToCss` impl will try to
|
||||
/// serialize as few components as possible, like for example in `border-width`.
|
||||
|
@ -52,21 +52,17 @@ impl<T> Rect<T>
|
|||
}
|
||||
}
|
||||
|
||||
impl<L> Animatable for Rect<L>
|
||||
impl<L> Animate for Rect<L>
|
||||
where
|
||||
L: Animatable,
|
||||
L: Animate,
|
||||
{
|
||||
fn add_weighted(
|
||||
&self,
|
||||
other: &Self,
|
||||
self_portion: f64,
|
||||
other_portion: f64,
|
||||
) -> Result<Self, ()> {
|
||||
let first = self.0.add_weighted(&other.0, self_portion, other_portion)?;
|
||||
let second = self.1.add_weighted(&other.1, self_portion, other_portion)?;
|
||||
let third = self.2.add_weighted(&other.2, self_portion, other_portion)?;
|
||||
let fourth = self.3.add_weighted(&other.3, self_portion, other_portion)?;
|
||||
Ok(Rect(first, second, third, fourth))
|
||||
fn animate(&self, other: &Self, procedure: Procedure) -> Result<Self, ()> {
|
||||
Ok(Rect(
|
||||
self.0.animate(&other.0, procedure)?,
|
||||
self.1.animate(&other.1, procedure)?,
|
||||
self.2.animate(&other.2, procedure)?,
|
||||
self.3.animate(&other.3, procedure)?,
|
||||
))
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -7,9 +7,8 @@
|
|||
use app_units::Au;
|
||||
use cssparser::Parser;
|
||||
use parser::ParserContext;
|
||||
use properties::animated_properties::Animatable;
|
||||
use style_traits::ParseError;
|
||||
use values::animated::ToAnimatedZero;
|
||||
use values::animated::{Animate, Procedure, ToAnimatedZero};
|
||||
use values::distance::{ComputeSquaredDistance, SquaredDistance};
|
||||
|
||||
/// A generic value for the `initial-letter` property.
|
||||
|
@ -72,18 +71,19 @@ impl<Value> Spacing<Value> {
|
|||
}
|
||||
}
|
||||
|
||||
impl<Value> Animatable for Spacing<Value>
|
||||
where Value: Animatable + From<Au>,
|
||||
impl<Value> Animate for Spacing<Value>
|
||||
where
|
||||
Value: Animate + From<Au>,
|
||||
{
|
||||
#[inline]
|
||||
fn add_weighted(&self, other: &Self, self_portion: f64, other_portion: f64) -> Result<Self, ()> {
|
||||
fn animate(&self, other: &Self, procedure: Procedure) -> Result<Self, ()> {
|
||||
if let (&Spacing::Normal, &Spacing::Normal) = (self, other) {
|
||||
return Ok(Spacing::Normal);
|
||||
}
|
||||
let zero = Value::from(Au(0));
|
||||
let this = self.value().unwrap_or(&zero);
|
||||
let other = other.value().unwrap_or(&zero);
|
||||
this.add_weighted(other, self_portion, other_portion).map(Spacing::Value)
|
||||
Ok(Spacing::Value(this.animate(other, procedure)?))
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue