style: Only accept the CSS2 font-variant values (normal/small-caps) in the font shorthand; CSS Fonts 3/4 font-variant additions are not allowed

Differential Revision: https://phabricator.services.mozilla.com/D149440
This commit is contained in:
Jonathan Kew 2022-06-16 12:13:54 +00:00 committed by Martin Robinson
parent 6a5f012d3b
commit becb855b3a

View file

@ -31,6 +31,7 @@
derive_value_info="False"
spec="https://drafts.csswg.org/css-fonts-3/#propdef-font"
>
use crate::computed_values::font_variant_caps::T::SmallCaps;
use crate::parser::Parse;
use crate::properties::longhands::{font_family, font_style, font_weight, font_stretch};
use crate::properties::longhands::font_variant_caps;
@ -100,8 +101,11 @@
}
}
if variant_caps.is_none() {
if let Ok(value) = input.try_parse(|input| font_variant_caps::parse(context, input)) {
variant_caps = Some(value);
// The only variant-caps value allowed is small-caps (from CSS2); the added values
// defined by CSS Fonts 3 and later are not accepted.
// https://www.w3.org/TR/css-fonts-4/#font-prop
if input.try_parse(|input| input.expect_ident_matching("small-caps")).is_ok() {
variant_caps = Some(font_variant_caps::SpecifiedValue::Keyword(SmallCaps));
continue
}
}
@ -205,6 +209,14 @@
FontStretch::System(..) => return Ok(()),
};
// The only variant-caps value allowed in the shorthand is small-caps (from CSS2);
// the added values defined by CSS Fonts 3 and later are not supported.
// https://www.w3.org/TR/css-fonts-4/#font-prop
if self.font_variant_caps != &font_variant_caps::get_initial_specified_value() &&
*self.font_variant_caps != font_variant_caps::SpecifiedValue::Keyword(SmallCaps) {
return Ok(());
}
% for name in "style variant_caps weight".split():
if self.font_${name} != &font_${name}::get_initial_specified_value() {
self.font_${name}.to_css(dest)?;