SVG length parsing mode

SVG allows non-zero lengths to be accepted and assumes they are in px.  This
adds this length parsing mode to Servo.

MozReview-Commit-ID: Kxd3x64r9Ye
This commit is contained in:
J. Ryan Stinnett 2017-04-12 17:40:48 +08:00
parent 0936dd24d0
commit 6069e44f02
18 changed files with 130 additions and 53 deletions

View file

@ -551,7 +551,12 @@ impl 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 value.value == 0. => Ok(Length::zero()),
Token::Number(ref value) => {
if value.value != 0. && !context.length_parsing_mode.allows_unitless_lengths() {
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| {
CalcLengthOrPercentage::parse_length(context, input, num_context)