Derive ToCss for TransitionProperty

This commit is contained in:
Anthony Ramine 2018-03-03 00:03:18 +01:00
parent 83a2312867
commit 13c40f4fb8
2 changed files with 23 additions and 17 deletions

View file

@ -26,10 +26,9 @@ use properties::{LonghandId, ShorthandId};
use servo_arc::Arc; use servo_arc::Arc;
use smallvec::SmallVec; use smallvec::SmallVec;
use std::{cmp, ptr}; use std::{cmp, ptr};
use std::fmt::{self, Write};
use std::mem::{self, ManuallyDrop}; use std::mem::{self, ManuallyDrop};
#[cfg(feature = "gecko")] use hash::FnvHashMap; #[cfg(feature = "gecko")] use hash::FnvHashMap;
use style_traits::{CssWriter, ParseError, ToCss}; use style_traits::ParseError;
use super::ComputedValues; use super::ComputedValues;
use values::{CSSFloat, CustomIdent, Either}; use values::{CSSFloat, CustomIdent, Either};
use values::animated::{Animate, Procedure, ToAnimatedValue, ToAnimatedZero}; use values::animated::{Animate, Procedure, ToAnimatedValue, ToAnimatedZero};
@ -79,7 +78,7 @@ pub fn nscsspropertyid_is_animatable(property: nsCSSPropertyID) -> bool {
/// a shorthand with at least one transitionable longhand component, or an unsupported property. /// a shorthand with at least one transitionable longhand component, or an unsupported property.
// NB: This needs to be here because it needs all the longhands generated // NB: This needs to be here because it needs all the longhands generated
// beforehand. // beforehand.
#[derive(Clone, Debug, Eq, Hash, MallocSizeOf, PartialEq)] #[derive(Clone, Debug, Eq, Hash, MallocSizeOf, PartialEq, ToCss)]
pub enum TransitionProperty { pub enum TransitionProperty {
/// A shorthand. /// A shorthand.
Shorthand(ShorthandId), Shorthand(ShorthandId),
@ -90,19 +89,6 @@ pub enum TransitionProperty {
Unsupported(CustomIdent), Unsupported(CustomIdent),
} }
impl ToCss for TransitionProperty {
fn to_css<W>(&self, dest: &mut CssWriter<W>) -> fmt::Result
where
W: Write,
{
match *self {
TransitionProperty::Shorthand(ref id) => dest.write_str(id.name()),
TransitionProperty::Longhand(ref id) => dest.write_str(id.name()),
TransitionProperty::Unsupported(ref id) => id.to_css(dest),
}
}
}
trivial_to_computed_value!(TransitionProperty); trivial_to_computed_value!(TransitionProperty);
impl TransitionProperty { impl TransitionProperty {

View file

@ -800,6 +800,16 @@ pub enum LonghandId {
% endfor % endfor
} }
impl ToCss for LonghandId {
#[inline]
fn to_css<W>(&self, dest: &mut CssWriter<W>) -> fmt::Result
where
W: Write,
{
dest.write_str(self.name())
}
}
impl fmt::Debug for LonghandId { impl fmt::Debug for LonghandId {
fn fmt(&self, formatter: &mut fmt::Formatter) -> fmt::Result { fn fmt(&self, formatter: &mut fmt::Formatter) -> fmt::Result {
formatter.write_str(self.name()) formatter.write_str(self.name())
@ -1130,7 +1140,7 @@ where
} }
/// An identifier for a given shorthand property. /// An identifier for a given shorthand property.
#[derive(Clone, Copy, Debug, Eq, Hash, MallocSizeOf, PartialEq, ToCss)] #[derive(Clone, Copy, Debug, Eq, Hash, MallocSizeOf, PartialEq)]
pub enum ShorthandId { pub enum ShorthandId {
% for property in data.shorthands: % for property in data.shorthands:
/// ${property.name} /// ${property.name}
@ -1138,6 +1148,16 @@ pub enum ShorthandId {
% endfor % endfor
} }
impl ToCss for ShorthandId {
#[inline]
fn to_css<W>(&self, dest: &mut CssWriter<W>) -> fmt::Result
where
W: Write,
{
dest.write_str(self.name())
}
}
impl ShorthandId { impl ShorthandId {
/// Get the name for this shorthand property. /// Get the name for this shorthand property.
pub fn name(&self) -> &'static str { pub fn name(&self) -> &'static str {