Bug 1434130 part 7 - Have Parse derive respect #[css(skip)] on variant as well and derive Parse for KeywordSize. r?emilio
MozReview-Commit-ID: evSvk1RQGe
--- a/servo/components/style/values/generics/font.rs
+++ b/servo/components/style/values/generics/font.rs
@@ -181,18 +181,19 @@ where
}
}
impl<Length> SpecifiedValueInfo for KeywordInfo<Length> {
const SUPPORTED_TYPES: u8 = <KeywordSize as SpecifiedValueInfo>::SUPPORTED_TYPES;
}
/// CSS font keywords
-#[derive(Animate, Clone, ComputeSquaredDistance, Copy, Debug, MallocSizeOf, PartialEq,
- SpecifiedValueInfo, ToAnimatedValue, ToAnimatedZero, ToCss)]
+#[derive(Animate, Clone, ComputeSquaredDistance, Copy, Debug, MallocSizeOf,
+ Parse, PartialEq, SpecifiedValueInfo, ToAnimatedValue, ToAnimatedZero,
+ ToCss)]
#[allow(missing_docs)]
pub enum KeywordSize {
#[css(keyword = "xx-small")]
XXSmall,
XSmall,
Small,
Medium,
Large,
--- a/servo/components/style/values/specified/font.rs
+++ b/servo/components/style/values/specified/font.rs
@@ -712,31 +712,16 @@ impl KeywordInfo {
KeywordInfo {
kw: self.kw,
factor: self.factor * factor,
offset: self.offset.scale_by(factor) + offset,
}
}
}
-impl KeywordSize {
- /// Parses a keyword size.
- pub fn parse<'i, 't>(input: &mut Parser<'i, 't>) -> Result<Self, ParseError<'i>> {
- try_match_ident_ignore_ascii_case! { input,
- "xx-small" => Ok(KeywordSize::XXSmall),
- "x-small" => Ok(KeywordSize::XSmall),
- "small" => Ok(KeywordSize::Small),
- "medium" => Ok(KeywordSize::Medium),
- "large" => Ok(KeywordSize::Large),
- "x-large" => Ok(KeywordSize::XLarge),
- "xx-large" => Ok(KeywordSize::XXLarge),
- }
- }
-}
-
/// This is the ratio applied for font-size: larger
/// and smaller by both Firefox and Chrome
const LARGER_FONT_SIZE_RATIO: f32 = 1.2;
/// The default font size.
pub const FONT_MEDIUM_PX: i32 = 16;
#[cfg(feature = "servo")]
--- a/servo/components/style_derive/parse.rs
+++ b/servo/components/style_derive/parse.rs
@@ -15,16 +15,20 @@ pub fn derive(input: DeriveInput) -> Tok
let match_body = s.variants().iter().fold(quote!(), |match_body, variant| {
let bindings = variant.bindings();
assert!(
bindings.is_empty(),
"Parse is only supported for single-variant enums for now"
);
let variant_attrs = cg::parse_variant_attrs_from_ast::<CssVariantAttrs>(&variant.ast());
+ if variant_attrs.skip {
+ return match_body;
+ }
+
let identifier = cg::to_css_identifier(
&variant_attrs.keyword.unwrap_or(variant.ast().ident.as_ref().into()),
);
let ident = &variant.ast().ident;
let mut body = quote! {
#match_body
#identifier => Ok(#name::#ident),