mirror of
https://github.com/servo/servo.git
synced 2025-08-04 13:10:20 +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
|
/// A macro for implementing `ToComputedValue`, and `Parse` traits for
|
||||||
/// the enums defined using `define_css_keyword_enum` macro.
|
/// the enums defined using `define_css_keyword_enum` macro.
|
||||||
///
|
///
|
||||||
|
|
|
@ -32,13 +32,16 @@
|
||||||
ignored_when_colors_disabled=True,
|
ignored_when_colors_disabled=True,
|
||||||
)}
|
)}
|
||||||
|
|
||||||
${helpers.predefined_type("border-%s-style" % side_name, "BorderStyle",
|
${helpers.predefined_type(
|
||||||
"specified::BorderStyle::None",
|
"border-%s-style" % side_name, "BorderStyle",
|
||||||
alias=maybe_moz_logical_alias(product, side, "-moz-border-%s-style"),
|
"specified::BorderStyle::None",
|
||||||
spec=maybe_logical_spec(side, "style"),
|
alias=maybe_moz_logical_alias(product, side, "-moz-border-%s-style"),
|
||||||
flags="APPLIES_TO_FIRST_LETTER",
|
spec=maybe_logical_spec(side, "style"),
|
||||||
animation_value_type="discrete" if not is_logical else "none",
|
flags="APPLIES_TO_FIRST_LETTER",
|
||||||
logical=is_logical)}
|
animation_value_type="discrete" if not is_logical else "none",
|
||||||
|
logical=is_logical,
|
||||||
|
needs_context=False,
|
||||||
|
)}
|
||||||
|
|
||||||
${helpers.predefined_type("border-%s-width" % side_name,
|
${helpers.predefined_type("border-%s-width" % side_name,
|
||||||
"BorderSideWidth",
|
"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",
|
spec="https://drafts.csswg.org/css-backgrounds/#border-color",
|
||||||
allow_quirks=True)}
|
allow_quirks=True)}
|
||||||
|
|
||||||
${helpers.four_sides_shorthand("border-style", "border-%s-style",
|
${helpers.four_sides_shorthand(
|
||||||
"specified::BorderStyle::parse",
|
"border-style",
|
||||||
spec="https://drafts.csswg.org/css-backgrounds/#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="${
|
<%helpers:shorthand name="border-width" sub_properties="${
|
||||||
' '.join('border-%s-width' % side
|
' '.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 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);
|
style = Some(value);
|
||||||
any = true;
|
any = true;
|
||||||
continue
|
continue
|
||||||
|
|
|
@ -161,20 +161,23 @@ fn parse_number_with_clamping_mode<'i, 't>(
|
||||||
// 17.6.2.1. Higher values override lower values.
|
// 17.6.2.1. Higher values override lower values.
|
||||||
//
|
//
|
||||||
// FIXME(emilio): Should move to border.rs
|
// FIXME(emilio): Should move to border.rs
|
||||||
define_numbered_css_keyword_enum! { BorderStyle:
|
#[allow(missing_docs)]
|
||||||
"none" => None = -1,
|
#[cfg_attr(feature = "servo", derive(Deserialize, Serialize))]
|
||||||
"solid" => Solid = 6,
|
#[derive(Clone, Copy, Debug, Eq, MallocSizeOf, Ord, Parse, PartialEq)]
|
||||||
"double" => Double = 7,
|
#[derive(PartialOrd, ToCss)]
|
||||||
"dotted" => Dotted = 4,
|
pub enum BorderStyle {
|
||||||
"dashed" => Dashed = 5,
|
None = -1,
|
||||||
"hidden" => Hidden = -2,
|
Solid = 6,
|
||||||
"groove" => Groove = 1,
|
Double = 7,
|
||||||
"ridge" => Ridge = 3,
|
Dotted = 4,
|
||||||
"inset" => Inset = 0,
|
Dashed = 5,
|
||||||
"outset" => Outset = 2,
|
Hidden = -2,
|
||||||
|
Groove = 1,
|
||||||
|
Ridge = 3,
|
||||||
|
Inset = 0,
|
||||||
|
Outset = 2,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
impl BorderStyle {
|
impl BorderStyle {
|
||||||
/// Whether this border style is either none or hidden.
|
/// Whether this border style is either none or hidden.
|
||||||
pub fn none_or_hidden(&self) -> bool {
|
pub fn none_or_hidden(&self) -> bool {
|
||||||
|
|
|
@ -39,10 +39,10 @@ impl OutlineStyle {
|
||||||
|
|
||||||
impl Parse for OutlineStyle {
|
impl Parse for OutlineStyle {
|
||||||
fn parse<'i, 't>(
|
fn parse<'i, 't>(
|
||||||
context: &ParserContext,
|
_context: &ParserContext,
|
||||||
input: &mut Parser<'i, 't>
|
input: &mut Parser<'i, 't>
|
||||||
) -> Result<OutlineStyle, ParseError<'i>> {
|
) -> 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 {
|
if let BorderStyle::Hidden = border_style {
|
||||||
return Err(input.new_custom_error(SelectorParseErrorKind::UnexpectedIdent("hidden".into())));
|
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() {
|
fn test_border_style() {
|
||||||
use style::values::specified::BorderStyle;
|
use style::values::specified::BorderStyle;
|
||||||
|
|
||||||
assert_roundtrip_with_context!(BorderStyle::parse, r#"none"#);
|
assert_roundtrip_with_context!(<BorderStyle as Parse>::parse, r#"none"#);
|
||||||
assert_roundtrip_with_context!(BorderStyle::parse, r#"hidden"#);
|
assert_roundtrip_with_context!(<BorderStyle as Parse>::parse, r#"hidden"#);
|
||||||
assert_roundtrip_with_context!(BorderStyle::parse, r#"solid"#);
|
assert_roundtrip_with_context!(<BorderStyle as Parse>::parse, r#"solid"#);
|
||||||
assert_roundtrip_with_context!(BorderStyle::parse, r#"double"#);
|
assert_roundtrip_with_context!(<BorderStyle as Parse>::parse, r#"double"#);
|
||||||
assert_roundtrip_with_context!(BorderStyle::parse, r#"dotted"#);
|
assert_roundtrip_with_context!(<BorderStyle as Parse>::parse, r#"dotted"#);
|
||||||
assert_roundtrip_with_context!(BorderStyle::parse, r#"dashed"#);
|
assert_roundtrip_with_context!(<BorderStyle as Parse>::parse, r#"dashed"#);
|
||||||
assert_roundtrip_with_context!(BorderStyle::parse, r#"groove"#);
|
assert_roundtrip_with_context!(<BorderStyle as Parse>::parse, r#"groove"#);
|
||||||
assert_roundtrip_with_context!(BorderStyle::parse, r#"ridge"#);
|
assert_roundtrip_with_context!(<BorderStyle as Parse>::parse, r#"ridge"#);
|
||||||
assert_roundtrip_with_context!(BorderStyle::parse, r#"inset"#);
|
assert_roundtrip_with_context!(<BorderStyle as Parse>::parse, r#"inset"#);
|
||||||
assert_roundtrip_with_context!(BorderStyle::parse, r#"outset"#);
|
assert_roundtrip_with_context!(<BorderStyle as Parse>::parse, r#"outset"#);
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue