Skip to main content

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