Derive some more ToCss implementations

This commit is contained in:
Anthony Ramine 2017-07-11 15:32:59 +02:00
parent 21ecf47693
commit ec289fbe6a
4 changed files with 5 additions and 70 deletions

View file

@ -405,8 +405,8 @@ ${helpers.single_keyword_system("font-variant-caps",
no_viewport_percentage!(SpecifiedValue);
#[derive(Debug, Clone, PartialEq, Eq, Copy)]
#[cfg_attr(feature = "servo", derive(HeapSizeOf))]
#[derive(Clone, Copy, Debug, Eq, PartialEq, ToCss)]
pub enum SpecifiedValue {
Normal,
Bold,
@ -416,19 +416,6 @@ ${helpers.single_keyword_system("font-variant-caps",
System(SystemFont),
}
impl ToCss for SpecifiedValue {
fn to_css<W>(&self, dest: &mut W) -> fmt::Result where W: fmt::Write {
match *self {
SpecifiedValue::Normal => dest.write_str("normal"),
SpecifiedValue::Bold => dest.write_str("bold"),
SpecifiedValue::Bolder => dest.write_str("bolder"),
SpecifiedValue::Lighter => dest.write_str("lighter"),
SpecifiedValue::Weight(weight) => weight.to_css(dest),
SpecifiedValue::System(sys) => sys.to_css(dest),
}
}
}
/// normal | bold | bolder | lighter | 100 | 200 | 300 | 400 | 500 | 600 | 700 | 800 | 900
pub fn parse<'i, 't>(context: &ParserContext, input: &mut Parser<'i, 't>)
-> Result<SpecifiedValue, ParseError<'i>> {
@ -1008,7 +995,7 @@ ${helpers.single_keyword_system("font-variant-caps",
no_viewport_percentage!(SpecifiedValue);
#[derive(Copy, Clone, Debug, PartialEq)]
#[derive(Clone, Copy, Debug, PartialEq, ToCss)]
#[cfg_attr(feature = "servo", derive(HeapSizeOf))]
pub enum SpecifiedValue {
None,
@ -1016,18 +1003,6 @@ ${helpers.single_keyword_system("font-variant-caps",
System(SystemFont),
}
impl ToCss for SpecifiedValue {
fn to_css<W>(&self, dest: &mut W) -> fmt::Result
where W: fmt::Write,
{
match *self {
SpecifiedValue::None => dest.write_str("none"),
SpecifiedValue::Number(number) => number.to_css(dest),
SpecifiedValue::System(sys) => sys.to_css(dest),
}
}
}
impl ToComputedValue for SpecifiedValue {
type ComputedValue = computed_value::T;

View file

@ -27,8 +27,8 @@
String(Box<str>),
}
#[derive(PartialEq, Eq, Clone, Debug)]
#[cfg_attr(feature = "servo", derive(HeapSizeOf))]
#[derive(Clone, Debug, Eq, PartialEq, ToCss)]
pub struct SpecifiedValue {
pub first: Side,
pub second: Option<Side>
@ -130,17 +130,6 @@
}
}
}
impl ToCss for SpecifiedValue {
fn to_css<W>(&self, dest: &mut W) -> fmt::Result where W: fmt::Write {
self.first.to_css(dest)?;
if let Some(ref second) = self.second {
dest.write_str(" ")?;
second.to_css(dest)?;
}
Ok(())
}
}
</%helpers:longhand>
${helpers.single_keyword("unicode-bidi",

View file

@ -13,7 +13,7 @@ use style_traits::{ToCss, ParseError};
/// A generic value for the `initial-letter` property.
#[cfg_attr(feature = "servo", derive(HeapSizeOf))]
#[derive(Clone, Copy, Debug, HasViewportPercentage, PartialEq, ToComputedValue)]
#[derive(Clone, Copy, Debug, HasViewportPercentage, PartialEq, ToComputedValue, ToCss)]
pub enum InitialLetter<Number, Integer> {
/// `normal`
Normal,
@ -29,29 +29,6 @@ impl<N, I> InitialLetter<N, I> {
}
}
impl<N, I> ToCss for InitialLetter<N, I>
where
N: ToCss,
I: ToCss,
{
fn to_css<W>(&self, dest: &mut W) -> fmt::Result
where
W: fmt::Write,
{
match *self {
InitialLetter::Normal => dest.write_str("normal"),
InitialLetter::Specified(ref size, ref sink) => {
size.to_css(dest)?;
if let Some(ref sink) = *sink {
dest.write_str(" ")?;
sink.to_css(dest)?;
}
Ok(())
},
}
}
}
/// A generic spacing value for the `letter-spacing` and `word-spacing` properties.
#[cfg_attr(feature = "servo", derive(HeapSizeOf))]
#[derive(Clone, Copy, Debug, HasViewportPercentage, PartialEq, ToComputedValue, ToCss)]

View file

@ -299,7 +299,7 @@ impl ToComputedValue for Color {
/// Specified color value, but resolved to just RGBA for computed value
/// with value from color property at the same context.
#[derive(Clone, PartialEq, Debug)]
#[derive(Clone, Debug, PartialEq, ToCss)]
#[cfg_attr(feature = "servo", derive(HeapSizeOf))]
pub struct RGBAColor(pub Color);
@ -311,12 +311,6 @@ impl Parse for RGBAColor {
}
}
impl ToCss for RGBAColor {
fn to_css<W>(&self, dest: &mut W) -> fmt::Result where W: fmt::Write {
self.0.to_css(dest)
}
}
impl ToComputedValue for RGBAColor {
type ComputedValue = RGBA;