diff options
author | Patrick Walton <pcwalton@mimiga.net> | 2015-03-09 12:33:04 -0700 |
---|---|---|
committer | Simon Sapin <simon.sapin@exyr.org> | 2015-04-27 17:12:07 +0200 |
commit | 48299a53cbe39d1a8a9bd4547a678d1d1cc345ae (patch) | |
tree | dbbfd2ad7f938e4fd634f81cceca19df707ff792 /components/style/values.rs | |
parent | 92359c7b9addfe7ee161760aad20368bafd76c26 (diff) | |
download | servo-48299a53cbe39d1a8a9bd4547a678d1d1cc345ae.tar.gz servo-48299a53cbe39d1a8a9bd4547a678d1d1cc345ae.zip |
layout: Implement most of `border-collapse` per CSS 2.1 § 17.6.2.
Known issues:
* Collapsed borders do not correctly affect the border-box of the table
itself.
* The content widths of all cells in a column and the content height of
all cells in a row is the same in this patch, but not in Gecko and
WebKit.
* Corners are not painted well. The spec does not say what to do here.
* Column spans are not handled well. The spec does not say what to do
here either.
Diffstat (limited to 'components/style/values.rs')
-rw-r--r-- | components/style/values.rs | 66 |
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. |