style/values/generics/
effects.rs

1/* This Source Code Form is subject to the terms of the Mozilla Public
2 * License, v. 2.0. If a copy of the MPL was not distributed with this
3 * file, You can obtain one at https://mozilla.org/MPL/2.0/. */
4
5//! Generic types for CSS values related to effects.
6
7use crate::values::generics::{NonNegative, ZeroToOne};
8
9/// A generic value for a single `box-shadow`.
10#[derive(
11    Animate,
12    Clone,
13    ComputeSquaredDistance,
14    Debug,
15    MallocSizeOf,
16    PartialEq,
17    SpecifiedValueInfo,
18    ToAnimatedValue,
19    ToAnimatedZero,
20    ToCss,
21    ToResolvedValue,
22    ToShmem,
23)]
24#[repr(C)]
25pub struct GenericBoxShadow<Color, SizeLength, BlurShapeLength, ShapeLength> {
26    /// The base shadow.
27    pub base: GenericSimpleShadow<Color, SizeLength, BlurShapeLength>,
28    /// The spread radius.
29    pub spread: ShapeLength,
30    /// Whether this is an inset box shadow.
31    #[animation(constant)]
32    #[css(represents_keyword)]
33    pub inset: bool,
34}
35
36pub use self::GenericBoxShadow as BoxShadow;
37
38/// A generic value for a single `filter`.
39#[cfg_attr(feature = "servo", derive(Deserialize, Serialize))]
40#[derive(
41    Clone,
42    ComputeSquaredDistance,
43    Debug,
44    MallocSizeOf,
45    PartialEq,
46    SpecifiedValueInfo,
47    ToAnimatedValue,
48    ToComputedValue,
49    ToCss,
50    ToResolvedValue,
51    ToShmem,
52)]
53#[animation(no_bound(U))]
54#[repr(C, u8)]
55pub enum GenericFilter<Angle, Factor, Length, Shadow, U> {
56    /// `blur(<length>)`
57    #[css(function)]
58    Blur(#[animation(field_bound)] NonNegative<Length>),
59    /// `brightness(<factor>)`
60    #[css(function)]
61    Brightness(#[animation(field_bound)] NonNegative<Factor>),
62    /// `contrast(<factor>)`
63    #[css(function)]
64    Contrast(#[animation(field_bound)] NonNegative<Factor>),
65    /// `grayscale(<factor>)`
66    #[css(function)]
67    Grayscale(#[animation(field_bound)] ZeroToOne<Factor>),
68    /// `hue-rotate(<angle>)`
69    #[css(function)]
70    HueRotate(Angle),
71    /// `invert(<factor>)`
72    #[css(function)]
73    Invert(#[animation(field_bound)] ZeroToOne<Factor>),
74    /// `opacity(<factor>)`
75    #[css(function)]
76    Opacity(#[animation(field_bound)] ZeroToOne<Factor>),
77    /// `saturate(<factor>)`
78    #[css(function)]
79    Saturate(#[animation(field_bound)] NonNegative<Factor>),
80    /// `sepia(<factor>)`
81    #[css(function)]
82    Sepia(#[animation(field_bound)] ZeroToOne<Factor>),
83    /// `drop-shadow(...)`
84    #[css(function)]
85    DropShadow(Shadow),
86    /// `<url>`
87    #[animation(error)]
88    Url(U),
89}
90
91pub use self::GenericFilter as Filter;
92
93/// A generic value for the `drop-shadow()` filter and the `text-shadow` property.
94///
95/// Contrary to the canonical order from the spec, the color is serialised
96/// first, like in Gecko and Webkit.
97#[derive(
98    Animate,
99    Clone,
100    ComputeSquaredDistance,
101    Debug,
102    MallocSizeOf,
103    PartialEq,
104    SpecifiedValueInfo,
105    ToAnimatedValue,
106    ToAnimatedZero,
107    ToCss,
108    ToResolvedValue,
109    ToShmem,
110)]
111#[repr(C)]
112pub struct GenericSimpleShadow<Color, SizeLength, ShapeLength> {
113    /// Color.
114    pub color: Color,
115    /// Horizontal radius.
116    pub horizontal: SizeLength,
117    /// Vertical radius.
118    pub vertical: SizeLength,
119    /// Blur radius.
120    pub blur: ShapeLength,
121}
122
123pub use self::GenericSimpleShadow as SimpleShadow;