style: Remove system font support for various font longhands

We don't use them[1], and these are generally not properties that
authors would be able to set via the font shorthand anyways.

Let's simplify the code. This fixes the font-variant bug and also
unblocks further clean-ups of these properties in the future.

[1]: https://searchfox.org/mozilla-central/rev/59f0bf3c13dd455d9f5415b89178de701ea6b850/widget/LookAndFeelTypes.ipdlh#12-18

Differential Revision: https://phabricator.services.mozilla.com/D160352
This commit is contained in:
Emilio Cobos Álvarez 2022-10-26 14:42:49 +00:00 committed by Martin Robinson
parent 3c4d198ad7
commit efdf518acc
7 changed files with 156 additions and 588 deletions

View file

@ -17,10 +17,8 @@ use crate::values::generics::font::FontStyle as GenericFontStyle;
#[cfg(feature = "gecko")] #[cfg(feature = "gecko")]
use crate::values::specified::font::MetricsOverride; use crate::values::specified::font::MetricsOverride;
#[cfg(feature = "gecko")] #[cfg(feature = "gecko")]
use crate::values::specified::font::SpecifiedFontFeatureSettings; use crate::values::specified::font::{FontFeatureSettings, FontVariationSettings};
use crate::values::specified::font::SpecifiedFontStyle; use crate::values::specified::font::SpecifiedFontStyle;
#[cfg(feature = "gecko")]
use crate::values::specified::font::SpecifiedFontVariationSettings;
use crate::values::specified::font::{AbsoluteFontWeight, FontStretch as SpecifiedFontStretch}; use crate::values::specified::font::{AbsoluteFontWeight, FontStretch as SpecifiedFontStretch};
use crate::values::specified::url::SpecifiedUrl; use crate::values::specified::url::SpecifiedUrl;
use crate::values::specified::Angle; use crate::values::specified::Angle;
@ -760,10 +758,10 @@ font_face_descriptors! {
"unicode-range" unicode_range / mUnicodeRange: Vec<UnicodeRange>, "unicode-range" unicode_range / mUnicodeRange: Vec<UnicodeRange>,
/// The feature settings of this font face. /// The feature settings of this font face.
"font-feature-settings" feature_settings / mFontFeatureSettings: SpecifiedFontFeatureSettings, "font-feature-settings" feature_settings / mFontFeatureSettings: FontFeatureSettings,
/// The variation settings of this font face. /// The variation settings of this font face.
"font-variation-settings" variation_settings / mFontVariationSettings: SpecifiedFontVariationSettings, "font-variation-settings" variation_settings / mFontVariationSettings: FontVariationSettings,
/// The language override of this font face. /// The language override of this font face.
"font-language-override" language_override / mFontLanguageOverride: font_language_override::SpecifiedValue, "font-language-override" language_override / mFontLanguageOverride: font_language_override::SpecifiedValue,

View file

@ -29,13 +29,7 @@ ALL_AXES = [(axis, False) for axis in PHYSICAL_AXES] + [
] ]
SYSTEM_FONT_LONGHANDS = """font_family font_size font_style SYSTEM_FONT_LONGHANDS = """font_family font_size font_style
font_variant_caps font_stretch font_kerning font_stretch font_weight""".split()
font_variant_position font_weight
font_size_adjust font_variant_alternates
font_variant_ligatures font_variant_east_asian
font_variant_numeric font_language_override
font_feature_settings font_variation_settings
font_optical_sizing""".split()
# Bitfield values for all rule types which can have property declarations. # Bitfield values for all rule types which can have property declarations.
STYLE_RULE = 1 << 0 STYLE_RULE = 1 << 0

View file

@ -537,104 +537,6 @@
} }
</%def> </%def>
<%def name="single_keyword_system(name, values, **kwargs)">
<%
keyword_kwargs = {a: kwargs.pop(a, None) for a in [
'gecko_constant_prefix',
'gecko_enum_prefix',
'extra_gecko_values',
'extra_servo_values',
'custom_consts',
'gecko_inexhaustive',
]}
keyword = keyword=Keyword(name, values, **keyword_kwargs)
%>
<%call expr="longhand(name, keyword=Keyword(name, values, **keyword_kwargs), **kwargs)">
use crate::values::specified::font::SystemFont;
pub mod computed_value {
#[cfg_attr(feature = "servo", derive(Deserialize, Serialize))]
#[derive(
Clone,
Copy,
Debug,
Eq,
FromPrimitive,
Hash,
MallocSizeOf,
Parse,
PartialEq,
SpecifiedValueInfo,
ToCss,
ToResolvedValue,
ToShmem,
)]
pub enum T {
% for value in keyword.values_for(engine):
${to_camel_case(value)},
% endfor
}
${gecko_keyword_conversion(keyword, keyword.values_for(engine), type="T", cast_to="i32")}
}
#[cfg_attr(feature = "gecko", derive(MallocSizeOf))]
#[derive(Clone, Copy, Debug, Eq, PartialEq, SpecifiedValueInfo, ToCss, ToShmem)]
pub enum SpecifiedValue {
Keyword(computed_value::T),
#[css(skip)]
System(SystemFont),
}
pub fn parse<'i, 't>(_: &ParserContext, input: &mut Parser<'i, 't>) -> Result<SpecifiedValue, ParseError<'i>> {
Ok(SpecifiedValue::Keyword(computed_value::T::parse(input)?))
}
impl ToComputedValue for SpecifiedValue {
type ComputedValue = computed_value::T;
fn to_computed_value(&self, _cx: &Context) -> Self::ComputedValue {
match *self {
SpecifiedValue::Keyword(v) => v,
% if engine == "gecko":
SpecifiedValue::System(_) => {
_cx.cached_system_font.as_ref().unwrap().${to_rust_ident(name)}
}
% else:
SpecifiedValue::System(system_font) => {
match system_font {}
}
% endif
}
}
fn from_computed_value(other: &computed_value::T) -> Self {
SpecifiedValue::Keyword(*other)
}
}
#[inline]
pub fn get_initial_value() -> computed_value::T {
computed_value::T::${to_camel_case(values.split()[0])}
}
#[inline]
pub fn get_initial_specified_value() -> SpecifiedValue {
SpecifiedValue::Keyword(computed_value::T::${to_camel_case(values.split()[0])})
}
impl SpecifiedValue {
pub fn system_font(f: SystemFont) -> Self {
SpecifiedValue::System(f)
}
pub fn get_system(&self) -> Option<SystemFont> {
if let SpecifiedValue::System(s) = *self {
Some(s)
} else {
None
}
}
}
</%call>
</%def>
<%def name="gecko_keyword_conversion(keyword, values=None, type='SpecifiedValue', cast_to=None)"> <%def name="gecko_keyword_conversion(keyword, values=None, type='SpecifiedValue', cast_to=None)">
<% <%
if not values: if not values:

View file

