Skip to content

Commit

Permalink
Derive some more ToCss implementations
Browse files Browse the repository at this point in the history
  • Loading branch information
nox committed Jul 11, 2017
1 parent 21ecf47 commit ec289fb
Show file tree
Hide file tree
Showing 4 changed files with 5 additions and 70 deletions.
29 changes: 2 additions & 27 deletions components/style/properties/longhand/font.mako.rs
Expand Up @@ -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,
Expand All @@ -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>> {
Expand Down Expand Up @@ -1008,26 +995,14 @@ ${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,
Number(specified::Number),
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;

Expand Down
13 changes: 1 addition & 12 deletions components/style/properties/longhand/text.mako.rs
Expand Up @@ -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>
Expand Down Expand Up @@ -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",
Expand Down
25 changes: 1 addition & 24 deletions components/style/values/generics/text.rs
Expand Up @@ -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,
Expand All @@ -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)]
Expand Down
8 changes: 1 addition & 7 deletions components/style/values/specified/color.rs
Expand Up @@ -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);

Expand All @@ -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;

Expand Down

0 comments on commit ec289fb

Please sign in to comment.