Auto merge of #17446 - servo:derive-all-the-things, r=emilio

Simplify machinery to serialise optional parts of CSS values

<!-- Reviewable:start -->
This change is [<img src="https://reviewable.io/review_button.svg" height="34" align="absmiddle" alt="Reviewable"/>](https://reviewable.io/reviews/servo/servo/17446)
<!-- Reviewable:end -->
This commit is contained in:
bors-servo 2017-06-22 01:19:51 -07:00 committed by GitHub
commit 0913d65243
8 changed files with 152 additions and 131 deletions

View file

@ -214,7 +214,6 @@ ${helpers.predefined_type("border-image-outset", "LengthOrNumberRect",
<%helpers:longhand name="border-image-repeat" animation_value_type="discrete"
spec="https://drafts.csswg.org/css-backgrounds/#border-image-repeat">
use std::fmt;
use style_traits::ToCss;
no_viewport_percentage!(SpecifiedValue);
@ -227,8 +226,8 @@ ${helpers.predefined_type("border-image-outset", "LengthOrNumberRect",
pub struct T(pub RepeatKeyword, pub RepeatKeyword);
}
#[derive(Debug, Clone, PartialEq)]
#[cfg_attr(feature = "servo", derive(HeapSizeOf))]
#[derive(Debug, Clone, PartialEq, ToCss)]
pub struct SpecifiedValue(pub RepeatKeyword,
pub Option<RepeatKeyword>);
@ -238,17 +237,6 @@ ${helpers.predefined_type("border-image-outset", "LengthOrNumberRect",
"round" => Round,
"space" => Space);
impl ToCss for SpecifiedValue {
fn to_css<W>(&self, dest: &mut W) -> fmt::Result where W: fmt::Write {
self.0.to_css(dest)?;
if let Some(second) = self.1 {
dest.write_str(" ")?;
second.to_css(dest)?;
}
Ok(())
}
}
#[inline]
pub fn get_initial_value() -> computed_value::T {
computed_value::T(RepeatKeyword::Stretch, RepeatKeyword::Stretch)

View file

@ -23,8 +23,6 @@ ${helpers.single_keyword("caption-side", "top bottom",
<%helpers:longhand name="border-spacing" animation_value_type="ComputedValue" boxed="True"
spec="https://drafts.csswg.org/css-tables/#propdef-border-spacing">
use app_units::Au;
use std::fmt;
use style_traits::ToCss;
use values::specified::{AllowQuirks, Length};
pub mod computed_value {
@ -64,8 +62,8 @@ ${helpers.single_keyword("caption-side", "top bottom",
}
}
#[derive(Clone, Debug, HasViewportPercentage, PartialEq)]
#[cfg_attr(feature = "servo", derive(HeapSizeOf))]
#[derive(Clone, Debug, HasViewportPercentage, PartialEq, ToCss)]
pub struct SpecifiedValue {
pub horizontal: Length,
pub vertical: Option<Length>,
@ -79,19 +77,6 @@ ${helpers.single_keyword("caption-side", "top bottom",
}
}
impl ToCss for SpecifiedValue {
fn to_css<W>(&self, dest: &mut W) -> fmt::Result
where W: fmt::Write,
{
self.horizontal.to_css(dest)?;
if let Some(vertical) = self.vertical.as_ref() {
dest.write_str(" ")?;
vertical.to_css(dest)?;
}
Ok(())
}
}
impl ToComputedValue for SpecifiedValue {
type ComputedValue = computed_value::T;