diff options
author | Emilio Cobos Álvarez <emilio@crisal.io> | 2018-04-29 04:48:47 +0200 |
---|---|---|
committer | Emilio Cobos Álvarez <emilio@crisal.io> | 2018-05-05 16:20:22 +0200 |
commit | c508d8576dafb13a4f0d51a837508f7984e4c1a8 (patch) | |
tree | c6d6a2b1c135dbfda7f11ea6599b53b9f086bfae | |
parent | a375baf84b029c56222d3fe8a304f374ab1c9549 (diff) | |
download | servo-c508d8576dafb13a4f0d51a837508f7984e4c1a8.tar.gz servo-c508d8576dafb13a4f0d51a837508f7984e4c1a8.zip |
style: Move represents_keyword to the css attributes.
Bug: 1457635
Reviewed-by: xidorn
MozReview-Commit-ID: 21yuU4h34AQ
-rw-r--r-- | components/style/values/generics/border.rs | 21 | ||||
-rw-r--r-- | components/style/values/generics/effects.rs | 30 | ||||
-rw-r--r-- | components/style/values/specified/font.rs | 4 | ||||
-rw-r--r-- | components/style/values/specified/position.rs | 18 | ||||
-rw-r--r-- | components/style_derive/specified_value_info.rs | 5 | ||||
-rw-r--r-- | components/style_derive/to_css.rs | 10 | ||||
-rw-r--r-- | components/style_traits/specified_value_info.rs | 2 | ||||
-rw-r--r-- | components/style_traits/values.rs | 3 |
8 files changed, 24 insertions, 69 deletions
diff --git a/components/style/values/generics/border.rs b/components/style/values/generics/border.rs index 6230a1cf36a..c25560ed0f1 100644 --- a/components/style/values/generics/border.rs +++ b/components/style/values/generics/border.rs @@ -23,12 +23,13 @@ pub enum BorderImageSideWidth<LengthOrPercentage, Number> { /// A generic value for the `border-image-slice` property. #[derive(Clone, Copy, Debug, MallocSizeOf, PartialEq, SpecifiedValueInfo, - ToComputedValue)] + ToComputedValue, ToCss)] pub struct BorderImageSlice<NumberOrPercentage> { /// The offsets. + #[css(field_bound)] pub offsets: Rect<NumberOrPercentage>, /// Whether to fill the middle part. - #[value_info(represents_keyword)] + #[css(represents_keyword)] pub fill: bool, } @@ -86,22 +87,6 @@ where } } -impl<N> ToCss for BorderImageSlice<N> -where - N: PartialEq + ToCss, -{ - fn to_css<W>(&self, dest: &mut CssWriter<W>) -> fmt::Result - where - W: Write, - { - self.offsets.to_css(dest)?; - if self.fill { - dest.write_str(" fill")?; - } - Ok(()) - } -} - impl<L> BorderRadius<L> { /// Returns a new `BorderRadius<L>`. #[inline] diff --git a/components/style/values/generics/effects.rs b/components/style/values/generics/effects.rs index 7a76cdeb7bc..e5ee10fcada 100644 --- a/components/style/values/generics/effects.rs +++ b/components/style/values/generics/effects.rs @@ -4,14 +4,12 @@ //! Generic types for CSS values related to effects. -use std::fmt::{self, Write}; -use style_traits::values::{CssWriter, SequenceWriter, ToCss}; #[cfg(feature = "gecko")] use values::specified::url::SpecifiedUrl; /// A generic value for a single `box-shadow`. #[derive(Animate, Clone, Debug, MallocSizeOf, PartialEq, SpecifiedValueInfo, - ToAnimatedValue, ToAnimatedZero)] + ToAnimatedValue, ToAnimatedZero, ToCss)] pub struct BoxShadow<Color, SizeLength, BlurShapeLength, ShapeLength> { /// The base shadow. pub base: SimpleShadow<Color, SizeLength, BlurShapeLength>, @@ -19,7 +17,7 @@ pub struct BoxShadow<Color, SizeLength, BlurShapeLength, ShapeLength> { pub spread: ShapeLength, /// Whether this is an inset box shadow. #[animation(constant)] - #[value_info(represents_keyword)] + #[css(represents_keyword)] pub inset: bool, } @@ -80,27 +78,3 @@ pub struct SimpleShadow<Color, SizeLength, ShapeLength> { /// Blur radius. pub blur: ShapeLength, } - -impl<Color, SizeLength, BlurShapeLength, ShapeLength> ToCss - for BoxShadow<Color, SizeLength, BlurShapeLength, ShapeLength> -where - Color: ToCss, - SizeLength: ToCss, - BlurShapeLength: ToCss, - ShapeLength: ToCss, -{ - fn to_css<W>(&self, dest: &mut CssWriter<W>) -> fmt::Result - where - W: Write, - { - { - let mut writer = SequenceWriter::new(&mut *dest, " "); - writer.item(&self.base)?; - writer.item(&self.spread)?; - } - if self.inset { - dest.write_str(" inset")?; - } - Ok(()) - } -} diff --git a/components/style/values/specified/font.rs b/components/style/values/specified/font.rs index 8ec4354ab7a..266d7c52c09 100644 --- a/components/style/values/specified/font.rs +++ b/components/style/values/specified/font.rs @@ -1947,11 +1947,11 @@ pub struct FontSynthesis { /// If a `font-weight` is requested that the font family does not contain, /// the user agent may synthesize the requested weight from the weights /// that do exist in the font family. - #[value_info(represents_keyword)] + #[css(represents_keyword)] pub weight: bool, /// If a font-style is requested that the font family does not contain, /// the user agent may synthesize the requested style from the normal face in the font family. - #[value_info(represents_keyword)] + #[css(represents_keyword)] pub style: bool, } diff --git a/components/style/values/specified/position.rs b/components/style/values/specified/position.rs index 0f2669f0a02..17a5db17bcb 100644 --- a/components/style/values/specified/position.rs +++ b/components/style/values/specified/position.rs @@ -424,14 +424,14 @@ pub enum AutoFlow { } #[derive(Clone, Copy, Debug, Eq, MallocSizeOf, PartialEq, SpecifiedValueInfo, - ToComputedValue)] + ToComputedValue, ToCss)] /// Controls how the auto-placement algorithm works /// specifying exactly how auto-placed items get flowed into the grid pub struct GridAutoFlow { /// Specifiy how auto-placement algorithm fills each `row` or `column` in turn pub autoflow: AutoFlow, /// Specify use `dense` packing algorithm or not - #[value_info(represents_keyword)] + #[css(represents_keyword)] pub dense: bool, } @@ -446,20 +446,6 @@ impl GridAutoFlow { } } -impl ToCss for GridAutoFlow { - fn to_css<W>(&self, dest: &mut CssWriter<W>) -> fmt::Result - where - W: Write, - { - self.autoflow.to_css(dest)?; - - if self.dense { - dest.write_str(" dense")?; - } - Ok(()) - } -} - impl Parse for GridAutoFlow { /// [ row | column ] || dense fn parse<'i, 't>( diff --git a/components/style_derive/specified_value_info.rs b/components/style_derive/specified_value_info.rs index 11ad7a0d1b4..7aae081641d 100644 --- a/components/style_derive/specified_value_info.rs +++ b/components/style_derive/specified_value_info.rs @@ -140,13 +140,13 @@ fn derive_struct_fields<'a>( values.push(value.to_string()); } } - if info_attrs.represents_keyword { + let css_attrs = cg::parse_field_attrs::<CssFieldAttrs>(field); + if css_attrs.represents_keyword { let ident = field.ident.as_ref() .expect("only named field should use represents_keyword"); values.push(cg::to_css_identifier(ident.as_ref())); return None; } - let css_attrs = cg::parse_field_attrs::<CssFieldAttrs>(field); if let Some(if_empty) = css_attrs.if_empty { values.push(if_empty); } @@ -176,6 +176,5 @@ struct ValueInfoVariantAttrs { #[darling(attributes(value_info), default)] #[derive(Default, FromField)] struct ValueInfoFieldAttrs { - represents_keyword: bool, other_values: Option<String>, } diff --git a/components/style_derive/to_css.rs b/components/style_derive/to_css.rs index 722107da0cd..7ac7d3a1ae7 100644 --- a/components/style_derive/to_css.rs +++ b/components/style_derive/to_css.rs @@ -189,6 +189,15 @@ fn derive_single_field_expr( writer.item(&item)?; } } + } else if attrs.represents_keyword { + let ident = + field.ast().ident.as_ref().expect("Unnamed field with represents_keyword?"); + let ident = cg::to_css_identifier(ident.as_ref()); + quote! { + if *#field { + writer.raw_item(#ident)?; + } + } } else { if attrs.field_bound { let ty = &field.ast().ty; @@ -236,5 +245,6 @@ pub struct CssFieldAttrs { pub field_bound: bool, pub iterable: bool, pub skip: bool, + pub represents_keyword: bool, pub skip_if: Option<Path>, } diff --git a/components/style_traits/specified_value_info.rs b/components/style_traits/specified_value_info.rs index 28e1eef25e6..d9f4578b1a8 100644 --- a/components/style_traits/specified_value_info.rs +++ b/components/style_traits/specified_value_info.rs @@ -56,8 +56,6 @@ pub type KeywordsCollectFn<'a> = &'a mut FnMut(&[&'static str]); /// * `#[value_info(starts_with_keyword)]` can be used on variants to /// add the name of a non-unit variant (serialized like `ToCss`) into /// `collect_completion_keywords`. -/// * `#[value_info(represents_keyword)]` can be used on fields into -/// `collect_completion_keywords`. pub trait SpecifiedValueInfo { /// Supported CssTypes by the given value type. /// diff --git a/components/style_traits/values.rs b/components/style_traits/values.rs index 481eb1aff6d..9a618067fd7 100644 --- a/components/style_traits/values.rs +++ b/components/style_traits/values.rs @@ -37,6 +37,9 @@ use std::fmt::{self, Write}; /// * if `#[css(skip_if = "function")]` is found on a field, the `ToCss` call /// for that field is skipped if `function` returns true. This function is /// provided the field as an argument; +/// * `#[css(represents_keyword)]` can be used on bool fields in order to +/// serialize the field name if the field is true, or nothing otherwise. It +/// also collects those keywords for `SpecifiedValueInfo`. /// * finally, one can put `#[css(derive_debug)]` on the whole type, to /// implement `Debug` by a single call to `ToCss::to_css`. pub trait ToCss { |