Implement the unitless length quirk for position properties

This commit is contained in:
Anthony Ramine 2017-04-24 13:27:10 +02:00
parent 91cc30046b
commit 46913ffe1d
3 changed files with 586 additions and 306 deletions

View file

@ -13,7 +13,8 @@
${helpers.predefined_type(side, "LengthOrPercentageOrAuto", ${helpers.predefined_type(side, "LengthOrPercentageOrAuto",
"computed::LengthOrPercentageOrAuto::Auto", "computed::LengthOrPercentageOrAuto::Auto",
spec="https://www.w3.org/TR/CSS2/visuren.html#propdef-%s" % side, spec="https://www.w3.org/TR/CSS2/visuren.html#propdef-%s" % side,
animation_value_type="ComputedValue")} animation_value_type="ComputedValue",
allow_quirks=True)}
% endfor % endfor
// offset-* logical properties, map to "top" / "left" / "bottom" / "right" // offset-* logical properties, map to "top" / "left" / "bottom" / "right"
% for side in LOGICAL_SIDES: % for side in LOGICAL_SIDES:

View file

@ -1307,15 +1307,19 @@ impl ToCss for LengthOrPercentageOrAuto {
} }
impl LengthOrPercentageOrAuto { impl LengthOrPercentageOrAuto {
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<Self, ()> { -> Result<Self, ()> {
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) =>
NoCalcLength::parse_dimension(context, value.value, unit).map(LengthOrPercentageOrAuto::Length), NoCalcLength::parse_dimension(context, value.value, unit).map(LengthOrPercentageOrAuto::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(LengthOrPercentageOrAuto::Percentage(Percentage(value.unit_value))), Ok(LengthOrPercentageOrAuto::Percentage(Percentage(value.unit_value))),
Token::Number(ref value) if value.value == 0. => { 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(LengthOrPercentageOrAuto::Length( Ok(LengthOrPercentageOrAuto::Length(
@ -1337,7 +1341,7 @@ impl LengthOrPercentageOrAuto {
/// Parse a non-negative length, percentage, or auto. /// Parse a non-negative length, percentage, or auto.
#[inline] #[inline]
pub fn parse_non_negative(context: &ParserContext, input: &mut Parser) -> Result<LengthOrPercentageOrAuto, ()> { pub fn parse_non_negative(context: &ParserContext, input: &mut Parser) -> Result<LengthOrPercentageOrAuto, ()> {
Self::parse_internal(context, input, AllowedLengthType::NonNegative) Self::parse_internal(context, input, AllowedLengthType::NonNegative, AllowQuirks::No)
} }
/// Returns the `auto` value. /// Returns the `auto` value.
@ -1354,7 +1358,18 @@ impl LengthOrPercentageOrAuto {
impl Parse for LengthOrPercentageOrAuto { impl Parse for LengthOrPercentageOrAuto {
#[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_quirky(context, input, AllowQuirks::No)
}
}
impl LengthOrPercentageOrAuto {
/// Parses, with quirks.
#[inline]
pub fn parse_quirky(context: &ParserContext,
input: &mut Parser,
allow_quirks: AllowQuirks)
-> Result<Self, ()> {
Self::parse_internal(context, input, AllowedLengthType::All, allow_quirks)
} }
} }

File diff suppressed because it is too large Load diff