servo: Merge #16623 - Move impl's into macro for macro-generated keyword types (from aacunningham:issue-16604-define-keyword-type-modification); r=Wafflespeanut
authorAaron Cunningham <aa.cunningham@outlook.com>
Fri, 28 Apr 2017 08:09:13 -0500
changeset 355685 b2572094f9fffb71820ec50b08fde070445d0bce
parent 355684 44468104c31e97cc1604855b61fb3771df303f18
child 355686 7a15ded20926001f13ef322524a37797f77b74a4
push id89727
push userkwierso@gmail.com
push dateFri, 28 Apr 2017 23:47:07 +0000
treeherdermozilla-inbound@7274bcb9165f [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersWafflespeanut
milestone55.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
servo: Merge #16623 - Move impl's into macro for macro-generated keyword types (from aacunningham:issue-16604-define-keyword-type-modification); r=Wafflespeanut 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. <!-- Please describe your changes on the following line: --> --- <!-- Thank you for contributing to Servo! Please replace each `[ ]` by `[X]` when the step is complete, and replace `__` with appropriate data: --> - [X] `./mach build -d` does not report any errors - [X] `./mach test-tidy` does not report any errors - [X] These changes fix #16604 (github issue number if applicable). <!-- Either: --> - [ ] There are tests for these changes OR - [X] These changes do not require tests because this doesn't add any new features, just alters `impl` locations <!-- Also, please make sure that "Allow edits from maintainers" checkbox is checked, so that we can help you if you get stuck somewhere along the way.--> <!-- Pull requests that do not address these steps are welcome, but they will require additional verification as part of the review process. --> Source-Repo: https://github.com/servo/servo Source-Revision: ad87d36a69e79cc53b516b4d0d8bddaaa5d431f5
servo/components/style/properties/helpers/animated_properties.mako.rs
servo/components/style/values/mod.rs
--- a/servo/components/style/properties/helpers/animated_properties.mako.rs
+++ b/servo/components/style/properties/helpers/animated_properties.mako.rs
@@ -28,19 +28,19 @@ use properties::longhands::visibility::c
 #[cfg(feature = "gecko")] use properties::{PropertyDeclarationId, LonghandId};
 #[cfg(feature = "servo")] use servo_atoms::Atom;
 use std::cmp;
 #[cfg(feature = "gecko")] use std::collections::HashMap;
 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};
 use values::computed::ToComputedValue;
 use values::generics::position as generic_position;
 
 
 /// A given transition property, that is either `All`, or an animatable
@@ -625,30 +625,16 @@ impl<T: RepeatableListInterpolate> Inter
 /// https://drafts.csswg.org/css-transitions/#animtype-number
 impl Interpolate for Au {
     #[inline]
     fn interpolate(&self, other: &Self, progress: f64) -> Result<Self, ()> {
         Ok(Au((self.0 as f64 + (other.0 as f64 - self.0 as f64) * progress).round() as i32))
     }
 }
 
-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,
 {
     #[inline]
     fn interpolate(&self, other: &Option<T>, progress: f64) -> Result<Option<T>, ()> {
         match (self, other) {
             (&Some(ref this), &Some(ref other)) => {
                 Ok(this.interpolate(other, progress).ok())
@@ -1105,26 +1091,16 @@ impl Interpolate for ClipRect {
             Ok(${item}List(result))
         }
     }
 </%def>
 
 ${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
 fn can_interpolate_list(from_list: &[TransformOperation],
                         to_list: &[TransformOperation]) -> bool {
     // Lists must be equal length
     if from_list.len() != to_list.len() {
         return false;
@@ -2239,30 +2215,16 @@ impl<T: ComputeDistance> ComputeDistance
 
 impl ComputeDistance for Au {
     #[inline]
     fn compute_distance(&self, other: &Self) -> Result<f64, ()> {
         self.0.compute_distance(&other.0)
     }
 }
 
-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,
 {
     #[inline]
     fn compute_distance(&self, other: &Self) -> Result<f64, ()> {
         match (self, other) {
             (&Some(ref this), &Some(ref other)) => {
                 this.compute_distance(other)
@@ -2524,28 +2486,16 @@ impl ComputeDistance for LengthOrPercent
              LengthOrPercentageOrNone::Percentage(ref other)) => {
                 this.compute_distance(other)
             },
             _ => Err(())
         }
     }
 }
 
-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, ()> {
         match (*self, *other) {
             (MinLength::LengthOrPercentage(ref this),
              MinLength::LengthOrPercentage(ref other)) => {
                 this.compute_distance(other)
             },
--- a/servo/components/style/values/mod.rs
+++ b/servo/components/style/values/mod.rs
@@ -6,16 +6,17 @@
 //!
 //! [values]: https://drafts.csswg.org/css-values/
 
 #![deny(missing_docs)]
 
 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};
 use std::hash;
 use style_traits::ToCss;
 
 macro_rules! define_numbered_css_keyword_enum {
     ($name: ident: $( $css: expr => $variant: ident = $value: expr ),+,) => {
@@ -121,16 +122,30 @@ macro_rules! define_keyword_type {
         pub struct $name;
 
         impl ::style_traits::ToCss for $name {
             fn to_css<W>(&self, dest: &mut W) -> ::std::fmt::Result where W: ::std::fmt::Write {
                 write!(dest, $css)
             }
         }
 
+        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)
             }
         }
 
         impl Parse for $name {
             fn parse(_context: &ParserContext, input: &mut ::cssparser::Parser) -> Result<$name, ()> {