diff --git a/components/style/properties/longhand/list.mako.rs b/components/style/properties/longhand/list.mako.rs index 149bed1e07a..bead5054b95 100644 --- a/components/style/properties/longhand/list.mako.rs +++ b/components/style/properties/longhand/list.mako.rs @@ -30,69 +30,13 @@ ${helpers.single_keyword("list-style-position", "outside inside", animation_valu 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; - - /// | | 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> { - 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.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", diff --git a/components/style/values/computed/list.rs b/components/style/values/computed/list.rs index 0e248797055..2e5584c69d9 100644 --- a/components/style/values/computed/list.rs +++ b/components/style/values/computed/list.rs @@ -5,6 +5,8 @@ //! `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`. diff --git a/components/style/values/computed/mod.rs b/components/style/values/computed/mod.rs index fd0de347155..4ad0992d698 100644 --- a/components/style/values/computed/mod.rs +++ b/components/style/values/computed/mod.rs @@ -55,6 +55,8 @@ pub use self::length::{CalcLengthOrPercentage, Length, LengthOrNone, LengthOrNum 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}; diff --git a/components/style/values/specified/list.rs b/components/style/values/specified/list.rs index 7f3ae50eaad..88140945713 100644 --- a/components/style/values/specified/list.rs +++ b/components/style/values/specified/list.rs @@ -9,8 +9,70 @@ 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 { + /// | none + CounterStyle(CounterStyleOrNone), + /// + 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; + + let counter_style = if value == structs::NS_STYLE_LIST_STYLE_NONE { + CounterStyleOrNone::None + } else { + 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"), + })) + }; + + ListStyleType::CounterStyle(counter_style) + } +} + +#[cfg(feature = "gecko")] +impl Parse for ListStyleType { + fn parse<'i, 't>(context: &ParserContext, input: &mut Parser<'i, 't>) + -> Result> { + Ok(if let Ok(style) = input.try(|i| CounterStyleOrNone::parse(context, i)) { + ListStyleType::CounterStyle(style) + } else { + 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); diff --git a/components/style/values/specified/mod.rs b/components/style/values/specified/mod.rs index dae8ed33efe..7be271fdd34 100644 --- a/components/style/values/specified/mod.rs +++ b/components/style/values/specified/mod.rs @@ -50,6 +50,8 @@ 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;