Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Start using the ToCss trait, to be used for CSS serialization #4455

Merged
merged 8 commits into from Dec 29, 2014
Prev

Move the define_css_keyword_enum macro to the style crate.

  • Loading branch information
SimonSapin committed Dec 29, 2014
commit a29cb0e5d0292a812c28d9143565b9936c57f39e
@@ -51,52 +51,6 @@ pub fn plugin_registrar(reg: &mut Registry) {
}


#[macro_export]
macro_rules! define_css_keyword_enum {
($name: ident: $( $css: expr => $variant: ident ),+,) => {
define_css_keyword_enum!($name: $( $css => $variant ),+)
};
($name: ident: $( $css: expr => $variant: ident ),+) => {
#[allow(non_camel_case_types)]
#[deriving(Clone, Eq, PartialEq, FromPrimitive)]
pub enum $name {
$( $variant ),+
}

impl $name {
pub fn parse(component_value: &::cssparser::ast::ComponentValue) -> Result<$name, ()> {
match component_value {
&::cssparser::ast::Ident(ref value) => {
match_ignore_ascii_case! { value:
$( $css => Ok($name::$variant) ),+
_ => Err(())
}
}
_ => Err(())
}
}
}

impl ::std::fmt::Show for $name {
#[inline]
fn fmt(&self, f: &mut ::std::fmt::Formatter) -> ::std::fmt::Result {
use cssparser::ToCss;
self.fmt_to_css(f)
}
}

impl ::cssparser::ToCss for $name {
fn to_css<W>(&self, dest: &mut W) -> ::text_writer::Result
where W: ::text_writer::TextWriter {
match self {
$( &$name::$variant => dest.write_str($css) ),+
}
}
}
}
}


#[macro_export]
macro_rules! match_ignore_ascii_case {
( $value: expr: $( $string: expr => $result: expr ),+ _ => $fallback: expr, ) => {
@@ -3,11 +3,58 @@
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */

#![allow(non_camel_case_types)]
#![macro_escape]

use url::{Url, UrlParser};

pub use servo_util::geometry::Au;


macro_rules! define_css_keyword_enum {
($name: ident: $( $css: expr => $variant: ident ),+,) => {
define_css_keyword_enum!($name: $( $css => $variant ),+)
};
($name: ident: $( $css: expr => $variant: ident ),+) => {
#[allow(non_camel_case_types)]
#[deriving(Clone, Eq, PartialEq, FromPrimitive)]
pub enum $name {
$( $variant ),+
}

impl $name {
pub fn parse(component_value: &::cssparser::ast::ComponentValue) -> Result<$name, ()> {
match component_value {
&::cssparser::ast::Ident(ref value) => {
match_ignore_ascii_case! { value:
$( $css => Ok($name::$variant) ),+
_ => Err(())
}
}
_ => Err(())
}
}
}

impl ::std::fmt::Show for $name {
#[inline]
fn fmt(&self, f: &mut ::std::fmt::Formatter) -> ::std::fmt::Result {
use cssparser::ToCss;
self.fmt_to_css(f)
}
}

impl ::cssparser::ToCss for $name {
fn to_css<W>(&self, dest: &mut W) -> ::text_writer::Result
where W: ::text_writer::TextWriter {
match self {
$( &$name::$variant => dest.write_str($css) ),+
}
}
}
}
}


pub type CSSFloat = f64;

pub mod specified {
ProTip! Use n and p to navigate between commits in a pull request.
You can’t perform that action at this time.