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