servo: Merge #19636 - Move list-style-type outside of mako (from jonleighton:issue-19629); r=emilio
authorJon Leighton <j@jonathanleighton.com>
Sun, 24 Dec 2017 14:08:55 -0600
changeset 449184 141523ef2f47722bb75e566cb98811cce24dc17c
parent 449183 4aff11adf2bf66b6f9a172a2829a98795107f54e
child 449185 28380f18db0a89327ea5f8ca4942cfab7668304e
push id8527
push userCallek@gmail.com
push dateThu, 11 Jan 2018 21:05:50 +0000
treeherdermozilla-beta@95342d212a7a [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersemilio
milestone59.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
servo: Merge #19636 - Move list-style-type outside of mako (from jonleighton:issue-19629); r=emilio Closes issue #19629 r? emilio Source-Repo: https://github.com/servo/servo Source-Revision: 9a207d17c57cb8133b198933f754989358b7638e
servo/components/style/properties/longhand/list.mako.rs
servo/components/style/values/computed/list.rs
servo/components/style/values/computed/mod.rs
servo/components/style/values/specified/list.rs
servo/components/style/values/specified/mod.rs
--- a/servo/components/style/properties/longhand/list.mako.rs
+++ b/servo/components/style/properties/longhand/list.mako.rs
@@ -25,79 +25,23 @@
     ${helpers.single_keyword("list-style-type", """
         disc none circle square decimal disclosure-open disclosure-closed lower-alpha upper-alpha
         arabic-indic bengali cambodian cjk-decimal devanagari gujarati gurmukhi kannada khmer lao
         malayalam mongolian myanmar oriya persian telugu thai tibetan cjk-earthly-branch
         cjk-heavenly-stem lower-greek hiragana hiragana-iroha katakana katakana-iroha""",
         animation_value_type="discrete",
         spec="https://drafts.csswg.org/css-lists/#propdef-list-style-type")}
 % else:
-    <%helpers:longhand name="list-style-type" animation_value_type="discrete" boxed="True"
-                       spec="https://drafts.csswg.org/css-lists/#propdef-list-style-type">
-        use values::CustomIdent;
-        use values::generics::CounterStyleOrNone;
-
-        pub use self::computed_value::T as SpecifiedValue;
-
-        pub mod computed_value {
-            use values::generics::CounterStyleOrNone;
-
-            /// <counter-style> | <string> | none
-            #[derive(Clone, Debug, Eq, MallocSizeOf, PartialEq, ToComputedValue, ToCss)]
-            pub enum T {
-                CounterStyle(CounterStyleOrNone),
-                String(String),
-            }
-        }
-
-        #[cfg(feature = "gecko")]
-        impl SpecifiedValue {
-            /// Convert from gecko keyword to list-style-type.
-            ///
-            /// This should only be used for mapping type attribute to
-            /// list-style-type, and thus only values possible in that
-            /// attribute is considered here.
-            pub fn from_gecko_keyword(value: u32) -> Self {
-                use gecko_bindings::structs;
-                SpecifiedValue::CounterStyle(if value == structs::NS_STYLE_LIST_STYLE_NONE {
-                    CounterStyleOrNone::None
-                } else {
-                    <%
-                        values = """disc circle square decimal lower-roman
-                                    upper-roman lower-alpha upper-alpha""".split()
-                    %>
-                    CounterStyleOrNone::Name(CustomIdent(match value {
-                        % for style in values:
-                        structs::NS_STYLE_LIST_STYLE_${style.replace('-', '_').upper()} => atom!("${style}"),
-                        % endfor
-                        _ => unreachable!("Unknown counter style keyword value"),
-                    }))
-                })
-            }
-        }
-
-        #[inline]
-        pub fn get_initial_value() -> computed_value::T {
-            computed_value::T::CounterStyle(CounterStyleOrNone::disc())
-        }
-
-        #[inline]
-        pub fn get_initial_specified_value() -> SpecifiedValue {
-            SpecifiedValue::CounterStyle(CounterStyleOrNone::disc())
-        }
-
-        pub fn parse<'i, 't>(context: &ParserContext, input: &mut Parser<'i, 't>)
-                             -> Result<SpecifiedValue, ParseError<'i>> {
-            Ok(if let Ok(style) = input.try(|i| CounterStyleOrNone::parse(context, i)) {
-                SpecifiedValue::CounterStyle(style)
-            } else {
-                SpecifiedValue::String(input.expect_string()?.as_ref().to_owned())
-            })
-        }
-    </%helpers:longhand>
+    ${helpers.predefined_type("list-style-type",
+                              "ListStyleType",
+                              "computed::ListStyleType::disc()",
+                              initial_specified_value="specified::ListStyleType::disc()",
+                              animation_value_type="discrete",
+                              boxed="True",
+                              spec="https://drafts.csswg.org/css-lists/#propdef-list-style-type")}
 % endif
 
 ${helpers.predefined_type("list-style-image",
                           "ListStyleImage",
                           initial_value="specified::ListStyleImage::none()",
                           initial_specified_value="specified::ListStyleImage::none()",
                           animation_value_type="discrete",
                           boxed=product == "gecko",
--- a/servo/components/style/values/computed/list.rs
+++ b/servo/components/style/values/computed/list.rs
@@ -1,15 +1,17 @@
 /* This Source Code Form is subject to the terms of the Mozilla Public
  * License, v. 2.0. If a copy of the MPL was not distributed with this
  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
 
 //! `list` computed values.
 
 pub use values::specified::list::{ListStyleImage, Quotes};
+#[cfg(feature = "gecko")]
+pub use values::specified::list::ListStyleType;
 
 impl Quotes {
     /// Initial value for `quotes`.
     ///
     /// FIXME(emilio): This should ideally not allocate.
     #[inline]
     pub fn get_initial_value() -> Quotes {
         Quotes(vec![
--- a/servo/components/style/values/computed/mod.rs
+++ b/servo/components/style/values/computed/mod.rs
@@ -50,16 +50,18 @@ pub use self::image::{Gradient, Gradient
 pub use self::gecko::ScrollSnapPoint;
 pub use self::rect::LengthOrNumberRect;
 pub use super::{Auto, Either, None_};
 pub use super::specified::{BorderStyle, TextDecorationLine};
 pub use self::length::{CalcLengthOrPercentage, Length, LengthOrNone, LengthOrNumber, LengthOrPercentage};
 pub use self::length::{LengthOrPercentageOrAuto, LengthOrPercentageOrNone, MaxLength, MozLength};
 pub use self::length::{CSSPixelLength, NonNegativeLength, NonNegativeLengthOrPercentage};
 pub use self::list::{ListStyleImage, Quotes};
+#[cfg(feature = "gecko")]
+pub use self::list::ListStyleType;
 pub use self::outline::OutlineStyle;
 pub use self::percentage::Percentage;
 pub use self::position::{Position, GridAutoFlow, GridTemplateAreas};
 pub use self::svg::{SVGLength, SVGOpacity, SVGPaint, SVGPaintKind, SVGStrokeDashArray, SVGWidth};
 pub use self::table::XSpan;
 pub use self::text::{InitialLetter, LetterSpacing, LineHeight, TextAlign, TextOverflow, WordSpacing};
 pub use self::time::Time;
 pub use self::transform::{TimingFunction, Transform, TransformOperation, TransformOrigin};
--- a/servo/components/style/values/specified/list.rs
+++ b/servo/components/style/values/specified/list.rs
@@ -4,18 +4,80 @@
 
 //! `list` specified values.
 
 use cssparser::{Parser, Token};
 use parser::{Parse, ParserContext};
 use std::fmt;
 use style_traits::{ParseError, StyleParseErrorKind, ToCss};
 use values::{Either, None_};
+#[cfg(feature = "gecko")]
+use values::CustomIdent;
+#[cfg(feature = "gecko")]
+use values::generics::CounterStyleOrNone;
 use values::specified::UrlOrNone;
 
+/// Specified and computed `list-style-type` property.
+#[cfg(feature = "gecko")]
+#[derive(Clone, Debug, Eq, MallocSizeOf, PartialEq, ToComputedValue, ToCss)]
+pub enum ListStyleType {
+    /// <counter-style> | none
+    CounterStyle(CounterStyleOrNone),
+    /// <string>
+    String(String),
+}
+
+#[cfg(feature = "gecko")]
+impl ListStyleType {
+    /// Initial specified value for `list-style-type`.
+    #[inline]
+    pub fn disc() -> Self {
+        ListStyleType::CounterStyle(CounterStyleOrNone::disc())
+    }
+
+    /// Convert from gecko keyword to list-style-type.
+    ///
+    /// This should only be used for mapping type attribute to
+    /// list-style-type, and thus only values possible in that
+    /// attribute is considered here.
+    pub fn from_gecko_keyword(value: u32) -> Self {
+        use gecko_bindings::structs;
+
+        if value == structs::NS_STYLE_LIST_STYLE_NONE {
+            return ListStyleType::CounterStyle(CounterStyleOrNone::None);
+        }
+
+        ListStyleType::CounterStyle(CounterStyleOrNone::Name(CustomIdent(match value {
+            structs::NS_STYLE_LIST_STYLE_DISC => atom!("disc"),
+            structs::NS_STYLE_LIST_STYLE_CIRCLE => atom!("circle"),
+            structs::NS_STYLE_LIST_STYLE_SQUARE => atom!("square"),
+            structs::NS_STYLE_LIST_STYLE_DECIMAL => atom!("decimal"),
+            structs::NS_STYLE_LIST_STYLE_LOWER_ROMAN => atom!("lower-roman"),
+            structs::NS_STYLE_LIST_STYLE_UPPER_ROMAN => atom!("upper-roman"),
+            structs::NS_STYLE_LIST_STYLE_LOWER_ALPHA => atom!("lower-alpha"),
+            structs::NS_STYLE_LIST_STYLE_UPPER_ALPHA => atom!("upper-alpha"),
+            _ => unreachable!("Unknown counter style keyword value"),
+        })))
+    }
+}
+
+#[cfg(feature = "gecko")]
+impl Parse for ListStyleType {
+    fn parse<'i, 't>(
+        context: &ParserContext,
+        input: &mut Parser<'i, 't>
+    ) -> Result<Self, ParseError<'i>> {
+        if let Ok(style) = input.try(|i| CounterStyleOrNone::parse(context, i)) {
+            return Ok(ListStyleType::CounterStyle(style))
+        }
+
+        Ok(ListStyleType::String(input.expect_string()?.as_ref().to_owned()))
+    }
+}
+
 /// Specified and computed `list-style-image` property.
 #[derive(Clone, Debug, MallocSizeOf, PartialEq, ToCss)]
 pub struct ListStyleImage(pub UrlOrNone);
 
 // FIXME(nox): This is wrong, there are different types for specified
 // and computed URLs in Servo.
 trivial_to_computed_value!(ListStyleImage);
 
--- a/servo/components/style/values/specified/mod.rs
+++ b/servo/components/style/values/specified/mod.rs
@@ -45,16 +45,18 @@ pub use self::image::{ColorStop, EndingS
 pub use self::image::{GradientItem, GradientKind, Image, ImageLayer, MozImageRect};
 pub use self::length::{AbsoluteLength, CalcLengthOrPercentage, CharacterWidth};
 pub use self::length::{FontRelativeLength, Length, LengthOrNone, LengthOrNumber};
 pub use self::length::{LengthOrPercentage, LengthOrPercentageOrAuto};
 pub use self::length::{LengthOrPercentageOrNone, MaxLength, MozLength};
 pub use self::length::{NoCalcLength, ViewportPercentageLength};
 pub use self::length::NonNegativeLengthOrPercentage;
 pub use self::list::{ListStyleImage, Quotes};
+#[cfg(feature = "gecko")]
+pub use self::list::ListStyleType;
 pub use self::outline::OutlineStyle;
 pub use self::rect::LengthOrNumberRect;
 pub use self::percentage::Percentage;
 pub use self::position::{Position, PositionComponent, GridAutoFlow, GridTemplateAreas};
 pub use self::svg::{SVGLength, SVGOpacity, SVGPaint, SVGPaintKind, SVGStrokeDashArray, SVGWidth};
 pub use self::table::XSpan;
 pub use self::text::{InitialLetter, LetterSpacing, LineHeight, TextDecorationLine};
 pub use self::text::{TextAlign, TextAlignKeyword, TextOverflow, WordSpacing};