From 5df250bc053a15752faf3006927e251c5d116768 Mon Sep 17 00:00:00 2001 From: Ravi Shankar Date: Thu, 3 Nov 2016 21:10:03 +0530 Subject: [PATCH] Add unit structs for representing keywords: auto, none, normal --- components/style/values/mod.rs | 35 ++++++++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) diff --git a/components/style/values/mod.rs b/components/style/values/mod.rs index f817a8f01eb..485b46c82a2 100644 --- a/components/style/values/mod.rs +++ b/components/style/values/mod.rs @@ -63,6 +63,41 @@ impl HasViewportPercentage for T where T: NoViewportPercentage { } } +use self::computed::ComputedValueAsSpecified; + +macro_rules! define_keyword_type { + ($name: ident, $css: expr) => { + #[derive(Clone, PartialEq, Copy)] + #[cfg_attr(feature = "servo", derive(HeapSizeOf))] + pub struct $name; + + impl ::style_traits::ToCss for $name { + fn to_css(&self, dest: &mut W) -> ::std::fmt::Result where W: ::std::fmt::Write { + write!(dest, $css) + } + } + + impl fmt::Debug for $name { + fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { + write!(f, $css) + } + } + + impl Parse for $name { + fn parse(input: &mut ::cssparser::Parser) -> Result<$name, ()> { + input.expect_ident_matching($css).map(|_| $name) + } + } + + impl ComputedValueAsSpecified for $name {} + impl NoViewportPercentage for $name {} + }; +} + +define_keyword_type!(None_, "none"); +define_keyword_type!(Auto, "auto"); +define_keyword_type!(Normal, "normal"); + #[derive(Clone, PartialEq, Copy)] #[cfg_attr(feature = "servo", derive(HeapSizeOf))] pub enum Either {