Refactor ListStyleType

This commit is contained in:
Jon Leighton 2017-12-23 21:24:46 +01:00
parent 214b423bbd
commit 53e868e203

View file

@ -41,10 +41,11 @@ impl ListStyleType {
pub fn from_gecko_keyword(value: u32) -> Self { pub fn from_gecko_keyword(value: u32) -> Self {
use gecko_bindings::structs; use gecko_bindings::structs;
let counter_style = if value == structs::NS_STYLE_LIST_STYLE_NONE { if value == structs::NS_STYLE_LIST_STYLE_NONE {
CounterStyleOrNone::None return ListStyleType::CounterStyle(CounterStyleOrNone::None);
} else { }
CounterStyleOrNone::Name(CustomIdent(match value {
ListStyleType::CounterStyle(CounterStyleOrNone::Name(CustomIdent(match value {
structs::NS_STYLE_LIST_STYLE_DISC => atom!("disc"), structs::NS_STYLE_LIST_STYLE_DISC => atom!("disc"),
structs::NS_STYLE_LIST_STYLE_CIRCLE => atom!("circle"), structs::NS_STYLE_LIST_STYLE_CIRCLE => atom!("circle"),
structs::NS_STYLE_LIST_STYLE_SQUARE => atom!("square"), structs::NS_STYLE_LIST_STYLE_SQUARE => atom!("square"),
@ -54,22 +55,21 @@ impl ListStyleType {
structs::NS_STYLE_LIST_STYLE_LOWER_ALPHA => atom!("lower-alpha"), structs::NS_STYLE_LIST_STYLE_LOWER_ALPHA => atom!("lower-alpha"),
structs::NS_STYLE_LIST_STYLE_UPPER_ALPHA => atom!("upper-alpha"), structs::NS_STYLE_LIST_STYLE_UPPER_ALPHA => atom!("upper-alpha"),
_ => unreachable!("Unknown counter style keyword value"), _ => unreachable!("Unknown counter style keyword value"),
})) })))
};
ListStyleType::CounterStyle(counter_style)
} }
} }
#[cfg(feature = "gecko")] #[cfg(feature = "gecko")]
impl Parse for ListStyleType { impl Parse for ListStyleType {
fn parse<'i, 't>(context: &ParserContext, input: &mut Parser<'i, 't>) fn parse<'i, 't>(
-> Result<ListStyleType, ParseError<'i>> { context: &ParserContext,
Ok(if let Ok(style) = input.try(|i| CounterStyleOrNone::parse(context, i)) { input: &mut Parser<'i, 't>
ListStyleType::CounterStyle(style) ) -> Result<Self, ParseError<'i>> {
} else { if let Ok(style) = input.try(|i| CounterStyleOrNone::parse(context, i)) {
ListStyleType::String(input.expect_string()?.as_ref().to_owned()) return Ok(ListStyleType::CounterStyle(style))
}) }
Ok(ListStyleType::String(input.expect_string()?.as_ref().to_owned()))
} }
} }