From 7341574b664c95ec9486eb91bebae6a2db975aea Mon Sep 17 00:00:00 2001 From: Hiroyuki Ikezoe Date: Wed, 14 Jun 2017 09:51:53 +0900 Subject: [PATCH] Make AllowedLengthType.is_ok() returning true if parsing mode allows all numeric values. Even if the type is NonNegative and the given value is a negative. --- components/style/values/specified/length.rs | 26 ++++++++++----------- components/style_traits/values.rs | 6 ++++- components/style_traits/viewport.rs | 11 ++++++--- 3 files changed, 26 insertions(+), 17 deletions(-) diff --git a/components/style/values/specified/length.rs b/components/style/values/specified/length.rs index d2e6e45d407..2e42d502b1c 100644 --- a/components/style/values/specified/length.rs +++ b/components/style/values/specified/length.rs @@ -611,9 +611,9 @@ impl Length { -> Result> { let token = try!(input.next()); match token { - Token::Dimension(ref value, ref unit) if num_context.is_ok(value.value) => + Token::Dimension(ref value, ref unit) if num_context.is_ok(context.parsing_mode, value.value) => Length::parse_dimension(context, value.value, unit), - Token::Number(ref value) if num_context.is_ok(value.value) => { + Token::Number(ref value) if num_context.is_ok(context.parsing_mode, value.value) => { if value.value != 0. && !context.parsing_mode.allows_unitless_lengths() && !allow_quirks.allowed(context.quirks_mode) { @@ -801,11 +801,11 @@ impl LengthOrPercentage { { let token = try!(input.next()); match token { - Token::Dimension(ref value, ref unit) if num_context.is_ok(value.value) => + Token::Dimension(ref value, ref unit) if num_context.is_ok(context.parsing_mode, value.value) => NoCalcLength::parse_dimension(context, value.value, unit).map(LengthOrPercentage::Length), - Token::Percentage(ref value) if num_context.is_ok(value.unit_value) => + Token::Percentage(ref value) if num_context.is_ok(context.parsing_mode, value.unit_value) => return Ok(LengthOrPercentage::Percentage(Percentage(value.unit_value))), - Token::Number(value) if num_context.is_ok(value.value) => { + Token::Number(value) if num_context.is_ok(context.parsing_mode, value.value) => { if value.value != 0. && !context.parsing_mode.allows_unitless_lengths() && !allow_quirks.allowed(context.quirks_mode) { @@ -935,11 +935,11 @@ impl LengthOrPercentageOrAuto { -> Result> { let token = try!(input.next()); match token { - Token::Dimension(ref value, ref unit) if num_context.is_ok(value.value) => + Token::Dimension(ref value, ref unit) if num_context.is_ok(context.parsing_mode, value.value) => NoCalcLength::parse_dimension(context, value.value, unit).map(LengthOrPercentageOrAuto::Length), - Token::Percentage(ref value) if num_context.is_ok(value.unit_value) => + Token::Percentage(ref value) if num_context.is_ok(context.parsing_mode, value.unit_value) => Ok(LengthOrPercentageOrAuto::Percentage(Percentage(value.unit_value))), - Token::Number(ref value) if num_context.is_ok(value.value) => { + Token::Number(ref value) if num_context.is_ok(context.parsing_mode, value.value) => { if value.value != 0. && !context.parsing_mode.allows_unitless_lengths() && !allow_quirks.allowed(context.quirks_mode) { @@ -1031,11 +1031,11 @@ impl LengthOrPercentageOrNone { { let token = try!(input.next()); match token { - Token::Dimension(ref value, ref unit) if num_context.is_ok(value.value) => + Token::Dimension(ref value, ref unit) if num_context.is_ok(context.parsing_mode, value.value) => NoCalcLength::parse_dimension(context, value.value, unit).map(LengthOrPercentageOrNone::Length), - Token::Percentage(ref value) if num_context.is_ok(value.unit_value) => + Token::Percentage(ref value) if num_context.is_ok(context.parsing_mode, value.unit_value) => Ok(LengthOrPercentageOrNone::Percentage(Percentage(value.unit_value))), - Token::Number(value) if num_context.is_ok(value.value) => { + Token::Number(value) if num_context.is_ok(context.parsing_mode, value.value) => { if value.value != 0. && !context.parsing_mode.allows_unitless_lengths() && !allow_quirks.allowed(context.quirks_mode) { return Err(StyleParseError::UnspecifiedError.into()) @@ -1113,10 +1113,10 @@ impl LengthOrPercentageOrAutoOrContent { let num_context = AllowedLengthType::NonNegative; let token = try!(input.next()); match token { - Token::Dimension(ref value, ref unit) if num_context.is_ok(value.value) => + Token::Dimension(ref value, ref unit) if num_context.is_ok(context.parsing_mode, value.value) => NoCalcLength::parse_dimension(context, value.value, unit) .map(LengthOrPercentageOrAutoOrContent::Length), - Token::Percentage(ref value) if num_context.is_ok(value.unit_value) => + Token::Percentage(ref value) if num_context.is_ok(context.parsing_mode, value.unit_value) => Ok(LengthOrPercentageOrAutoOrContent::Percentage(Percentage(value.unit_value))), Token::Number(ref value) if value.value == 0. => Ok(Self::zero()), diff --git a/components/style_traits/values.rs b/components/style_traits/values.rs index 6c31da16664..af6fb247ce0 100644 --- a/components/style_traits/values.rs +++ b/components/style_traits/values.rs @@ -204,6 +204,7 @@ macro_rules! __define_css_keyword_enum__actual { /// Helper types for the handling of specified values. pub mod specified { + use ParsingMode; use app_units::Au; use std::cmp; @@ -228,7 +229,10 @@ pub mod specified { impl AllowedLengthType { /// Whether value is valid for this allowed length type. #[inline] - pub fn is_ok(&self, value: f32) -> bool { + pub fn is_ok(&self, parsing_mode: ParsingMode, value: f32) -> bool { + if parsing_mode.allows_all_numeric_values() { + return true; + } match *self { AllowedLengthType::All => true, AllowedLengthType::NonNegative => value >= 0., diff --git a/components/style_traits/viewport.rs b/components/style_traits/viewport.rs index 9a77a554f29..4bfaef849ac 100644 --- a/components/style_traits/viewport.rs +++ b/components/style_traits/viewport.rs @@ -9,7 +9,6 @@ use cssparser::{Parser, ToCss, ParseError as CssParseError, BasicParseError}; use euclid::size::TypedSize2D; use std::ascii::AsciiExt; use std::fmt; -use values::specified::AllowedLengthType; define_css_keyword_enum!(UserZoom: "zoom" => Zoom, @@ -141,12 +140,18 @@ impl Zoom { /// /// https://drafts.csswg.org/css-device-adapt/#descdef-viewport-zoom pub fn parse<'i, 't>(input: &mut Parser<'i, 't>) -> Result> { + use PARSING_MODE_DEFAULT; use cssparser::Token; + use values::specified::AllowedLengthType::NonNegative; match try!(input.next()) { - Token::Percentage(ref value) if AllowedLengthType::NonNegative.is_ok(value.unit_value) => + // TODO: This parse() method should take ParserContext as an + // argument, and pass ParsingMode owned by the ParserContext to + // is_ok() instead of using PARSING_MODE_DEFAULT directly. + // In order to do so, we might want to move these stuff into style::stylesheets::viewport_rule. + Token::Percentage(ref value) if NonNegative.is_ok(PARSING_MODE_DEFAULT, value.unit_value) => Ok(Zoom::Percentage(value.unit_value)), - Token::Number(ref value) if AllowedLengthType::NonNegative.is_ok(value.value) => + Token::Number(ref value) if NonNegative.is_ok(PARSING_MODE_DEFAULT, value.value) => Ok(Zoom::Number(value.value)), Token::Ident(ref value) if value.eq_ignore_ascii_case("auto") => Ok(Zoom::Auto),