@ -34,7 +34,7 @@ ${helpers.predefined_type(
"all-petite-caps": "ALLPETITE", "all-petite-caps": "ALLPETITE",
"titling-caps": "TITLING" } %> "titling-caps": "TITLING" } %>
${helpers.single_keyword_system( ${helpers.single_keyword(
"font-variant-caps", "font-variant-caps",
"normal small-caps", "normal small-caps",
engines="gecko servo", engines="gecko servo",
@ -74,8 +74,8 @@ ${helpers.predefined_type(
"font-size-adjust", "font-size-adjust",
"FontSizeAdjust", "FontSizeAdjust",
engines="gecko", engines="gecko",
initial_value="computed::FontSizeAdjust::none()", initial_value="computed::FontSizeAdjust::None",
initial_specified_value="specified::FontSizeAdjust::none()", initial_specified_value="specified::FontSizeAdjust::None",
animation_value_type="FontSizeAdjust", animation_value_type="FontSizeAdjust",
spec="https://drafts.csswg.org/css-fonts/#propdef-font-size-adjust", spec="https://drafts.csswg.org/css-fonts/#propdef-font-size-adjust",
)} )}
@ -100,7 +100,7 @@ ${helpers.predefined_type(
servo_restyle_damage="rebuild_and_reflow", servo_restyle_damage="rebuild_and_reflow",
)} )}
${helpers.single_keyword_system( ${helpers.single_keyword(
"font-kerning", "font-kerning",
"auto none normal", "auto none normal",
engines="gecko", engines="gecko",
@ -114,8 +114,8 @@ ${helpers.predefined_type(
"font-variant-alternates", "font-variant-alternates",
"FontVariantAlternates", "FontVariantAlternates",
engines="gecko", engines="gecko",
initial_value="computed::FontVariantAlternates::get_initial_value()", initial_value="computed::FontVariantAlternates::default()",
initial_specified_value="specified::FontVariantAlternates::get_initial_specified_value()", initial_specified_value="specified::FontVariantAlternates::default()",
animation_value_type="discrete", animation_value_type="discrete",
spec="https://drafts.csswg.org/css-fonts/#propdef-font-variant-alternates", spec="https://drafts.csswg.org/css-fonts/#propdef-font-variant-alternates",
)} )}
@ -162,7 +162,7 @@ ${helpers.predefined_type(
spec="https://drafts.csswg.org/css-fonts/#propdef-font-variant-numeric", spec="https://drafts.csswg.org/css-fonts/#propdef-font-variant-numeric",
)} )}
${helpers.single_keyword_system( ${helpers.single_keyword(
"font-variant-position", "font-variant-position",
"normal sub super", "normal sub super",
engines="gecko", engines="gecko",
@ -206,7 +206,7 @@ ${helpers.predefined_type(
spec="https://drafts.csswg.org/css-fonts-3/#propdef-font-language-override", spec="https://drafts.csswg.org/css-fonts-3/#propdef-font-language-override",
)} )}
${helpers.single_keyword_system( ${helpers.single_keyword(
"font-optical-sizing", "font-optical-sizing",
"auto none", "auto none",
engines="gecko", engines="gecko",
@ -343,16 +343,6 @@ pub mod system_font {
use std::hash::{Hash, Hasher}; use std::hash::{Hash, Hasher};
use crate::values::computed::{ToComputedValue, Context}; use crate::values::computed::{ToComputedValue, Context};
use crate::values::specified::font::SystemFont; use crate::values::specified::font::SystemFont;
<%
kw_font_props = """font_variant_caps
font_kerning font_variant_position font_variant_ligatures
font_variant_east_asian font_variant_numeric
font_optical_sizing""".split()
kw_cast = """font_variant_caps font_kerning font_variant_position
font_optical_sizing""".split()
%>
// ComputedValues are compared at times // ComputedValues are compared at times
// so we need these impls. We don't want to // so we need these impls. We don't want to
// add Eq to Number (which contains a float) // add Eq to Number (which contains a float)
@ -401,20 +391,6 @@ pub mod system_font {
font_weight: system.weight, font_weight: system.weight,
font_stretch: system.stretch, font_stretch: system.stretch,
font_style: system.style, font_style: system.style,
font_size_adjust: system.sizeAdjust,
% for kwprop in kw_font_props:
${kwprop}: longhands::${kwprop}::computed_value::T::from_gecko_keyword(
system.${to_camel_case_lower(kwprop.replace('font_', ''))}
% if kwprop in kw_cast:
as u32
% endif
),
% endfor
font_language_override: longhands::font_language_override::computed_value
::T(system.languageOverride),
font_feature_settings: longhands::font_feature_settings::get_initial_value(),
font_variation_settings: longhands::font_variation_settings::get_initial_value(),
font_variant_alternates: longhands::font_variant_alternates::get_initial_value(),
system_font: *self, system_font: *self,
}; };
unsafe { bindings::Gecko_nsFont_Destroy(system); } unsafe { bindings::Gecko_nsFont_Destroy(system); }

View file

@ -35,13 +35,13 @@
> >
use crate::computed_values::font_variant_caps::T::SmallCaps; use crate::computed_values::font_variant_caps::T::SmallCaps;
use crate::parser::Parse; use crate::parser::Parse;
use crate::properties::longhands::{font_family, font_style, font_weight, font_stretch}; use crate::properties::longhands::{font_family, font_style, font_size, font_weight, font_stretch};
use crate::properties::longhands::font_variant_caps; use crate::properties::longhands::font_variant_caps;
use crate::values::specified::text::LineHeight; use crate::values::specified::text::LineHeight;
use crate::values::specified::FontSize; use crate::values::specified::FontSize;
use crate::values::specified::font::{FontStretch, FontStretchKeyword}; use crate::values::specified::font::{FontStretch, FontStretchKeyword};
#[cfg(feature = "gecko")] #[cfg(feature = "gecko")]
use crate::values::specified::font::{FontPalette, SystemFont}; use crate::values::specified::font::SystemFont;
<% <%
gecko_sub_properties = "kerning language_override size_adjust \ gecko_sub_properties = "kerning language_override size_adjust \
@ -72,16 +72,12 @@
if let Ok(sys) = input.try_parse(SystemFont::parse) { if let Ok(sys) = input.try_parse(SystemFont::parse) {
return Ok(expanded! { return Ok(expanded! {
% for name in SYSTEM_FONT_LONGHANDS: % for name in SYSTEM_FONT_LONGHANDS:
% if name == "font_size": ${name}: ${name}::SpecifiedValue::system_font(sys),
${name}: FontSize::system_font(sys),
% else:
${name}: ${name}::SpecifiedValue::system_font(sys),
% endif
% endfor % endfor
// line-height and palette are just reset to initial
line_height: LineHeight::normal(), line_height: LineHeight::normal(),
font_palette: FontPalette::normal(), % for name in gecko_sub_properties + ["variant_caps"]:
font_variant_emoji: font_variant_emoji::get_initial_specified_value(), font_${name}: font_${name}::get_initial_specified_value(),
% endfor
}) })
} }
% endif % endif
@ -110,7 +106,7 @@
// defined by CSS Fonts 3 and later are not accepted. // defined by CSS Fonts 3 and later are not accepted.
// https://www.w3.org/TR/css-fonts-4/#font-prop // https://www.w3.org/TR/css-fonts-4/#font-prop
if input.try_parse(|input| input.expect_ident_matching("small-caps")).is_ok() { if input.try_parse(|input| input.expect_ident_matching("small-caps")).is_ok() {
variant_caps = Some(font_variant_caps::SpecifiedValue::Keyword(SmallCaps)); variant_caps = Some(SmallCaps);
continue continue
} }
} }
@ -228,7 +224,7 @@
// the added values defined by CSS Fonts 3 and later are not supported. // the added values defined by CSS Fonts 3 and later are not supported.
// https://www.w3.org/TR/css-fonts-4/#font-prop // https://www.w3.org/TR/css-fonts-4/#font-prop
if self.font_variant_caps != &font_variant_caps::get_initial_specified_value() && if self.font_variant_caps != &font_variant_caps::get_initial_specified_value() &&
*self.font_variant_caps != font_variant_caps::SpecifiedValue::Keyword(SmallCaps) { *self.font_variant_caps != SmallCaps {
return Ok(()); return Ok(());
} }
@ -362,7 +358,7 @@
// The 'none' value sets 'font-variant-ligatures' to 'none' and resets all other sub properties // The 'none' value sets 'font-variant-ligatures' to 'none' and resets all other sub properties
// to their initial value. // to their initial value.
% if engine == "gecko": % if engine == "gecko":
ligatures = Some(FontVariantLigatures::none()); ligatures = Some(FontVariantLigatures::NONE);
% endif % endif
} else { } else {
let mut has_custom_value: bool = false; let mut has_custom_value: bool = false;
@ -402,7 +398,7 @@
let has_none_ligatures = let has_none_ligatures =
% if engine == "gecko": % if engine == "gecko":
self.font_variant_ligatures == &FontVariantLigatures::none(); self.font_variant_ligatures == &FontVariantLigatures::NONE;
% else: % else:
false; false;
% endif % endif

View file

@ -26,7 +26,7 @@ use style_traits::{CssWriter, ParseError, ToCss};
pub use crate::values::computed::Length as MozScriptMinSize; pub use crate::values::computed::Length as MozScriptMinSize;
pub use crate::values::specified::font::FontPalette; pub use crate::values::specified::font::FontPalette;
pub use crate::values::specified::font::{FontSynthesis, MozScriptSizeMultiplier}; pub use crate::values::specified::font::{FontSynthesis, MozScriptSizeMultiplier};
pub use crate::values::specified::font::{XLang, XTextZoom}; pub use crate::values::specified::font::{FontVariantAlternates, FontVariantEastAsian, FontVariantLigatures, FontVariantNumeric, XLang, XTextZoom};
pub use crate::values::specified::Integer as SpecifiedInteger; pub use crate::values::specified::Integer as SpecifiedInteger;
/// Generic template for font property type classes that use a fixed-point /// Generic template for font property type classes that use a fixed-point
@ -742,26 +742,6 @@ impl FontSizeAdjust {
} }
} }
/// Use VariantAlternatesList as computed type of FontVariantAlternates
pub type FontVariantAlternates = specified::VariantAlternatesList;
impl FontVariantAlternates {
/// Get initial value with VariantAlternatesList
#[inline]
pub fn get_initial_value() -> Self {
Self::default()
}
}
/// Use VariantEastAsian as computed type of FontVariantEastAsian
pub type FontVariantEastAsian = specified::VariantEastAsian;
/// Use VariantLigatures as computed type of FontVariantLigatures
pub type FontVariantLigatures = specified::VariantLigatures;
/// Use VariantNumeric as computed type of FontVariantNumeric
pub type FontVariantNumeric = specified::VariantNumeric;
/// Use FontSettings as computed type of FontFeatureSettings. /// Use FontSettings as computed type of FontFeatureSettings.
pub type FontFeatureSettings = FontSettings<FeatureTagValue<Integer>>; pub type FontFeatureSettings = FontSettings<FeatureTagValue<Integer>>;

View file

@ -8,7 +8,6 @@
use crate::context::QuirksMode; use crate::context::QuirksMode;
use crate::parser::{Parse, ParserContext}; use crate::parser::{Parse, ParserContext};
use crate::values::computed::font::{FamilyName, FontFamilyList, SingleFontFamily}; use crate::values::computed::font::{FamilyName, FontFamilyList, SingleFontFamily};
use crate::values::computed::FontSizeAdjust as ComputedFontSizeAdjust;
use crate::values::computed::Percentage as ComputedPercentage; use crate::values::computed::Percentage as ComputedPercentage;
use crate::values::computed::{font as computed, Length, NonNegativeLength}; use crate::values::computed::{font as computed, Length, NonNegativeLength};
use crate::values::computed::{CSSPixelLength, Context, ToComputedValue}; use crate::values::computed::{CSSPixelLength, Context, ToComputedValue};
@ -704,23 +703,7 @@ impl Parse for FamilyName {
} }
/// Preserve the readability of text when font fallback occurs /// Preserve the readability of text when font fallback occurs
#[derive(Clone, Copy, Debug, MallocSizeOf, PartialEq, SpecifiedValueInfo, ToCss, ToShmem)] pub type FontSizeAdjust = GenericFontSizeAdjust<NonNegativeNumber>;
#[allow(missing_docs)]
pub enum FontSizeAdjust {
Value(GenericFontSizeAdjust<NonNegativeNumber>),
#[css(skip)]
System(SystemFont),
}
impl FontSizeAdjust {
#[inline]
/// Default value of font-size-adjust
pub fn none() -> Self {
FontSizeAdjust::Value(GenericFontSizeAdjust::None)
}
system_font_methods!(FontSizeAdjust, font_size_adjust);
}
impl Parse for FontSizeAdjust { impl Parse for FontSizeAdjust {
fn parse<'i, 't>( fn parse<'i, 't>(
@ -734,41 +717,24 @@ impl Parse for FontSizeAdjust {
#[cfg(feature = "servo")] #[cfg(feature = "servo")]
let basis_enabled = false; let basis_enabled = false;
let basis = match_ignore_ascii_case! { &ident, let basis = match_ignore_ascii_case! { &ident,
"none" => return Ok(FontSizeAdjust::none()), "none" => return Ok(Self::None),
// Check for size adjustment basis keywords if enabled. // Check for size adjustment basis keywords if enabled.
"ex-height" if basis_enabled => GenericFontSizeAdjust::ExHeight, "ex-height" if basis_enabled => Self::ExHeight,
"cap-height" if basis_enabled => GenericFontSizeAdjust::CapHeight, "cap-height" if basis_enabled => Self::CapHeight,
"ch-width" if basis_enabled => GenericFontSizeAdjust::ChWidth, "ch-width" if basis_enabled => Self::ChWidth,
"ic-width" if basis_enabled => GenericFontSizeAdjust::IcWidth, "ic-width" if basis_enabled => Self::IcWidth,
"ic-height" if basis_enabled => GenericFontSizeAdjust::IcHeight, "ic-height" if basis_enabled => Self::IcHeight,
// Unknown (or disabled) keyword. // Unknown (or disabled) keyword.
_ => return Err(location.new_custom_error( _ => return Err(location.new_custom_error(
SelectorParseErrorKind::UnexpectedIdent(ident) SelectorParseErrorKind::UnexpectedIdent(ident)
)), )),
}; };
let value = NonNegativeNumber::parse(context, input)?; let value = NonNegativeNumber::parse(context, input)?;
return Ok(FontSizeAdjust::Value(basis(value))); return Ok(basis(value));
} }
// Without a basis keyword, the number refers to the 'ex-height' metric. // Without a basis keyword, the number refers to the 'ex-height' metric.
let value = NonNegativeNumber::parse(context, input)?; let value = NonNegativeNumber::parse(context, input)?;
Ok(FontSizeAdjust::Value(GenericFontSizeAdjust::ExHeight( Ok(Self::ExHeight(value))
value,
)))
}
}
impl ToComputedValue for FontSizeAdjust {
type ComputedValue = ComputedFontSizeAdjust;
fn to_computed_value(&self, context: &Context) -> Self::ComputedValue {
match *self {
FontSizeAdjust::Value(v) => v.to_computed_value(context),
FontSizeAdjust::System(_) => self.compute_system(context),
}
}
fn from_computed_value(computed: &ComputedFontSizeAdjust) -> Self {
Self::Value(ToComputedValue::from_computed_value(computed))
} }
} }
@ -1060,7 +1026,7 @@ bitflags! {
} }
#[derive( #[derive(
Clone, Debug, MallocSizeOf, PartialEq, SpecifiedValueInfo, ToCss, ToResolvedValue, ToShmem, Clone, Debug, MallocSizeOf, PartialEq, SpecifiedValueInfo, ToCss, ToComputedValue, ToResolvedValue, ToShmem,
)] )]
#[repr(C, u8)] #[repr(C, u8)]
/// Set of variant alternates /// Set of variant alternates
@ -1094,17 +1060,18 @@ pub enum VariantAlternates {
MallocSizeOf, MallocSizeOf,
PartialEq, PartialEq,
SpecifiedValueInfo, SpecifiedValueInfo,
ToComputedValue,
ToCss, ToCss,
ToResolvedValue, ToResolvedValue,
ToShmem, ToShmem,
)] )]
#[repr(transparent)] #[repr(transparent)]
/// List of Variant Alternates /// List of Variant Alternates
pub struct VariantAlternatesList( pub struct FontVariantAlternates(
#[css(if_empty = "normal", iterable)] crate::OwnedSlice<VariantAlternates>, #[css(if_empty = "normal", iterable)] crate::OwnedSlice<VariantAlternates>,
); );
impl VariantAlternatesList { impl FontVariantAlternates {
/// Returns the length of all variant alternates. /// Returns the length of all variant alternates.
pub fn len(&self) -> usize { pub fn len(&self) -> usize {
self.0.iter().fold(0, |acc, alternate| match *alternate { self.0.iter().fold(0, |acc, alternate| match *alternate {
@ -1119,38 +1086,11 @@ impl VariantAlternatesList {
} }
} }
#[derive(Clone, Debug, MallocSizeOf, PartialEq, SpecifiedValueInfo, ToCss, ToShmem)]
/// Control over the selection of these alternate glyphs
pub enum FontVariantAlternates {
/// Use alternative glyph from value
Value(VariantAlternatesList),
/// Use system font glyph
#[css(skip)]
System(SystemFont),
}
impl FontVariantAlternates { impl FontVariantAlternates {
#[inline] #[inline]
/// Get initial specified value with VariantAlternatesList /// Get initial specified value with VariantAlternatesList
pub fn get_initial_specified_value() -> Self { pub fn get_initial_specified_value() -> Self {
FontVariantAlternates::Value(Default::default()) Default::default()
}
system_font_methods!(FontVariantAlternates, font_variant_alternates);
}
impl ToComputedValue for FontVariantAlternates {
type ComputedValue = computed::FontVariantAlternates;
fn to_computed_value(&self, context: &Context) -> computed::FontVariantAlternates {
match *self {
FontVariantAlternates::Value(ref v) => v.clone(),
FontVariantAlternates::System(_) => self.compute_system(context),
}
}
fn from_computed_value(other: &computed::FontVariantAlternates) -> Self {
FontVariantAlternates::Value(other.clone())
} }
} }
@ -1171,7 +1111,7 @@ impl Parse for FontVariantAlternates {
.try_parse(|input| input.expect_ident_matching("normal")) .try_parse(|input| input.expect_ident_matching("normal"))
.is_ok() .is_ok()
{ {
return Ok(FontVariantAlternates::Value(Default::default())); return Ok(Default::default());
} }
let mut alternates = Vec::new(); let mut alternates = Vec::new();
@ -1250,9 +1190,7 @@ impl Parse for FontVariantAlternates {
if parsed_alternates.is_empty() { if parsed_alternates.is_empty() {
return Err(input.new_custom_error(StyleParseErrorKind::UnspecifiedError)); return Err(input.new_custom_error(StyleParseErrorKind::UnspecifiedError));
} }
Ok(FontVariantAlternates::Value(VariantAlternatesList( Ok(FontVariantAlternates(alternates.into()))
alternates.into(),
)))
} }
} }
@ -1264,9 +1202,9 @@ macro_rules! impl_variant_east_asian {
)+ )+
} => { } => {
bitflags! { bitflags! {
#[derive(MallocSizeOf, ToResolvedValue, ToShmem)] #[derive(MallocSizeOf, ToComputedValue, ToResolvedValue, ToShmem)]
/// Vairants for east asian variant /// Vairants for east asian variant
pub struct VariantEastAsian: u16 { pub struct FontVariantEastAsian: u16 {
/// None of the features /// None of the features
const NORMAL = 0; const NORMAL = 0;
$( $(
@ -1276,7 +1214,7 @@ macro_rules! impl_variant_east_asian {
} }
} }
impl ToCss for VariantEastAsian { impl ToCss for FontVariantEastAsian {
fn to_css<W>(&self, dest: &mut CssWriter<W>) -> fmt::Result fn to_css<W>(&self, dest: &mut CssWriter<W>) -> fmt::Result
where where
W: Write, W: Write,
@ -1287,7 +1225,7 @@ macro_rules! impl_variant_east_asian {
let mut writer = SequenceWriter::new(dest, " "); let mut writer = SequenceWriter::new(dest, " ");
$( $(
if self.intersects(VariantEastAsian::$ident) { if self.intersects(Self::$ident) {
writer.raw_item($css)?; writer.raw_item($css)?;
} }
)+ )+
@ -1301,11 +1239,11 @@ macro_rules! impl_variant_east_asian {
pub fn assert_variant_east_asian_matches() { pub fn assert_variant_east_asian_matches() {
use crate::gecko_bindings::structs; use crate::gecko_bindings::structs;
$( $(
debug_assert_eq!(structs::$gecko as u16, VariantEastAsian::$ident.bits()); debug_assert_eq!(structs::$gecko as u16, FontVariantEastAsian::$ident.bits());
)+ )+
} }
impl SpecifiedValueInfo for VariantEastAsian { impl SpecifiedValueInfo for FontVariantEastAsian {
fn collect_completion_keywords(f: KeywordsCollectFn) { fn collect_completion_keywords(f: KeywordsCollectFn) {
f(&["normal", $($css,)+]); f(&["normal", $($css,)+]);
} }
@ -1335,7 +1273,7 @@ impl_variant_east_asian! {
} }
#[cfg(feature = "gecko")] #[cfg(feature = "gecko")]
impl VariantEastAsian { impl FontVariantEastAsian {
/// Obtain a specified value from a Gecko keyword value /// Obtain a specified value from a Gecko keyword value
/// ///
/// Intended for use with presentation attributes, not style structs /// Intended for use with presentation attributes, not style structs
@ -1350,43 +1288,7 @@ impl VariantEastAsian {
} }
#[cfg(feature = "gecko")] #[cfg(feature = "gecko")]
impl_gecko_keyword_conversions!(VariantEastAsian, u16); impl_gecko_keyword_conversions!(FontVariantEastAsian, u16);
#[cfg_attr(feature = "gecko", derive(MallocSizeOf))]
#[derive(Clone, Copy, Debug, PartialEq, SpecifiedValueInfo, ToCss, ToShmem)]
/// Allows control of glyph substitution and sizing in East Asian text.
pub enum FontVariantEastAsian {
/// Value variant with `variant-east-asian`
Value(VariantEastAsian),
/// System font variant
#[css(skip)]
System(SystemFont),
}
impl FontVariantEastAsian {
#[inline]
/// Get default `font-variant-east-asian` with `empty` variant
pub fn empty() -> Self {
FontVariantEastAsian::Value(VariantEastAsian::empty())
}
system_font_methods!(FontVariantEastAsian, font_variant_east_asian);
}
impl ToComputedValue for FontVariantEastAsian {
type ComputedValue = computed::FontVariantEastAsian;
fn to_computed_value(&self, context: &Context) -> computed::FontVariantEastAsian {
match *self {
FontVariantEastAsian::Value(ref v) => v.clone(),
FontVariantEastAsian::System(_) => self.compute_system(context),
}
}
fn from_computed_value(other: &computed::FontVariantEastAsian) -> Self {
FontVariantEastAsian::Value(other.clone())
}
}
impl Parse for FontVariantEastAsian { impl Parse for FontVariantEastAsian {
/// normal | [ <east-asian-variant-values> || <east-asian-width-values> || ruby ] /// normal | [ <east-asian-variant-values> || <east-asian-width-values> || ruby ]
@ -1395,59 +1297,59 @@ impl Parse for FontVariantEastAsian {
fn parse<'i, 't>( fn parse<'i, 't>(
_context: &ParserContext, _context: &ParserContext,
input: &mut Parser<'i, 't>, input: &mut Parser<'i, 't>,
) -> Result<FontVariantEastAsian, ParseError<'i>> { ) -> Result<Self, ParseError<'i>> {
let mut result = VariantEastAsian::empty(); let mut result = Self::empty();
if input if input
.try_parse(|input| input.expect_ident_matching("normal")) .try_parse(|input| input.expect_ident_matching("normal"))
.is_ok() .is_ok()
{ {
return Ok(FontVariantEastAsian::Value(result)); return Ok(result);
} }
while let Ok(flag) = input.try_parse(|input| { while let Ok(flag) = input.try_parse(|input| {
Ok( Ok(
match_ignore_ascii_case! { &input.expect_ident().map_err(|_| ())?, match_ignore_ascii_case! { &input.expect_ident().map_err(|_| ())?,
"jis78" => "jis78" =>
exclusive_value!((result, VariantEastAsian::JIS78 | VariantEastAsian::JIS83 | exclusive_value!((result, Self::JIS78 | Self::JIS83 |
VariantEastAsian::JIS90 | VariantEastAsian::JIS04 | Self::JIS90 | Self::JIS04 |
VariantEastAsian::SIMPLIFIED | VariantEastAsian::TRADITIONAL Self::SIMPLIFIED | Self::TRADITIONAL
) => VariantEastAsian::JIS78), ) => Self::JIS78),
"jis83" => "jis83" =>
exclusive_value!((result, VariantEastAsian::JIS78 | VariantEastAsian::JIS83 | exclusive_value!((result, Self::JIS78 | Self::JIS83 |
VariantEastAsian::JIS90 | VariantEastAsian::JIS04 | Self::JIS90 | Self::JIS04 |
VariantEastAsian::SIMPLIFIED | VariantEastAsian::TRADITIONAL Self::SIMPLIFIED | Self::TRADITIONAL
) => VariantEastAsian::JIS83), ) => Self::JIS83),
"jis90" => "jis90" =>
exclusive_value!((result, VariantEastAsian::JIS78 | VariantEastAsian::JIS83 | exclusive_value!((result, Self::JIS78 | Self::JIS83 |
VariantEastAsian::JIS90 | VariantEastAsian::JIS04 | Self::JIS90 | Self::JIS04 |
VariantEastAsian::SIMPLIFIED | VariantEastAsian::TRADITIONAL Self::SIMPLIFIED | Self::TRADITIONAL
) => VariantEastAsian::JIS90), ) => Self::JIS90),
"jis04" => "jis04" =>
exclusive_value!((result, VariantEastAsian::JIS78 | VariantEastAsian::JIS83 | exclusive_value!((result, Self::JIS78 | Self::JIS83 |
VariantEastAsian::JIS90 | VariantEastAsian::JIS04 | Self::JIS90 | Self::JIS04 |
VariantEastAsian::SIMPLIFIED | VariantEastAsian::TRADITIONAL Self::SIMPLIFIED | Self::TRADITIONAL
) => VariantEastAsian::JIS04), ) => Self::JIS04),
"simplified" => "simplified" =>
exclusive_value!((result, VariantEastAsian::JIS78 | VariantEastAsian::JIS83 | exclusive_value!((result, Self::JIS78 | Self::JIS83 |
VariantEastAsian::JIS90 | VariantEastAsian::JIS04 | Self::JIS90 | Self::JIS04 |
VariantEastAsian::SIMPLIFIED | VariantEastAsian::TRADITIONAL Self::SIMPLIFIED | Self::TRADITIONAL
) => VariantEastAsian::SIMPLIFIED), ) => Self::SIMPLIFIED),
"traditional" => "traditional" =>
exclusive_value!((result, VariantEastAsian::JIS78 | VariantEastAsian::JIS83 | exclusive_value!((result, Self::JIS78 | Self::JIS83 |
VariantEastAsian::JIS90 | VariantEastAsian::JIS04 | Self::JIS90 | Self::JIS04 |
VariantEastAsian::SIMPLIFIED | VariantEastAsian::TRADITIONAL Self::SIMPLIFIED | Self::TRADITIONAL
) => VariantEastAsian::TRADITIONAL), ) => Self::TRADITIONAL),
"full-width" => "full-width" =>
exclusive_value!((result, VariantEastAsian::FULL_WIDTH | exclusive_value!((result, Self::FULL_WIDTH |
VariantEastAsian::PROPORTIONAL_WIDTH Self::PROPORTIONAL_WIDTH
) => VariantEastAsian::FULL_WIDTH), ) => Self::FULL_WIDTH),
"proportional-width" => "proportional-width" =>
exclusive_value!((result, VariantEastAsian::FULL_WIDTH | exclusive_value!((result, Self::FULL_WIDTH |
VariantEastAsian::PROPORTIONAL_WIDTH Self::PROPORTIONAL_WIDTH
) => VariantEastAsian::PROPORTIONAL_WIDTH), ) => Self::PROPORTIONAL_WIDTH),
"ruby" => "ruby" =>
exclusive_value!((result, VariantEastAsian::RUBY) => VariantEastAsian::RUBY), exclusive_value!((result, Self::RUBY) => Self::RUBY),
_ => return Err(()), _ => return Err(()),
}, },
) )
@ -1456,7 +1358,7 @@ impl Parse for FontVariantEastAsian {
} }
if !result.is_empty() { if !result.is_empty() {
Ok(FontVariantEastAsian::Value(result)) Ok(result)
} else { } else {
Err(input.new_custom_error(StyleParseErrorKind::UnspecifiedError)) Err(input.new_custom_error(StyleParseErrorKind::UnspecifiedError))
} }
@ -1471,9 +1373,9 @@ macro_rules! impl_variant_ligatures {
)+ )+
} => { } => {
bitflags! { bitflags! {
#[derive(MallocSizeOf, ToResolvedValue, ToShmem)] #[derive(MallocSizeOf, ToComputedValue, ToResolvedValue, ToShmem)]
/// Variants of ligatures /// Variants of ligatures
pub struct VariantLigatures: u16 { pub struct FontVariantLigatures: u16 {
/// Specifies that common default features are enabled /// Specifies that common default features are enabled
const NORMAL = 0; const NORMAL = 0;
$( $(
@ -1483,7 +1385,7 @@ macro_rules! impl_variant_ligatures {
} }
} }
impl ToCss for VariantLigatures { impl ToCss for FontVariantLigatures {
fn to_css<W>(&self, dest: &mut CssWriter<W>) -> fmt::Result fn to_css<W>(&self, dest: &mut CssWriter<W>) -> fmt::Result
where where
W: Write, W: Write,
@ -1491,13 +1393,13 @@ macro_rules! impl_variant_ligatures {
if self.is_empty() { if self.is_empty() {
return dest.write_str("normal"); return dest.write_str("normal");
} }
if self.contains(VariantLigatures::NONE) { if self.contains(FontVariantLigatures::NONE) {
return dest.write_str("none"); return dest.write_str("none");
} }
let mut writer = SequenceWriter::new(dest, " "); let mut writer = SequenceWriter::new(dest, " ");
$( $(
if self.intersects(VariantLigatures::$ident) { if self.intersects(FontVariantLigatures::$ident) {
writer.raw_item($css)?; writer.raw_item($css)?;
} }
)+ )+
@ -1511,11 +1413,11 @@ macro_rules! impl_variant_ligatures {
pub fn assert_variant_ligatures_matches() { pub fn assert_variant_ligatures_matches() {
use crate::gecko_bindings::structs; use crate::gecko_bindings::structs;
$( $(
debug_assert_eq!(structs::$gecko as u16, VariantLigatures::$ident.bits()); debug_assert_eq!(structs::$gecko as u16, FontVariantLigatures::$ident.bits());
)+ )+
} }
impl SpecifiedValueInfo for VariantLigatures { impl SpecifiedValueInfo for FontVariantLigatures {
fn collect_completion_keywords(f: KeywordsCollectFn) { fn collect_completion_keywords(f: KeywordsCollectFn) {
f(&["normal", $($css,)+]); f(&["normal", $($css,)+]);
} }
@ -1546,7 +1448,7 @@ impl_variant_ligatures! {
} }
#[cfg(feature = "gecko")] #[cfg(feature = "gecko")]
impl VariantLigatures { impl FontVariantLigatures {
/// Obtain a specified value from a Gecko keyword value /// Obtain a specified value from a Gecko keyword value
/// ///
/// Intended for use with presentation attributes, not style structs /// Intended for use with presentation attributes, not style structs
@ -1561,50 +1463,7 @@ impl VariantLigatures {
} }
#[cfg(feature = "gecko")] #[cfg(feature = "gecko")]
impl_gecko_keyword_conversions!(VariantLigatures, u16); impl_gecko_keyword_conversions!(FontVariantLigatures, u16);
#[cfg_attr(feature = "gecko", derive(MallocSizeOf))]
#[derive(Clone, Copy, Debug, PartialEq, SpecifiedValueInfo, ToCss, ToShmem)]
/// Ligatures and contextual forms are ways of combining glyphs
/// to produce more harmonized forms
pub enum FontVariantLigatures {
/// Value variant with `variant-ligatures`
Value(VariantLigatures),
/// System font variant
#[css(skip)]
System(SystemFont),
}
impl FontVariantLigatures {
system_font_methods!(FontVariantLigatures, font_variant_ligatures);
/// Default value of `font-variant-ligatures` as `empty`
#[inline]
pub fn empty() -> FontVariantLigatures {
FontVariantLigatures::Value(VariantLigatures::empty())
}
#[inline]
/// Get `none` variant of `font-variant-ligatures`
pub fn none() -> FontVariantLigatures {
FontVariantLigatures::Value(VariantLigatures::NONE)
}
}
impl ToComputedValue for FontVariantLigatures {
type ComputedValue = computed::FontVariantLigatures;
fn to_computed_value(&self, context: &Context) -> computed::FontVariantLigatures {
match *self {
FontVariantLigatures::Value(ref v) => v.clone(),
FontVariantLigatures::System(_) => self.compute_system(context),
}
}
fn from_computed_value(other: &computed::FontVariantLigatures) -> Self {
FontVariantLigatures::Value(other.clone())
}
}
impl Parse for FontVariantLigatures { impl Parse for FontVariantLigatures {
/// normal | none | /// normal | none |
@ -1619,57 +1478,56 @@ impl Parse for FontVariantLigatures {
fn parse<'i, 't>( fn parse<'i, 't>(
_context: &ParserContext, _context: &ParserContext,
input: &mut Parser<'i, 't>, input: &mut Parser<'i, 't>,
) -> Result<FontVariantLigatures, ParseError<'i>> { ) -> Result<Self, ParseError<'i>> {
let mut result = VariantLigatures::empty(); let mut result = Self::empty();
if input if input
.try_parse(|input| input.expect_ident_matching("normal")) .try_parse(|input| input.expect_ident_matching("normal"))
.is_ok() .is_ok()
{ {
return Ok(FontVariantLigatures::Value(result)); return Ok(result);
} }
if input if input
.try_parse(|input| input.expect_ident_matching("none")) .try_parse(|input| input.expect_ident_matching("none"))
.is_ok() .is_ok()
{ {
return Ok(FontVariantLigatures::Value(VariantLigatures::NONE)); return Ok(Self::NONE);
} }
while let Ok(flag) = input.try_parse(|input| { while let Ok(flag) = input.try_parse(|input| {
Ok( Ok(
match_ignore_ascii_case! { &input.expect_ident().map_err(|_| ())?, match_ignore_ascii_case! { &input.expect_ident().map_err(|_| ())?,
"common-ligatures" => "common-ligatures" =>
exclusive_value!((result, VariantLigatures::COMMON_LIGATURES | exclusive_value!((result, Self::COMMON_LIGATURES |
VariantLigatures::NO_COMMON_LIGATURES Self::NO_COMMON_LIGATURES
) => VariantLigatures::COMMON_LIGATURES), ) => Self::COMMON_LIGATURES),
"no-common-ligatures" => "no-common-ligatures" =>
exclusive_value!((result, VariantLigatures::COMMON_LIGATURES | exclusive_value!((result, Self::COMMON_LIGATURES |
VariantLigatures::NO_COMMON_LIGATURES Self::NO_COMMON_LIGATURES
) => VariantLigatures::NO_COMMON_LIGATURES), ) => Self::NO_COMMON_LIGATURES),
"discretionary-ligatures" => "discretionary-ligatures" =>
exclusive_value!((result, VariantLigatures::DISCRETIONARY_LIGATURES | exclusive_value!((result, Self::DISCRETIONARY_LIGATURES |
VariantLigatures::NO_DISCRETIONARY_LIGATURES Self::NO_DISCRETIONARY_LIGATURES
) => VariantLigatures::DISCRETIONARY_LIGATURES), ) => Self::DISCRETIONARY_LIGATURES),
"no-discretionary-ligatures" => "no-discretionary-ligatures" =>
exclusive_value!((result, VariantLigatures::DISCRETIONARY_LIGATURES | exclusive_value!((result, Self::DISCRETIONARY_LIGATURES |
VariantLigatures::NO_DISCRETIONARY_LIGATURES Self::NO_DISCRETIONARY_LIGATURES
) => VariantLigatures::NO_DISCRETIONARY_LIGATURES), ) => Self::NO_DISCRETIONARY_LIGATURES),
"historical-ligatures" => "historical-ligatures" =>
exclusive_value!((result, VariantLigatures::HISTORICAL_LIGATURES | exclusive_value!((result, Self::HISTORICAL_LIGATURES |
VariantLigatures::NO_HISTORICAL_LIGATURES Self::NO_HISTORICAL_LIGATURES
) => VariantLigatures::HISTORICAL_LIGATURES), ) => Self::HISTORICAL_LIGATURES),
"no-historical-ligatures" => "no-historical-ligatures" =>
exclusive_value!((result, VariantLigatures::HISTORICAL_LIGATURES | exclusive_value!((result, Self::HISTORICAL_LIGATURES |
VariantLigatures::NO_HISTORICAL_LIGATURES Self::NO_HISTORICAL_LIGATURES
) => VariantLigatures::NO_HISTORICAL_LIGATURES), ) => Self::NO_HISTORICAL_LIGATURES),
"contextual" => "contextual" =>
exclusive_value!((result, VariantLigatures::CONTEXTUAL | exclusive_value!((result, Self::CONTEXTUAL |
VariantLigatures::NO_CONTEXTUAL Self::NO_CONTEXTUAL
) => VariantLigatures::CONTEXTUAL), ) => Self::CONTEXTUAL),
"no-contextual" => "no-contextual" =>
exclusive_value!((result, VariantLigatures::CONTEXTUAL | exclusive_value!((result, Self::CONTEXTUAL |
VariantLigatures::NO_CONTEXTUAL Self::NO_CONTEXTUAL
) => VariantLigatures::NO_CONTEXTUAL), ) => Self::NO_CONTEXTUAL),
_ => return Err(()), _ => return Err(()),
}, },
) )
@ -1678,7 +1536,7 @@ impl Parse for FontVariantLigatures {
} }
if !result.is_empty() { if !result.is_empty() {
Ok(FontVariantLigatures::Value(result)) Ok(result)
} else { } else {
Err(input.new_custom_error(StyleParseErrorKind::UnspecifiedError)) Err(input.new_custom_error(StyleParseErrorKind::UnspecifiedError))
} }
@ -1693,9 +1551,9 @@ macro_rules! impl_variant_numeric {
)+ )+
} => { } => {
bitflags! { bitflags! {
#[derive(MallocSizeOf, ToResolvedValue, ToShmem)] #[derive(MallocSizeOf, ToComputedValue, ToResolvedValue, ToShmem)]
/// Vairants of numeric values /// Vairants of numeric values
pub struct VariantNumeric: u8 { pub struct FontVariantNumeric: u8 {
/// None of other variants are enabled. /// None of other variants are enabled.
const NORMAL = 0; const NORMAL = 0;
$( $(
@ -1705,7 +1563,7 @@ macro_rules! impl_variant_numeric {
} }
} }
impl ToCss for VariantNumeric { impl ToCss for FontVariantNumeric {
fn to_css<W>(&self, dest: &mut CssWriter<W>) -> fmt::Result fn to_css<W>(&self, dest: &mut CssWriter<W>) -> fmt::Result
where where
W: Write, W: Write,
@ -1716,7 +1574,7 @@ macro_rules! impl_variant_numeric {
let mut writer = SequenceWriter::new(dest, " "); let mut writer = SequenceWriter::new(dest, " ");
$( $(
if self.intersects(VariantNumeric::$ident) { if self.intersects(FontVariantNumeric::$ident) {
writer.raw_item($css)?; writer.raw_item($css)?;
} }
)+ )+
@ -1730,11 +1588,11 @@ macro_rules! impl_variant_numeric {
pub fn assert_variant_numeric_matches() { pub fn assert_variant_numeric_matches() {
use crate::gecko_bindings::structs; use crate::gecko_bindings::structs;
$( $(
debug_assert_eq!(structs::$gecko as u8, VariantNumeric::$ident.bits()); debug_assert_eq!(structs::$gecko as u8, FontVariantNumeric::$ident.bits());
)+ )+
} }
impl SpecifiedValueInfo for VariantNumeric { impl SpecifiedValueInfo for FontVariantNumeric {
fn collect_completion_keywords(f: KeywordsCollectFn) { fn collect_completion_keywords(f: KeywordsCollectFn) {
f(&["normal", $($css,)+]); f(&["normal", $($css,)+]);
} }
@ -1762,7 +1620,7 @@ impl_variant_numeric! {
} }
#[cfg(feature = "gecko")] #[cfg(feature = "gecko")]
impl VariantNumeric { impl FontVariantNumeric {
/// Obtain a specified value from a Gecko keyword value /// Obtain a specified value from a Gecko keyword value
/// ///
/// Intended for use with presentation attributes, not style structs /// Intended for use with presentation attributes, not style structs
@ -1777,43 +1635,7 @@ impl VariantNumeric {
} }
#[cfg(feature = "gecko")] #[cfg(feature = "gecko")]
impl_gecko_keyword_conversions!(VariantNumeric, u8); impl_gecko_keyword_conversions!(FontVariantNumeric, u8);
#[cfg_attr(feature = "gecko", derive(MallocSizeOf))]
#[derive(Clone, Copy, Debug, PartialEq, SpecifiedValueInfo, ToCss, ToShmem)]
/// Specifies control over numerical forms.
pub enum FontVariantNumeric {
/// Value variant with `variant-numeric`
Value(VariantNumeric),
/// System font
#[css(skip)]
System(SystemFont),
}
impl FontVariantNumeric {
#[inline]
/// Default value of `font-variant-numeric` as `empty`
pub fn empty() -> FontVariantNumeric {
FontVariantNumeric::Value(VariantNumeric::empty())
}
system_font_methods!(FontVariantNumeric, font_variant_numeric);
}
impl ToComputedValue for FontVariantNumeric {
type ComputedValue = computed::FontVariantNumeric;
fn to_computed_value(&self, context: &Context) -> computed::FontVariantNumeric {
match *self {
FontVariantNumeric::Value(ref v) => v.clone(),
FontVariantNumeric::System(_) => self.compute_system(context),
}
}
fn from_computed_value(other: &computed::FontVariantNumeric) -> Self {
FontVariantNumeric::Value(other.clone())
}
}
impl Parse for FontVariantNumeric { impl Parse for FontVariantNumeric {
/// normal | /// normal |
@ -1828,47 +1650,47 @@ impl Parse for FontVariantNumeric {
fn parse<'i, 't>( fn parse<'i, 't>(
_context: &ParserContext, _context: &ParserContext,
input: &mut Parser<'i, 't>, input: &mut Parser<'i, 't>,
) -> Result<FontVariantNumeric, ParseError<'i>> { ) -> Result<Self, ParseError<'i>> {
let mut result = VariantNumeric::empty(); let mut result = Self::empty();
if input if input
.try_parse(|input| input.expect_ident_matching("normal")) .try_parse(|input| input.expect_ident_matching("normal"))
.is_ok() .is_ok()
{ {
return Ok(FontVariantNumeric::Value(result)); return Ok(result);
} }
while let Ok(flag) = input.try_parse(|input| { while let Ok(flag) = input.try_parse(|input| {
Ok( Ok(
match_ignore_ascii_case! { &input.expect_ident().map_err(|_| ())?, match_ignore_ascii_case! { &input.expect_ident().map_err(|_| ())?,
"ordinal" => "ordinal" =>
exclusive_value!((result, VariantNumeric::ORDINAL) => VariantNumeric::ORDINAL), exclusive_value!((result, Self::ORDINAL) => Self::ORDINAL),
"slashed-zero" => "slashed-zero" =>
exclusive_value!((result, VariantNumeric::SLASHED_ZERO) => VariantNumeric::SLASHED_ZERO), exclusive_value!((result, Self::SLASHED_ZERO) => Self::SLASHED_ZERO),
"lining-nums" => "lining-nums" =>
exclusive_value!((result, VariantNumeric::LINING_NUMS | exclusive_value!((result, Self::LINING_NUMS |
VariantNumeric::OLDSTYLE_NUMS Self::OLDSTYLE_NUMS
) => VariantNumeric::LINING_NUMS), ) => Self::LINING_NUMS),
"oldstyle-nums" => "oldstyle-nums" =>
exclusive_value!((result, VariantNumeric::LINING_NUMS | exclusive_value!((result, Self::LINING_NUMS |
VariantNumeric::OLDSTYLE_NUMS Self::OLDSTYLE_NUMS
) => VariantNumeric::OLDSTYLE_NUMS), ) => Self::OLDSTYLE_NUMS),
"proportional-nums" => "proportional-nums" =>
exclusive_value!((result, VariantNumeric::PROPORTIONAL_NUMS | exclusive_value!((result, Self::PROPORTIONAL_NUMS |
VariantNumeric::TABULAR_NUMS Self::TABULAR_NUMS
) => VariantNumeric::PROPORTIONAL_NUMS), ) => Self::PROPORTIONAL_NUMS),
"tabular-nums" => "tabular-nums" =>
exclusive_value!((result, VariantNumeric::PROPORTIONAL_NUMS | exclusive_value!((result, Self::PROPORTIONAL_NUMS |
VariantNumeric::TABULAR_NUMS Self::TABULAR_NUMS
) => VariantNumeric::TABULAR_NUMS), ) => Self::TABULAR_NUMS),
"diagonal-fractions" => "diagonal-fractions" =>
exclusive_value!((result, VariantNumeric::DIAGONAL_FRACTIONS | exclusive_value!((result, Self::DIAGONAL_FRACTIONS |
VariantNumeric::STACKED_FRACTIONS Self::STACKED_FRACTIONS
) => VariantNumeric::DIAGONAL_FRACTIONS), ) => Self::DIAGONAL_FRACTIONS),
"stacked-fractions" => "stacked-fractions" =>
exclusive_value!((result, VariantNumeric::DIAGONAL_FRACTIONS | exclusive_value!((result, Self::DIAGONAL_FRACTIONS |
VariantNumeric::STACKED_FRACTIONS Self::STACKED_FRACTIONS
) => VariantNumeric::STACKED_FRACTIONS), ) => Self::STACKED_FRACTIONS),
_ => return Err(()), _ => return Err(()),
}, },
) )
@ -1877,7 +1699,7 @@ impl Parse for FontVariantNumeric {
} }
if !result.is_empty() { if !result.is_empty() {
Ok(FontVariantNumeric::Value(result)) Ok(result)
} else { } else {
Err(input.new_custom_error(StyleParseErrorKind::UnspecifiedError)) Err(input.new_custom_error(StyleParseErrorKind::UnspecifiedError))
} }
@ -1885,53 +1707,7 @@ impl Parse for FontVariantNumeric {
} }
/// This property provides low-level control over OpenType or TrueType font features. /// This property provides low-level control over OpenType or TrueType font features.
pub type SpecifiedFontFeatureSettings = FontSettings<FeatureTagValue<Integer>>; pub type FontFeatureSettings = FontSettings<FeatureTagValue<Integer>>;
/// Define initial settings that apply when the font defined by an @font-face
/// rule is rendered.
#[derive(Clone, Debug, MallocSizeOf, PartialEq, SpecifiedValueInfo, ToCss, ToShmem)]
pub enum FontFeatureSettings {
/// Value of `FontSettings`
Value(SpecifiedFontFeatureSettings),
/// System font
#[css(skip)]
System(SystemFont),
}
impl FontFeatureSettings {
#[inline]
/// Get default value of `font-feature-settings` as normal
pub fn normal() -> FontFeatureSettings {
FontFeatureSettings::Value(FontSettings::normal())
}
system_font_methods!(FontFeatureSettings, font_feature_settings);
}
impl ToComputedValue for FontFeatureSettings {
type ComputedValue = computed::FontFeatureSettings;
fn to_computed_value(&self, context: &Context) -> computed::FontFeatureSettings {
match *self {
FontFeatureSettings::Value(ref v) => v.to_computed_value(context),
FontFeatureSettings::System(_) => self.compute_system(context),
}
}
fn from_computed_value(other: &computed::FontFeatureSettings) -> Self {
FontFeatureSettings::Value(ToComputedValue::from_computed_value(other))
}
}
impl Parse for FontFeatureSettings {
/// normal | <feature-tag-value>#
fn parse<'i, 't>(
context: &ParserContext,
input: &mut Parser<'i, 't>,
) -> Result<FontFeatureSettings, ParseError<'i>> {
SpecifiedFontFeatureSettings::parse(context, input).map(FontFeatureSettings::Value)
}
}
#[derive( #[derive(
Clone, Copy, Debug, MallocSizeOf, PartialEq, ToComputedValue, ToResolvedValue, ToShmem, Clone, Copy, Debug, MallocSizeOf, PartialEq, ToComputedValue, ToResolvedValue, ToShmem,
@ -2094,9 +1870,6 @@ pub enum FontLanguageOverride {
/// specifies the OpenType language system to be used instead of /// specifies the OpenType language system to be used instead of
/// the language system implied by the language of the element /// the language system implied by the language of the element
Override(Box<str>), Override(Box<str>),
/// Use system font
#[css(skip)]
System(SystemFont),
} }
impl FontLanguageOverride { impl FontLanguageOverride {
@ -2115,22 +1888,16 @@ impl FontLanguageOverride {
FontLanguageOverride::Override(ref lang) => { FontLanguageOverride::Override(ref lang) => {
computed::FontLanguageOverride::from_str(lang) computed::FontLanguageOverride::from_str(lang)
}, },
FontLanguageOverride::System(..) => unreachable!(),
} }
} }
system_font_methods!(FontLanguageOverride, font_language_override);
} }
impl ToComputedValue for FontLanguageOverride { impl ToComputedValue for FontLanguageOverride {
type ComputedValue = computed::FontLanguageOverride; type ComputedValue = computed::FontLanguageOverride;
#[inline] #[inline]
fn to_computed_value(&self, context: &Context) -> computed::FontLanguageOverride { fn to_computed_value(&self, _: &Context) -> computed::FontLanguageOverride {
match *self { self.compute_non_system()
FontLanguageOverride::System(_) => self.compute_system(context),
_ => self.compute_non_system(),
}
} }
#[inline] #[inline]
fn from_computed_value(computed: &computed::FontLanguageOverride) -> Self { fn from_computed_value(computed: &computed::FontLanguageOverride) -> Self {
@ -2216,53 +1983,8 @@ impl ToCss for FontPalette {
/// This property provides low-level control over OpenType or TrueType font /// This property provides low-level control over OpenType or TrueType font
/// variations. /// variations.
pub type SpecifiedFontVariationSettings = FontSettings<VariationValue<Number>>; pub type FontVariationSettings = FontSettings<VariationValue<Number>>;
/// Define initial settings that apply when the font defined by an @font-face
/// rule is rendered.
#[derive(Clone, Debug, MallocSizeOf, PartialEq, SpecifiedValueInfo, ToCss, ToShmem)]
pub enum FontVariationSettings {
/// Value of `FontSettings`
Value(SpecifiedFontVariationSettings),
/// System font
#[css(skip)]
System(SystemFont),
}
impl FontVariationSettings {
#[inline]
/// Get default value of `font-variation-settings` as normal
pub fn normal() -> FontVariationSettings {
FontVariationSettings::Value(FontSettings::normal())
}
system_font_methods!(FontVariationSettings, font_variation_settings);
}
impl ToComputedValue for FontVariationSettings {
type ComputedValue = computed::FontVariationSettings;
fn to_computed_value(&self, context: &Context) -> computed::FontVariationSettings {
match *self {
FontVariationSettings::Value(ref v) => v.to_computed_value(context),
FontVariationSettings::System(_) => self.compute_system(context),
}
}
fn from_computed_value(other: &computed::FontVariationSettings) -> Self {
FontVariationSettings::Value(ToComputedValue::from_computed_value(other))
}
}
impl Parse for FontVariationSettings {
/// normal | <variation-tag-value>#
fn parse<'i, 't>(
context: &ParserContext,
input: &mut Parser<'i, 't>,
) -> Result<FontVariationSettings, ParseError<'i>> {
SpecifiedFontVariationSettings::parse(context, input).map(FontVariationSettings::Value)
}
}
fn parse_one_feature_value<'i, 't>( fn parse_one_feature_value<'i, 't>(
context: &ParserContext, context: &ParserContext,