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.
This commit is contained in:
Hiroyuki Ikezoe 2017-06-14 09:51:53 +09:00
parent 8bfed4cb3c
commit 7341574b66
3 changed files with 26 additions and 17 deletions

View file

@ -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<Zoom, ParseError<'i>> {
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),