Skip to content

Commit

Permalink
style: Add some attributes for SpecifiedValueInfo to help deriving mo…
Browse files Browse the repository at this point in the history
…re from types.

Bug: 1434130
Reviewed-by: emilio
MozReview-Commit-ID: IyohSTbUO31
  • Loading branch information
upsuper authored and emilio committed Apr 29, 2018
1 parent 0021c70 commit 0f7f9ee
Show file tree
Hide file tree
Showing 17 changed files with 137 additions and 36 deletions.
4 changes: 4 additions & 0 deletions components/style/values/generics/basic_shape.rs
Expand Up @@ -69,6 +69,7 @@ pub enum BasicShape<H, V, LengthOrPercentage> {

/// <https://drafts.csswg.org/css-shapes/#funcdef-inset>
#[allow(missing_docs)]
#[css(function = "inset")]
#[derive(Animate, Clone, ComputeSquaredDistance, Debug, MallocSizeOf, PartialEq,
SpecifiedValueInfo, ToComputedValue)]
pub struct InsetRect<LengthOrPercentage> {
Expand All @@ -78,6 +79,7 @@ pub struct InsetRect<LengthOrPercentage> {

/// <https://drafts.csswg.org/css-shapes/#funcdef-circle>
#[allow(missing_docs)]
#[css(function)]
#[derive(Animate, Clone, ComputeSquaredDistance, Copy, Debug, MallocSizeOf,
PartialEq, SpecifiedValueInfo, ToComputedValue)]
pub struct Circle<H, V, LengthOrPercentage> {
Expand All @@ -87,6 +89,7 @@ pub struct Circle<H, V, LengthOrPercentage> {

/// <https://drafts.csswg.org/css-shapes/#funcdef-ellipse>
#[allow(missing_docs)]
#[css(function)]
#[derive(Animate, Clone, ComputeSquaredDistance, Copy, Debug, MallocSizeOf,
PartialEq, SpecifiedValueInfo, ToComputedValue)]
pub struct Ellipse<H, V, LengthOrPercentage> {
Expand All @@ -110,6 +113,7 @@ pub enum ShapeRadius<LengthOrPercentage> {
/// A generic type for representing the `polygon()` function
///
/// <https://drafts.csswg.org/css-shapes/#funcdef-polygon>
#[css(function)]
#[derive(Clone, Debug, MallocSizeOf, PartialEq, SpecifiedValueInfo,
ToComputedValue)]
pub struct Polygon<LengthOrPercentage> {
Expand Down
1 change: 1 addition & 0 deletions components/style/values/generics/border.rs
Expand Up @@ -28,6 +28,7 @@ pub struct BorderImageSlice<NumberOrPercentage> {
/// The offsets.
pub offsets: Rect<NumberOrPercentage>,
/// Whether to fill the middle part.
#[value_info(represents_keyword)]
pub fill: bool,
}

Expand Down
2 changes: 1 addition & 1 deletion components/style/values/generics/counters.rs
Expand Up @@ -59,7 +59,7 @@ impl<I> Deref for CounterReset<I> {
/// Keyword `none` is represented by an empty vector.
#[derive(Clone, Debug, MallocSizeOf, PartialEq, SpecifiedValueInfo,
ToComputedValue)]
pub struct Counters<I>(Box<[(CustomIdent, I)]>);
pub struct Counters<I>(#[css(if_empty = "none")] Box<[(CustomIdent, I)]>);

impl<I> Default for Counters<I> {
#[inline]
Expand Down
1 change: 1 addition & 0 deletions components/style/values/generics/effects.rs
Expand Up @@ -19,6 +19,7 @@ pub struct BoxShadow<Color, SizeLength, BlurShapeLength, ShapeLength> {
pub spread: ShapeLength,
/// Whether this is an inset box shadow.
#[animation(constant)]
#[value_info(represents_keyword)]
pub inset: bool,
}

Expand Down
10 changes: 6 additions & 4 deletions components/style/values/generics/grid.rs
Expand Up @@ -198,10 +198,12 @@ pub enum TrackSize<L> {
/// and a flexible `<track-breadth>`
///
/// <https://drafts.csswg.org/css-grid/#valdef-grid-template-columns-minmax>
#[css(function)]
Minmax(TrackBreadth<L>, TrackBreadth<L>),
/// A `fit-content` function.
///
/// <https://drafts.csswg.org/css-grid/#valdef-grid-template-columns-fit-content>
#[css(function)]
FitContent(L),
}

Expand Down Expand Up @@ -346,8 +348,7 @@ where
/// The initial argument of the `repeat` function.
///
/// <https://drafts.csswg.org/css-grid/#typedef-track-repeat>
#[derive(Clone, Copy, Debug, MallocSizeOf, PartialEq, SpecifiedValueInfo,
ToComputedValue, ToCss)]
#[derive(Clone, Copy, Debug, MallocSizeOf, PartialEq, ToComputedValue, ToCss)]
pub enum RepeatCount<Integer> {
/// A positive integer. This is allowed only for `<track-repeat>` and `<fixed-repeat>`
Number(Integer),
Expand Down Expand Up @@ -384,6 +385,7 @@ impl Parse for RepeatCount<specified::Integer> {
/// values in its computed form.
#[derive(Clone, Debug, MallocSizeOf, PartialEq, SpecifiedValueInfo,
ToComputedValue)]
#[css(function = "repeat")]
pub struct TrackRepeat<L, I> {
/// The number of times for the value to be repeated (could also be `auto-fit` or `auto-fill`)
pub count: RepeatCount<I>,
Expand Down Expand Up @@ -481,8 +483,7 @@ pub enum TrackListValue<LengthOrPercentage, Integer> {
/// The type of a `<track-list>` as determined during parsing.
///
/// <https://drafts.csswg.org/css-grid/#typedef-track-list>
#[derive(Clone, Copy, Debug, MallocSizeOf, PartialEq, SpecifiedValueInfo,
ToComputedValue)]
#[derive(Clone, Copy, Debug, MallocSizeOf, PartialEq, ToComputedValue)]
pub enum TrackListType {
/// [`<auto-track-list>`](https://drafts.csswg.org/css-grid/#typedef-auto-track-list)
///
Expand Down Expand Up @@ -510,6 +511,7 @@ pub struct TrackList<LengthOrPercentage, Integer> {
///
/// In order to avoid parsing the same value multiple times, this does a single traversal
/// and arrives at the type of value it has parsed (or bails out gracefully with an error).
#[css(skip)]
pub list_type: TrackListType,
/// A vector of `<track-size> | <track-repeat>` values.
pub values: Vec<TrackListValue<LengthOrPercentage, Integer>>,
Expand Down
1 change: 1 addition & 0 deletions components/style/values/generics/image.rs
Expand Up @@ -26,6 +26,7 @@ pub enum Image<Gradient, MozImageRect, ImageUrl> {
/// A `-moz-image-rect` image. Also fairly large and rare.
Rect(Box<MozImageRect>),
/// A `-moz-element(# <element-id>)`
#[css(function = "-moz-element")]
Element(Atom),
/// A paint worklet image.
/// <https://drafts.css-houdini.org/css-paint-api/>
Expand Down
8 changes: 6 additions & 2 deletions components/style/values/generics/transform.rs
Expand Up @@ -80,7 +80,9 @@ pub struct TransformOrigin<H, V, Depth> {
/// A generic timing function.
///
/// <https://drafts.csswg.org/css-timing-1/#single-timing-function-production>
#[derive(Clone, Copy, Debug, MallocSizeOf, PartialEq, ToCss)]
#[derive(Clone, Copy, Debug, MallocSizeOf, PartialEq, SpecifiedValueInfo,
ToCss)]
#[value_info(ty = "TIMING_FUNCTION")]
pub enum TimingFunction<Integer, Number> {
/// `linear | ease | ease-in | ease-out | ease-in-out`
Keyword(TimingKeyword),
Expand All @@ -95,6 +97,7 @@ pub enum TimingFunction<Integer, Number> {
},
/// `step-start | step-end | steps(<integer>, [ start | end ]?)`
#[css(comma, function)]
#[value_info(other_values = "step-start,step-end")]
Steps(Integer, #[css(skip_if = "is_end")] StepPosition),
/// `frames(<integer>)`
#[css(comma, function)]
Expand All @@ -103,7 +106,8 @@ pub enum TimingFunction<Integer, Number> {

#[allow(missing_docs)]
#[cfg_attr(feature = "servo", derive(Deserialize, Serialize))]
#[derive(Clone, Copy, Debug, Eq, MallocSizeOf, Parse, PartialEq, ToComputedValue, ToCss)]
#[derive(Clone, Copy, Debug, Eq, MallocSizeOf, Parse, PartialEq,
SpecifiedValueInfo, ToComputedValue, ToCss)]
pub enum TimingKeyword {
Linear,
Ease,
Expand Down
13 changes: 6 additions & 7 deletions components/style/values/specified/box.rs
Expand Up @@ -9,7 +9,7 @@ use cssparser::Parser;
use parser::{Parse, ParserContext};
use selectors::parser::SelectorParseErrorKind;
use std::fmt::{self, Write};
use style_traits::{CssWriter, ParseError, SpecifiedValueInfo, StyleParseErrorKind, ToCss};
use style_traits::{CssWriter, ParseError, StyleParseErrorKind, ToCss};
use values::{CustomIdent, KeyframesName};
use values::generics::box_::AnimationIterationCount as GenericAnimationIterationCount;
use values::generics::box_::Perspective as GenericPerspective;
Expand Down Expand Up @@ -298,6 +298,7 @@ impl AnimationIterationCount {
/// A value for the `animation-name` property.
#[derive(Clone, Debug, Eq, Hash, MallocSizeOf, PartialEq, SpecifiedValueInfo,
ToComputedValue)]
#[value_info(other_values = "none")]
pub struct AnimationName(pub Option<KeyframesName>);

impl AnimationName {
Expand Down Expand Up @@ -420,8 +421,9 @@ impl Parse for WillChange {

bitflags! {
#[cfg_attr(feature = "gecko", derive(MallocSizeOf))]
#[derive(ToComputedValue)]
#[derive(SpecifiedValueInfo, ToComputedValue)]
/// These constants match Gecko's `NS_STYLE_TOUCH_ACTION_*` constants.
#[value_info(other_values = "auto,none,manipulation,pan-x,pan-y")]
pub struct TouchAction: u8 {
/// `none` variant
const TOUCH_ACTION_NONE = 1 << 0;
Expand Down Expand Up @@ -493,8 +495,6 @@ impl Parse for TouchAction {
}
}

impl SpecifiedValueInfo for TouchAction {}

#[cfg(feature = "gecko")]
impl_bitflags_conversions!(TouchAction);

Expand Down Expand Up @@ -522,7 +522,8 @@ pub fn assert_touch_action_matches() {
}

bitflags! {
#[derive(MallocSizeOf, ToComputedValue)]
#[derive(MallocSizeOf, ToComputedValue, SpecifiedValueInfo)]
#[value_info(other_values = "none,strict,layout,style,paint")]
/// Constants for contain: https://drafts.csswg.org/css-contain/#contain-property
pub struct Contain: u8 {
/// `layout` variant, turns on layout containment
Expand Down Expand Up @@ -605,8 +606,6 @@ impl Parse for Contain {
}
}

impl SpecifiedValueInfo for Contain {}

/// A specified value for the `perspective` property.
pub type Perspective = GenericPerspective<NonNegativeLength>;

Expand Down
2 changes: 2 additions & 0 deletions components/style/values/specified/font.rs
Expand Up @@ -1945,9 +1945,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)]
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)]
pub style: bool,
}

Expand Down
1 change: 1 addition & 0 deletions components/style/values/specified/inherited_box.rs
Expand Up @@ -21,6 +21,7 @@ pub struct ImageOrientation {
pub angle: Option<Angle>,

/// Whether or not "flip" was specified
#[value_info(other_values = "flip,from-image")]
pub flipped: bool,
}

Expand Down
3 changes: 2 additions & 1 deletion components/style/values/specified/list.rs
Expand Up @@ -78,9 +78,10 @@ impl Parse for ListStyleType {
///
/// FIXME(emilio): It's a shame that this allocates all the time it's computed,
/// probably should just be refcounted.
/// FIXME This can probably derive ToCss.
#[derive(Clone, Debug, MallocSizeOf, PartialEq, SpecifiedValueInfo,
ToComputedValue)]
pub struct Quotes(pub Box<[(Box<str>, Box<str>)]>);
pub struct Quotes(#[css(if_empty = "none")] pub Box<[(Box<str>, Box<str>)]>);

impl ToCss for Quotes {
fn to_css<W>(&self, dest: &mut CssWriter<W>) -> fmt::Result
Expand Down
7 changes: 4 additions & 3 deletions components/style/values/specified/mod.rs
Expand Up @@ -570,6 +570,7 @@ pub type GridTemplateComponent = GenericGridTemplateComponent<LengthOrPercentage

#[derive(Clone, Debug, MallocSizeOf, PartialEq, SpecifiedValueInfo)]
/// rect(<top>, <left>, <bottom>, <right>) used by clip and image-region
#[css(function = "rect")]
pub struct ClipRect {
/// <top> (<length> | <auto>)
pub top: Option<Length>,
Expand Down Expand Up @@ -757,7 +758,9 @@ impl AllowQuirks {
/// An attr(...) rule
///
/// `[namespace? `|`]? ident`
#[derive(Clone, Debug, Eq, MallocSizeOf, PartialEq, ToComputedValue)]
#[derive(Clone, Debug, Eq, MallocSizeOf, PartialEq, SpecifiedValueInfo,
ToComputedValue)]
#[css(function)]
pub struct Attr {
/// Optional namespace prefix and URL.
pub namespace: Option<(Prefix, Namespace)>,
Expand Down Expand Up @@ -852,5 +855,3 @@ impl ToCss for Attr {
dest.write_str(")")
}
}

impl SpecifiedValueInfo for Attr {}
1 change: 1 addition & 0 deletions components/style/values/specified/position.rs
Expand Up @@ -431,6 +431,7 @@ 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)]
pub dense: bool,
}

