mirror of
https://github.com/servo/servo.git
synced 2025-08-03 12:40:06 +01:00
style: add css(function, iterable), and derive ToCss for VariantAlternates.
This commit is contained in:
parent
33fa728d6e
commit
06f8f0384b
2 changed files with 25 additions and 60 deletions
|
@ -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<W>(&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]>);
|
||||
|
|
|
@ -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,
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue