mirror of
https://github.com/servo/servo.git
synced 2025-06-13 02:44:29 +00:00
Move the define_css_keyword_enum macro to the style crate.
This commit is contained in:
parent
5e08e96e38
commit
a29cb0e5d0
2 changed files with 47 additions and 46 deletions
|
@ -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_export]
|
||||||
macro_rules! match_ignore_ascii_case {
|
macro_rules! match_ignore_ascii_case {
|
||||||
( $value: expr: $( $string: expr => $result: expr ),+ _ => $fallback: expr, ) => {
|
( $value: expr: $( $string: expr => $result: expr ),+ _ => $fallback: expr, ) => {
|
||||||
|
|
|
@ -3,11 +3,58 @@
|
||||||
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
||||||
|
|
||||||
#![allow(non_camel_case_types)]
|
#![allow(non_camel_case_types)]
|
||||||
|
#![macro_escape]
|
||||||
|
|
||||||
use url::{Url, UrlParser};
|
use url::{Url, UrlParser};
|
||||||
|
|
||||||
pub use servo_util::geometry::Au;
|
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 type CSSFloat = f64;
|
||||||
|
|
||||||
pub mod specified {
|
pub mod specified {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue