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

Derive ToCss for DeclaredValue

<!-- 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/20192)
<!-- Reviewable:end -->
This commit is contained in:
bors-servo 2018-03-04 09:29:01 -05:00 committed by GitHub
commit a716dfd40b
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -1308,7 +1308,7 @@ impl ShorthandId {
/// Servo's representation of a declared value for a given `T`, which is the /// Servo's representation of a declared value for a given `T`, which is the
/// declared value for that property. /// declared value for that property.
#[derive(Clone, Debug, Eq, PartialEq)] #[derive(Clone, Debug, Eq, PartialEq, ToCss)]
pub enum DeclaredValue<'a, T: 'a> { pub enum DeclaredValue<'a, T: 'a> {
/// A known specified value from the stylesheet. /// A known specified value from the stylesheet.
Value(&'a T), Value(&'a T),
@ -1360,6 +1360,19 @@ pub struct UnparsedValue {
from_shorthand: Option<ShorthandId>, from_shorthand: Option<ShorthandId>,
} }
impl ToCss for UnparsedValue {
fn to_css<W>(&self, dest: &mut CssWriter<W>) -> fmt::Result
where
W: Write,
{
// https://drafts.csswg.org/css-variables/#variables-in-shorthands
if self.from_shorthand.is_none() {
dest.write_str(&*self.css)?;
}
Ok(())
}
}
impl UnparsedValue { impl UnparsedValue {
fn substitute_variables( fn substitute_variables(
&self, &self,
@ -1425,25 +1438,6 @@ impl UnparsedValue {
} }
} }
impl<'a, T: ToCss> ToCss for DeclaredValue<'a, T> {
fn to_css<W>(&self, dest: &mut CssWriter<W>) -> fmt::Result
where
W: Write,
{
match *self {
DeclaredValue::Value(ref inner) => inner.to_css(dest),
DeclaredValue::WithVariables(ref with_variables) => {
// https://drafts.csswg.org/css-variables/#variables-in-shorthands
if with_variables.from_shorthand.is_none() {
dest.write_str(&*with_variables.css)?
}
Ok(())
},
DeclaredValue::CSSWideKeyword(ref keyword) => keyword.to_css(dest),
}
}
}
/// An identifier for a given property declaration, which can be either a /// An identifier for a given property declaration, which can be either a
/// longhand or a custom property. /// longhand or a custom property.
#[derive(Clone, Copy, PartialEq)] #[derive(Clone, Copy, PartialEq)]
@ -1742,14 +1736,7 @@ impl ToCss for VariableDeclaration {
where where
W: fmt::Write, W: fmt::Write,
{ {
// https://drafts.csswg.org/css-variables/#variables-in-shorthands self.value.to_css(dest)
match self.value.from_shorthand {
None => {
dest.write_str(&*self.value.css)?
}
Some(..) => {},
}
Ok(())
} }
} }