Move impl's into macro for macro-generated keyword types

Three keyword types are created through a macro but have some of their
impl's handled elsewhere. Since all impl's are the same, this commit
moves them into the macro to have them auto generated, for more concise
code.
This commit is contained in:
Aaron Cunningham 2017-04-26 12:38:21 -07:00
parent 18c72ac28d
commit f6d09a39f8
2 changed files with 17 additions and 52 deletions

View file

@ -33,9 +33,9 @@ use std::fmt;
use style_traits::ToCss; use style_traits::ToCss;
use super::ComputedValues; use super::ComputedValues;
use values::CSSFloat; use values::CSSFloat;
use values::{Auto, Either, Normal, generics}; use values::{Auto, Either, generics};
use values::computed::{Angle, LengthOrPercentageOrAuto, LengthOrPercentageOrNone}; use values::computed::{Angle, LengthOrPercentageOrAuto, LengthOrPercentageOrNone};
use values::computed::{BorderRadiusSize, ClipRect, LengthOrNone}; use values::computed::{BorderRadiusSize, ClipRect};
use values::computed::{CalcLengthOrPercentage, Context, LengthOrPercentage}; use values::computed::{CalcLengthOrPercentage, Context, LengthOrPercentage};
use values::computed::{MaxLength, MinLength}; use values::computed::{MaxLength, MinLength};
use values::computed::position::{HorizontalPosition, VerticalPosition}; use values::computed::position::{HorizontalPosition, VerticalPosition};
@ -628,20 +628,6 @@ impl Interpolate for Au {
} }
} }
impl Interpolate for Auto {
#[inline]
fn interpolate(&self, _other: &Self, _progress: f64) -> Result<Self, ()> {
Ok(Auto)
}
}
impl Interpolate for Normal {
#[inline]
fn interpolate(&self, _other: &Self, _progress: f64) -> Result<Self, ()> {
Ok(Normal)
}
}
impl <T> Interpolate for Option<T> impl <T> Interpolate for Option<T>
where T: Interpolate, where T: Interpolate,
{ {
@ -1108,16 +1094,6 @@ impl Interpolate for ClipRect {
${impl_interpolate_for_shadow('BoxShadow', 'CSSParserColor::RGBA(RGBA::transparent())',)} ${impl_interpolate_for_shadow('BoxShadow', 'CSSParserColor::RGBA(RGBA::transparent())',)}
${impl_interpolate_for_shadow('TextShadow', 'CSSParserColor::RGBA(RGBA::transparent())',)} ${impl_interpolate_for_shadow('TextShadow', 'CSSParserColor::RGBA(RGBA::transparent())',)}
impl Interpolate for LengthOrNone {
fn interpolate(&self, other: &Self, progress: f64) -> Result<Self, ()> {
match (*self, *other) {
(Either::First(ref length), Either::First(ref other)) =>
length.interpolate(&other, progress).map(Either::First),
_ => Err(()),
}
}
}
/// Check if it's possible to do a direct numerical interpolation /// Check if it's possible to do a direct numerical interpolation
/// between these two transform lists. /// between these two transform lists.
/// http://dev.w3.org/csswg/css-transforms/#transform-transform-animation /// http://dev.w3.org/csswg/css-transforms/#transform-transform-animation
@ -2242,20 +2218,6 @@ impl ComputeDistance for Au {
} }
} }
impl ComputeDistance for Auto {
#[inline]
fn compute_distance(&self, _other: &Self) -> Result<f64, ()> {
Err(())
}
}
impl ComputeDistance for Normal {
#[inline]
fn compute_distance(&self, _other: &Self) -> Result<f64, ()> {
Err(())
}
}
impl <T> ComputeDistance for Option<T> impl <T> ComputeDistance for Option<T>
where T: ComputeDistance, where T: ComputeDistance,
{ {
@ -2527,18 +2489,6 @@ impl ComputeDistance for LengthOrPercentageOrNone {
} }
} }
impl ComputeDistance for LengthOrNone {
#[inline]
fn compute_distance(&self, other: &Self) -> Result<f64, ()> {
match (*self, *other) {
(Either::First(ref length), Either::First(ref other)) => {
length.compute_distance(other)
},
_ => Err(()),
}
}
}
impl ComputeDistance for MinLength { impl ComputeDistance for MinLength {
#[inline] #[inline]
fn compute_distance(&self, other: &Self) -> Result<f64, ()> { fn compute_distance(&self, other: &Self) -> Result<f64, ()> {

View file

@ -11,6 +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::{ComputeDistance, Interpolate};
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};
@ -126,6 +127,20 @@ macro_rules! define_keyword_type {
} }
} }
impl Interpolate 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 { 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)