style: Move font-feature-settings outside of mako

This commit is contained in:
CYBAI 2017-11-20 11:26:09 +08:00
parent db5fb74a4d
commit 70033edccd
5 changed files with 91 additions and 75 deletions

View file

@ -15,42 +15,6 @@
%endif %endif
</%def> </%def>
// Define ToComputedValue, ToCss, and other boilerplate for a specified value
// which is of the form `enum SpecifiedValue {Value(..), System(SystemFont)}`
<%def name="simple_system_boilerplate(name)">
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
}
}
}
impl ToComputedValue for SpecifiedValue {
type ComputedValue = computed_value::T;
fn to_computed_value(&self, _context: &Context) -> computed_value::T {
match *self {
SpecifiedValue::Value(ref v) => v.clone(),
SpecifiedValue::System(_) => {
<%self:nongecko_unreachable>
_context.cached_system_font.as_ref().unwrap().${name}.clone()
</%self:nongecko_unreachable>
}
}
}
fn from_computed_value(other: &computed_value::T) -> Self {
SpecifiedValue::Value(other.clone())
}
}
</%def>
<%helpers:longhand name="font-family" animation_value_type="discrete" <%helpers:longhand name="font-family" animation_value_type="discrete"
flags="APPLIES_TO_FIRST_LETTER APPLIES_TO_FIRST_LINE APPLIES_TO_PLACEHOLDER" flags="APPLIES_TO_FIRST_LETTER APPLIES_TO_FIRST_LINE APPLIES_TO_PLACEHOLDER"
spec="https://drafts.csswg.org/css-fonts/#propdef-font-family"> spec="https://drafts.csswg.org/css-fonts/#propdef-font-family">
@ -698,43 +662,16 @@ ${helpers.single_keyword_system("font-variant-position",
flags="APPLIES_TO_FIRST_LETTER APPLIES_TO_FIRST_LINE APPLIES_TO_PLACEHOLDER", flags="APPLIES_TO_FIRST_LETTER APPLIES_TO_FIRST_LINE APPLIES_TO_PLACEHOLDER",
animation_value_type="discrete")} animation_value_type="discrete")}
<%helpers:longhand name="font-feature-settings" products="gecko" animation_value_type="discrete" ${helpers.predefined_type("font-feature-settings",
extra_prefixes="moz" boxed="True" "FontFeatureSettings",
flags="APPLIES_TO_FIRST_LETTER APPLIES_TO_FIRST_LINE APPLIES_TO_PLACEHOLDER" products="gecko",
spec="https://drafts.csswg.org/css-fonts/#propdef-font-feature-settings"> initial_value="computed::FontFeatureSettings::normal()",
use properties::longhands::system_font::SystemFont; initial_specified_value="specified::FontFeatureSettings::normal()",
use values::generics::FontSettings; extra_prefixes="moz",
boxed=True,
#[cfg_attr(feature = "gecko", derive(MallocSizeOf))] animation_value_type="discrete",
#[derive(Clone, Debug, PartialEq, ToCss)] flags="APPLIES_TO_FIRST_LETTER APPLIES_TO_FIRST_LINE APPLIES_TO_PLACEHOLDER",
pub enum SpecifiedValue { spec="https://drafts.csswg.org/css-fonts/#propdef-font-feature-settings")}
Value(computed_value::T),
System(SystemFont)
}
<%self:simple_system_boilerplate name="font_feature_settings"></%self:simple_system_boilerplate>
pub mod computed_value {
use values::generics::{FontSettings, FontSettingTagInt};
pub type T = FontSettings<FontSettingTagInt>;
}
#[inline]
pub fn get_initial_value() -> computed_value::T {
FontSettings::Normal
}
#[inline]
pub fn get_initial_specified_value() -> SpecifiedValue {
SpecifiedValue::Value(FontSettings::Normal)
}
/// normal | <feature-tag-value>#
pub fn parse<'i, 't>(context: &ParserContext, input: &mut Parser<'i, 't>)
-> Result<SpecifiedValue, ParseError<'i>> {
computed_value::T::parse(context, input).map(SpecifiedValue::Value)
}
</%helpers:longhand>
<% <%
# This spec link is too long to fit elsewhere # This spec link is too long to fit elsewhere

View file

@ -11,6 +11,7 @@ use style_traits::ToCss;
use values::CSSFloat; use values::CSSFloat;
use values::animated::{ToAnimatedValue, ToAnimatedZero}; use values::animated::{ToAnimatedValue, ToAnimatedZero};
use values::computed::{Context, NonNegativeLength, ToComputedValue}; use values::computed::{Context, NonNegativeLength, ToComputedValue};
use values::generics::{FontSettings, FontSettingTagInt};
use values::specified::font as specified; use values::specified::font as specified;
use values::specified::length::{FontBaseSize, NoCalcLength}; use values::specified::length::{FontBaseSize, NoCalcLength};
@ -286,6 +287,17 @@ pub type FontVariantLigatures = specified::VariantLigatures;
/// Use VariantNumeric as computed type of FontVariantNumeric /// Use VariantNumeric as computed type of FontVariantNumeric
pub type FontVariantNumeric = specified::VariantNumeric; pub type FontVariantNumeric = specified::VariantNumeric;
/// Use FontSettings as computed type of FontFeatureSettings
pub type FontFeatureSettings = FontSettings<FontSettingTagInt>;
impl FontFeatureSettings {
#[inline]
/// Default value of `font-feature-settings` as `normal`
pub fn normal() -> FontFeatureSettings {
FontSettings::Normal
}
}
/// font-language-override can only have a single three-letter /// font-language-override can only have a single three-letter
/// OpenType "language system" tag, so we should be able to compute /// OpenType "language system" tag, so we should be able to compute
/// it and store it as a 32-bit integer /// it and store it as a 32-bit integer

