From dcae5860a881400e12f1396595479246aa590f6b Mon Sep 17 00:00:00 2001 From: Anthony Ramine Date: Sun, 11 Mar 2018 21:18:46 +0100 Subject: [PATCH] =?UTF-8?q?Share=20a=20single=20#[animation(no=5Fbound(?= =?UTF-8?q?=E2=80=A6))]=20for=20the=20animation=20traits?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- components/style/values/generics/basic_shape.rs | 2 +- components/style/values/generics/svg.rs | 7 ++----- components/style_derive/animate.rs | 15 ++++++++++++--- .../style_derive/compute_squared_distance.rs | 9 ++++----- components/style_derive/to_animated_zero.rs | 13 +++---------- 5 files changed, 22 insertions(+), 24 deletions(-) diff --git a/components/style/values/generics/basic_shape.rs b/components/style/values/generics/basic_shape.rs index 27185ef8be6..8c798b468ae 100644 --- a/components/style/values/generics/basic_shape.rs +++ b/components/style/values/generics/basic_shape.rs @@ -43,7 +43,7 @@ pub enum ShapeBox { /// A shape source, for some reference box. #[allow(missing_docs)] -#[animate(no_bound(ImageOrUrl))] +#[animation(no_bound(ImageOrUrl))] #[derive(Animate, Clone, Debug, MallocSizeOf, PartialEq, ToComputedValue, ToCss)] pub enum ShapeSource { #[animation(error)] diff --git a/components/style/values/generics/svg.rs b/components/style/values/generics/svg.rs index 83f1790056c..a856633ff47 100644 --- a/components/style/values/generics/svg.rs +++ b/components/style/values/generics/svg.rs @@ -15,10 +15,9 @@ use values::distance::{ComputeSquaredDistance, SquaredDistance}; /// An SVG paint value /// /// -#[animate(no_bound(UrlPaintServer))] +#[animation(no_bound(UrlPaintServer))] #[derive(Animate, Clone, ComputeSquaredDistance, Debug, MallocSizeOf, PartialEq)] #[derive(ToAnimatedValue, ToComputedValue, ToCss)] -#[distance(no_bound(UrlPaintServer))] pub struct SVGPaint { /// The paint source pub kind: SVGPaintKind, @@ -31,11 +30,9 @@ pub struct SVGPaint { /// Whereas the spec only allows PaintServer /// to have a fallback, Gecko lets the context /// properties have a fallback as well. -#[animate(no_bound(UrlPaintServer))] +#[animation(no_bound(UrlPaintServer))] #[derive(Animate, Clone, ComputeSquaredDistance, Debug, MallocSizeOf, PartialEq)] #[derive(ToAnimatedValue, ToAnimatedZero, ToComputedValue, ToCss)] -#[distance(no_bound(UrlPaintServer))] -#[zero(no_bound(UrlPaintServer))] pub enum SVGPaintKind { /// `none` #[animation(error)] diff --git a/components/style_derive/animate.rs b/components/style_derive/animate.rs index 06767000383..e54f1819c99 100644 --- a/components/style_derive/animate.rs +++ b/components/style_derive/animate.rs @@ -9,8 +9,8 @@ use syn::{DeriveInput, Path}; use synstructure::{Structure, VariantInfo}; pub fn derive(mut input: DeriveInput) -> Tokens { - let input_attrs = cg::parse_input_attrs::(&input); - let no_bound = input_attrs.no_bound.unwrap_or_default(); + let animation_input_attrs = cg::parse_input_attrs::(&input); + let no_bound = animation_input_attrs.no_bound.unwrap_or_default(); let mut where_clause = input.generics.where_clause.take(); for param in input.generics.type_params() { if !no_bound.contains(¶m.ident) { @@ -37,6 +37,7 @@ pub fn derive(mut input: DeriveInput) -> Tokens { }); if append_error_clause { + let input_attrs = cg::parse_input_attrs::(&input); if let Some(fallback) = input_attrs.fallback { match_body.append_all(quote! { (this, other) => #fallback(this, other, procedure) @@ -104,13 +105,21 @@ fn derive_variant_arm(variant: &VariantInfo) -> Result { #[derive(Default, FromDeriveInput)] struct AnimateInputAttrs { fallback: Option, - no_bound: Option, +} + +#[darling(attributes(animation), default)] +#[derive(Default, FromDeriveInput)] +pub struct AnimationInputAttrs { + pub no_bound: Option, } #[darling(attributes(animation), default)] #[derive(Default, FromVariant)] pub struct AnimationVariantAttrs { pub error: bool, + // Only here because of structs, where the struct definition acts as a + // variant itself. + pub no_bound: Option, } #[darling(attributes(animation), default)] diff --git a/components/style_derive/compute_squared_distance.rs b/components/style_derive/compute_squared_distance.rs index c978751054d..07408bbcddb 100644 --- a/components/style_derive/compute_squared_distance.rs +++ b/components/style_derive/compute_squared_distance.rs @@ -2,16 +2,15 @@ * License, v. 2.0. If a copy of the MPL was not distributed with this * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ -use animate::AnimationVariantAttrs; +use animate::{AnimationInputAttrs, AnimationVariantAttrs}; use cg; -use darling::util::IdentList; use quote::Tokens; use syn::{DeriveInput, Path}; use synstructure; pub fn derive(mut input: DeriveInput) -> Tokens { - let input_attrs = cg::parse_input_attrs::(&input); - let no_bound = input_attrs.no_bound.unwrap_or_default(); + let animation_input_attrs = cg::parse_input_attrs::(&input); + let no_bound = animation_input_attrs.no_bound.unwrap_or_default(); let mut where_clause = input.generics.where_clause.take(); for param in input.generics.type_params() { if !no_bound.contains(¶m.ident) { @@ -67,6 +66,7 @@ pub fn derive(mut input: DeriveInput) -> Tokens { input.generics.where_clause = where_clause; if append_error_clause { + let input_attrs = cg::parse_input_attrs::(&input); if let Some(fallback) = input_attrs.fallback { match_body.append_all(quote! { (this, other) => #fallback(this, other) @@ -99,7 +99,6 @@ pub fn derive(mut input: DeriveInput) -> Tokens { #[derive(Default, FromDeriveInput)] struct DistanceInputAttrs { fallback: Option, - no_bound: Option, } #[darling(attributes(distance), default)] diff --git a/components/style_derive/to_animated_zero.rs b/components/style_derive/to_animated_zero.rs index 53194280240..9ee786f7ec8 100644 --- a/components/style_derive/to_animated_zero.rs +++ b/components/style_derive/to_animated_zero.rs @@ -2,16 +2,15 @@ * License, v. 2.0. If a copy of the MPL was not distributed with this * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ -use animate::{AnimationVariantAttrs, AnimationFieldAttrs}; +use animate::{AnimationFieldAttrs, AnimationInputAttrs, AnimationVariantAttrs}; use cg; -use darling::util::IdentList; use quote; use syn; use synstructure; pub fn derive(mut input: syn::DeriveInput) -> quote::Tokens { - let input_attrs = cg::parse_input_attrs::(&input); - let no_bound = input_attrs.no_bound.unwrap_or_default(); + let animation_input_attrs = cg::parse_input_attrs::(&input); + let no_bound = animation_input_attrs.no_bound.unwrap_or_default(); let mut where_clause = input.generics.where_clause.take(); for param in input.generics.type_params() { if !no_bound.contains(¶m.ident) { @@ -63,9 +62,3 @@ pub fn derive(mut input: syn::DeriveInput) -> quote::Tokens { } } } - -#[darling(attributes(zero), default)] -#[derive(Default, FromDeriveInput)] -struct ZeroInputAttrs { - no_bound: Option, -}