mirror of
https://github.com/servo/servo.git
synced 2025-08-04 05:00:08 +01:00
Kill define_numbered_css_keyword_enum
This commit is contained in:
parent
1f8777bb0b
commit
bac8781cc7
6 changed files with 45 additions and 74 deletions
|
@ -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<W>(
|
||||
&self,
|
||||
dest: &mut ::style_traits::CssWriter<W>,
|
||||
) -> ::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.
|
||||
///
|
||||
|
|
|
@ -32,13 +32,16 @@
|
|||
ignored_when_colors_disabled=True,
|
||||
)}
|
||||
|
||||
${helpers.predefined_type("border-%s-style" % side_name, "BorderStyle",
|
||||
${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)}
|
||||
logical=is_logical,
|
||||
needs_context=False,
|
||||
)}
|
||||
|
||||
${helpers.predefined_type("border-%s-width" % side_name,
|
||||
"BorderSideWidth",
|
||||
|
|
|
@ -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",
|
||||
${helpers.four_sides_shorthand(
|
||||
"border-style",
|
||||
"border-%s-style",
|
||||
"specified::BorderStyle::parse",
|
||||
spec="https://drafts.csswg.org/css-backgrounds/#border-style")}
|
||||
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
|
||||
|
|
|
@ -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 {
|
||||
|
|
|
@ -39,10 +39,10 @@ impl OutlineStyle {
|
|||
|
||||
impl Parse for OutlineStyle {
|
||||
fn parse<'i, 't>(
|
||||
context: &ParserContext,
|
||||
_context: &ParserContext,
|
||||
input: &mut Parser<'i, 't>
|
||||
) -> Result<OutlineStyle, ParseError<'i>> {
|
||||
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())));
|
||||
}
|
||||
|
|
|
@ -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!(<BorderStyle as Parse>::parse, r#"none"#);
|
||||
assert_roundtrip_with_context!(<BorderStyle as Parse>::parse, r#"hidden"#);
|
||||
assert_roundtrip_with_context!(<BorderStyle as Parse>::parse, r#"solid"#);
|
||||
assert_roundtrip_with_context!(<BorderStyle as Parse>::parse, r#"double"#);
|
||||
assert_roundtrip_with_context!(<BorderStyle as Parse>::parse, r#"dotted"#);
|
||||
assert_roundtrip_with_context!(<BorderStyle as Parse>::parse, r#"dashed"#);
|
||||
assert_roundtrip_with_context!(<BorderStyle as Parse>::parse, r#"groove"#);
|
||||
assert_roundtrip_with_context!(<BorderStyle as Parse>::parse, r#"ridge"#);
|
||||
assert_roundtrip_with_context!(<BorderStyle as Parse>::parse, r#"inset"#);
|
||||
assert_roundtrip_with_context!(<BorderStyle as Parse>::parse, r#"outset"#);
|
||||
}
|
||||
|
||||
#[test]
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue