diff --git a/components/style/values/specified/length.rs b/components/style/values/specified/length.rs index 2e42d502b1c..a2662247d6f 100644 --- a/components/style/values/specified/length.rs +++ b/components/style/values/specified/length.rs @@ -715,11 +715,12 @@ impl ToCss for Percentage { impl Percentage { /// Parse a specific kind of percentage. - pub fn parse_with_clamping_mode<'i, 't>(input: &mut Parser<'i, 't>, - context: AllowedNumericType) + pub fn parse_with_clamping_mode<'i, 't>(context: &ParserContext, + input: &mut Parser<'i, 't>, + num_context: AllowedNumericType) -> Result> { match try!(input.next()) { - Token::Percentage(ref value) if context.is_ok(value.unit_value) => { + Token::Percentage(ref value) if num_context.is_ok(context.parsing_mode, value.unit_value) => { Ok(Percentage(value.unit_value)) } t => Err(BasicParseError::UnexpectedToken(t).into()) @@ -727,8 +728,10 @@ impl Percentage { } /// Parses a percentage token, but rejects it if it's negative. - pub fn parse_non_negative<'i, 't>(input: &mut Parser<'i, 't>) -> Result> { - Self::parse_with_clamping_mode(input, AllowedNumericType::NonNegative) + pub fn parse_non_negative<'i, 't>(context: &ParserContext, + input: &mut Parser<'i, 't>) + -> Result> { + Self::parse_with_clamping_mode(context, input, AllowedNumericType::NonNegative) } /// 0% @@ -746,8 +749,8 @@ impl Percentage { impl Parse for Percentage { #[inline] - fn parse<'i, 't>(_context: &ParserContext, input: &mut Parser<'i, 't>) -> Result> { - Self::parse_with_clamping_mode(input, AllowedNumericType::All) + fn parse<'i, 't>(context: &ParserContext, input: &mut Parser<'i, 't>) -> Result> { + Self::parse_with_clamping_mode(context, input, AllowedNumericType::All) } } diff --git a/components/style/values/specified/mod.rs b/components/style/values/specified/mod.rs index 80ce0db08d0..112a3c38bc6 100644 --- a/components/style/values/specified/mod.rs +++ b/components/style/values/specified/mod.rs @@ -120,7 +120,7 @@ pub fn parse_number_with_clamping_mode<'i, 't>(context: &ParserContext, clamping_mode: AllowedNumericType) -> Result> { match try!(input.next()) { - Token::Number(ref value) if clamping_mode.is_ok(value.value) => { + Token::Number(ref value) if clamping_mode.is_ok(context.parsing_mode, value.value) => { Ok(Number { value: value.value.min(f32::MAX).max(f32::MIN), calc_clamping_mode: None, @@ -364,14 +364,21 @@ impl Time { input: &mut Parser<'i, 't>, clamping_mode: AllowedNumericType) -> Result> { + use style_traits::PARSING_MODE_DEFAULT; + match input.next() { - Ok(Token::Dimension(ref value, ref unit)) if clamping_mode.is_ok(value.value) => { + // Note that we generally pass ParserContext to is_ok() to check + // that the ParserMode of the ParserContext allows all numeric + // values for SMIL regardless of clamping_mode, but in this Time + // value case, the value does not animate for SMIL at all, so we use + // PARSING_MODE_DEFAULT directly. + Ok(Token::Dimension(ref value, ref unit)) if clamping_mode.is_ok(PARSING_MODE_DEFAULT, value.value) => { Time::parse_dimension(value.value, &unit, /* from_calc = */ false) .map_err(|()| StyleParseError::UnspecifiedError.into()) } Ok(Token::Function(ref name)) if name.eq_ignore_ascii_case("calc") => { match input.parse_nested_block(|i| CalcNode::parse_time(context, i)) { - Ok(time) if clamping_mode.is_ok(time.seconds) => Ok(time), + Ok(time) if clamping_mode.is_ok(PARSING_MODE_DEFAULT, time.seconds) => Ok(time), _ => Err(StyleParseError::UnspecifiedError.into()), } } @@ -457,21 +464,13 @@ impl Number { #[allow(missing_docs)] pub fn parse_non_negative<'i, 't>(context: &ParserContext, input: &mut Parser<'i, 't>) -> Result> { - if context.parsing_mode.allows_all_numeric_values() { - parse_number(context, input) - } else { - parse_number_with_clamping_mode(context, input, AllowedNumericType::NonNegative) - } + parse_number_with_clamping_mode(context, input, AllowedNumericType::NonNegative) } #[allow(missing_docs)] pub fn parse_at_least_one<'i, 't>(context: &ParserContext, input: &mut Parser<'i, 't>) -> Result> { - if context.parsing_mode.allows_all_numeric_values() { - parse_number(context, input) - } else { - parse_number_with_clamping_mode(context, input, AllowedNumericType::AtLeastOne) - } + parse_number_with_clamping_mode(context, input, AllowedNumericType::AtLeastOne) } } @@ -522,7 +521,7 @@ impl NumberOrPercentage { input: &mut Parser<'i, 't>, type_: AllowedNumericType) -> Result> { - if let Ok(per) = input.try(|i| Percentage::parse_with_clamping_mode(i, type_)) { + if let Ok(per) = input.try(|i| Percentage::parse_with_clamping_mode(context, i, type_)) { return Ok(NumberOrPercentage::Percentage(per)); } diff --git a/components/style_traits/values.rs b/components/style_traits/values.rs index af6fb247ce0..3a587ac81f9 100644 --- a/components/style_traits/values.rs +++ b/components/style_traits/values.rs @@ -265,7 +265,10 @@ pub mod specified { impl AllowedNumericType { /// Whether the value fits the rules of this numeric type. #[inline] - pub fn is_ok(&self, val: f32) -> bool { + pub fn is_ok(&self, parsing_mode: ParsingMode, val: f32) -> bool { + if parsing_mode.allows_all_numeric_values() { + return true; + } match *self { AllowedNumericType::All => true, AllowedNumericType::NonNegative => val >= 0.0,