Support unit variants when deriving ToCss

This commit is contained in:
Anthony Ramine 2017-06-07 14:53:31 +02:00
parent 7d09ce0495
commit 45e8b0e8c7
14 changed files with 71 additions and 242 deletions

View file

@ -545,8 +545,6 @@ ${helpers.predefined_type("animation-timing-function",
extra_prefixes="moz webkit"
spec="https://drafts.csswg.org/css-animations/#propdef-animation-iteration-count",
allowed_in_keyframe_block="False">
use std::fmt;
use style_traits::ToCss;
use values::computed::ComputedValueAsSpecified;
pub mod computed_value {
@ -554,8 +552,8 @@ ${helpers.predefined_type("animation-timing-function",
}
// https://drafts.csswg.org/css-animations/#animation-iteration-count
#[derive(Debug, Clone, PartialEq)]
#[cfg_attr(feature = "servo", derive(HeapSizeOf))]
#[derive(Debug, Clone, PartialEq, ToCss)]
pub enum SpecifiedValue {
Number(f32),
Infinite,
@ -576,15 +574,6 @@ ${helpers.predefined_type("animation-timing-function",
}
}
impl ToCss for SpecifiedValue {
fn to_css<W>(&self, dest: &mut W) -> fmt::Result where W: fmt::Write {
match *self {
SpecifiedValue::Number(n) => write!(dest, "{}", n),
SpecifiedValue::Infinite => dest.write_str("infinite"),
}
}
}
no_viewport_percentage!(SpecifiedValue);
#[inline]

View file

@ -1039,28 +1039,15 @@ ${helpers.single_keyword_system("font-variant-caps",
pub mod computed_value {
use properties::animated_properties::Animatable;
use std::fmt;
use style_traits::ToCss;
use values::CSSFloat;
#[derive(Copy, Clone, Debug, PartialEq)]
#[cfg_attr(feature = "servo", derive(HeapSizeOf))]
#[derive(Copy, Clone, Debug, PartialEq, ToCss)]
pub enum T {
None,
Number(CSSFloat),
}
impl ToCss for T {
fn to_css<W>(&self, dest: &mut W) -> fmt::Result
where W: fmt::Write,
{
match *self {
T::None => dest.write_str("none"),
T::Number(number) => number.to_css(dest),
}
}
}
impl T {
pub fn from_gecko_adjust(gecko: f32) -> Self {
if gecko == -1.0 {
@ -2214,9 +2201,7 @@ ${helpers.single_keyword("-moz-math-variant",
use app_units::Au;
use cssparser::Parser;
use properties::longhands;
use std::fmt;
use std::hash::{Hash, Hasher};
use style_traits::ToCss;
use values::computed::{ToComputedValue, Context};
<%
system_fonts = """caption icon menu message-box small-caption status-bar
@ -2230,23 +2215,13 @@ ${helpers.single_keyword("-moz-math-variant",
kw_cast = """font_style font_variant_caps font_stretch
font_kerning font_variant_position""".split()
%>
#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash)]
#[derive(Clone, Copy, Debug, Eq, Hash, PartialEq, ToCss)]
pub enum SystemFont {
% for font in system_fonts:
${to_camel_case(font)},
% endfor
}
impl ToCss for SystemFont {
fn to_css<W>(&self, dest: &mut W) -> fmt::Result where W: fmt::Write {
dest.write_str(match *self {
% for font in system_fonts:
SystemFont::${to_camel_case(font)} => "${font}",
% endfor
})
}
}
// ComputedValues are compared at times
// so we need these impls. We don't want to
// add Eq to Number (which contains a float)

View file

@ -450,8 +450,8 @@ impl PropertyDeclarationIdSet {
% endfor
/// An enum to represent a CSS Wide keyword.
#[derive(Copy, Clone, PartialEq, Eq, Debug)]
#[cfg_attr(feature = "servo", derive(HeapSizeOf))]
#[derive(Copy, Clone, Debug, Eq, PartialEq, ToCss)]
pub enum CSSWideKeyword {
/// The `initial` keyword.
Initial,
@ -483,12 +483,6 @@ impl CSSWideKeyword {
}
}
impl ToCss for CSSWideKeyword {
fn to_css<W>(&self, dest: &mut W) -> fmt::Result where W: fmt::Write {
dest.write_str(self.to_str())
}
}
impl Parse for CSSWideKeyword {
fn parse(_context: &ParserContext, input: &mut Parser) -> Result<Self, ()> {
let ident = input.expect_ident()?;
@ -628,8 +622,8 @@ impl LonghandId {
}
/// An identifier for a given shorthand property.
#[derive(Clone, Copy, Eq, PartialEq, Debug)]
#[cfg_attr(feature = "servo", derive(HeapSizeOf))]
#[derive(Clone, Copy, Debug, Eq, PartialEq, ToCss)]
pub enum ShorthandId {
% for property in data.shorthands:
/// ${property.name}
@ -637,14 +631,6 @@ pub enum ShorthandId {
% endfor
}
impl ToCss for ShorthandId {
fn to_css<W>(&self, dest: &mut W) -> fmt::Result
where W: fmt::Write,
{
dest.write_str(self.name())
}
}
impl ShorthandId {
/// Get the name for this shorthand property.
pub fn name(&self) -> &'static str {