Share a single #[animation(no_bound(…))] for the animation traits

This commit is contained in:
Anthony Ramine 2018-03-11 21:18:46 +01:00
parent ba12a344c6
commit dcae5860a8
5 changed files with 22 additions and 24 deletions

View file

@ -43,7 +43,7 @@ pub enum ShapeBox {
/// A shape source, for some reference box. /// A shape source, for some reference box.
#[allow(missing_docs)] #[allow(missing_docs)]
#[animate(no_bound(ImageOrUrl))] #[animation(no_bound(ImageOrUrl))]
#[derive(Animate, Clone, Debug, MallocSizeOf, PartialEq, ToComputedValue, ToCss)] #[derive(Animate, Clone, Debug, MallocSizeOf, PartialEq, ToComputedValue, ToCss)]
pub enum ShapeSource<BasicShape, ReferenceBox, ImageOrUrl> { pub enum ShapeSource<BasicShape, ReferenceBox, ImageOrUrl> {
#[animation(error)] #[animation(error)]

View file

@ -15,10 +15,9 @@ use values::distance::{ComputeSquaredDistance, SquaredDistance};
/// An SVG paint value /// An SVG paint value
/// ///
/// <https://www.w3.org/TR/SVG2/painting.html#SpecifyingPaint> /// <https://www.w3.org/TR/SVG2/painting.html#SpecifyingPaint>
#[animate(no_bound(UrlPaintServer))] #[animation(no_bound(UrlPaintServer))]
#[derive(Animate, Clone, ComputeSquaredDistance, Debug, MallocSizeOf, PartialEq)] #[derive(Animate, Clone, ComputeSquaredDistance, Debug, MallocSizeOf, PartialEq)]
#[derive(ToAnimatedValue, ToComputedValue, ToCss)] #[derive(ToAnimatedValue, ToComputedValue, ToCss)]
#[distance(no_bound(UrlPaintServer))]
pub struct SVGPaint<ColorType, UrlPaintServer> { pub struct SVGPaint<ColorType, UrlPaintServer> {
/// The paint source /// The paint source
pub kind: SVGPaintKind<ColorType, UrlPaintServer>, pub kind: SVGPaintKind<ColorType, UrlPaintServer>,
@ -31,11 +30,9 @@ pub struct SVGPaint<ColorType, UrlPaintServer> {
/// Whereas the spec only allows PaintServer /// Whereas the spec only allows PaintServer
/// to have a fallback, Gecko lets the context /// to have a fallback, Gecko lets the context
/// properties have a fallback as well. /// properties have a fallback as well.
#[animate(no_bound(UrlPaintServer))] #[animation(no_bound(UrlPaintServer))]
#[derive(Animate, Clone, ComputeSquaredDistance, Debug, MallocSizeOf, PartialEq)] #[derive(Animate, Clone, ComputeSquaredDistance, Debug, MallocSizeOf, PartialEq)]
#[derive(ToAnimatedValue, ToAnimatedZero, ToComputedValue, ToCss)] #[derive(ToAnimatedValue, ToAnimatedZero, ToComputedValue, ToCss)]
#[distance(no_bound(UrlPaintServer))]
#[zero(no_bound(UrlPaintServer))]
pub enum SVGPaintKind<ColorType, UrlPaintServer> { pub enum SVGPaintKind<ColorType, UrlPaintServer> {
/// `none` /// `none`
#[animation(error)] #[animation(error)]

View file

@ -9,8 +9,8 @@ use syn::{DeriveInput, Path};
use synstructure::{Structure, VariantInfo}; use synstructure::{Structure, VariantInfo};
pub fn derive(mut input: DeriveInput) -> Tokens { pub fn derive(mut input: DeriveInput) -> Tokens {
let input_attrs = cg::parse_input_attrs::<AnimateInputAttrs>(&input); let animation_input_attrs = cg::parse_input_attrs::<AnimationInputAttrs>(&input);
let no_bound = input_attrs.no_bound.unwrap_or_default(); let no_bound = animation_input_attrs.no_bound.unwrap_or_default();
let mut where_clause = input.generics.where_clause.take(); let mut where_clause = input.generics.where_clause.take();
for param in input.generics.type_params() { for param in input.generics.type_params() {
if !no_bound.contains(&param.ident) { if !no_bound.contains(&param.ident) {
@ -37,6 +37,7 @@ pub fn derive(mut input: DeriveInput) -> Tokens {
}); });
if append_error_clause { if append_error_clause {
let input_attrs = cg::parse_input_attrs::<AnimateInputAttrs>(&input);
if let Some(fallback) = input_attrs.fallback { if let Some(fallback) = input_attrs.fallback {
match_body.append_all(quote! { match_body.append_all(quote! {
(this, other) => #fallback(this, other, procedure) (this, other) => #fallback(this, other, procedure)
@ -104,13 +105,21 @@ fn derive_variant_arm(variant: &VariantInfo) -> Result<Tokens, ()> {
#[derive(Default, FromDeriveInput)] #[derive(Default, FromDeriveInput)]
struct AnimateInputAttrs { struct AnimateInputAttrs {
fallback: Option<Path>, fallback: Option<Path>,
no_bound: Option<IdentList>, }
#[darling(attributes(animation), default)]
#[derive(Default, FromDeriveInput)]
pub struct AnimationInputAttrs {
pub no_bound: Option<IdentList>,
} }
#[darling(attributes(animation), default)] #[darling(attributes(animation), default)]
#[derive(Default, FromVariant)] #[derive(Default, FromVariant)]
pub struct AnimationVariantAttrs { pub struct AnimationVariantAttrs {
pub error: bool, pub error: bool,
// Only here because of structs, where the struct definition acts as a
// variant itself.
pub no_bound: Option<IdentList>,
} }
#[darling(attributes(animation), default)] #[darling(attributes(animation), default)]

View file

@ -2,16 +2,15 @@
* License, v. 2.0. If a copy of the MPL was not distributed with this * 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/. */ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
use animate::AnimationVariantAttrs; use animate::{AnimationInputAttrs, AnimationVariantAttrs};
use cg; use cg;
use darling::util::IdentList;
use quote::Tokens; use quote::Tokens;
use syn::{DeriveInput, Path}; use syn::{DeriveInput, Path};
use synstructure; use synstructure;
pub fn derive(mut input: DeriveInput) -> Tokens { pub fn derive(mut input: DeriveInput) -> Tokens {
let input_attrs = cg::parse_input_attrs::<DistanceInputAttrs>(&input); let animation_input_attrs = cg::parse_input_attrs::<AnimationInputAttrs>(&input);
let no_bound = input_attrs.no_bound.unwrap_or_default(); let no_bound = animation_input_attrs.no_bound.unwrap_or_default();
let mut where_clause = input.generics.where_clause.take(); let mut where_clause = input.generics.where_clause.take();
for param in input.generics.type_params() { for param in input.generics.type_params() {
if !no_bound.contains(&param.ident) { if !no_bound.contains(&param.ident) {
@ -67,6 +66,7 @@ pub fn derive(mut input: DeriveInput) -> Tokens {
input.generics.where_clause = where_clause; input.generics.where_clause = where_clause;
if append_error_clause { if append_error_clause {
let input_attrs = cg::parse_input_attrs::<DistanceInputAttrs>(&input);
if let Some(fallback) = input_attrs.fallback { if let Some(fallback) = input_attrs.fallback {
match_body.append_all(quote! { match_body.append_all(quote! {
(this, other) => #fallback(this, other) (this, other) => #fallback(this, other)
@ -99,7 +99,6 @@ pub fn derive(mut input: DeriveInput) -> Tokens {
#[derive(Default, FromDeriveInput)] #[derive(Default, FromDeriveInput)]
struct DistanceInputAttrs { struct DistanceInputAttrs {
fallback: Option<Path>, fallback: Option<Path>,
no_bound: Option<IdentList>,
} }
#[darling(attributes(distance), default)] #[darling(attributes(distance), default)]

View file

@ -2,16 +2,15 @@
* License, v. 2.0. If a copy of the MPL was not distributed with this * 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/. */ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
use animate::{AnimationVariantAttrs, AnimationFieldAttrs}; use animate::{AnimationFieldAttrs, AnimationInputAttrs, AnimationVariantAttrs};
use cg; use cg;
use darling::util::IdentList;
use quote; use quote;
use syn; use syn;
use synstructure; use synstructure;
pub fn derive(mut input: syn::DeriveInput) -> quote::Tokens { pub fn derive(mut input: syn::DeriveInput) -> quote::Tokens {
let input_attrs = cg::parse_input_attrs::<ZeroInputAttrs>(&input); let animation_input_attrs = cg::parse_input_attrs::<AnimationInputAttrs>(&input);
let no_bound = input_attrs.no_bound.unwrap_or_default(); let no_bound = animation_input_attrs.no_bound.unwrap_or_default();
let mut where_clause = input.generics.where_clause.take(); let mut where_clause = input.generics.where_clause.take();
for param in input.generics.type_params() { for param in input.generics.type_params() {
if !no_bound.contains(&param.ident) { if !no_bound.contains(&param.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<IdentList>,
}