mirror of
https://github.com/servo/servo.git
synced 2025-08-05 13:40:08 +01:00
Move #[css(iterable)] on fields rather than variants
This commit is contained in:
parent
f5393cef8d
commit
85950a801f
10 changed files with 44 additions and 51 deletions
|
@ -547,9 +547,8 @@ impl Parse for Fallback {
|
||||||
|
|
||||||
/// <https://drafts.csswg.org/css-counter-styles/#descdef-counter-style-symbols>
|
/// <https://drafts.csswg.org/css-counter-styles/#descdef-counter-style-symbols>
|
||||||
#[cfg_attr(feature = "gecko", derive(MallocSizeOf))]
|
#[cfg_attr(feature = "gecko", derive(MallocSizeOf))]
|
||||||
#[css(iterable)]
|
|
||||||
#[derive(Clone, Debug, Eq, PartialEq, ToComputedValue, ToCss)]
|
#[derive(Clone, Debug, Eq, PartialEq, ToComputedValue, ToCss)]
|
||||||
pub struct Symbols(pub Vec<Symbol>);
|
pub struct Symbols(#[css(iterable)] pub Vec<Symbol>);
|
||||||
|
|
||||||
impl Parse for Symbols {
|
impl Parse for Symbols {
|
||||||
fn parse<'i, 't>(context: &ParserContext, input: &mut Parser<'i, 't>) -> Result<Self, ParseError<'i>> {
|
fn parse<'i, 't>(context: &ParserContext, input: &mut Parser<'i, 't>) -> Result<Self, ParseError<'i>> {
|
||||||
|
|
|
@ -25,10 +25,11 @@ pub use gecko::media_queries::{Device, Expression};
|
||||||
|
|
||||||
/// A type that encapsulates a media query list.
|
/// A type that encapsulates a media query list.
|
||||||
#[cfg_attr(feature = "servo", derive(MallocSizeOf))]
|
#[cfg_attr(feature = "servo", derive(MallocSizeOf))]
|
||||||
#[css(comma, iterable)]
|
#[css(comma)]
|
||||||
#[derive(Clone, Debug, ToCss)]
|
#[derive(Clone, Debug, ToCss)]
|
||||||
pub struct MediaList {
|
pub struct MediaList {
|
||||||
/// The list of media queries.
|
/// The list of media queries.
|
||||||
|
#[css(iterable)]
|
||||||
pub media_queries: Vec<MediaQuery>,
|
pub media_queries: Vec<MediaQuery>,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -126,9 +126,7 @@
|
||||||
% endif
|
% endif
|
||||||
% if not allow_empty:
|
% if not allow_empty:
|
||||||
% if separator == "Comma":
|
% if separator == "Comma":
|
||||||
#[css(comma, iterable)]
|
#[css(comma)]
|
||||||
% else:
|
|
||||||
#[css(iterable)]
|
|
||||||
% endif
|
% endif
|
||||||
#[derive(ToCss)]
|
#[derive(ToCss)]
|
||||||
% endif
|
% endif
|
||||||
|
@ -136,6 +134,9 @@
|
||||||
% if allow_empty and allow_empty != "NotInitial":
|
% if allow_empty and allow_empty != "NotInitial":
|
||||||
pub Vec<single_value::T>,
|
pub Vec<single_value::T>,
|
||||||
% else:
|
% else:
|
||||||
|
% if not allow_empty:
|
||||||
|
#[css(iterable)]
|
||||||
|
% endif
|
||||||
pub SmallVec<[single_value::T; 1]>,
|
pub SmallVec<[single_value::T; 1]>,
|
||||||
% endif
|
% endif
|
||||||
);
|
);
|
||||||
|
@ -189,13 +190,16 @@
|
||||||
#[derive(Clone, Debug, MallocSizeOf, PartialEq)]
|
#[derive(Clone, Debug, MallocSizeOf, PartialEq)]
|
||||||
% if not allow_empty:
|
% if not allow_empty:
|
||||||
% if separator == "Comma":
|
% if separator == "Comma":
|
||||||
#[css(comma, iterable)]
|
#[css(comma)]
|
||||||
% else:
|
|
||||||
#[css(iterable)]
|
|
||||||
% endif
|
% endif
|
||||||
#[derive(ToCss)]
|
#[derive(ToCss)]
|
||||||
% endif
|
% endif
|
||||||
pub struct SpecifiedValue(pub Vec<single_value::SpecifiedValue>);
|
pub struct SpecifiedValue(
|
||||||
|
% if not allow_empty:
|
||||||
|
#[css(iterable)]
|
||||||
|
% endif
|
||||||
|
pub Vec<single_value::SpecifiedValue>,
|
||||||
|
);
|
||||||
|
|
||||||
% if allow_empty:
|
% if allow_empty:
|
||||||
impl ToCss for SpecifiedValue {
|
impl ToCss for SpecifiedValue {
|
||||||
|
|
|
@ -176,9 +176,9 @@ impl UrlMatchingFunction {
|
||||||
/// The `@document` rule's condition is written as a comma-separated list of
|
/// The `@document` rule's condition is written as a comma-separated list of
|
||||||
/// URL matching functions, and the condition evaluates to true whenever any
|
/// URL matching functions, and the condition evaluates to true whenever any
|
||||||
/// one of those functions evaluates to true.
|
/// one of those functions evaluates to true.
|
||||||
#[css(comma, iterable)]
|
#[css(comma)]
|
||||||
#[derive(Clone, Debug, ToCss)]
|
#[derive(Clone, Debug, ToCss)]
|
||||||
pub struct DocumentCondition(Vec<UrlMatchingFunction>);
|
pub struct DocumentCondition(#[css(iterable)] Vec<UrlMatchingFunction>);
|
||||||
|
|
||||||
impl DocumentCondition {
|
impl DocumentCondition {
|
||||||
/// Parse a document condition.
|
/// Parse a document condition.
|
||||||
|
|
|
@ -118,9 +118,8 @@ impl ToGeckoFontFeatureValues for PairValues {
|
||||||
}
|
}
|
||||||
|
|
||||||
/// A @font-feature-values block declaration value that keeps a list of values.
|
/// A @font-feature-values block declaration value that keeps a list of values.
|
||||||
#[css(iterable)]
|
|
||||||
#[derive(Clone, Debug, PartialEq, ToCss)]
|
#[derive(Clone, Debug, PartialEq, ToCss)]
|
||||||
pub struct VectorValues(pub Vec<u32>);
|
pub struct VectorValues(#[css(iterable)] pub Vec<u32>);
|
||||||
|
|
||||||
impl Parse for VectorValues {
|
impl Parse for VectorValues {
|
||||||
fn parse<'i, 't>(_context: &ParserContext, input: &mut Parser<'i, 't>)
|
fn parse<'i, 't>(_context: &ParserContext, input: &mut Parser<'i, 't>)
|
||||||
|
|
|
@ -145,9 +145,9 @@ impl KeyframePercentage {
|
||||||
|
|
||||||
/// A keyframes selector is a list of percentages or from/to symbols, which are
|
/// A keyframes selector is a list of percentages or from/to symbols, which are
|
||||||
/// converted at parse time to percentages.
|
/// converted at parse time to percentages.
|
||||||
#[css(comma, iterable)]
|
#[css(comma)]
|
||||||
#[derive(Clone, Debug, Eq, PartialEq, ToCss)]
|
#[derive(Clone, Debug, Eq, PartialEq, ToCss)]
|
||||||
pub struct KeyframeSelector(Vec<KeyframePercentage>);
|
pub struct KeyframeSelector(#[css(iterable)] Vec<KeyframePercentage>);
|
||||||
|
|
||||||
impl KeyframeSelector {
|
impl KeyframeSelector {
|
||||||
/// Return the list of percentages this selector contains.
|
/// Return the list of percentages this selector contains.
|
||||||
|
|
|
@ -369,9 +369,9 @@ pub enum OverflowClipBox {
|
||||||
pub enum WillChange {
|
pub enum WillChange {
|
||||||
/// Expresses no particular intent
|
/// Expresses no particular intent
|
||||||
Auto,
|
Auto,
|
||||||
#[css(comma, iterable)]
|
|
||||||
/// <custom-ident>
|
/// <custom-ident>
|
||||||
AnimateableFeatures(Box<[CustomIdent]>),
|
#[css(comma)]
|
||||||
|
AnimateableFeatures(#[css(iterable)] Box<[CustomIdent]>),
|
||||||
}
|
}
|
||||||
|
|
||||||
impl WillChange {
|
impl WillChange {
|
||||||
|
|
|
@ -92,8 +92,7 @@ pub enum Content {
|
||||||
#[cfg(feature = "gecko")]
|
#[cfg(feature = "gecko")]
|
||||||
MozAltContent,
|
MozAltContent,
|
||||||
/// Content items.
|
/// Content items.
|
||||||
#[css(iterable)]
|
Items(#[css(iterable)] Box<[ContentItem]>),
|
||||||
Items(Box<[ContentItem]>),
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Items for the `content` property.
|
/// Items for the `content` property.
|
||||||
|
|
|
@ -152,8 +152,8 @@ impl From<LengthOrPercentage> for FontSize {
|
||||||
#[derive(Clone, Debug, Eq, Hash, PartialEq, ToCss)]
|
#[derive(Clone, Debug, Eq, Hash, PartialEq, ToCss)]
|
||||||
pub enum FontFamily {
|
pub enum FontFamily {
|
||||||
/// List of `font-family`
|
/// List of `font-family`
|
||||||
#[css(iterable, comma)]
|
#[css(comma)]
|
||||||
Values(FontFamilyList),
|
Values(#[css(iterable)] FontFamilyList),
|
||||||
/// System font
|
/// System font
|
||||||
System(SystemFont),
|
System(SystemFont),
|
||||||
}
|
}
|
||||||
|
@ -718,11 +718,11 @@ pub enum VariantAlternates {
|
||||||
#[css(function)]
|
#[css(function)]
|
||||||
Stylistic(CustomIdent),
|
Stylistic(CustomIdent),
|
||||||
/// Enables display with stylistic sets
|
/// Enables display with stylistic sets
|
||||||
#[css(comma, function, iterable)]
|
#[css(comma, function)]
|
||||||
Styleset(Box<[CustomIdent]>),
|
Styleset(#[css(iterable)] Box<[CustomIdent]>),
|
||||||
/// Enables display of specific character variants
|
/// Enables display of specific character variants
|
||||||
#[css(comma, function, iterable)]
|
#[css(comma, function)]
|
||||||
CharacterVariant(Box<[CustomIdent]>),
|
CharacterVariant(#[css(iterable)] Box<[CustomIdent]>),
|
||||||
/// Enables display of swash glyphs
|
/// Enables display of swash glyphs
|
||||||
#[css(function)]
|
#[css(function)]
|
||||||
Swash(CustomIdent),
|
Swash(CustomIdent),
|
||||||
|
|
|
@ -4,7 +4,7 @@
|
||||||
|
|
||||||
use cg::{self, WhereClause};
|
use cg::{self, WhereClause};
|
||||||
use darling::util::Override;
|
use darling::util::Override;
|
||||||
use quote::Tokens;
|
use quote::{ToTokens, Tokens};
|
||||||
use syn::{self, Data};
|
use syn::{self, Data};
|
||||||
use synstructure::{Structure, VariantInfo};
|
use synstructure::{Structure, VariantInfo};
|
||||||
|
|
||||||
|
@ -18,7 +18,6 @@ pub fn derive(input: syn::DeriveInput) -> Tokens {
|
||||||
if let Data::Enum(_) = input.data {
|
if let Data::Enum(_) = input.data {
|
||||||
assert!(input_attrs.function.is_none(), "#[css(function)] is not allowed on enums");
|
assert!(input_attrs.function.is_none(), "#[css(function)] is not allowed on enums");
|
||||||
assert!(!input_attrs.comma, "#[css(comma)] is not allowed on enums");
|
assert!(!input_attrs.comma, "#[css(comma)] is not allowed on enums");
|
||||||
assert!(!input_attrs.iterable, "#[css(iterable)] is not allowed on enums");
|
|
||||||
}
|
}
|
||||||
let s = Structure::new(&input);
|
let s = Structure::new(&input);
|
||||||
|
|
||||||
|
@ -86,30 +85,24 @@ fn derive_variant_arm(
|
||||||
}
|
}
|
||||||
} else if !bindings.is_empty() {
|
} else if !bindings.is_empty() {
|
||||||
let mut expr = quote! {};
|
let mut expr = quote! {};
|
||||||
if variant_attrs.iterable {
|
|
||||||
assert_eq!(bindings.len(), 1);
|
|
||||||
let binding = &bindings[0];
|
|
||||||
expr = quote! {
|
|
||||||
#expr
|
|
||||||
|
|
||||||
for item in #binding.iter() {
|
|
||||||
writer.item(&item)?;
|
|
||||||
}
|
|
||||||
};
|
|
||||||
} else {
|
|
||||||
for binding in bindings {
|
for binding in bindings {
|
||||||
let attrs = cg::parse_field_attrs::<CssFieldAttrs>(&binding.ast());
|
let attrs = cg::parse_field_attrs::<CssFieldAttrs>(&binding.ast());
|
||||||
if attrs.skip {
|
if attrs.skip {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
let variant_expr = if attrs.iterable {
|
||||||
|
quote! {
|
||||||
|
for item in #binding.iter() {
|
||||||
|
writer.item(&item)?;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} else {
|
||||||
if !attrs.ignore_bound {
|
if !attrs.ignore_bound {
|
||||||
where_clause.add_trait_bound(&binding.ast().ty);
|
where_clause.add_trait_bound(&binding.ast().ty);
|
||||||
}
|
}
|
||||||
expr = quote! {
|
quote!{ writer.item(#binding)?; }
|
||||||
#expr
|
|
||||||
writer.item(#binding)?;
|
|
||||||
};
|
};
|
||||||
}
|
variant_expr.to_tokens(&mut expr)
|
||||||
}
|
}
|
||||||
|
|
||||||
quote! {{
|
quote! {{
|
||||||
|
@ -148,15 +141,12 @@ struct CssInputAttrs {
|
||||||
function: Option<Override<String>>,
|
function: Option<Override<String>>,
|
||||||
// Here because structs variants are also their whole type definition.
|
// Here because structs variants are also their whole type definition.
|
||||||
comma: bool,
|
comma: bool,
|
||||||
// Here because structs variants are also their whole type definition.
|
|
||||||
iterable: bool,
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#[darling(attributes(css), default)]
|
#[darling(attributes(css), default)]
|
||||||
#[derive(Default, FromVariant)]
|
#[derive(Default, FromVariant)]
|
||||||
pub struct CssVariantAttrs {
|
pub struct CssVariantAttrs {
|
||||||
pub function: Option<Override<String>>,
|
pub function: Option<Override<String>>,
|
||||||
pub iterable: bool,
|
|
||||||
pub comma: bool,
|
pub comma: bool,
|
||||||
pub dimension: bool,
|
pub dimension: bool,
|
||||||
pub keyword: Option<String>,
|
pub keyword: Option<String>,
|
||||||
|
@ -167,5 +157,6 @@ pub struct CssVariantAttrs {
|
||||||
#[derive(Default, FromField)]
|
#[derive(Default, FromField)]
|
||||||
struct CssFieldAttrs {
|
struct CssFieldAttrs {
|
||||||
ignore_bound: bool,
|
ignore_bound: bool,
|
||||||
|
iterable: bool,
|
||||||
skip: bool,
|
skip: bool,
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue