Skip to content

Commit

Permalink
Implement the unitless length quirk for physical size extremums
Browse files Browse the repository at this point in the history
  • Loading branch information
nox committed Apr 27, 2017
1 parent 2aea6d8 commit 37118e1
Show file tree
Hide file tree
Showing 4 changed files with 51 additions and 59 deletions.
14 changes: 11 additions & 3 deletions components/style/properties/longhand/position.mako.rs
Expand Up @@ -179,7 +179,7 @@ ${helpers.predefined_type("flex-basis",
use std::fmt;
use style_traits::ToCss;
use values::HasViewportPercentage;
use values::specified::${MinMax}Length;
use values::specified::{AllowQuirks, ${MinMax}Length};

impl HasViewportPercentage for SpecifiedValue {
fn has_viewport_percentage(&self) -> bool {
Expand All @@ -201,7 +201,11 @@ ${helpers.predefined_type("flex-basis",
${MinMax}Length::${initial}
}
fn parse(context: &ParserContext, input: &mut Parser) -> Result<SpecifiedValue, ()> {
% if logical:
let ret = ${MinMax}Length::parse(context, input);
% else:
let ret = ${MinMax}Length::parse_quirky(context, input, AllowQuirks::Yes);
% endif
// Keyword values don't make sense in the block direction; don't parse them
% if "block" in size:
if let Ok(${MinMax}Length::ExtremumLength(..)) = ret {
Expand Down Expand Up @@ -256,13 +260,17 @@ ${helpers.predefined_type("flex-basis",
"computed::LengthOrPercentage::Length(Au(0))",
"parse_non_negative",
spec=spec % ("min-%s" % size),
animation_value_type="ComputedValue", logical = logical)}
animation_value_type="ComputedValue",
logical=logical,
allow_quirks=not logical)}
${helpers.predefined_type("max-%s" % size,
"LengthOrPercentageOrNone",
"computed::LengthOrPercentageOrNone::None",
"parse_non_negative",
spec=spec % ("min-%s" % size),
animation_value_type="ComputedValue", logical = logical)}
animation_value_type="ComputedValue",
logical=logical,
allow_quirks=not logical)}
% endif
% endfor

Expand Down
46 changes: 39 additions & 7 deletions components/style/values/specified/length.rs
Expand Up @@ -1434,16 +1434,20 @@ impl ToCss for LengthOrPercentageOrNone {
}
}
impl LengthOrPercentageOrNone {
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<LengthOrPercentageOrNone, ()>
{
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(LengthOrPercentageOrNone::Length),
Token::Percentage(ref value) if num_context.is_ok(value.unit_value) =>
Ok(LengthOrPercentageOrNone::Percentage(Percentage(value.unit_value))),
Token::Number(ref value) if value.value == 0. => {
if value.value != 0. && !context.length_parsing_mode.allows_unitless_lengths() {
Token::Number(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(LengthOrPercentageOrNone::Length(
Expand All @@ -1461,17 +1465,27 @@ impl LengthOrPercentageOrNone {
_ => Err(())
}
}

/// Parse a non-negative LengthOrPercentageOrNone.
#[inline]
pub fn parse_non_negative(context: &ParserContext, input: &mut Parser) -> Result<Self, ()> {
Self::parse_internal(context, input, AllowedLengthType::NonNegative)
Self::parse_non_negative_quirky(context, input, AllowQuirks::No)
}

/// Parse a non-negative LengthOrPercentageOrNone, with quirks.
#[inline]
pub fn parse_non_negative_quirky(context: &ParserContext,
input: &mut Parser,
allow_quirks: AllowQuirks)
-> Result<Self, ()> {
Self::parse_internal(context, input, AllowedLengthType::NonNegative, allow_quirks)
}
}

impl Parse for LengthOrPercentageOrNone {
#[inline]
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 Down Expand Up @@ -1615,8 +1629,17 @@ impl ToCss for MinLength {

impl Parse for MinLength {
fn parse(context: &ParserContext, input: &mut Parser) -> Result<Self, ()> {
MinLength::parse_quirky(context, input, AllowQuirks::No)
}
}

impl MinLength {
/// Parses, with quirks.
pub fn parse_quirky(context: &ParserContext,
input: &mut Parser,
allow_quirks: AllowQuirks) -> Result<Self, ()> {
input.try(ExtremumLength::parse).map(MinLength::ExtremumLength)
.or_else(|()| input.try(|i| LengthOrPercentage::parse_non_negative(context, i))
.or_else(|()| input.try(|i| LengthOrPercentage::parse_non_negative_quirky(context, i, allow_quirks))
.map(MinLength::LengthOrPercentage))
.or_else(|()| input.expect_ident_matching("auto").map(|()| MinLength::Auto))
}
Expand Down Expand Up @@ -1656,8 +1679,17 @@ impl ToCss for MaxLength {

impl Parse for MaxLength {
fn parse(context: &ParserContext, input: &mut Parser) -> Result<Self, ()> {
MaxLength::parse_quirky(context, input, AllowQuirks::No)
}
}

impl MaxLength {
/// Parses, with quirks.
pub fn parse_quirky(context: &ParserContext,
input: &mut Parser,
allow_quirks: AllowQuirks) -> Result<Self, ()> {
input.try(ExtremumLength::parse).map(MaxLength::ExtremumLength)
.or_else(|()| input.try(|i| LengthOrPercentage::parse_non_negative(context, i))
.or_else(|()| input.try(|i| LengthOrPercentage::parse_non_negative_quirky(context, i, allow_quirks))
.map(MaxLength::LengthOrPercentage))
.or_else(|()| {
match_ignore_ascii_case! { &try!(input.expect_ident()),
Expand Down
2 changes: 1 addition & 1 deletion ports/geckolib/glue.rs
Expand Up @@ -511,7 +511,7 @@ pub extern "C" fn Servo_StyleSheet_Empty(mode: SheetParsingMode) -> RawServoStyl
Arc::new(Stylesheet::from_str(
"", unsafe { dummy_url_data() }.clone(), origin,
Arc::new(shared_lock.wrap(MediaList::empty())),
shared_lock, None, &RustLogReporter, QuirksMode::NoQuirks, Wh0u64)
shared_lock, None, &RustLogReporter, QuirksMode::NoQuirks, 0u64)
).into_strong()
}

Expand Down
48 changes: 0 additions & 48 deletions tests/wpt/metadata/quirks-mode/unitless-length.html.ini
Expand Up @@ -12,18 +12,6 @@
expected:
if os == "mac": FAIL

[max-height: 1 (quirks)]
expected: FAIL

[max-width: 1 (quirks)]
expected: FAIL

[min-height: 1 (quirks)]
expected: FAIL

[min-width: 1 (quirks)]
expected: FAIL

[padding-top: 1 (quirks)]
expected: FAIL

Expand Down Expand Up @@ -72,18 +60,6 @@
expected:
if os == "mac": FAIL

[max-height: +1 (quirks)]
expected: FAIL

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

[min-height: +1 (quirks)]
expected: FAIL

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

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

Expand Down Expand Up @@ -168,18 +144,6 @@
expected:
if os == "mac": FAIL

[max-height: 1.5 (quirks)]
expected: FAIL

[max-width: 1.5 (quirks)]
expected: FAIL

[min-height: 1.5 (quirks)]
expected: FAIL

[min-width: 1.5 (quirks)]
expected: FAIL

[padding-top: 1.5 (quirks)]
expected: FAIL

Expand Down Expand Up @@ -228,18 +192,6 @@
expected:
if os == "mac": FAIL

[max-height: +1.5 (quirks)]
expected: FAIL

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

[min-height: +1.5 (quirks)]
expected: FAIL

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

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

Expand Down

0 comments on commit 37118e1

Please sign in to comment.