Implement the unitless length quirk for physical size extremums

This commit is contained in:
Anthony Ramine 2017-04-25 00:59:01 +02:00
parent 2aea6d8907
commit 37118e1e45
4 changed files with 51 additions and 59 deletions

View file

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

View file

@ -1434,7 +1434,10 @@ impl ToCss for LengthOrPercentageOrNone {
} }
} }
impl 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, ()> -> Result<LengthOrPercentageOrNone, ()>
{ {
match try!(input.next()) { match try!(input.next()) {
@ -1442,8 +1445,9 @@ impl LengthOrPercentageOrNone {
NoCalcLength::parse_dimension(context, value.value, unit).map(LengthOrPercentageOrNone::Length), NoCalcLength::parse_dimension(context, value.value, unit).map(LengthOrPercentageOrNone::Length),
Token::Percentage(ref value) if num_context.is_ok(value.unit_value) => Token::Percentage(ref value) if num_context.is_ok(value.unit_value) =>
Ok(LengthOrPercentageOrNone::Percentage(Percentage(value.unit_value))), Ok(LengthOrPercentageOrNone::Percentage(Percentage(value.unit_value))),
Token::Number(ref value) if value.value == 0. => { Token::Number(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(LengthOrPercentageOrNone::Length( Ok(LengthOrPercentageOrNone::Length(
@ -1461,17 +1465,27 @@ impl LengthOrPercentageOrNone {
_ => Err(()) _ => Err(())
} }
} }
/// Parse a non-negative LengthOrPercentageOrNone. /// Parse a non-negative LengthOrPercentageOrNone.
#[inline] #[inline]
pub fn parse_non_negative(context: &ParserContext, input: &mut Parser) -> Result<Self, ()> { 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 { impl Parse for LengthOrPercentageOrNone {
#[inline] #[inline]
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)
} }
} }
@ -1615,8 +1629,17 @@ impl ToCss for MinLength {
impl Parse for MinLength { impl Parse for MinLength {
fn parse(context: &ParserContext, input: &mut Parser) -> Result<Self, ()> { 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) 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)) .map(MinLength::LengthOrPercentage))
.or_else(|()| input.expect_ident_matching("auto").map(|()| MinLength::Auto)) .or_else(|()| input.expect_ident_matching("auto").map(|()| MinLength::Auto))
} }
@ -1656,8 +1679,17 @@ impl ToCss for MaxLength {
impl Parse for MaxLength { impl Parse for MaxLength {
fn parse(context: &ParserContext, input: &mut Parser) -> Result<Self, ()> { 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) 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)) .map(MaxLength::LengthOrPercentage))
.or_else(|()| { .or_else(|()| {
match_ignore_ascii_case! { &try!(input.expect_ident()), match_ignore_ascii_case! { &try!(input.expect_ident()),

View file

@ -511,7 +511,7 @@ pub extern "C" fn Servo_StyleSheet_Empty(mode: SheetParsingMode) -> RawServoStyl
Arc::new(Stylesheet::from_str( Arc::new(Stylesheet::from_str(
"", unsafe { dummy_url_data() }.clone(), origin, "", unsafe { dummy_url_data() }.clone(), origin,
Arc::new(shared_lock.wrap(MediaList::empty())), Arc::new(shared_lock.wrap(MediaList::empty())),
shared_lock, None, &RustLogReporter, QuirksMode::NoQuirks, Wh0u64) shared_lock, None, &RustLogReporter, QuirksMode::NoQuirks, 0u64)
).into_strong() ).into_strong()
} }

View file

@ -12,18 +12,6 @@
expected: expected:
if os == "mac": FAIL 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)] [padding-top: 1 (quirks)]
expected: FAIL expected: FAIL
@ -72,18 +60,6 @@
expected: expected:
if os == "mac": FAIL 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)] [padding-top: +1 (quirks)]
expected: FAIL expected: FAIL
@ -168,18 +144,6 @@
expected: expected:
if os == "mac": FAIL 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)] [padding-top: 1.5 (quirks)]
expected: FAIL expected: FAIL
@ -228,18 +192,6 @@
expected: expected:
if os == "mac": FAIL 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)] [padding-top: +1.5 (quirks)]
expected: FAIL expected: FAIL