Bug 1365629: Respect parsing mode in LengthOrPercentage. r?hiro
MozReview-Commit-ID: GJrh6XOZ8wJ
--- 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") =>