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,
allowed_in_keyframe_block=True, complex_color=False, cast_type='u8',
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
if not spec:
raise TypeError("Spec should be specified for %s" % name)
@ -166,6 +166,7 @@ class Longhand(object):
self.boxed = arg_to_bool(boxed)
self.flags = flags.split() if flags else []
self.allowed_in_page_rule = arg_to_bool(allowed_in_page_rule)
self.allow_quirks = allow_quirks
# https://drafts.csswg.org/css-animations/#keyframes
# > 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))
% else:
-> Result<SpecifiedValue, ()> {
parse(context, input)
% if property.allow_quirks:
parse_quirky(context, input, specified::AllowQuirks::Yes)
% else:
parse(context, input)
% endif
% endif
}
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 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 properties::longhands::system_font::SystemFont;
use properties::style_structs::Font;
use std::fmt;
use style_traits::ToCss;
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::length::FontBaseSize;
@ -843,9 +843,19 @@ ${helpers.single_keyword_system("font-variant-caps",
))
}
}
/// <length> | <percentage> | <absolute-size> | <relative-size>
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))
}

View file

@ -1204,7 +1204,16 @@ impl LengthOrPercentage {
/// Parse a non-negative length.
#[inline]
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

View file

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