Implement the unitless length quirk for border-spacing

This commit is contained in:
Anthony Ramine 2017-04-24 11:48:00 +02:00
parent 080f74ca63
commit 03d24e8361
3 changed files with 24 additions and 31 deletions

View file

@ -26,6 +26,7 @@ ${helpers.single_keyword("caption-side", "top bottom",
use std::fmt; use std::fmt;
use style_traits::ToCss; use style_traits::ToCss;
use values::HasViewportPercentage; use values::HasViewportPercentage;
use values::specified::{AllowQuirks, Length};
pub mod computed_value { pub mod computed_value {
use app_units::Au; use app_units::Au;
@ -60,8 +61,8 @@ ${helpers.single_keyword("caption-side", "top bottom",
#[derive(Clone, Debug, PartialEq)] #[derive(Clone, Debug, PartialEq)]
#[cfg_attr(feature = "servo", derive(HeapSizeOf))] #[cfg_attr(feature = "servo", derive(HeapSizeOf))]
pub struct SpecifiedValue { pub struct SpecifiedValue {
pub horizontal: specified::Length, pub horizontal: Length,
pub vertical: Option<specified::Length>, pub vertical: Option<Length>,
} }
#[inline] #[inline]
@ -117,11 +118,11 @@ ${helpers.single_keyword("caption-side", "top bottom",
pub fn parse(context: &ParserContext, input: &mut Parser) -> Result<SpecifiedValue,()> { pub fn parse(context: &ParserContext, input: &mut Parser) -> Result<SpecifiedValue,()> {
let mut first = None; let mut first = None;
let mut second = None; let mut second = None;
match specified::Length::parse_non_negative(context, input) { match Length::parse_non_negative_quirky(context, input, AllowQuirks::Yes) {
Err(()) => (), Err(()) => (),
Ok(length) => { Ok(length) => {
first = Some(length); first = Some(length);
if let Ok(len) = input.try(|input| specified::Length::parse_non_negative(context, input)) { if let Ok(len) = input.try(|i| Length::parse_non_negative_quirky(context, i, AllowQuirks::Yes)) {
second = Some(len); second = Some(len);
} }
} }

View file

@ -563,13 +563,17 @@ impl Length {
} }
#[inline] #[inline]
fn parse_internal(context: &ParserContext, input: &mut Parser, num_context: AllowedLengthType) fn parse_internal(context: &ParserContext,
input: &mut Parser,
num_context: AllowedLengthType,
allow_quirks: AllowQuirks)
-> Result<Length, ()> { -> Result<Length, ()> {
match try!(input.next()) { match try!(input.next()) {
Token::Dimension(ref value, ref unit) if num_context.is_ok(value.value) => Token::Dimension(ref value, ref unit) if num_context.is_ok(value.value) =>
Length::parse_dimension(context, value.value, unit), Length::parse_dimension(context, value.value, unit),
Token::Number(ref value) => { Token::Number(ref value) if num_context.is_ok(value.value) => {
if value.value != 0. && !context.length_parsing_mode.allows_unitless_lengths() { if value.value != 0. && !context.length_parsing_mode.allows_unitless_lengths() &&
!allow_quirks.allowed(context.quirks_mode) {
return Err(()) return Err(())
} }
Ok(Length::NoCalc(NoCalcLength::Absolute(AbsoluteLength::Px(value.value)))) Ok(Length::NoCalc(NoCalcLength::Absolute(AbsoluteLength::Px(value.value))))
@ -585,7 +589,16 @@ impl Length {
/// Parse a non-negative length /// Parse a non-negative length
#[inline] #[inline]
pub fn parse_non_negative(context: &ParserContext, input: &mut Parser) -> Result<Length, ()> { pub fn parse_non_negative(context: &ParserContext, input: &mut Parser) -> Result<Length, ()> {
Self::parse_internal(context, input, AllowedLengthType::NonNegative) Self::parse_non_negative_quirky(context, input, AllowQuirks::No)
}
/// Parse a non-negative length, allowing quirks.
#[inline]
pub fn parse_non_negative_quirky(context: &ParserContext,
input: &mut Parser,
allow_quirks: AllowQuirks)
-> Result<Length, ()> {
Self::parse_internal(context, input, AllowedLengthType::NonNegative, allow_quirks)
} }
/// Get an absolute length from a px value. /// Get an absolute length from a px value.
@ -605,7 +618,7 @@ impl Length {
impl Parse for Length { impl Parse for Length {
fn parse(context: &ParserContext, input: &mut Parser) -> Result<Self, ()> { fn parse(context: &ParserContext, input: &mut Parser) -> Result<Self, ()> {
Self::parse_internal(context, input, AllowedLengthType::All) Self::parse_internal(context, input, AllowedLengthType::All, AllowQuirks::No)
} }
} }
@ -616,7 +629,7 @@ impl<T: Parse> Either<Length, T> {
if let Ok(v) = input.try(|input| T::parse(context, input)) { if let Ok(v) = input.try(|input| T::parse(context, input)) {
return Ok(Either::Second(v)); return Ok(Either::Second(v));
} }
Length::parse_internal(context, input, AllowedLengthType::NonNegative).map(Either::First) Length::parse_internal(context, input, AllowedLengthType::NonNegative, AllowQuirks::No).map(Either::First)
} }
} }

View file

@ -1,8 +1,5 @@
[unitless-length.html] [unitless-length.html]
type: testharness type: testharness
[border-spacing: 1 (quirks)]
expected: FAIL
[border-top-width: 1 (quirks)] [border-top-width: 1 (quirks)]
expected: FAIL expected: FAIL
@ -102,9 +99,6 @@
[word-spacing: 1 (quirks)] [word-spacing: 1 (quirks)]
expected: FAIL expected: FAIL
[border-spacing: +1 (quirks)]
expected: FAIL
[border-top-width: +1 (quirks)] [border-top-width: +1 (quirks)]
expected: FAIL expected: FAIL
@ -255,9 +249,6 @@
[word-spacing: -1 (quirks)] [word-spacing: -1 (quirks)]
expected: FAIL expected: FAIL
[border-spacing: 1.5 (quirks)]
expected: FAIL
[border-top-width: 1.5 (quirks)] [border-top-width: 1.5 (quirks)]
expected: FAIL expected: FAIL
@ -357,9 +348,6 @@
[word-spacing: 1.5 (quirks)] [word-spacing: 1.5 (quirks)]
expected: FAIL expected: FAIL
[border-spacing: +1.5 (quirks)]
expected: FAIL
[border-top-width: +1.5 (quirks)] [border-top-width: +1.5 (quirks)]
expected: FAIL expected: FAIL
@ -1248,9 +1236,6 @@
[top: calc(2 * 2px) (standards)] [top: calc(2 * 2px) (standards)]
expected: FAIL expected: FAIL
[border-spacing: 1px 2 (quirks)]
expected: FAIL
[border-width: 1px 2 (quirks)] [border-width: 1px 2 (quirks)]
expected: FAIL expected: FAIL
@ -1260,9 +1245,6 @@
[padding: 1px 2 (quirks)] [padding: 1px 2 (quirks)]
expected: FAIL expected: FAIL
[border-spacing: 1 2px (quirks)]
expected: FAIL
[border-width: 1 2px (quirks)] [border-width: 1 2px (quirks)]
expected: FAIL expected: FAIL
@ -1272,9 +1254,6 @@
[padding: 1 2px (quirks)] [padding: 1 2px (quirks)]
expected: FAIL expected: FAIL
[border-spacing: 1 +2 (quirks)]
expected: FAIL
[border-width: 1 +2 (quirks)] [border-width: 1 +2 (quirks)]
expected: FAIL expected: FAIL