diff --git a/components/style/macros.rs b/components/style/macros.rs index c3bf87b51a4..8dfbbfd9760 100644 --- a/components/style/macros.rs +++ b/components/style/macros.rs @@ -65,45 +65,6 @@ macro_rules! try_match_ident_ignore_ascii_case { }} } -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, missing_docs)] - #[derive(Clone, Copy, Debug, Eq, MallocSizeOf, Ord, PartialEq, PartialOrd)] - #[cfg_attr(feature = "servo", derive(Deserialize, Serialize))] - pub enum $name { - $( $variant = $value ),+ - } - - impl $crate::parser::Parse for $name { - fn parse<'i, 't>( - _context: &$crate::parser::ParserContext, - input: &mut ::cssparser::Parser<'i, 't>, - ) -> Result<$name, ::style_traits::ParseError<'i>> { - try_match_ident_ignore_ascii_case! { input, - $( $css => Ok($name::$variant), )+ - } - } - } - - impl ::style_traits::ToCss for $name { - fn to_css( - &self, - dest: &mut ::style_traits::CssWriter, - ) -> ::std::fmt::Result - where - W: ::std::fmt::Write, - { - match *self { - $( $name::$variant => dest.write_str($css) ),+ - } - } - } - } -} - /// A macro for implementing `ToComputedValue`, and `Parse` traits for /// the enums defined using `define_css_keyword_enum` macro. /// diff --git a/components/style/properties/longhand/border.mako.rs b/components/style/properties/longhand/border.mako.rs index a24c31acf88..b7c20fd6218 100644 --- a/components/style/properties/longhand/border.mako.rs +++ b/components/style/properties/longhand/border.mako.rs @@ -32,13 +32,16 @@ ignored_when_colors_disabled=True, )} - ${helpers.predefined_type("border-%s-style" % side_name, "BorderStyle", - "specified::BorderStyle::None", - alias=maybe_moz_logical_alias(product, side, "-moz-border-%s-style"), - spec=maybe_logical_spec(side, "style"), - flags="APPLIES_TO_FIRST_LETTER", - animation_value_type="discrete" if not is_logical else "none", - logical=is_logical)} + ${helpers.predefined_type( + "border-%s-style" % side_name, "BorderStyle", + "specified::BorderStyle::None", + alias=maybe_moz_logical_alias(product, side, "-moz-border-%s-style"), + spec=maybe_logical_spec(side, "style"), + flags="APPLIES_TO_FIRST_LETTER", + animation_value_type="discrete" if not is_logical else "none", + logical=is_logical, + needs_context=False, + )} ${helpers.predefined_type("border-%s-width" % side_name, "BorderSideWidth", diff --git a/components/style/properties/shorthand/border.mako.rs b/components/style/properties/shorthand/border.mako.rs index 0209ebb2376..ec462510bf7 100644 --- a/components/style/properties/shorthand/border.mako.rs +++ b/components/style/properties/shorthand/border.mako.rs @@ -9,9 +9,13 @@ ${helpers.four_sides_shorthand("border-color", "border-%s-color", "specified::Co spec="https://drafts.csswg.org/css-backgrounds/#border-color", allow_quirks=True)} -${helpers.four_sides_shorthand("border-style", "border-%s-style", - "specified::BorderStyle::parse", - spec="https://drafts.csswg.org/css-backgrounds/#border-style")} +${helpers.four_sides_shorthand( + "border-style", + "border-%s-style", + "specified::BorderStyle::parse", + needs_context=False, + spec="https://drafts.csswg.org/css-backgrounds/#border-style", +)} <%helpers:shorthand name="border-width" sub_properties="${ ' '.join('border-%s-width' % side @@ -63,7 +67,7 @@ pub fn parse_border<'i, 't>(context: &ParserContext, input: &mut Parser<'i, 't>) } } if style.is_none() { - if let Ok(value) = input.try(|i| BorderStyle::parse(context, i)) { + if let Ok(value) = input.try(BorderStyle::parse) { style = Some(value); any = true; continue diff --git a/components/style/values/specified/mod.rs b/components/style/values/specified/mod.rs index 9875914c2d4..32d9a46f14d 100644 --- a/components/style/values/specified/mod.rs +++ b/components/style/values/specified/mod.rs @@ -161,20 +161,23 @@ fn parse_number_with_clamping_mode<'i, 't>( // 17.6.2.1. Higher values override lower values. // // FIXME(emilio): Should move to border.rs -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, +#[allow(missing_docs)] +#[cfg_attr(feature = "servo", derive(Deserialize, Serialize))] +#[derive(Clone, Copy, Debug, Eq, MallocSizeOf, Ord, Parse, PartialEq)] +#[derive(PartialOrd, ToCss)] +pub enum BorderStyle { + None = -1, + Solid = 6, + Double = 7, + Dotted = 4, + Dashed = 5, + Hidden = -2, + Groove = 1, + Ridge = 3, + Inset = 0, + Outset = 2, } - impl BorderStyle { /// Whether this border style is either none or hidden. pub fn none_or_hidden(&self) -> bool { diff --git a/components/style/values/specified/outline.rs b/components/style/values/specified/outline.rs index 48385242275..a9366c185db 100644 --- a/components/style/values/specified/outline.rs +++ b/components/style/values/specified/outline.rs @@ -39,10 +39,10 @@ impl OutlineStyle { impl Parse for OutlineStyle { fn parse<'i, 't>( - context: &ParserContext, + _context: &ParserContext, input: &mut Parser<'i, 't> ) -> Result> { - if let Ok(border_style) = input.try(|i| BorderStyle::parse(context, i)) { + if let Ok(border_style) = input.try(BorderStyle::parse) { if let BorderStyle::Hidden = border_style { return Err(input.new_custom_error(SelectorParseErrorKind::UnexpectedIdent("hidden".into()))); } diff --git a/tests/unit/style/parsing/border.rs b/tests/unit/style/parsing/border.rs index e92b59dd2fb..0eadbec4f31 100644 --- a/tests/unit/style/parsing/border.rs +++ b/tests/unit/style/parsing/border.rs @@ -168,16 +168,16 @@ fn border_image_outset_should_return_length_on_length_zero() { fn test_border_style() { use style::values::specified::BorderStyle; - assert_roundtrip_with_context!(BorderStyle::parse, r#"none"#); - assert_roundtrip_with_context!(BorderStyle::parse, r#"hidden"#); - assert_roundtrip_with_context!(BorderStyle::parse, r#"solid"#); - assert_roundtrip_with_context!(BorderStyle::parse, r#"double"#); - assert_roundtrip_with_context!(BorderStyle::parse, r#"dotted"#); - assert_roundtrip_with_context!(BorderStyle::parse, r#"dashed"#); - assert_roundtrip_with_context!(BorderStyle::parse, r#"groove"#); - assert_roundtrip_with_context!(BorderStyle::parse, r#"ridge"#); - assert_roundtrip_with_context!(BorderStyle::parse, r#"inset"#); - assert_roundtrip_with_context!(BorderStyle::parse, r#"outset"#); + assert_roundtrip_with_context!(::parse, r#"none"#); + assert_roundtrip_with_context!(::parse, r#"hidden"#); + assert_roundtrip_with_context!(::parse, r#"solid"#); + assert_roundtrip_with_context!(::parse, r#"double"#); + assert_roundtrip_with_context!(::parse, r#"dotted"#); + assert_roundtrip_with_context!(::parse, r#"dashed"#); + assert_roundtrip_with_context!(::parse, r#"groove"#); + assert_roundtrip_with_context!(::parse, r#"ridge"#); + assert_roundtrip_with_context!(::parse, r#"inset"#); + assert_roundtrip_with_context!(::parse, r#"outset"#); } #[test]