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