View file

@ -38,7 +38,8 @@ pub use self::border::{BorderImageSlice, BorderImageWidth, BorderImageSideWidth}
pub use self::border::{BorderRadius, BorderCornerRadius, BorderSpacing}; pub use self::border::{BorderRadius, BorderCornerRadius, BorderSpacing};
pub use self::font::{FontSize, FontSizeAdjust, FontSynthesis, FontWeight, FontVariantAlternates}; pub use self::font::{FontSize, FontSizeAdjust, FontSynthesis, FontWeight, FontVariantAlternates};
pub use self::font::{FontLanguageOverride, FontVariantSettings, FontVariantEastAsian}; pub use self::font::{FontLanguageOverride, FontVariantSettings, FontVariantEastAsian};
pub use self::font::{FontVariantLigatures, FontVariantNumeric, MozScriptLevel, MozScriptMinSize, XTextZoom}; pub use self::font::{FontVariantLigatures, FontVariantNumeric, FontFeatureSettings};
pub use self::font::{MozScriptLevel, MozScriptMinSize, XTextZoom};
pub use self::box_::{AnimationIterationCount, AnimationName, ScrollSnapType, VerticalAlign}; pub use self::box_::{AnimationIterationCount, AnimationName, ScrollSnapType, VerticalAlign};
pub use self::color::{Color, ColorPropertyValue, RGBAColor}; pub use self::color::{Color, ColorPropertyValue, RGBAColor};
pub use self::effects::{BoxShadow, Filter, SimpleShadow}; pub use self::effects::{BoxShadow, Filter, SimpleShadow};

View file

@ -1573,6 +1573,71 @@ impl Parse for FontVariantNumeric {
} }
} }
#[cfg_attr(feature = "gecko", derive(MallocSizeOf))]
#[derive(Clone, Debug, PartialEq, ToCss)]
/// Define initial settings that apply when the font defined
/// by an @font-face rule is rendered.
pub enum FontFeatureSettings {
/// Value of `FontSettings`
Value(computed::FontFeatureSettings),
/// System font
System(SystemFont)
}
impl FontFeatureSettings {
#[inline]
/// Get default value of `font-feature-settings` as normal
pub fn normal() -> FontFeatureSettings {
FontFeatureSettings::Value(FontSettings::Normal)
}
/// Get `font-feature-settings` with system font
pub fn system_font(f: SystemFont) -> Self {
FontFeatureSettings::System(f)
}
/// Get system font
pub fn get_system(&self) -> Option<SystemFont> {
if let FontFeatureSettings::System(s) = *self {
Some(s)
} else {
None
}
}
}
impl ToComputedValue for FontFeatureSettings {
type ComputedValue = computed::FontFeatureSettings;
fn to_computed_value(&self, _context: &Context) -> computed::FontFeatureSettings {
match *self {
FontFeatureSettings::Value(ref v) => v.clone(),
FontFeatureSettings::System(_) => {
#[cfg(feature = "gecko")] {
_context.cached_system_font.as_ref().unwrap().font_feature_settings.clone()
}
#[cfg(feature = "servo")] {
unreachable!()
}
}
}
}
fn from_computed_value(other: &computed::FontFeatureSettings) -> Self {
FontFeatureSettings::Value(other.clone())
}
}
impl Parse for FontFeatureSettings {
/// normal | <feature-tag-value>#
fn parse<'i, 't>(
context: &ParserContext,
input: &mut Parser<'i, 't>
) -> Result<FontFeatureSettings, ParseError<'i>> {
computed::FontFeatureSettings::parse(context, input).map(FontFeatureSettings::Value)
}
}
#[derive(Clone, Debug, MallocSizeOf, PartialEq, ToComputedValue)] #[derive(Clone, Debug, MallocSizeOf, PartialEq, ToComputedValue)]
/// Whether user agents are allowed to synthesize bold or oblique font faces /// Whether user agents are allowed to synthesize bold or oblique font faces
/// when a font family lacks bold or italic faces /// when a font family lacks bold or italic faces

View file

@ -32,7 +32,8 @@ pub use self::border::{BorderCornerRadius, BorderImageSlice, BorderImageWidth};
pub use self::border::{BorderImageSideWidth, BorderRadius, BorderSideWidth, BorderSpacing}; pub use self::border::{BorderImageSideWidth, BorderRadius, BorderSideWidth, BorderSpacing};
pub use self::font::{FontSize, FontSizeAdjust, FontSynthesis, FontWeight, FontVariantAlternates}; pub use self::font::{FontSize, FontSizeAdjust, FontSynthesis, FontWeight, FontVariantAlternates};
pub use self::font::{FontLanguageOverride, FontVariantSettings, FontVariantEastAsian}; pub use self::font::{FontLanguageOverride, FontVariantSettings, FontVariantEastAsian};
pub use self::font::{FontVariantLigatures, FontVariantNumeric, MozScriptLevel, MozScriptMinSize, XTextZoom}; pub use self::font::{FontVariantLigatures, FontVariantNumeric, FontFeatureSettings};
pub use self::font::{MozScriptLevel, MozScriptMinSize, XTextZoom};
pub use self::box_::{AnimationIterationCount, AnimationName, ScrollSnapType, VerticalAlign}; pub use self::box_::{AnimationIterationCount, AnimationName, ScrollSnapType, VerticalAlign};
pub use self::color::{Color, ColorPropertyValue, RGBAColor}; pub use self::color::{Color, ColorPropertyValue, RGBAColor};
pub use self::effects::{BoxShadow, Filter, SimpleShadow}; pub use self::effects::{BoxShadow, Filter, SimpleShadow};