diff --git a/components/style/values/specified/font.rs b/components/style/values/specified/font.rs index da2fa9432e8..aa56b39336f 100644 --- a/components/style/values/specified/font.rs +++ b/components/style/values/specified/font.rs @@ -636,81 +636,31 @@ bitflags! { } } -#[derive(Clone, Debug, MallocSizeOf, PartialEq)] +#[derive(Clone, Debug, MallocSizeOf, PartialEq, ToCss)] /// Set of variant alternates pub enum VariantAlternates { /// Enables display of stylistic alternates + #[css(function)] Stylistic(CustomIdent), /// Enables display with stylistic sets + #[css(comma, function, iterable)] Styleset(Box<[CustomIdent]>), /// Enables display of specific character variants + #[css(comma, function, iterable)] CharacterVariant(Box<[CustomIdent]>), /// Enables display of swash glyphs + #[css(function)] Swash(CustomIdent), /// Enables replacement of default glyphs with ornaments + #[css(function)] Ornaments(CustomIdent), /// Enables display of alternate annotation forms + #[css(function)] Annotation(CustomIdent), /// Enables display of historical forms HistoricalForms, } -impl ToCss for VariantAlternates { - fn to_css(&self, dest: &mut W) -> fmt::Result where W: fmt::Write { - match *self { - VariantAlternates::Swash(ref atom) => { - dest.write_str("swash")?; - dest.write_str("(")?; - atom.to_css(dest)?; - dest.write_str(")") - }, - VariantAlternates::Stylistic(ref atom) => { - dest.write_str("stylistic")?; - dest.write_str("(")?; - atom.to_css(dest)?; - dest.write_str(")") - }, - VariantAlternates::Ornaments(ref atom) => { - dest.write_str("ornaments")?; - dest.write_str("(")?; - atom.to_css(dest)?; - dest.write_str(")") - }, - VariantAlternates::Annotation(ref atom) => { - dest.write_str("annotation")?; - dest.write_str("(")?; - atom.to_css(dest)?; - dest.write_str(")") - }, - VariantAlternates::Styleset(ref vec) => { - dest.write_str("styleset")?; - dest.write_str("(")?; - let mut iter = vec.iter(); - iter.next().unwrap().to_css(dest)?; - for c in iter { - dest.write_str(", ")?; - c.to_css(dest)?; - } - dest.write_str(")") - }, - VariantAlternates::CharacterVariant(ref vec) => { - dest.write_str("character-variant")?; - dest.write_str("(")?; - let mut iter = vec.iter(); - iter.next().unwrap().to_css(dest)?; - for c in iter { - dest.write_str(", ")?; - c.to_css(dest)?; - } - dest.write_str(")") - }, - VariantAlternates::HistoricalForms => { - dest.write_str("historical-forms") - }, - } - } -} - #[derive(Clone, Debug, MallocSizeOf, PartialEq)] /// List of Variant Alternates pub struct VariantAlternatesList(pub Box<[VariantAlternates]>); diff --git a/components/style_derive/to_css.rs b/components/style_derive/to_css.rs index 6ae438ccbd2..70fb01692a7 100644 --- a/components/style_derive/to_css.rs +++ b/components/style_derive/to_css.rs @@ -21,13 +21,27 @@ pub fn derive(input: DeriveInput) -> Tokens { let separator = if variant_attrs.comma { ", " } else { " " }; let mut expr = if !bindings.is_empty() { let mut expr = quote! {}; - for binding in bindings { - where_clause.add_trait_bound(&binding.field.ty); + + if variant_attrs.function && variant_attrs.iterable { + assert_eq!(bindings.len(), 1); + let binding = &bindings[0]; expr = quote! { #expr - writer.item(#binding)?; + + for item in #binding.iter() { + writer.item(item)?; + } }; + } else { + for binding in bindings { + where_clause.add_trait_bound(&binding.field.ty); + expr = quote! { + #expr + writer.item(#binding)?; + }; + } } + quote! {{ let mut writer = ::style_traits::values::SequenceWriter::new(&mut *dest, #separator); #expr @@ -89,6 +103,7 @@ struct CssInputAttrs { #[derive(Default, FromVariant)] struct CssVariantAttrs { function: bool, + iterable: bool, comma: bool, }