Implement the unitless length quirk for font-size

This commit is contained in:
Anthony Ramine 2017-04-24 16:12:36 +02:00
parent ba59fafb44
commit 0e7308e6dc
5 changed files with 30 additions and 18 deletions

View file

@ -140,7 +140,7 @@ class Longhand(object):
need_clone=False, need_index=False, gecko_ffi_name=None, depend_on_viewport_size=False, need_clone=False, need_index=False, gecko_ffi_name=None, depend_on_viewport_size=False,
allowed_in_keyframe_block=True, complex_color=False, cast_type='u8', allowed_in_keyframe_block=True, complex_color=False, cast_type='u8',
has_uncacheable_values=False, logical=False, alias=None, extra_prefixes=None, boxed=False, has_uncacheable_values=False, logical=False, alias=None, extra_prefixes=None, boxed=False,
flags=None, allowed_in_page_rule=False): flags=None, allowed_in_page_rule=False, allow_quirks=False):
self.name = name self.name = name
if not spec: if not spec:
raise TypeError("Spec should be specified for %s" % name) raise TypeError("Spec should be specified for %s" % name)
@ -166,6 +166,7 @@ class Longhand(object):
self.boxed = arg_to_bool(boxed) self.boxed = arg_to_bool(boxed)
self.flags = flags.split() if flags else [] self.flags = flags.split() if flags else []
self.allowed_in_page_rule = arg_to_bool(allowed_in_page_rule) self.allowed_in_page_rule = arg_to_bool(allowed_in_page_rule)
self.allow_quirks = allow_quirks
# https://drafts.csswg.org/css-animations/#keyframes # https://drafts.csswg.org/css-animations/#keyframes
# > The <declaration-list> inside of <keyframe-block> accepts any CSS property # > The <declaration-list> inside of <keyframe-block> accepts any CSS property

View file

@ -375,7 +375,11 @@
parse(context, input).map(|result| Box::new(result)) parse(context, input).map(|result| Box::new(result))
% else: % else:
-> Result<SpecifiedValue, ()> { -> Result<SpecifiedValue, ()> {
parse(context, input) % if property.allow_quirks:
parse_quirky(context, input, specified::AllowQuirks::Yes)
% else:
parse(context, input)
% endif
% endif % endif
} }
pub fn parse_declared(context: &ParserContext, input: &mut Parser) pub fn parse_declared(context: &ParserContext, input: &mut Parser)

View file

@ -550,14 +550,14 @@ ${helpers.single_keyword_system("font-variant-caps",
</%helpers:longhand> </%helpers:longhand>
<%helpers:longhand name="font-size" need_clone="True" animation_value_type="ComputedValue" <%helpers:longhand name="font-size" need_clone="True" animation_value_type="ComputedValue"
spec="https://drafts.csswg.org/css-fonts/#propdef-font-size"> allow_quirks="True" spec="https://drafts.csswg.org/css-fonts/#propdef-font-size">
use app_units::Au; use app_units::Au;
use properties::longhands::system_font::SystemFont; use properties::longhands::system_font::SystemFont;
use properties::style_structs::Font; use properties::style_structs::Font;
use std::fmt; use std::fmt;
use style_traits::ToCss; use style_traits::ToCss;
use values::{FONT_MEDIUM_PX, HasViewportPercentage}; use values::{FONT_MEDIUM_PX, HasViewportPercentage};
use values::specified::{FontRelativeLength, LengthOrPercentage, Length}; use values::specified::{AllowQuirks, FontRelativeLength, LengthOrPercentage, Length};
use values::specified::{NoCalcLength, Percentage}; use values::specified::{NoCalcLength, Percentage};
use values::specified::length::FontBaseSize; use values::specified::length::FontBaseSize;
@ -843,9 +843,19 @@ ${helpers.single_keyword_system("font-variant-caps",
)) ))
} }
} }
/// <length> | <percentage> | <absolute-size> | <relative-size> /// <length> | <percentage> | <absolute-size> | <relative-size>
pub fn parse(context: &ParserContext, input: &mut Parser) -> Result<SpecifiedValue, ()> { pub fn parse(context: &ParserContext, input: &mut Parser) -> Result<SpecifiedValue, ()> {
if let Ok(lop) = input.try(|i| specified::LengthOrPercentage::parse_non_negative(context, i)) { parse_quirky(context, input, AllowQuirks::No)
}
/// Parses a font-size, with quirks.
pub fn parse_quirky(context: &ParserContext,
input: &mut Parser,
allow_quirks: AllowQuirks)
-> Result<SpecifiedValue, ()> {
use self::specified::LengthOrPercentage;
if let Ok(lop) = input.try(|i| LengthOrPercentage::parse_non_negative_quirky(context, i, allow_quirks)) {
return Ok(SpecifiedValue::Length(lop)) return Ok(SpecifiedValue::Length(lop))
} }

View file

@ -1204,7 +1204,16 @@ impl LengthOrPercentage {
/// Parse a non-negative length. /// Parse a non-negative length.
#[inline] #[inline]
pub fn parse_non_negative(context: &ParserContext, input: &mut Parser) -> Result<LengthOrPercentage, ()> { pub fn parse_non_negative(context: &ParserContext, input: &mut Parser) -> Result<LengthOrPercentage, ()> {
Self::parse_internal(context, input, AllowedLengthType::NonNegative, AllowQuirks::No) Self::parse_non_negative_quirky(context, input, AllowQuirks::No)
}
/// Parse a non-negative length, with quirks.
#[inline]
pub fn parse_non_negative_quirky(context: &ParserContext,
input: &mut Parser,
allow_quirks: AllowQuirks)
-> Result<LengthOrPercentage, ()> {
Self::parse_internal(context, input, AllowedLengthType::NonNegative, allow_quirks)
} }
/// Parse a length, treating dimensionless numbers as pixels /// Parse a length, treating dimensionless numbers as pixels

View file

@ -12,9 +12,6 @@
expected: expected:
if os == "mac": FAIL if os == "mac": FAIL
[font-size: 1 (quirks)]
expected: FAIL
[height: 1 (quirks)] [height: 1 (quirks)]
expected: FAIL expected: FAIL
@ -96,9 +93,6 @@
expected: expected:
if os == "mac": FAIL if os == "mac": FAIL
[font-size: +1 (quirks)]
expected: FAIL
[height: +1 (quirks)] [height: +1 (quirks)]
expected: FAIL expected: FAIL
@ -231,9 +225,6 @@
expected: expected:
if os == "mac": FAIL if os == "mac": FAIL
[font-size: 1.5 (quirks)]
expected: FAIL
[height: 1.5 (quirks)] [height: 1.5 (quirks)]
expected: FAIL expected: FAIL
@ -315,9 +306,6 @@
expected: expected:
if os == "mac": FAIL if os == "mac": FAIL
[font-size: +1.5 (quirks)]
expected: FAIL
[height: +1.5 (quirks)] [height: +1.5 (quirks)]
expected: FAIL expected: FAIL