Share more strings between Debug implementations for property-based types.

This commit is contained in:
Josh Matthews 2017-09-07 15:58:36 -07:00
parent ecd8abb178
commit d41baf7f5f
2 changed files with 68 additions and 5 deletions

View file

@ -32,6 +32,7 @@ use selectors::parser::SelectorParseError;
use smallvec::SmallVec;
use std::borrow::Cow;
use std::cmp;
use std::fmt;
#[cfg(feature = "gecko")] use hash::FnvHashMap;
use style_traits::ParseError;
use super::ComputedValues;
@ -72,7 +73,7 @@ pub trait RepeatableListAnimatable: Animate {}
/// NOTE: This includes the 'display' property since it is animatable from SMIL even though it is
/// not animatable from CSS animations or Web Animations. CSS transitions also does not allow
/// animating 'display', but for CSS transitions we have the separate TransitionProperty type.
#[derive(Clone, Debug, Eq, Hash, PartialEq)]
#[derive(Clone, Eq, Hash, PartialEq)]
#[cfg_attr(feature = "gecko", derive(MallocSizeOf))]
#[cfg_attr(feature = "servo", derive(HeapSizeOf))]
pub enum AnimatableLonghand {
@ -84,6 +85,19 @@ pub enum AnimatableLonghand {
% endfor
}
impl fmt::Debug for AnimatableLonghand {
fn fmt(&self, formatter: &mut fmt::Formatter) -> fmt::Result {
let name = match *self {
% for property in data.longhands:
% if property.animatable:
AnimatableLonghand::${property.camel_case} => "${property.camel_case}",
% endif
% endfor
};
formatter.write_str(name)
}
}
impl AnimatableLonghand {
/// Returns true if this AnimatableLonghand is one of the discretely animatable properties.
pub fn is_discrete(&self) -> bool {
@ -204,7 +218,7 @@ pub fn nscsspropertyid_is_animatable(property: nsCSSPropertyID) -> bool {
// beforehand.
#[cfg_attr(feature = "gecko", derive(MallocSizeOf))]
#[cfg_attr(feature = "servo", derive(HeapSizeOf))]
#[derive(Clone, Debug, Eq, Hash, PartialEq, ToCss, ToComputedValue)]
#[derive(Clone, Eq, Hash, PartialEq, ToCss, ToComputedValue)]
pub enum TransitionProperty {
/// All, any transitionable property changing should generate a transition.
All,
@ -219,6 +233,25 @@ pub enum TransitionProperty {
Unsupported(CustomIdent)
}
impl fmt::Debug for TransitionProperty {
fn fmt(&self, formatter: &mut fmt::Formatter) -> fmt::Result {
let name = match *self {
% for property in data.longhands + data.shorthands_except_all():
% if property.transitionable:
TransitionProperty::${property.camel_case} => "${property.camel_case}",
% endif
% endfor
TransitionProperty::All => "All",
TransitionProperty::Unsupported(ref ident) => {
formatter.write_str("Unsupported(")?;
ident.fmt(formatter)?;
return formatter.write_str(")");
}
};
formatter.write_str(name)
}
}
impl TransitionProperty {
/// Iterates over each longhand property.
pub fn each<F: FnMut(&TransitionProperty) -> ()>(mut cb: F) {
@ -484,7 +517,7 @@ unsafe impl HasSimpleFFI for AnimationValueMap {}
///
/// FIXME: We need to add a path for custom properties, but that's trivial after
/// this (is a similar path to that of PropertyDeclaration).
#[derive(Clone, Debug, PartialEq)]
#[derive(Clone, PartialEq)]
#[cfg_attr(feature = "servo", derive(HeapSizeOf))]
pub enum AnimationValue {
% for prop in data.longhands:
@ -499,6 +532,19 @@ pub enum AnimationValue {
% endfor
}
impl fmt::Debug for AnimationValue {
fn fmt(&self, formatter: &mut fmt::Formatter) -> fmt::Result {
let name = match *self {
% for prop in data.longhands:
% if prop.animatable:
AnimationValue::${prop.camel_case}(..) => "${prop.camel_case}",
% endif
% endfor
};
formatter.write_str(name)
}
}
impl AnimationValue {
/// "Uncompute" this animation value in order to be used inside the CSS
/// cascade.

View file

@ -446,7 +446,7 @@ bitflags! {
}
/// An identifier for a given longhand property.
#[derive(Clone, Copy, Debug, Eq, PartialEq)]
#[derive(Clone, Copy, Eq, PartialEq)]
#[cfg_attr(feature = "gecko", derive(MallocSizeOf))]
#[cfg_attr(feature = "servo", derive(HeapSizeOf))]
pub enum LonghandId {
@ -456,6 +456,12 @@ pub enum LonghandId {
% endfor
}
impl fmt::Debug for LonghandId {
fn fmt(&self, formatter: &mut fmt::Formatter) -> fmt::Result {
formatter.write_str(self.name())
}
}
impl LonghandId {
/// Get the name of this longhand property.
pub fn name(&self) -> &'static str {
@ -3597,7 +3603,7 @@ pub fn modify_border_style_for_inline_sides(style: &mut Arc<ComputedValues>,
}
/// An identifier for a given alias property.
#[derive(Clone, Copy, Debug, Eq, PartialEq)]
#[derive(Clone, Copy, Eq, PartialEq)]
#[cfg_attr(feature = "servo", derive(HeapSizeOf))]
pub enum AliasId {
% for i, property in enumerate(data.all_aliases()):
@ -3606,6 +3612,17 @@ pub enum AliasId {
% endfor
}
impl fmt::Debug for AliasId {
fn fmt(&self, formatter: &mut fmt::Formatter) -> fmt::Result {
let name = match *self {
% for property in data.all_aliases():
AliasId::${property.camel_case} => "${property.camel_case}",
% endfor
};
formatter.write_str(name)
}
}
impl AliasId {
/// Returns an nsCSSPropertyID.
#[cfg(feature = "gecko")]