Don't use define_css_keyword_enum in style anymore

This commit is contained in:
Anthony Ramine 2018-01-30 13:52:11 +01:00
parent 09e304adb3
commit 3d99a4489c
14 changed files with 174 additions and 158 deletions

View file

@ -67,13 +67,17 @@ impl ToCss for UrlSource {
/// A font-display value for a @font-face rule. /// A font-display value for a @font-face rule.
/// The font-display descriptor determines how a font face is displayed based /// The font-display descriptor determines how a font face is displayed based
/// on whether and when it is downloaded and ready to use. /// on whether and when it is downloaded and ready to use.
define_css_keyword_enum!(FontDisplay: #[allow(missing_docs)]
"auto" => Auto, #[cfg_attr(feature = "servo", derive(Deserialize, Serialize))]
"block" => Block, #[derive(Clone, Copy, Debug, Eq, MallocSizeOf, Parse, PartialEq)]
"swap" => Swap, #[derive(ToComputedValue, ToCss)]
"fallback" => Fallback, pub enum FontDisplay {
"optional" => Optional); Auto,
add_impls_for_keyword_enum!(FontDisplay); Block,
Swap,
Fallback,
Optional,
}
/// A font-weight value for a @font-face rule. /// A font-weight value for a @font-face rule.
/// The font-weight CSS property specifies the weight or boldness of the font. /// The font-weight CSS property specifies the weight or boldness of the font.

View file

@ -25,8 +25,6 @@
#![deny(missing_docs)] #![deny(missing_docs)]
#![recursion_limit = "500"] // For define_css_keyword_enum! in -moz-appearance
extern crate app_units; extern crate app_units;
extern crate arrayvec; extern crate arrayvec;
extern crate atomic_refcell; extern crate atomic_refcell;
@ -72,7 +70,6 @@ extern crate smallbitvec;
extern crate smallvec; extern crate smallvec;
#[macro_use] #[macro_use]
extern crate style_derive; extern crate style_derive;
#[macro_use]
extern crate style_traits; extern crate style_traits;
extern crate time; extern crate time;
extern crate uluru; extern crate uluru;

View file

@ -65,28 +65,6 @@ macro_rules! try_match_ident_ignore_ascii_case {
}} }}
} }
/// A macro for implementing `ToComputedValue`, and `Parse` traits for
/// the enums defined using `define_css_keyword_enum` macro.
///
/// NOTE: We should either move `Parse` trait to `style_traits`
/// or `define_css_keyword_enum` macro to this crate, but that
/// may involve significant cleanup in both the crates.
macro_rules! add_impls_for_keyword_enum {
($name:ident) => {
impl $crate::parser::Parse for $name {
#[inline]
fn parse<'i, 't>(
_context: &$crate::parser::ParserContext,
input: &mut ::cssparser::Parser<'i, 't>,
) -> Result<Self, ::style_traits::ParseError<'i>> {
$name::parse(input)
}
}
trivial_to_computed_value!($name);
};
}
macro_rules! define_keyword_type { macro_rules! define_keyword_type {
($name: ident, $css: expr) => { ($name: ident, $css: expr) => {
#[allow(missing_docs)] #[allow(missing_docs)]

View file

@ -424,22 +424,15 @@
use properties::longhands::system_font::SystemFont; use properties::longhands::system_font::SystemFont;
pub mod computed_value { pub mod computed_value {
use cssparser::Parser; #[cfg_attr(feature = "servo", derive(Deserialize, Serialize))]
use parser::{Parse, ParserContext}; #[derive(Clone, Copy, Debug, Eq, Hash, MallocSizeOf, Parse)]
#[derive(PartialEq, ToCss)]
use style_traits::ParseError; pub enum T {
define_css_keyword_enum! { T:
% for value in keyword.values_for(product): % for value in keyword.values_for(product):
"${value}" => ${to_camel_case(value)}, ${to_camel_case(value)},
% endfor % endfor
} }
impl Parse for T {
fn parse<'i, 't>(_: &ParserContext, input: &mut Parser<'i, 't>) -> Result<Self, ParseError<'i>> {
T::parse(input)
}
}
${gecko_keyword_conversion(keyword, keyword.values_for(product), type="T", cast_to="i32")} ${gecko_keyword_conversion(keyword, keyword.values_for(product), type="T", cast_to="i32")}
} }
@ -604,25 +597,31 @@
<%def name="inner_body(keyword, extra_specified=None, needs_conversion=False)"> <%def name="inner_body(keyword, extra_specified=None, needs_conversion=False)">
% if extra_specified or keyword.aliases_for(product): % if extra_specified or keyword.aliases_for(product):
define_css_keyword_enum! { SpecifiedValue: #[cfg_attr(feature = "servo", derive(Deserialize, Serialize))]
values { #[derive(Clone, Copy, Debug, Eq, MallocSizeOf, Parse, PartialEq, ToCss)]
pub enum SpecifiedValue {
% for value in keyword.values_for(product) + (extra_specified or "").split(): % for value in keyword.values_for(product) + (extra_specified or "").split():
"${value}" => ${to_camel_case(value)}, <%
aliases = []
for alias, v in keyword.aliases_for(product).iteritems():
if value == v:
aliases.append(alias)
%>
% if aliases:
#[css(aliases = "${','.join(aliases)}")]
% endif
${to_camel_case(value)},
% endfor % endfor
} }
aliases {
% for alias, value in keyword.aliases_for(product).iteritems():
"${alias}" => ${to_camel_case(value)},
% endfor
}
}
% else: % else:
pub use self::computed_value::T as SpecifiedValue; pub use self::computed_value::T as SpecifiedValue;
% endif % endif
pub mod computed_value { pub mod computed_value {
define_css_keyword_enum! { T: #[cfg_attr(feature = "servo", derive(Deserialize, Serialize))]
#[derive(Clone, Copy, Debug, Eq, MallocSizeOf, Parse, PartialEq, ToCss)]
pub enum T {
% for value in data.longhands_by_name[name].keyword.values_for(product): % for value in data.longhands_by_name[name].keyword.values_for(product):
"${value}" => ${to_camel_case(value)}, ${to_camel_case(value)},
% endfor % endfor
} }
} }
@ -639,13 +638,6 @@
-> Result<SpecifiedValue, ParseError<'i>> { -> Result<SpecifiedValue, ParseError<'i>> {
SpecifiedValue::parse(input) SpecifiedValue::parse(input)
} }
impl Parse for SpecifiedValue {
#[inline]
fn parse<'i, 't>(_context: &ParserContext, input: &mut Parser<'i, 't>)
-> Result<SpecifiedValue, ParseError<'i>> {
SpecifiedValue::parse(input)
}
}
% if needs_conversion: % if needs_conversion:
<% <%

View file

@ -115,11 +115,14 @@ ${helpers.predefined_type("border-image-outset", "LengthOrNumberRect",
pub struct SpecifiedValue(pub RepeatKeyword, pub struct SpecifiedValue(pub RepeatKeyword,
pub Option<RepeatKeyword>); pub Option<RepeatKeyword>);
define_css_keyword_enum!(RepeatKeyword: #[cfg_attr(feature = "servo", derive(Deserialize, Serialize))]
"stretch" => Stretch, #[derive(Clone, Copy, Debug, Eq, MallocSizeOf, Parse, PartialEq, ToCss)]
"repeat" => Repeat, pub enum RepeatKeyword {
"round" => Round, Stretch,
"space" => Space); Repeat,
Round,
Space,
}
#[inline] #[inline]
pub fn get_initial_value() -> computed_value::T { pub fn get_initial_value() -> computed_value::T {

View file

@ -279,12 +279,14 @@ ${helpers.predefined_type(
} }
} }
define_css_keyword_enum!(ShapeKeyword: #[derive(Clone, Copy, Debug, Eq, MallocSizeOf, Parse, PartialEq, ToCss)]
"dot" => Dot, pub enum ShapeKeyword {
"circle" => Circle, Dot,
"double-circle" => DoubleCircle, Circle,
"triangle" => Triangle, DoubleCircle,
"sesame" => Sesame); Triangle,
Sesame,
}
impl ShapeKeyword { impl ShapeKeyword {
pub fn char(&self, fill: bool) -> &str { pub fn char(&self, fill: bool) -> &str {
@ -381,14 +383,19 @@ ${helpers.predefined_type(
<%helpers:longhand name="text-emphasis-position" animation_value_type="discrete" products="gecko" <%helpers:longhand name="text-emphasis-position" animation_value_type="discrete" products="gecko"
spec="https://drafts.csswg.org/css-text-decor/#propdef-text-emphasis-position"> spec="https://drafts.csswg.org/css-text-decor/#propdef-text-emphasis-position">
define_css_keyword_enum!(HorizontalWritingModeValue: #[derive(Clone, Copy, Debug, Eq, MallocSizeOf, Parse, PartialEq)]
"over" => Over, #[derive(ToComputedValue, ToCss)]
"under" => Under); pub enum HorizontalWritingModeValue {
add_impls_for_keyword_enum!(VerticalWritingModeValue); Over,
define_css_keyword_enum!(VerticalWritingModeValue: Under,
"right" => Right, }
"left" => Left);
add_impls_for_keyword_enum!(HorizontalWritingModeValue); #[derive(Clone, Copy, Debug, Eq, MallocSizeOf, Parse, PartialEq)]
#[derive(ToComputedValue, ToCss)]
pub enum VerticalWritingModeValue {
Right,
Left,
}
#[derive(Clone, Debug, MallocSizeOf, PartialEq, ToComputedValue, ToCss)] #[derive(Clone, Debug, MallocSizeOf, PartialEq, ToComputedValue, ToCss)]
pub struct SpecifiedValue(pub HorizontalWritingModeValue, pub VerticalWritingModeValue); pub struct SpecifiedValue(pub HorizontalWritingModeValue, pub VerticalWritingModeValue);

View file

@ -30,13 +30,16 @@ pub enum GeometryBox {
pub type FloatAreaShape<BasicShape, Image> = ShapeSource<BasicShape, ShapeBox, Image>; pub type FloatAreaShape<BasicShape, Image> = ShapeSource<BasicShape, ShapeBox, Image>;
// https://drafts.csswg.org/css-shapes-1/#typedef-shape-box // https://drafts.csswg.org/css-shapes-1/#typedef-shape-box
define_css_keyword_enum!(ShapeBox: #[allow(missing_docs)]
"margin-box" => MarginBox, #[cfg_attr(feature = "servo", derive(Deserialize, Serialize))]
"border-box" => BorderBox, #[derive(Clone, Copy, Debug, Eq, MallocSizeOf, Parse, PartialEq)]
"padding-box" => PaddingBox, #[derive(ToComputedValue, ToCss)]
"content-box" => ContentBox pub enum ShapeBox {
); MarginBox,
add_impls_for_keyword_enum!(ShapeBox); BorderBox,
PaddingBox,
ContentBox,
}
/// A shape source, for some reference box. /// A shape source, for some reference box.
#[allow(missing_docs)] #[allow(missing_docs)]
@ -117,11 +120,14 @@ pub struct Polygon<LengthOrPercentage> {
// NOTE: Basic shapes spec says that these are the only two values, however // NOTE: Basic shapes spec says that these are the only two values, however
// https://www.w3.org/TR/SVG/painting.html#FillRuleProperty // https://www.w3.org/TR/SVG/painting.html#FillRuleProperty
// says that it can also be `inherit` // says that it can also be `inherit`
define_css_keyword_enum!(FillRule: #[allow(missing_docs)]
"nonzero" => Nonzero, #[cfg_attr(feature = "servo", derive(Deserialize, Serialize))]
"evenodd" => Evenodd #[derive(Clone, Copy, Debug, Eq, MallocSizeOf, Parse, PartialEq)]
); #[derive(ToComputedValue, ToCss)]
add_impls_for_keyword_enum!(FillRule); pub enum FillRule {
Nonzero,
Evenodd,
}
// FIXME(nox): Implement ComputeSquaredDistance for T types and stop // FIXME(nox): Implement ComputeSquaredDistance for T types and stop
// using PartialEq here, this will let us derive this impl. // using PartialEq here, this will let us derive this impl.

View file

@ -140,12 +140,15 @@ impl Parse for GridLine<specified::Integer> {
} }
} }
define_css_keyword_enum!{ TrackKeyword: #[allow(missing_docs)]
"auto" => Auto, #[cfg_attr(feature = "servo", derive(Deserialize, Serialize))]
"max-content" => MaxContent, #[derive(Clone, Copy, Debug, Eq, MallocSizeOf, Parse, PartialEq)]
"min-content" => MinContent #[derive(ToComputedValue, ToCss)]
pub enum TrackKeyword {
Auto,
MaxContent,
MinContent,
} }
add_impls_for_keyword_enum!(TrackKeyword);
/// A track breadth for explicit grid track sizing. It's generic solely to /// A track breadth for explicit grid track sizing. It's generic solely to
/// avoid re-implementing it for the computed type. /// avoid re-implementing it for the computed type.

View file

@ -97,15 +97,18 @@ pub enum Ellipse<LengthOrPercentage> {
} }
/// <https://drafts.csswg.org/css-images/#typedef-extent-keyword> /// <https://drafts.csswg.org/css-images/#typedef-extent-keyword>
define_css_keyword_enum!(ShapeExtent: #[allow(missing_docs)]
"closest-side" => ClosestSide, #[cfg_attr(feature = "servo", derive(Deserialize, Serialize))]
"farthest-side" => FarthestSide, #[derive(Clone, Copy, Debug, Eq, MallocSizeOf, Parse, PartialEq)]
"closest-corner" => ClosestCorner, #[derive(ToComputedValue, ToCss)]
"farthest-corner" => FarthestCorner, pub enum ShapeExtent {
"contain" => Contain, ClosestSide,
"cover" => Cover FarthestSide,
); ClosestCorner,
add_impls_for_keyword_enum!(ShapeExtent); FarthestCorner,
Contain,
Cover,
}
/// A gradient item. /// A gradient item.
/// <https://drafts.csswg.org/css-images-4/#color-stop-syntax> /// <https://drafts.csswg.org/css-images-4/#color-stop-syntax>

View file

@ -32,14 +32,17 @@ pub mod text;
pub mod transform; pub mod transform;
// https://drafts.csswg.org/css-counter-styles/#typedef-symbols-type // https://drafts.csswg.org/css-counter-styles/#typedef-symbols-type
define_css_keyword_enum! { SymbolsType: #[allow(missing_docs)]
"cyclic" => Cyclic, #[cfg_attr(feature = "servo", derive(Deserialize, Serialize))]
"numeric" => Numeric, #[derive(Clone, Copy, Debug, Eq, MallocSizeOf, Parse, PartialEq)]
"alphabetic" => Alphabetic, #[derive(ToComputedValue, ToCss)]
"symbolic" => Symbolic, pub enum SymbolsType {
"fixed" => Fixed, Cyclic,
Numeric,
Alphabetic,
Symbolic,
Fixed,
} }
add_impls_for_keyword_enum!(SymbolsType);
#[cfg(feature = "gecko")] #[cfg(feature = "gecko")]
impl SymbolsType { impl SymbolsType {

View file

@ -98,20 +98,26 @@ pub enum TimingFunction<Integer, Number> {
Frames(Integer), Frames(Integer),
} }
define_css_keyword_enum! { TimingKeyword: #[allow(missing_docs)]
"linear" => Linear, #[cfg_attr(feature = "servo", derive(Deserialize, Serialize))]
"ease" => Ease, #[derive(Clone, Copy, Debug, Eq, MallocSizeOf, Parse, PartialEq)]
"ease-in" => EaseIn, #[derive(ToComputedValue, ToCss)]
"ease-out" => EaseOut, pub enum TimingKeyword {
"ease-in-out" => EaseInOut, Linear,
Ease,
EaseIn,
EaseOut,
EaseInOut,
} }
add_impls_for_keyword_enum!(TimingKeyword);
define_css_keyword_enum! { StepPosition: #[allow(missing_docs)]
"start" => Start, #[cfg_attr(feature = "servo", derive(Deserialize, Serialize))]
"end" => End, #[derive(Clone, Copy, Debug, Eq, MallocSizeOf, Parse, PartialEq)]
#[derive(ToComputedValue, ToCss)]
pub enum StepPosition {
Start,
End,
} }
add_impls_for_keyword_enum!(StepPosition);
impl<H, V, D> TransformOrigin<H, V, D> { impl<H, V, D> TransformOrigin<H, V, D> {
/// Returns a new transform origin. /// Returns a new transform origin.

View file

@ -195,10 +195,14 @@ impl ToCss for KeyframesName {
} }
} }
// A type for possible values for min- and max- flavors of width, /// A type for possible values for min- and max- flavors of width,
// height, block-size, and inline-size. /// height, block-size, and inline-size.
define_css_keyword_enum!(ExtremumLength: #[allow(missing_docs)]
"-moz-max-content" => MozMaxContent, #[cfg_attr(feature = "servo", derive(Deserialize, Serialize))]
"-moz-min-content" => MozMinContent, #[derive(Clone, Copy, Debug, Eq, MallocSizeOf, Parse, PartialEq, ToCss)]
"-moz-fit-content" => MozFitContent, pub enum ExtremumLength {
"-moz-available" => MozAvailable); MozMaxContent,
MozMinContent,
MozFitContent,
MozAvailable,
}

View file

@ -320,25 +320,34 @@ impl Parse for AnimationName {
} }
} }
define_css_keyword_enum! { ScrollSnapType: #[allow(missing_docs)]
"none" => None, #[cfg_attr(feature = "servo", derive(Deserialize, Serialize))]
"mandatory" => Mandatory, #[derive(Clone, Copy, Debug, Eq, MallocSizeOf, Parse, PartialEq)]
"proximity" => Proximity, #[derive(ToComputedValue, ToCss)]
pub enum ScrollSnapType {
None,
Mandatory,
Proximity,
} }
add_impls_for_keyword_enum!(ScrollSnapType);
define_css_keyword_enum! { OverscrollBehavior: #[allow(missing_docs)]
"auto" => Auto, #[cfg_attr(feature = "servo", derive(Deserialize, Serialize))]
"contain" => Contain, #[derive(Clone, Copy, Debug, Eq, MallocSizeOf, Parse, PartialEq)]
"none" => None, #[derive(ToComputedValue, ToCss)]
pub enum OverscrollBehavior {
Auto,
Contain,
None,
} }
add_impls_for_keyword_enum!(OverscrollBehavior);
define_css_keyword_enum! { OverflowClipBox: #[allow(missing_docs)]
"padding-box" => PaddingBox, #[cfg_attr(feature = "servo", derive(Deserialize, Serialize))]
"content-box" => ContentBox, #[derive(Clone, Copy, Debug, Eq, MallocSizeOf, Parse, PartialEq)]
#[derive(ToComputedValue, ToCss)]
pub enum OverflowClipBox {
PaddingBox,
ContentBox,
} }
add_impls_for_keyword_enum!(OverflowClipBox);
#[derive(Clone, Debug, MallocSizeOf, PartialEq, ToComputedValue, ToCss)] #[derive(Clone, Debug, MallocSizeOf, PartialEq, ToComputedValue, ToCss)]
/// Provides a rendering hint to the user agent, /// Provides a rendering hint to the user agent,

View file

@ -47,12 +47,13 @@ pub enum Color {
#[cfg(feature = "gecko")] #[cfg(feature = "gecko")]
mod gecko { mod gecko {
define_css_keyword_enum! { SpecialColorKeyword: #[derive(Clone, Copy, Debug, Eq, Hash, MallocSizeOf, Parse, PartialEq, ToCss)]
"-moz-default-color" => MozDefaultColor, pub enum SpecialColorKeyword {
"-moz-default-background-color" => MozDefaultBackgroundColor, MozDefaultColor,
"-moz-hyperlinktext" => MozHyperlinktext, MozDefaultBackgroundColor,
"-moz-activehyperlinktext" => MozActiveHyperlinktext, MozHyperlinktext,
"-moz-visitedhyperlinktext" => MozVisitedHyperlinktext, MozActiveHyperlinktext,
MozVisitedHyperlinktext,
} }
} }