Bug 1365629: Respect parsing mode in LengthOrPercentage. r?hiro draft
authorEmilio Cobos Álvarez <emilio@crisal.io>
Sun, 21 May 2017 14:54:05 +0200
changeset 582110 14a4da57c0fb1d77317d1b8cbf822c184a51c6b6
parent 582107 8a54297a4e3bb63c1b5716afcaa436eb336ccb15
child 582111 635b26b26b4219028ffff1e163827680763d7307
push id59975
push userbmo:emilio+bugs@crisal.io
push dateSun, 21 May 2017 13:08:27 +0000
reviewershiro
bugs1365629
milestone55.0a1
Bug 1365629: Respect parsing mode in LengthOrPercentage. r?hiro MozReview-Commit-ID: GJrh6XOZ8wJ
servo/components/style/values/specified/length.rs
--- a/servo/components/style/values/specified/length.rs
+++ b/servo/components/style/values/specified/length.rs
@@ -615,17 +615,18 @@ impl Length {
                       input: &mut Parser,
                       num_context: AllowedLengthType,
                       allow_quirks: AllowQuirks)
                       -> Result<Length, ()> {
         match try!(input.next()) {
             Token::Dimension(ref value, ref unit) if num_context.is_ok(value.value) =>
                 Length::parse_dimension(context, value.value, unit),
             Token::Number(ref value) if num_context.is_ok(value.value) => {
-                if value.value != 0. && !context.parsing_mode.allows_unitless_lengths() &&
+                if value.value != 0. &&
+                   !context.parsing_mode.allows_unitless_lengths() &&
                    !allow_quirks.allowed(context.quirks_mode) {
                     return Err(())
                 }
                 Ok(Length::NoCalc(NoCalcLength::Absolute(AbsoluteLength::Px(value.value))))
             },
             Token::Function(ref name) if name.eq_ignore_ascii_case("calc") =>
                 input.parse_nested_block(|input| {
                     CalcNode::parse_length(context, input, num_context).map(|calc| Length::Calc(Box::new(calc)))
@@ -800,19 +801,24 @@ impl LengthOrPercentage {
                       allow_quirks: AllowQuirks)
                       -> Result<LengthOrPercentage, ()>
     {
         match try!(input.next()) {
             Token::Dimension(ref value, ref unit) if num_context.is_ok(value.value) =>
                 NoCalcLength::parse_dimension(context, value.value, unit).map(LengthOrPercentage::Length),
             Token::Percentage(ref value) if num_context.is_ok(value.unit_value) =>
                 Ok(LengthOrPercentage::Percentage(Percentage(value.unit_value))),
-            Token::Number(value) if value.value == 0. ||
-                                    (num_context.is_ok(value.value) && allow_quirks.allowed(context.quirks_mode)) =>
-                Ok(LengthOrPercentage::Length(NoCalcLength::from_px(value.value))),
+            Token::Number(value) if num_context.is_ok(value.value) => {
+                if value.value != 0. &&
+                   !context.parsing_mode.allows_unitless_lengths() &&
+                   !allow_quirks.allowed(context.quirks_mode) {
+                    return Err(())
+                }
+                Ok(LengthOrPercentage::Length(NoCalcLength::from_px(value.value)))
+            }
             Token::Function(ref name) if name.eq_ignore_ascii_case("calc") => {
                 let calc = try!(input.parse_nested_block(|i| {
                     CalcNode::parse_length_or_percentage(context, i, num_context)
                 }));
                 Ok(LengthOrPercentage::Calc(Box::new(calc)))
             },
             _ => Err(())
         }
@@ -937,17 +943,18 @@ impl LengthOrPercentageOrAuto {
                       allow_quirks: AllowQuirks)
                       -> Result<Self, ()> {
         match try!(input.next()) {
             Token::Dimension(ref value, ref unit) if num_context.is_ok(value.value) =>
                 NoCalcLength::parse_dimension(context, value.value, unit).map(LengthOrPercentageOrAuto::Length),
             Token::Percentage(ref value) if num_context.is_ok(value.unit_value) =>
                 Ok(LengthOrPercentageOrAuto::Percentage(Percentage(value.unit_value))),
             Token::Number(ref value) if num_context.is_ok(value.value) => {
-                if value.value != 0. && !context.parsing_mode.allows_unitless_lengths() &&
+                if value.value != 0. &&
+                   !context.parsing_mode.allows_unitless_lengths() &&
                    !allow_quirks.allowed(context.quirks_mode) {
                     return Err(())
                 }
                 Ok(LengthOrPercentageOrAuto::Length(
                     NoCalcLength::Absolute(AbsoluteLength::Px(value.value))
                 ))
             }
             Token::Ident(ref value) if value.eq_ignore_ascii_case("auto") =>