mirror of
https://github.com/servo/servo.git
synced 2025-08-03 12:40:06 +01:00
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:
parent
18c72ac28d
commit
f6d09a39f8
2 changed files with 17 additions and 52 deletions
|
@ -33,9 +33,9 @@ use std::fmt;
|
|||
use style_traits::ToCss;
|
||||
use super::ComputedValues;
|
||||
use values::CSSFloat;
|
||||
use values::{Auto, Either, Normal, generics};
|
||||
use values::{Auto, Either, generics};
|
||||
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::{MaxLength, MinLength};
|
||||
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>
|
||||
where T: Interpolate,
|
||||
{
|
||||
|
@ -1108,16 +1094,6 @@ impl Interpolate for ClipRect {
|
|||
${impl_interpolate_for_shadow('BoxShadow', '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
|
||||
/// between these two transform lists.
|
||||
/// 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>
|
||||
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 {
|
||||
#[inline]
|
||||
fn compute_distance(&self, other: &Self) -> Result<f64, ()> {
|
||||
|
|
|
@ -11,6 +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 std::ascii::AsciiExt;
|
||||
use std::borrow::Cow;
|
||||
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 {
|
||||
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
||||
write!(f, $css)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue