Merge ComputeDistance trait into Animatable trait

This commit is contained in:
Brian Birtles 2017-05-10 14:41:26 +09:00
parent 4d25e87ac6
commit 6dfc1d1aa8
10 changed files with 481 additions and 684 deletions

View file

@ -116,10 +116,7 @@
fn interpolate(&self, other: &Self, progress: f64) -> Result<Self, ()> { fn interpolate(&self, other: &Self, progress: f64) -> Result<Self, ()> {
self.0.interpolate(&other.0, progress).map(T) self.0.interpolate(&other.0, progress).map(T)
} }
}
use properties::animated_properties::ComputeDistance;
impl ComputeDistance for T {
#[inline] #[inline]
fn compute_distance(&self, other: &Self) -> Result<f64, ()> { fn compute_distance(&self, other: &Self) -> Result<f64, ()> {
self.0.compute_distance(&other.0) self.0.compute_distance(&other.0)
@ -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] #[inline]
fn compute_distance(&self, other: &Self) -> Result<f64, ()> { fn compute_distance(&self, other: &Self) -> Result<f64, ()> {
match (self, other) { match (self, other) {

File diff suppressed because it is too large Load diff

View file

@ -195,8 +195,7 @@ ${helpers.single_keyword("background-origin",
#[allow(missing_docs)] #[allow(missing_docs)]
pub mod computed_value { pub mod computed_value {
use values::computed::LengthOrPercentageOrAuto; use values::computed::LengthOrPercentageOrAuto;
use properties::animated_properties::{Animatable, ComputeDistance, use properties::animated_properties::{Animatable, RepeatableListAnimatable};
RepeatableListAnimatable};
#[derive(PartialEq, Clone, Debug)] #[derive(PartialEq, Clone, Debug)]
#[cfg_attr(feature = "servo", derive(HeapSizeOf))] #[cfg_attr(feature = "servo", derive(HeapSizeOf))]
@ -228,9 +227,7 @@ ${helpers.single_keyword("background-origin",
_ => Err(()), _ => Err(()),
} }
} }
}
impl ComputeDistance for T {
#[inline] #[inline]
fn compute_distance(&self, other: &Self) -> Result<f64, ()> { fn compute_distance(&self, other: &Self) -> Result<f64, ()> {
self.compute_squared_distance(other).map(|sd| sd.sqrt()) self.compute_squared_distance(other).map(|sd| sd.sqrt())

View file

@ -2181,7 +2181,7 @@ ${helpers.single_keyword("transform-style",
use values::specified::{NoCalcLength, LengthOrPercentage, Percentage}; use values::specified::{NoCalcLength, LengthOrPercentage, Percentage};
pub mod computed_value { pub mod computed_value {
use properties::animated_properties::{Animatable, ComputeDistance}; use properties::animated_properties::Animatable;
use values::computed::{Length, LengthOrPercentage}; use values::computed::{Length, LengthOrPercentage};
#[derive(Clone, Copy, Debug, PartialEq)] #[derive(Clone, Copy, Debug, PartialEq)]
@ -2201,9 +2201,7 @@ ${helpers.single_keyword("transform-style",
depth: try!(self.depth.interpolate(&other.depth, time)), depth: try!(self.depth.interpolate(&other.depth, time)),
}) })
} }
}
impl ComputeDistance for T {
#[inline] #[inline]
fn compute_distance(&self, other: &Self) -> Result<f64, ()> { fn compute_distance(&self, other: &Self) -> Result<f64, ()> {
self.compute_squared_distance(other).map(|sd| sd.sqrt()) self.compute_squared_distance(other).map(|sd| sd.sqrt())

View file

@ -1022,7 +1022,7 @@ ${helpers.single_keyword_system("font-variant-caps",
} }
pub mod computed_value { pub mod computed_value {
use properties::animated_properties::{Animatable, ComputeDistance}; use properties::animated_properties::Animatable;
use std::fmt; use std::fmt;
use style_traits::ToCss; use style_traits::ToCss;
use values::CSSFloat; use values::CSSFloat;
@ -1062,9 +1062,7 @@ ${helpers.single_keyword_system("font-variant-caps",
_ => Err(()), _ => Err(()),
} }
} }
}
impl ComputeDistance for T {
#[inline] #[inline]
fn compute_distance(&self, other: &Self) -> Result<f64, ()> { fn compute_distance(&self, other: &Self) -> Result<f64, ()> {
match (*self, *other) { match (*self, *other) {

View file

@ -30,7 +30,7 @@ ${helpers.single_keyword("caption-side", "top bottom",
pub mod computed_value { pub mod computed_value {
use app_units::Au; use app_units::Au;
use properties::animated_properties::{Animatable, ComputeDistance}; use properties::animated_properties::Animatable;
#[derive(Clone, Copy, Debug, PartialEq)] #[derive(Clone, Copy, Debug, PartialEq)]
#[cfg_attr(feature = "servo", derive(HeapSizeOf))] #[cfg_attr(feature = "servo", derive(HeapSizeOf))]
@ -48,9 +48,7 @@ ${helpers.single_keyword("caption-side", "top bottom",
vertical: try!(self.vertical.interpolate(&other.vertical, time)), vertical: try!(self.vertical.interpolate(&other.vertical, time)),
}) })
} }
}
impl ComputeDistance for T {
#[inline] #[inline]
fn compute_distance(&self, other: &Self) -> Result<f64, ()> { fn compute_distance(&self, other: &Self) -> Result<f64, ()> {
self.compute_squared_distance(other).map(|sd| sd.sqrt()) self.compute_squared_distance(other).map(|sd| sd.sqrt())

View file

@ -441,14 +441,13 @@ ${helpers.single_keyword("text-align-last",
pub mod computed_value { pub mod computed_value {
use app_units::Au; use app_units::Au;
use properties::animated_properties::{Animatable, ComputeDistance}; use properties::animated_properties::Animatable;
#[derive(Debug, Clone, PartialEq)] #[derive(Debug, Clone, PartialEq)]
#[cfg_attr(feature = "servo", derive(HeapSizeOf))] #[cfg_attr(feature = "servo", derive(HeapSizeOf))]
pub struct T(pub Option<Au>); pub struct T(pub Option<Au>);
${helpers.impl_animatable_for_option_tuple('Au(0)')} ${helpers.impl_animatable_for_option_tuple('Au(0)')}
${helpers.impl_compute_distance_for_option_tuple('Au(0)')}
} }
impl ToCss for computed_value::T { impl ToCss for computed_value::T {
@ -527,14 +526,13 @@ ${helpers.single_keyword("text-align-last",
} }
pub mod computed_value { pub mod computed_value {
use properties::animated_properties::{ComputeDistance, Animatable}; use properties::animated_properties::Animatable;
use values::computed::LengthOrPercentage; use values::computed::LengthOrPercentage;
#[derive(Debug, Clone, PartialEq)] #[derive(Debug, Clone, PartialEq)]
#[cfg_attr(feature = "servo", derive(HeapSizeOf))] #[cfg_attr(feature = "servo", derive(HeapSizeOf))]
pub struct T(pub Option<LengthOrPercentage>); pub struct T(pub Option<LengthOrPercentage>);
${helpers.impl_animatable_for_option_tuple('LengthOrPercentage::zero()')} ${helpers.impl_animatable_for_option_tuple('LengthOrPercentage::zero()')}
${helpers.impl_compute_distance_for_option_tuple('LengthOrPercentage::zero()')}
} }
impl ToCss for computed_value::T { impl ToCss for computed_value::T {

View file

@ -99,7 +99,7 @@ ${helpers.single_keyword("mask-mode",
pub use properties::longhands::background_position_x::single_value::parse; 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::SpecifiedValue;
pub use properties::longhands::background_position_x::single_value::computed_value; pub use properties::longhands::background_position_x::single_value::computed_value;
use properties::animated_properties::{Animatable, ComputeDistance, RepeatableListAnimatable}; use properties::animated_properties::{Animatable, RepeatableListAnimatable};
use properties::longhands::mask_position_x::computed_value::T as MaskPositionX; use properties::longhands::mask_position_x::computed_value::T as MaskPositionX;
impl Animatable for MaskPositionX { impl Animatable for MaskPositionX {
@ -110,13 +110,6 @@ ${helpers.single_keyword("mask-mode",
} }
impl RepeatableListAnimatable for MaskPositionX {} impl RepeatableListAnimatable for MaskPositionX {}
impl ComputeDistance for MaskPositionX {
#[inline]
fn compute_distance(&self, _other: &Self) -> Result<f64, ()> {
Err(())
}
}
</%helpers:vector_longhand> </%helpers:vector_longhand>
<%helpers:vector_longhand name="mask-position-y" products="gecko" <%helpers:vector_longhand name="mask-position-y" products="gecko"
@ -128,7 +121,7 @@ ${helpers.single_keyword("mask-mode",
pub use properties::longhands::background_position_y::single_value::parse; 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::SpecifiedValue;
pub use properties::longhands::background_position_y::single_value::computed_value; pub use properties::longhands::background_position_y::single_value::computed_value;
use properties::animated_properties::{Animatable, ComputeDistance, RepeatableListAnimatable}; use properties::animated_properties::{Animatable, RepeatableListAnimatable};
use properties::longhands::mask_position_y::computed_value::T as MaskPositionY; use properties::longhands::mask_position_y::computed_value::T as MaskPositionY;
impl Animatable for MaskPositionY { impl Animatable for MaskPositionY {
@ -139,13 +132,6 @@ ${helpers.single_keyword("mask-mode",
} }
impl RepeatableListAnimatable for MaskPositionY {} impl RepeatableListAnimatable for MaskPositionY {}
impl ComputeDistance for MaskPositionY {
#[inline]
fn compute_distance(&self, _other: &Self) -> Result<f64, ()> {
Err(())
}
}
</%helpers:vector_longhand> </%helpers:vector_longhand>
${helpers.single_keyword("mask-clip", ${helpers.single_keyword("mask-clip",

View file

@ -11,7 +11,7 @@
use Atom; use Atom;
pub use cssparser::{RGBA, Token, Parser, serialize_identifier, serialize_string}; pub use cssparser::{RGBA, Token, Parser, serialize_identifier, serialize_string};
use parser::{Parse, ParserContext}; use parser::{Parse, ParserContext};
use properties::animated_properties::{Animatable, ComputeDistance}; use properties::animated_properties::Animatable;
use std::ascii::AsciiExt; use std::ascii::AsciiExt;
use std::borrow::Cow; use std::borrow::Cow;
use std::fmt::{self, Debug}; use std::fmt::{self, Debug};
@ -134,13 +134,6 @@ macro_rules! define_keyword_type {
} }
} }
impl ComputeDistance for $name {
#[inline]
fn compute_distance(&self, _other: &Self) -> Result<f64, ()> {
Err(())
}
}
impl fmt::Debug for $name { impl fmt::Debug for $name {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
write!(f, $css) write!(f, $css)

View file

@ -75,7 +75,7 @@ use style::parser::{LengthParsingMode, ParserContext};
use style::properties::{CascadeFlags, ComputedValues, Importance, ParsedDeclaration, StyleBuilder}; use style::properties::{CascadeFlags, ComputedValues, Importance, ParsedDeclaration, StyleBuilder};
use style::properties::{PropertyDeclarationBlock, PropertyId}; use style::properties::{PropertyDeclarationBlock, PropertyId};
use style::properties::SKIP_ROOT_AND_ITEM_BASED_DISPLAY_FIXUP; use style::properties::SKIP_ROOT_AND_ITEM_BASED_DISPLAY_FIXUP;
use style::properties::animated_properties::{Animatable, AnimationValue, ComputeDistance, TransitionProperty}; use style::properties::animated_properties::{Animatable, AnimationValue, TransitionProperty};
use style::properties::parse_one_declaration; use style::properties::parse_one_declaration;
use style::restyle_hints::{self, RestyleHint}; use style::restyle_hints::{self, RestyleHint};
use style::rule_tree::{StrongRuleNode, StyleSource}; use style::rule_tree::{StrongRuleNode, StyleSource};