mirror of
https://github.com/servo/servo.git
synced 2025-08-06 06:00:15 +01:00
parent
8d21a79246
commit
4a305d1e62
21 changed files with 274 additions and 156 deletions
55
components/style_traits/values.rs
Normal file
55
components/style_traits/values.rs
Normal file
|
@ -0,0 +1,55 @@
|
|||
/* This Source Code Form is subject to the terms of the Mozilla Public
|
||||
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
||||
|
||||
#[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)]
|
||||
#[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) ),+
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
pub mod specified {
|
||||
#[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.,
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue