Bug 1434130 part 5 - Derive ToCss for values::generics::font::KeywordSize. r?emilio draft
authorXidorn Quan <me@upsuper.org>
Thu, 26 Apr 2018 15:08:16 +1000
changeset 788771 29990f9171efe771ea4d09fd129d37a4a1ec3870
parent 788770 f2c10917b105912bbe5fa06a986bbce08ebceac4
child 788772 fe72d293e8420ddb903883fb6c0b5970aead6a26
push id108088
push userxquan@mozilla.com
push dateFri, 27 Apr 2018 00:40:56 +0000
reviewersemilio
bugs1434130
milestone61.0a1
Bug 1434130 part 5 - Derive ToCss for values::generics::font::KeywordSize. r?emilio MozReview-Commit-ID: 9ek3PcqYiU3
servo/components/style/values/generics/font.rs
--- a/servo/components/style/values/generics/font.rs
+++ b/servo/components/style/values/generics/font.rs
@@ -182,28 +182,31 @@ 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,
-         ToAnimatedValue, ToAnimatedZero, SpecifiedValueInfo)]
+         SpecifiedValueInfo, ToAnimatedValue, ToAnimatedZero, ToCss)]
 #[allow(missing_docs)]
 pub enum KeywordSize {
+    #[css(keyword = "xx-small")]
     XXSmall,
     XSmall,
     Small,
     Medium,
     Large,
     XLarge,
+    #[css(keyword = "xx-large")]
     XXLarge,
     // This is not a real font keyword and will not parse
     // HTML font-size 7 corresponds to this value
+    #[css(skip)]
     XXXLarge,
 }
 
 impl KeywordSize {
     /// Convert to an HTML <font size> value
     #[inline]
     pub fn html_size(self) -> u8 {
         self as u8
@@ -211,40 +214,16 @@ impl KeywordSize {
 }
 
 impl Default for KeywordSize {
     fn default() -> Self {
         KeywordSize::Medium
     }
 }
 
-impl ToCss for KeywordSize {
-    fn to_css<W>(&self, dest: &mut CssWriter<W>) -> fmt::Result
-    where
-        W: Write,
-    {
-        dest.write_str(match *self {
-            KeywordSize::XXSmall => "xx-small",
-            KeywordSize::XSmall => "x-small",
-            KeywordSize::Small => "small",
-            KeywordSize::Medium => "medium",
-            KeywordSize::Large => "large",
-            KeywordSize::XLarge => "x-large",
-            KeywordSize::XXLarge => "xx-large",
-            KeywordSize::XXXLarge => {
-                debug_assert!(
-                    false,
-                    "We should never serialize specified values set via HTML presentation attributes"
-                );
-                "-servo-xxx-large"
-            },
-        })
-    }
-}
-
 /// A generic value for the `font-style` property.
 ///
 /// https://drafts.csswg.org/css-fonts-4/#font-style-prop
 #[allow(missing_docs)]
 #[derive(Animate, Clone, ComputeSquaredDistance, Copy, Debug, MallocSizeOf,
          PartialEq, SpecifiedValueInfo, ToAnimatedValue, ToAnimatedZero)]
 pub enum FontStyle<Angle> {
     #[animation(error)]