Bug 1434130 part 7 - Have Parse derive respect #[css(skip)] on variant as well and derive Parse for KeywordSize. r?emilio draft
authorXidorn Quan <me@upsuper.org>
Thu, 26 Apr 2018 17:25:40 +1000
changeset 788773 19f96541b1c1d147d92bf055b36abe4a7ed5c43d
parent 788772 fe72d293e8420ddb903883fb6c0b5970aead6a26
child 788774 a78f97b583f55fb2373d9629b16883584d93cfd1
push id108088
push userxquan@mozilla.com
push dateFri, 27 Apr 2018 00:40:56 +0000
reviewersemilio
bugs1434130
milestone61.0a1
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
servo/components/style/values/generics/font.rs
servo/components/style/values/specified/font.rs
servo/components/style_derive/parse.rs
--- 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),