aboutsummaryrefslogtreecommitdiffstats
path: root/components/style/values.rs
diff options
context:
space:
mode:
Diffstat (limited to 'components/style/values.rs')
-rw-r--r--components/style/values.rs66
1 files changed, 53 insertions, 13 deletions
diff --git a/components/style/values.rs b/components/style/values.rs
index 3d724829be0..267ed05a023 100644
--- a/components/style/values.rs
+++ b/components/style/values.rs
@@ -6,14 +6,13 @@
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, FromPrimitive, Copy, Hash)]
+ #[derive(Clone, Eq, PartialEq, FromPrimitive, Copy, Hash, RustcEncodable)]
pub enum $name {
$( $variant ),+
}
@@ -46,6 +45,45 @@ macro_rules! define_css_keyword_enum {
}
}
+macro_rules! define_numbered_css_keyword_enum {
+ ($name: ident: $( $css: expr => $variant: ident = $value: expr ),+,) => {
+ define_numbered_css_keyword_enum!($name: $( $css => $variant = $value ),+);
+ };
+ ($name: ident: $( $css: expr => $variant: ident = $value: expr ),+) => {
+ #[allow(non_camel_case_types)]
+ #[derive(Clone, Eq, PartialEq, FromPrimitive, Copy, RustcEncodable)]
+ pub enum $name {
+ $( $variant = $value ),+
+ }
+
+ 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 ::std::fmt::Debug 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;
@@ -850,17 +888,19 @@ pub mod specified {
})
}
- define_css_keyword_enum! { BorderStyle:
- "none" => none,
- "solid" => solid,
- "double" => double,
- "dotted" => dotted,
- "dashed" => dashed,
- "hidden" => hidden,
- "groove" => groove,
- "ridge" => ridge,
- "inset" => inset,
- "outset" => outset,
+ // The integer values here correspond to the border conflict resolution rules in CSS 2.1 §
+ // 17.6.2.1. Higher values override lower values.
+ define_numbered_css_keyword_enum! { BorderStyle:
+ "none" => none = -1,
+ "solid" => solid = 6,
+ "double" => double = 7,
+ "dotted" => dotted = 4,
+ "dashed" => dashed = 5,
+ "hidden" => hidden = -2,
+ "groove" => groove = 1,
+ "ridge" => ridge = 3,
+ "inset" => inset = 0,
+ "outset" => outset = 2,
}
/// A time in seconds according to CSS-VALUES § 6.2.