mirror of
https://github.com/servo/servo.git
synced 2025-08-03 04:30:10 +01:00
Implement the unitless length quirk for physical size extremums
This commit is contained in:
parent
2aea6d8907
commit
37118e1e45
4 changed files with 51 additions and 59 deletions
|
@ -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 {
|
||||
|
@ -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 {
|
||||
|
@ -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
|
||||
|
||||
|
|
|
@ -1434,7 +1434,10 @@ 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()) {
|
||||
|
@ -1442,8 +1445,9 @@ impl LengthOrPercentageOrNone {
|
|||
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(
|
||||
|
@ -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)
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -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))
|
||||
}
|
||||
|
@ -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()),
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue