mirror of
https://github.com/servo/servo.git
synced 2025-08-03 20:50:07 +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
|
/// Set of variant alternates
|
||||||
pub enum VariantAlternates {
|
pub enum VariantAlternates {
|
||||||
/// Enables display of stylistic alternates
|
/// Enables display of stylistic alternates
|
||||||
|
#[css(function)]
|
||||||
Stylistic(CustomIdent),
|
Stylistic(CustomIdent),
|
||||||
/// Enables display with stylistic sets
|
/// Enables display with stylistic sets
|
||||||
|
#[css(comma, function, iterable)]
|
||||||
Styleset(Box<[CustomIdent]>),
|
Styleset(Box<[CustomIdent]>),
|
||||||
/// Enables display of specific character variants
|
/// Enables display of specific character variants
|
||||||
|
#[css(comma, function, iterable)]
|
||||||
CharacterVariant(Box<[CustomIdent]>),
|
CharacterVariant(Box<[CustomIdent]>),
|
||||||
/// Enables display of swash glyphs
|
/// Enables display of swash glyphs
|
||||||
|
#[css(function)]
|
||||||
Swash(CustomIdent),
|
Swash(CustomIdent),
|
||||||
/// Enables replacement of default glyphs with ornaments
|
/// Enables replacement of default glyphs with ornaments
|
||||||
|
#[css(function)]
|
||||||
Ornaments(CustomIdent),
|
Ornaments(CustomIdent),
|
||||||
/// Enables display of alternate annotation forms
|
/// Enables display of alternate annotation forms
|
||||||
|
#[css(function)]
|
||||||
Annotation(CustomIdent),
|
Annotation(CustomIdent),
|
||||||
/// Enables display of historical forms
|
/// Enables display of historical forms
|
||||||
HistoricalForms,
|
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)]
|
#[derive(Clone, Debug, MallocSizeOf, PartialEq)]
|
||||||
/// List of Variant Alternates
|
/// List of Variant Alternates
|
||||||
pub struct VariantAlternatesList(pub Box<[VariantAlternates]>);
|
pub struct VariantAlternatesList(pub Box<[VariantAlternates]>);
|
||||||
|
|
|
@ -21,13 +21,27 @@ pub fn derive(input: DeriveInput) -> Tokens {
|
||||||
let separator = if variant_attrs.comma { ", " } else { " " };
|
let separator = if variant_attrs.comma { ", " } else { " " };
|
||||||
let mut expr = if !bindings.is_empty() {
|
let mut expr = if !bindings.is_empty() {
|
||||||
let mut expr = quote! {};
|
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 = quote! {
|
||||||
#expr
|
#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! {{
|
quote! {{
|
||||||
let mut writer = ::style_traits::values::SequenceWriter::new(&mut *dest, #separator);
|
let mut writer = ::style_traits::values::SequenceWriter::new(&mut *dest, #separator);
|
||||||
#expr
|
#expr
|
||||||
|
@ -89,6 +103,7 @@ struct CssInputAttrs {
|
||||||
#[derive(Default, FromVariant)]
|
#[derive(Default, FromVariant)]
|
||||||
struct CssVariantAttrs {
|
struct CssVariantAttrs {
|
||||||
function: bool,
|
function: bool,
|
||||||
|
iterable: bool,
|
||||||
comma: bool,
|
comma: bool,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue