Skip to content

Commit

Permalink
Auto merge of #16623 - aacunningham:issue-16604-define-keyword-type-m…
Browse files Browse the repository at this point in the history
…odification, r=Wafflespeanut

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.

<!-- 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. -->

<!-- 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/16623)
<!-- Reviewable:end -->
  • Loading branch information
bors-servo committed Apr 28, 2017
2 parents f128781 + f6d09a3 commit 543eb50
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 52 deletions.
54 changes: 2 additions & 52 deletions components/style/properties/helpers/animated_properties.mako.rs
Expand Up @@ -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};
Expand Down Expand Up @@ -630,20 +630,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,
{
Expand Down Expand Up @@ -1110,16 +1096,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
Expand Down Expand Up @@ -2244,20 +2220,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,
{
Expand Down Expand Up @@ -2529,18 +2491,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, ()> {
Expand Down
15 changes: 15 additions & 0 deletions components/style/values/mod.rs
Expand Up @@ -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};
Expand Down Expand Up @@ -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)
Expand Down

0 comments on commit 543eb50

Please sign in to comment.