Skip to content

Commit

Permalink
Implement the unitless length quirk for border-spacing
Browse files Browse the repository at this point in the history
  • Loading branch information
nox committed Apr 27, 2017
1 parent 080f74c commit 03d24e8
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 31 deletions.
9 changes: 5 additions & 4 deletions components/style/properties/longhand/inherited_table.mako.rs
Expand Up @@ -26,6 +26,7 @@ ${helpers.single_keyword("caption-side", "top bottom",
use std::fmt;
use style_traits::ToCss;
use values::HasViewportPercentage;
use values::specified::{AllowQuirks, Length};

pub mod computed_value {
use app_units::Au;
Expand Down Expand Up @@ -60,8 +61,8 @@ ${helpers.single_keyword("caption-side", "top bottom",
#[derive(Clone, Debug, PartialEq)]
#[cfg_attr(feature = "servo", derive(HeapSizeOf))]
pub struct SpecifiedValue {
pub horizontal: specified::Length,
pub vertical: Option<specified::Length>,
pub horizontal: Length,
pub vertical: Option<Length>,
}

#[inline]
Expand Down Expand Up @@ -117,11 +118,11 @@ ${helpers.single_keyword("caption-side", "top bottom",
pub fn parse(context: &ParserContext, input: &mut Parser) -> Result<SpecifiedValue,()> {
let mut first = None;
let mut second = None;
match specified::Length::parse_non_negative(context, input) {
match Length::parse_non_negative_quirky(context, input, AllowQuirks::Yes) {
Err(()) => (),
Ok(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);
}
}
Expand Down
25 changes: 19 additions & 6 deletions components/style/values/specified/length.rs
Expand Up @@ -563,13 +563,17 @@ impl Length {
}

#[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, ()> {
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. && !context.length_parsing_mode.allows_unitless_lengths() {
Token::Number(ref value) if num_context.is_ok(value.value) => {
if value.value != 0. && !context.length_parsing_mode.allows_unitless_lengths() &&
!allow_quirks.allowed(context.quirks_mode) {
return Err(())
}
Ok(Length::NoCalc(NoCalcLength::Absolute(AbsoluteLength::Px(value.value))))
Expand All @@ -585,7 +589,16 @@ impl Length {
/// Parse a non-negative length
#[inline]
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.
Expand All @@ -605,7 +618,7 @@ impl Length {

impl Parse for Length {
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)
}
}

Expand All @@ -616,7 +629,7 @@ impl<T: Parse> Either<Length, T> {
if let Ok(v) = input.try(|input| T::parse(context, input)) {
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)
}
}

Expand Down
21 changes: 0 additions & 21 deletions tests/wpt/metadata/quirks-mode/unitless-length.html.ini
@@ -1,8 +1,5 @@
[unitless-length.html]
type: testharness
[border-spacing: 1 (quirks)]
expected: FAIL

[border-top-width: 1 (quirks)]
expected: FAIL

Expand Down Expand Up @@ -102,9 +99,6 @@
[word-spacing: 1 (quirks)]
expected: FAIL

[border-spacing: +1 (quirks)]
expected: FAIL

[border-top-width: +1 (quirks)]
expected: FAIL

Expand Down Expand Up @@ -255,9 +249,6 @@
[word-spacing: -1 (quirks)]
expected: FAIL

[border-spacing: 1.5 (quirks)]
expected: FAIL

[border-top-width: 1.5 (quirks)]
expected: FAIL

Expand Down Expand Up @@ -357,9 +348,6 @@
[word-spacing: 1.5 (quirks)]
expected: FAIL

[border-spacing: +1.5 (quirks)]
expected: FAIL

[border-top-width: +1.5 (quirks)]
expected: FAIL

Expand Down Expand Up @@ -1248,9 +1236,6 @@
[top: calc(2 * 2px) (standards)]
expected: FAIL

[border-spacing: 1px 2 (quirks)]
expected: FAIL

[border-width: 1px 2 (quirks)]
expected: FAIL

Expand All @@ -1260,9 +1245,6 @@
[padding: 1px 2 (quirks)]
expected: FAIL

[border-spacing: 1 2px (quirks)]
expected: FAIL

[border-width: 1 2px (quirks)]
expected: FAIL

Expand All @@ -1272,9 +1254,6 @@
[padding: 1 2px (quirks)]
expected: FAIL

[border-spacing: 1 +2 (quirks)]
expected: FAIL

[border-width: 1 +2 (quirks)]
expected: FAIL

Expand Down

0 comments on commit 03d24e8

Please sign in to comment.