Expand Down
6 changes: 1 addition & 5 deletions components/style/values/specified/transform.rs
Expand Up @@ -7,7 +7,7 @@
use cssparser::Parser;
use parser::{Parse, ParserContext};
use selectors::parser::SelectorParseErrorKind;
use style_traits::{CssType, ParseError, SpecifiedValueInfo, StyleParseErrorKind};
use style_traits::{ParseError, StyleParseErrorKind};
use values::computed::{Context, LengthOrPercentage as ComputedLengthOrPercentage};
use values::computed::{Percentage as ComputedPercentage, ToComputedValue};
use values::computed::transform::TimingFunction as ComputedTimingFunction;
Expand Down Expand Up @@ -246,10 +246,6 @@ pub enum OriginComponent<S> {
/// A specified timing function.
pub type TimingFunction = generic::TimingFunction<Integer, Number>;

impl SpecifiedValueInfo for TimingFunction {
const SUPPORTED_TYPES: u8 = CssType::TIMING_FUNCTION;
}

impl Parse for TransformOrigin {
fn parse<'i, 't>(
context: &ParserContext,
Expand Down
2 changes: 1 addition & 1 deletion components/style_derive/lib.rs
Expand Up @@ -64,7 +64,7 @@ pub fn derive_to_css(stream: TokenStream) -> TokenStream {
to_css::derive(input).into()
}

#[proc_macro_derive(SpecifiedValueInfo, attributes(css))]
#[proc_macro_derive(SpecifiedValueInfo, attributes(css, value_info))]
pub fn derive_specified_value_info(stream: TokenStream) -> TokenStream {
let input = syn::parse(stream).unwrap();
specified_value_info::derive(input).into()
Expand Down

0 comments on commit 0f7f9ee

Please sign in to comment.