Bug 1434130 part 8 - Have TextAlign derive ToCss and unship char value from it. r?emilio draft
authorXidorn Quan <me@upsuper.org>
Thu, 26 Apr 2018 17:27:37 +1000
changeset 788774 a78f97b583f55fb2373d9629b16883584d93cfd1
parent 788773 19f96541b1c1d147d92bf055b36abe4a7ed5c43d
child 788775 adc038d9c64ae32ca74ecaa46ca5cf0b9d5fdb77
push id108088
push userxquan@mozilla.com
push dateFri, 27 Apr 2018 00:40:56 +0000
reviewersemilio
bugs1434130
milestone61.0a1
Bug 1434130 part 8 - Have TextAlign derive ToCss and unship char value from it. r?emilio MozReview-Commit-ID: CXDnyqzjQkq
layout/style/test/property_database.js
servo/components/style/values/specified/text.rs
--- a/layout/style/test/property_database.js
+++ b/layout/style/test/property_database.js
@@ -4420,17 +4420,17 @@ var gCSSProperties = {
   "text-align": {
     domProp: "textAlign",
     inherited: true,
     type: CSS_TYPE_LONGHAND,
     applies_to_placeholder: true,
     // don't know whether left and right are same as start
     initial_values: [ "start" ],
     other_values: [ "center", "justify", "end", "match-parent" ],
-    invalid_values: [ "true", "true true" ]
+    invalid_values: [ "true", "true true", "char", "-moz-center-or-inherit" ]
   },
   "text-align-last": {
     domProp: "textAlignLast",
     inherited: true,
     type: CSS_TYPE_LONGHAND,
     initial_values: [ "auto" ],
     other_values: [ "center", "justify", "start", "end", "left", "right" ],
     invalid_values: []
--- a/servo/components/style/values/specified/text.rs
+++ b/servo/components/style/values/specified/text.rs
@@ -350,23 +350,27 @@ impl Parse for TextDecorationLine {
             Ok(result)
         } else {
             Err(input.new_custom_error(StyleParseErrorKind::UnspecifiedError))
         }
     }
 }
 
 macro_rules! define_text_align_keyword {
-    ($($name: ident => $discriminant: expr,)+) => {
+    ($(
+        $(#[$($meta:tt)+])*
+        $name: ident => $discriminant: expr,
+    )+) => {
         /// Specified value of text-align keyword value.
         #[derive(Clone, Copy, Debug, Eq, Hash, MallocSizeOf, Parse, PartialEq,
                  SpecifiedValueInfo, ToComputedValue, ToCss)]
         #[allow(missing_docs)]
         pub enum TextAlignKeyword {
             $(
+                $(#[$($meta)+])*
                 $name = $discriminant,
             )+
         }
 
         impl TextAlignKeyword {
             /// Construct a TextAlignKeyword from u32.
             pub fn from_u32(discriminant: u32) -> Option<TextAlignKeyword> {
                 match discriminant {
@@ -387,16 +391,17 @@ define_text_align_keyword! {
     End => 1,
     Left => 2,
     Right => 3,
     Center => 4,
     Justify => 5,
     MozCenter => 6,
     MozLeft => 7,
     MozRight => 8,
+    #[css(skip)]
     Char => 10,
 }
 
 #[cfg(feature = "servo")]
 define_text_align_keyword! {
     Start => 0,
     End => 1,
     Left => 2,
@@ -413,28 +418,29 @@ impl TextAlignKeyword {
     #[inline]
     pub fn start() -> TextAlignKeyword {
         TextAlignKeyword::Start
     }
 }
 
 /// Specified value of text-align property.
 #[cfg_attr(feature = "gecko", derive(MallocSizeOf))]
-#[derive(Clone, Copy, Debug, Eq, Hash, PartialEq, SpecifiedValueInfo)]
+#[derive(Clone, Copy, Debug, Eq, Hash, PartialEq, SpecifiedValueInfo, ToCss)]
 pub enum TextAlign {
     /// Keyword value of text-align property.
     Keyword(TextAlignKeyword),
     /// `match-parent` value of text-align property. It has a different handling
     /// unlike other keywords.
     #[cfg(feature = "gecko")]
     MatchParent,
     /// `MozCenterOrInherit` value of text-align property. It cannot be parsed,
     /// only set directly on the elements and it has a different handling
     /// unlike other values.
     #[cfg(feature = "gecko")]
+    #[css(skip)]
     MozCenterOrInherit,
 }
 
 impl Parse for TextAlign {
     fn parse<'i, 't>(
         _context: &ParserContext,
         input: &mut Parser<'i, 't>,
     ) -> Result<Self, ParseError<'i>> {
@@ -449,31 +455,16 @@ impl Parse for TextAlign {
         }
         #[cfg(feature = "servo")]
         {
             return Err(input.new_custom_error(StyleParseErrorKind::UnspecifiedError));
         }
     }
 }
 
-impl ToCss for TextAlign {
-    fn to_css<W>(&self, dest: &mut CssWriter<W>) -> fmt::Result
-    where
-        W: Write,
-    {
-        match *self {
-            TextAlign::Keyword(key) => key.to_css(dest),
-            #[cfg(feature = "gecko")]
-            TextAlign::MatchParent => dest.write_str("match-parent"),
-            #[cfg(feature = "gecko")]
-            TextAlign::MozCenterOrInherit => Ok(()),
-        }
-    }
-}
-
 impl TextAlign {
     /// Convert an enumerated value coming from Gecko to a `TextAlign`.
     #[cfg(feature = "gecko")]
     pub fn from_gecko_keyword(kw: u32) -> Self {
         use gecko_bindings::structs::NS_STYLE_TEXT_ALIGN_MATCH_PARENT;
         if kw == NS_STYLE_TEXT_ALIGN_MATCH_PARENT {
             TextAlign::MatchParent
         } else {