mirror of
https://github.com/servo/servo.git
synced 2025-08-03 04:30:10 +01:00
Auto merge of #16792 - birtles:make-animatable-trait, r=hiro
Combine ComputeDuration and Interpolate into a single trait Pull request for [Gecko bug 1363573](https://bugzilla.mozilla.org/show_bug.cgi?id=1363573) The pull request has been reviewed by @hiikezoe --- - [X] `./mach build -d` does not report any errors - [X] `./mach test-tidy` does not report any errors - [X] There are tests for these changes in Gecko <!-- Reviewable:start --> --- This change is [<img src="https://reviewable.io/review_button.svg" height="34" align="absmiddle" alt="Reviewable"/>](https://reviewable.io/reviews/servo/servo/16792) <!-- Reviewable:end -->
This commit is contained in:
commit
0040160b38
11 changed files with 559 additions and 761 deletions
|
@ -111,15 +111,12 @@
|
|||
pub struct T(pub SmallVec<[single_value::T; 1]>);
|
||||
|
||||
% if delegate_animate:
|
||||
use properties::animated_properties::Interpolate;
|
||||
impl Interpolate for T {
|
||||
use properties::animated_properties::Animatable;
|
||||
impl Animatable for T {
|
||||
fn interpolate(&self, other: &Self, progress: f64) -> Result<Self, ()> {
|
||||
self.0.interpolate(&other.0, progress).map(T)
|
||||
}
|
||||
}
|
||||
|
||||
use properties::animated_properties::ComputeDistance;
|
||||
impl ComputeDistance for T {
|
||||
#[inline]
|
||||
fn compute_distance(&self, other: &Self) -> Result<f64, ()> {
|
||||
self.0.compute_distance(&other.0)
|
||||
|
@ -974,10 +971,10 @@
|
|||
%>
|
||||
</%def>
|
||||
|
||||
/// Macro for defining Interpolate trait for tuple struct which has Option<T>,
|
||||
/// Macro for defining Animatable trait for tuple struct which has Option<T>,
|
||||
/// e.g. struct T(pub Option<Au>).
|
||||
<%def name="impl_interpolate_for_option_tuple(value_for_none)">
|
||||
impl Interpolate for T {
|
||||
<%def name="impl_animatable_for_option_tuple(value_for_none)">
|
||||
impl Animatable for T {
|
||||
#[inline]
|
||||
fn interpolate(&self, other: &Self, progress: f64) -> Result<Self, ()> {
|
||||
match (self, other) {
|
||||
|
@ -995,13 +992,7 @@
|
|||
},
|
||||
}
|
||||
}
|
||||
}
|
||||
</%def>
|
||||
|
||||
/// Macro for defining ComputeDistance trait for tuple struct which has Option<T>,
|
||||
/// e.g. struct T(pub Option<Au>).
|
||||
<%def name="impl_compute_distance_for_option_tuple(value_for_none)">
|
||||
impl ComputeDistance for T {
|
||||
#[inline]
|
||||
fn compute_distance(&self, other: &Self) -> Result<f64, ()> {
|
||||
match (self, other) {
|
||||
|
|
File diff suppressed because it is too large
Load diff
|
@ -195,7 +195,7 @@ ${helpers.single_keyword("background-origin",
|
|||
#[allow(missing_docs)]
|
||||
pub mod computed_value {
|
||||
use values::computed::LengthOrPercentageOrAuto;
|
||||
use properties::animated_properties::{ComputeDistance, Interpolate, RepeatableListInterpolate};
|
||||
use properties::animated_properties::{Animatable, RepeatableListAnimatable};
|
||||
|
||||
#[derive(PartialEq, Clone, Debug)]
|
||||
#[cfg_attr(feature = "servo", derive(HeapSizeOf))]
|
||||
|
@ -212,9 +212,9 @@ ${helpers.single_keyword("background-origin",
|
|||
Contain,
|
||||
}
|
||||
|
||||
impl RepeatableListInterpolate for T {}
|
||||
impl RepeatableListAnimatable for T {}
|
||||
|
||||
impl Interpolate for T {
|
||||
impl Animatable for T {
|
||||
fn interpolate(&self, other: &Self, time: f64) -> Result<Self, ()> {
|
||||
use properties::longhands::background_size::single_value::computed_value::ExplicitSize;
|
||||
match (self, other) {
|
||||
|
@ -227,9 +227,7 @@ ${helpers.single_keyword("background-origin",
|
|||
_ => Err(()),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl ComputeDistance for T {
|
||||
#[inline]
|
||||
fn compute_distance(&self, other: &Self) -> Result<f64, ()> {
|
||||
self.compute_squared_distance(other).map(|sd| sd.sqrt())
|
||||
|
|
|
@ -2181,7 +2181,7 @@ ${helpers.single_keyword("transform-style",
|
|||
use values::specified::{NoCalcLength, LengthOrPercentage, Percentage};
|
||||
|
||||
pub mod computed_value {
|
||||
use properties::animated_properties::{ComputeDistance, Interpolate};
|
||||
use properties::animated_properties::Animatable;
|
||||
use values::computed::{Length, LengthOrPercentage};
|
||||
|
||||
#[derive(Clone, Copy, Debug, PartialEq)]
|
||||
|
@ -2192,7 +2192,7 @@ ${helpers.single_keyword("transform-style",
|
|||
pub depth: Length,
|
||||
}
|
||||
|
||||
impl Interpolate for T {
|
||||
impl Animatable for T {
|
||||
#[inline]
|
||||
fn interpolate(&self, other: &Self, time: f64) -> Result<Self, ()> {
|
||||
Ok(T {
|
||||
|
@ -2201,9 +2201,7 @@ ${helpers.single_keyword("transform-style",
|
|||
depth: try!(self.depth.interpolate(&other.depth, time)),
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
impl ComputeDistance for T {
|
||||
#[inline]
|
||||
fn compute_distance(&self, other: &Self) -> Result<f64, ()> {
|
||||
self.compute_squared_distance(other).map(|sd| sd.sqrt())
|
||||
|
|
|
@ -1022,7 +1022,7 @@ ${helpers.single_keyword_system("font-variant-caps",
|
|||
}
|
||||
|
||||
pub mod computed_value {
|
||||
use properties::animated_properties::{ComputeDistance, Interpolate};
|
||||
use properties::animated_properties::Animatable;
|
||||
use std::fmt;
|
||||
use style_traits::ToCss;
|
||||
use values::CSSFloat;
|
||||
|
@ -1054,7 +1054,7 @@ ${helpers.single_keyword_system("font-variant-caps",
|
|||
}
|
||||
}
|
||||
|
||||
impl Interpolate for T {
|
||||
impl Animatable for T {
|
||||
fn interpolate(&self, other: &Self, time: f64) -> Result<Self, ()> {
|
||||
match (*self, *other) {
|
||||
(T::Number(ref number), T::Number(ref other)) =>
|
||||
|
@ -1062,9 +1062,7 @@ ${helpers.single_keyword_system("font-variant-caps",
|
|||
_ => Err(()),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl ComputeDistance for T {
|
||||
#[inline]
|
||||
fn compute_distance(&self, other: &Self) -> Result<f64, ()> {
|
||||
match (*self, *other) {
|
||||
|
|
|
@ -30,7 +30,7 @@ ${helpers.single_keyword("caption-side", "top bottom",
|
|||
|
||||
pub mod computed_value {
|
||||
use app_units::Au;
|
||||
use properties::animated_properties::{ComputeDistance, Interpolate};
|
||||
use properties::animated_properties::Animatable;
|
||||
|
||||
#[derive(Clone, Copy, Debug, PartialEq)]
|
||||
#[cfg_attr(feature = "servo", derive(HeapSizeOf))]
|
||||
|
@ -40,7 +40,7 @@ ${helpers.single_keyword("caption-side", "top bottom",
|
|||
}
|
||||
|
||||
/// https://drafts.csswg.org/css-transitions/#animtype-simple-list
|
||||
impl Interpolate for T {
|
||||
impl Animatable for T {
|
||||
#[inline]
|
||||
fn interpolate(&self, other: &Self, time: f64) -> Result<Self, ()> {
|
||||
Ok(T {
|
||||
|
@ -48,9 +48,7 @@ ${helpers.single_keyword("caption-side", "top bottom",
|
|||
vertical: try!(self.vertical.interpolate(&other.vertical, time)),
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
impl ComputeDistance for T {
|
||||
#[inline]
|
||||
fn compute_distance(&self, other: &Self) -> Result<f64, ()> {
|
||||
self.compute_squared_distance(other).map(|sd| sd.sqrt())
|
||||
|
|
|
@ -441,14 +441,13 @@ ${helpers.single_keyword("text-align-last",
|
|||
|
||||
pub mod computed_value {
|
||||
use app_units::Au;
|
||||
use properties::animated_properties::{ComputeDistance, Interpolate};
|
||||
use properties::animated_properties::Animatable;
|
||||
|
||||
#[derive(Debug, Clone, PartialEq)]
|
||||
#[cfg_attr(feature = "servo", derive(HeapSizeOf))]
|
||||
pub struct T(pub Option<Au>);
|
||||
|
||||
${helpers.impl_interpolate_for_option_tuple('Au(0)')}
|
||||
${helpers.impl_compute_distance_for_option_tuple('Au(0)')}
|
||||
${helpers.impl_animatable_for_option_tuple('Au(0)')}
|
||||
}
|
||||
|
||||
impl ToCss for computed_value::T {
|
||||
|
@ -527,14 +526,13 @@ ${helpers.single_keyword("text-align-last",
|
|||
}
|
||||
|
||||
pub mod computed_value {
|
||||
use properties::animated_properties::{ComputeDistance, Interpolate};
|
||||
use properties::animated_properties::Animatable;
|
||||
use values::computed::LengthOrPercentage;
|
||||
#[derive(Debug, Clone, PartialEq)]
|
||||
#[cfg_attr(feature = "servo", derive(HeapSizeOf))]
|
||||
pub struct T(pub Option<LengthOrPercentage>);
|
||||
|
||||
${helpers.impl_interpolate_for_option_tuple('LengthOrPercentage::zero()')}
|
||||
${helpers.impl_compute_distance_for_option_tuple('LengthOrPercentage::zero()')}
|
||||
${helpers.impl_animatable_for_option_tuple('LengthOrPercentage::zero()')}
|
||||
}
|
||||
|
||||
impl ToCss for computed_value::T {
|
||||
|
|
|
@ -99,24 +99,17 @@ ${helpers.single_keyword("mask-mode",
|
|||
pub use properties::longhands::background_position_x::single_value::parse;
|
||||
pub use properties::longhands::background_position_x::single_value::SpecifiedValue;
|
||||
pub use properties::longhands::background_position_x::single_value::computed_value;
|
||||
use properties::animated_properties::{ComputeDistance, Interpolate, RepeatableListInterpolate};
|
||||
use properties::animated_properties::{Animatable, RepeatableListAnimatable};
|
||||
use properties::longhands::mask_position_x::computed_value::T as MaskPositionX;
|
||||
|
||||
impl Interpolate for MaskPositionX {
|
||||
impl Animatable for MaskPositionX {
|
||||
#[inline]
|
||||
fn interpolate(&self, other: &Self, progress: f64) -> Result<Self, ()> {
|
||||
Ok(MaskPositionX(try!(self.0.interpolate(&other.0, progress))))
|
||||
}
|
||||
}
|
||||
|
||||
impl RepeatableListInterpolate for MaskPositionX {}
|
||||
|
||||
impl ComputeDistance for MaskPositionX {
|
||||
#[inline]
|
||||
fn compute_distance(&self, _other: &Self) -> Result<f64, ()> {
|
||||
Err(())
|
||||
}
|
||||
}
|
||||
impl RepeatableListAnimatable for MaskPositionX {}
|
||||
</%helpers:vector_longhand>
|
||||
|
||||
<%helpers:vector_longhand name="mask-position-y" products="gecko"
|
||||
|
@ -128,24 +121,17 @@ ${helpers.single_keyword("mask-mode",
|
|||
pub use properties::longhands::background_position_y::single_value::parse;
|
||||
pub use properties::longhands::background_position_y::single_value::SpecifiedValue;
|
||||
pub use properties::longhands::background_position_y::single_value::computed_value;
|
||||
use properties::animated_properties::{ComputeDistance, Interpolate, RepeatableListInterpolate};
|
||||
use properties::animated_properties::{Animatable, RepeatableListAnimatable};
|
||||
use properties::longhands::mask_position_y::computed_value::T as MaskPositionY;
|
||||
|
||||
impl Interpolate for MaskPositionY {
|
||||
impl Animatable for MaskPositionY {
|
||||
#[inline]
|
||||
fn interpolate(&self, other: &Self, progress: f64) -> Result<Self, ()> {
|
||||
Ok(MaskPositionY(try!(self.0.interpolate(&other.0, progress))))
|
||||
}
|
||||
}
|
||||
|
||||
impl RepeatableListInterpolate for MaskPositionY {}
|
||||
|
||||
impl ComputeDistance for MaskPositionY {
|
||||
#[inline]
|
||||
fn compute_distance(&self, _other: &Self) -> Result<f64, ()> {
|
||||
Err(())
|
||||
}
|
||||
}
|
||||
impl RepeatableListAnimatable for MaskPositionY {}
|
||||
</%helpers:vector_longhand>
|
||||
|
||||
${helpers.single_keyword("mask-clip",
|
||||
|
|
|
@ -11,7 +11,7 @@
|
|||
use Atom;
|
||||
pub use cssparser::{RGBA, Token, Parser, serialize_identifier, serialize_string};
|
||||
use parser::{Parse, ParserContext};
|
||||
use properties::animated_properties::{ComputeDistance, Interpolate};
|
||||
use properties::animated_properties::Animatable;
|
||||
use std::ascii::AsciiExt;
|
||||
use std::borrow::Cow;
|
||||
use std::fmt::{self, Debug};
|
||||
|
@ -127,20 +127,13 @@ macro_rules! define_keyword_type {
|
|||
}
|
||||
}
|
||||
|
||||
impl Interpolate for $name {
|
||||
impl Animatable for $name {
|
||||
#[inline]
|
||||
fn interpolate(&self, _other: &Self, _progress: f64) -> Result<Self, ()> {
|
||||
Ok($name)
|
||||
}
|
||||
}
|
||||
|
||||
impl ComputeDistance for $name {
|
||||
#[inline]
|
||||
fn compute_distance(&self, _other: &Self) -> Result<f64, ()> {
|
||||
Err(())
|
||||
}
|
||||
}
|
||||
|
||||
impl fmt::Debug for $name {
|
||||
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
||||
write!(f, $css)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue