diff --git a/components/style/values/computed/font.rs b/components/style/values/computed/font.rs index 13cd36173662..b183f07153e1 100644 --- a/components/style/values/computed/font.rs +++ b/components/style/values/computed/font.rs @@ -5,10 +5,8 @@ //! Computed values for font properties use app_units::Au; -use cssparser::Parser; -use parser::{Parse, ParserContext}; use std::fmt; -use style_traits::{ParseError, StyleParseErrorKind, ToCss}; +use style_traits::ToCss; use values::animated::ToAnimatedValue; use values::computed::{Context, NonNegativeLength, ToComputedValue}; use values::specified::font as specified; @@ -136,14 +134,6 @@ impl FontWeight { } } -impl Parse for FontWeight { - fn parse<'i, 't>(_: &ParserContext, input: &mut Parser<'i, 't>) - -> Result> { - FontWeight::from_int(input.expect_integer()?) - .map_err(|_| input.new_custom_error(StyleParseErrorKind::UnspecifiedError)) - } -} - impl FontSize { /// The actual computed font size. pub fn size(self) -> Au { diff --git a/components/style/values/specified/font.rs b/components/style/values/specified/font.rs index 7cc21ddcfc6c..f521784abb58 100644 --- a/components/style/values/specified/font.rs +++ b/components/style/values/specified/font.rs @@ -7,7 +7,7 @@ #[cfg(feature = "gecko")] use Atom; use app_units::Au; -use cssparser::Parser; +use cssparser::{Parser, Token}; use parser::{Parse, ParserContext}; use properties::longhands::system_font::SystemFont; use std::fmt; @@ -58,19 +58,24 @@ impl FontWeight { } impl Parse for FontWeight { - fn parse<'i, 't>(context: &ParserContext, input: &mut Parser<'i, 't>) - -> Result> { - let result = input.try(|input| { - let ident = input.expect_ident().map_err(|_| ())?; - match_ignore_ascii_case! { &ident, - "normal" => Ok(FontWeight::Normal), - "bold" => Ok(FontWeight::Bold), - "bolder" => Ok(FontWeight::Bolder), - "lighter" => Ok(FontWeight::Lighter), - _ => Err(()) + fn parse<'i, 't>(_: &ParserContext, input: &mut Parser<'i, 't>) -> Result> { + let result = match *input.next()? { + Token::Ident(ref ident) => { + match_ignore_ascii_case! { ident, + "normal" => Ok(FontWeight::Normal), + "bold" => Ok(FontWeight::Bold), + "bolder" => Ok(FontWeight::Bolder), + "lighter" => Ok(FontWeight::Lighter), + _ => Err(()), + } } - }); - result.or_else(|_| computed::FontWeight::parse(context, input).map(FontWeight::Weight)) + Token::Number { int_value: Some(value), .. } => { + computed::FontWeight::from_int(value).map(FontWeight::Weight) + }, + _ => Err(()), + }; + + result.map_err(|_| input.new_custom_error(StyleParseErrorKind::UnspecifiedError)) } } @@ -83,16 +88,18 @@ impl ToComputedValue for FontWeight { FontWeight::Weight(weight) => weight, FontWeight::Normal => computed::FontWeight::normal(), FontWeight::Bold => computed::FontWeight::bold(), - FontWeight::Bolder => - context.builder.get_parent_font().clone_font_weight().bolder(), - FontWeight::Lighter => - context.builder.get_parent_font().clone_font_weight().lighter(), + FontWeight::Bolder => { + context.builder.get_parent_font().clone_font_weight().bolder() + }, + FontWeight::Lighter => { + context.builder.get_parent_font().clone_font_weight().lighter() + }, #[cfg(feature = "gecko")] - FontWeight::System(_) => - context.cached_system_font.as_ref().unwrap().font_weight.clone(), + FontWeight::System(_) => { + context.cached_system_font.as_ref().unwrap().font_weight.clone() + }, #[cfg(not(feature = "gecko"))] - FontWeight::System(_) => - unreachable!(), + FontWeight::System(_) => unreachable!(), } }