Add style_traits crate to improve crate separation,

closes #7353
This commit is contained in:
João Oliveira 2015-09-03 21:05:44 +01:00
parent 8d21a79246
commit 4a305d1e62
21 changed files with 274 additions and 156 deletions

View file

@ -6,37 +6,6 @@
pub use cssparser::RGBA;
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)]
#[derive(Clone, Eq, PartialEq, Copy, Hash, RustcEncodable, Debug, HeapSizeOf)]
#[derive(Deserialize, Serialize)]
pub enum $name {
$( $variant ),+
}
impl $name {
pub fn parse(input: &mut ::cssparser::Parser) -> Result<$name, ()> {
match_ignore_ascii_case! { try!(input.expect_ident()),
$( $css => Ok($name::$variant) ),+
_ => Err(())
}
}
}
impl ::cssparser::ToCss for $name {
fn to_css<W>(&self, dest: &mut W) -> ::std::fmt::Result
where W: ::std::fmt::Write {
match *self {
$( $name::$variant => dest.write_str($css) ),+
}
}
}
}
}
macro_rules! define_numbered_css_keyword_enum {
($name: ident: $( $css: expr => $variant: ident = $value: expr ),+,) => {
@ -83,25 +52,11 @@ pub mod specified {
use std::fmt;
use std::fmt::Write;
use std::ops::Mul;
use style_traits::values::specified::AllowedNumericType;
use super::CSSFloat;
use url::Url;
use util::geometry::Au;
#[derive(Clone, Copy, Debug, PartialEq, Eq)]
pub enum AllowedNumericType {
All,
NonNegative
}
impl AllowedNumericType {
#[inline]
pub fn is_ok(&self, value: f32) -> bool {
match *self {
AllowedNumericType::All => true,
AllowedNumericType::NonNegative => value >= 0.,
}
}
}
#[derive(Clone, PartialEq, Debug, HeapSizeOf)]
pub struct CSSColor {