style: Move font-variant-numeric outside of mako

This commit is contained in:
CYBAI 2017-11-18 17:57:22 +08:00
parent 7b886b4479
commit a38de8b540
6 changed files with 253 additions and 176 deletions

View file

@ -15,23 +15,6 @@
%endif
</%def>
#[cfg(feature = "gecko")]
macro_rules! impl_gecko_keyword_conversions {
($name: ident, $utype: ty) => {
impl From<$utype> for $name {
fn from(bits: $utype) -> $name {
$name::from_gecko_keyword(bits)
}
}
impl From<$name> for $utype {
fn from(v: $name) -> $utype {
v.to_gecko_keyword()
}
}
};
}
// 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)">
@ -679,17 +662,6 @@ ${helpers.predefined_type("font-variant-alternates",
flags="APPLIES_TO_FIRST_LETTER APPLIES_TO_FIRST_LINE APPLIES_TO_PLACEHOLDER",
spec="https://drafts.csswg.org/css-fonts/#propdef-font-variant-alternates")}
#[cfg(feature = "gecko")]
macro_rules! exclusive_value {
(($value:ident, $set:expr) => $ident:path) => {
if $value.intersects($set) {
return Err(())
} else {
$ident
}
}
}
${helpers.predefined_type("font-variant-east-asian",
"FontVariantEastAsian",
products="gecko",
@ -708,152 +680,14 @@ ${helpers.predefined_type("font-variant-ligatures",
flags="APPLIES_TO_FIRST_LETTER APPLIES_TO_FIRST_LINE APPLIES_TO_PLACEHOLDER",
spec="https://drafts.csswg.org/css-fonts/#propdef-font-variant-ligatures")}
<%helpers:longhand name="font-variant-numeric" products="gecko" animation_value_type="discrete"
flags="APPLIES_TO_FIRST_LETTER APPLIES_TO_FIRST_LINE APPLIES_TO_PLACEHOLDER"
spec="https://drafts.csswg.org/css-fonts/#propdef-font-variant-numeric">
use properties::longhands::system_font::SystemFont;
use std::fmt;
use style_traits::ToCss;
bitflags! {
#[derive(MallocSizeOf)]
pub struct VariantNumeric: u8 {
const NORMAL = 0;
const LINING_NUMS = 0x01;
const OLDSTYLE_NUMS = 0x02;
const PROPORTIONAL_NUMS = 0x04;
const TABULAR_NUMS = 0x08;
const DIAGONAL_FRACTIONS = 0x10;
const STACKED_FRACTIONS = 0x20;
const SLASHED_ZERO = 0x40;
const ORDINAL = 0x80;
}
}
#[cfg_attr(feature = "gecko", derive(MallocSizeOf))]
#[derive(Clone, Debug, PartialEq, ToCss)]
pub enum SpecifiedValue {
Value(VariantNumeric),
System(SystemFont)
}
<%self:simple_system_boilerplate name="font_variant_numeric"></%self:simple_system_boilerplate>
// servo_bit: gecko_bit
<% font_variant_numeric_map = { "VariantNumeric::LINING_NUMS": "LINING",
"VariantNumeric::OLDSTYLE_NUMS": "OLDSTYLE",
"VariantNumeric::PROPORTIONAL_NUMS": "PROPORTIONAL",
"VariantNumeric::TABULAR_NUMS": "TABULAR",
"VariantNumeric::DIAGONAL_FRACTIONS": "DIAGONAL_FRACTIONS",
"VariantNumeric::STACKED_FRACTIONS": "STACKED_FRACTIONS",
"VariantNumeric::SLASHED_ZERO": "SLASHZERO",
"VariantNumeric::ORDINAL": "ORDINAL" } %>
${helpers.gecko_bitflags_conversion(font_variant_numeric_map, 'NS_FONT_VARIANT_NUMERIC_',
'VariantNumeric')}
impl ToCss for VariantNumeric {
fn to_css<W>(&self, dest: &mut W) -> fmt::Result where W: fmt::Write {
if self.is_empty() {
return dest.write_str("normal")
}
let mut has_any = false;
macro_rules! write_value {
($ident:path => $str:expr) => {
if self.intersects($ident) {
if has_any {
dest.write_str(" ")?;
}
has_any = true;
dest.write_str($str)?;
}
}
}
write_value!(VariantNumeric::LINING_NUMS => "lining-nums");
write_value!(VariantNumeric::OLDSTYLE_NUMS => "oldstyle-nums");
write_value!(VariantNumeric::PROPORTIONAL_NUMS => "proportional-nums");
write_value!(VariantNumeric::TABULAR_NUMS => "tabular-nums");
write_value!(VariantNumeric::DIAGONAL_FRACTIONS => "diagonal-fractions");
write_value!(VariantNumeric::STACKED_FRACTIONS => "stacked-fractions");
write_value!(VariantNumeric::SLASHED_ZERO => "slashed-zero");
write_value!(VariantNumeric::ORDINAL => "ordinal");
debug_assert!(has_any);
Ok(())
}
}
pub mod computed_value {
pub type T = super::VariantNumeric;
}
#[inline]
pub fn get_initial_value() -> computed_value::T {
computed_value::T::empty()
}
#[inline]
pub fn get_initial_specified_value() -> SpecifiedValue {
SpecifiedValue::Value(VariantNumeric::empty())
}
/// normal |
/// [ <numeric-figure-values> ||
/// <numeric-spacing-values> ||
/// <numeric-fraction-values> ||
/// ordinal ||
/// slashed-zero ]
/// <numeric-figure-values> = [ lining-nums | oldstyle-nums ]
/// <numeric-spacing-values> = [ proportional-nums | tabular-nums ]
/// <numeric-fraction-values> = [ diagonal-fractions | stacked-fractions ]
<% numeric_figure_values = "VariantNumeric::LINING_NUMS | VariantNumeric::OLDSTYLE_NUMS" %>
<% numeric_spacing_values = "VariantNumeric::PROPORTIONAL_NUMS | VariantNumeric::TABULAR_NUMS" %>
<% numeric_fraction_values = "VariantNumeric::DIAGONAL_FRACTIONS | VariantNumeric::STACKED_FRACTIONS" %>
pub fn parse<'i, 't>(_context: &ParserContext, input: &mut Parser<'i, 't>)
-> Result<SpecifiedValue, ParseError<'i>> {
let mut result = VariantNumeric::empty();
if input.try(|input| input.expect_ident_matching("normal")).is_ok() {
return Ok(SpecifiedValue::Value(result))
}
while let Ok(flag) = input.try(|input| {
Ok(match_ignore_ascii_case! { &input.expect_ident().map_err(|_| ())?,
"ordinal" =>
exclusive_value!((result, VariantNumeric::ORDINAL) => VariantNumeric::ORDINAL),
"slashed-zero" =>
exclusive_value!((result, VariantNumeric::SLASHED_ZERO) => VariantNumeric::SLASHED_ZERO),
"lining-nums" =>
exclusive_value!((result, ${numeric_figure_values}) => VariantNumeric::LINING_NUMS),
"oldstyle-nums" =>
exclusive_value!((result, ${numeric_figure_values}) => VariantNumeric::OLDSTYLE_NUMS),
"proportional-nums" =>
exclusive_value!((result, ${numeric_spacing_values}) => VariantNumeric::PROPORTIONAL_NUMS),
"tabular-nums" =>
exclusive_value!((result, ${numeric_spacing_values}) => VariantNumeric::TABULAR_NUMS),
"diagonal-fractions" =>
exclusive_value!((result, ${numeric_fraction_values}) => VariantNumeric::DIAGONAL_FRACTIONS),
"stacked-fractions" =>
exclusive_value!((result, ${numeric_fraction_values}) => VariantNumeric::STACKED_FRACTIONS),
_ => return Err(()),
})
}) {
result.insert(flag);
}
if !result.is_empty() {
Ok(SpecifiedValue::Value(result))
} else {
Err(input.new_custom_error(StyleParseErrorKind::UnspecifiedError))
}
}
#[cfg(feature = "gecko")]
impl_gecko_keyword_conversions!(VariantNumeric, u8);
</%helpers:longhand>
${helpers.predefined_type("font-variant-numeric",
"FontVariantNumeric",
products="gecko",
initial_value="computed::FontVariantNumeric::empty()",
initial_specified_value="specified::FontVariantNumeric::empty()",
animation_value_type="discrete",
flags="APPLIES_TO_FIRST_LETTER APPLIES_TO_FIRST_LINE APPLIES_TO_PLACEHOLDER",
spec="https://drafts.csswg.org/css-fonts/#propdef-font-variant-numeric")}
${helpers.single_keyword_system("font-variant-position",
"normal sub super",