1use crate::derives::*;
8use crate::parser::{Parse, ParserContext};
9use cssparser::Parser;
10use style_traits::ParseError;
11
12#[derive(
14 Animate,
15 Clone,
16 ComputeSquaredDistance,
17 Debug,
18 MallocSizeOf,
19 PartialEq,
20 Parse,
21 SpecifiedValueInfo,
22 ToAnimatedValue,
23 ToAnimatedZero,
24 ToComputedValue,
25 ToCss,
26 ToResolvedValue,
27 ToShmem,
28)]
29#[repr(C, u8)]
30pub enum GenericSVGPaintFallback<C> {
31 None,
33 #[css(skip)]
36 Unset,
37 Color(C),
39}
40
41pub use self::GenericSVGPaintFallback as SVGPaintFallback;
42
43#[derive(
47 Animate,
48 Clone,
49 ComputeSquaredDistance,
50 Debug,
51 MallocSizeOf,
52 PartialEq,
53 SpecifiedValueInfo,
54 ToAnimatedValue,
55 ToAnimatedZero,
56 ToComputedValue,
57 ToCss,
58 ToResolvedValue,
59 ToShmem,
60 ToTyped,
61)]
62#[animation(no_bound(Url))]
63#[repr(C)]
64pub struct GenericSVGPaint<Color, Url> {
65 pub kind: GenericSVGPaintKind<Color, Url>,
67 pub fallback: GenericSVGPaintFallback<Color>,
69}
70
71pub use self::GenericSVGPaint as SVGPaint;
72
73impl<C, U> Default for SVGPaint<C, U> {
74 fn default() -> Self {
75 Self {
76 kind: SVGPaintKind::None,
77 fallback: SVGPaintFallback::Unset,
78 }
79 }
80}
81
82#[derive(
87 Animate,
88 Clone,
89 ComputeSquaredDistance,
90 Debug,
91 MallocSizeOf,
92 PartialEq,
93 Parse,
94 SpecifiedValueInfo,
95 ToAnimatedValue,
96 ToAnimatedZero,
97 ToComputedValue,
98 ToCss,
99 ToResolvedValue,
100 ToShmem,
101)]
102#[animation(no_bound(U))]
103#[repr(C, u8)]
104pub enum GenericSVGPaintKind<C, U> {
105 #[animation(error)]
107 None,
108 Color(C),
110 #[animation(error)]
112 PaintServer(U),
113 ContextFill,
115 ContextStroke,
117}
118
119pub use self::GenericSVGPaintKind as SVGPaintKind;
120
121impl<C: Parse, U: Parse> Parse for SVGPaint<C, U> {
122 fn parse<'i, 't>(
123 context: &ParserContext,
124 input: &mut Parser<'i, 't>,
125 ) -> Result<Self, ParseError<'i>> {
126 let kind = SVGPaintKind::parse(context, input)?;
127 if matches!(kind, SVGPaintKind::None | SVGPaintKind::Color(..)) {
128 return Ok(SVGPaint {
129 kind,
130 fallback: SVGPaintFallback::Unset,
131 });
132 }
133 let fallback = input
134 .try_parse(|i| SVGPaintFallback::parse(context, i))
135 .unwrap_or(SVGPaintFallback::Unset);
136 Ok(SVGPaint { kind, fallback })
137 }
138}
139
140#[derive(
142 Animate,
143 Clone,
144 ComputeSquaredDistance,
145 Copy,
146 Debug,
147 MallocSizeOf,
148 PartialEq,
149 SpecifiedValueInfo,
150 ToAnimatedValue,
151 ToAnimatedZero,
152 ToComputedValue,
153 ToCss,
154 ToResolvedValue,
155 ToShmem,
156 ToTyped,
157)]
158#[repr(C, u8)]
159pub enum GenericSVGLength<L> {
160 LengthPercentage(L),
162 #[animation(error)]
164 ContextValue,
165}
166
167pub use self::GenericSVGLength as SVGLength;
168
169#[derive(
171 Clone,
172 Debug,
173 MallocSizeOf,
174 PartialEq,
175 SpecifiedValueInfo,
176 ToAnimatedValue,
177 ToAnimatedZero,
178 ToComputedValue,
179 ToCss,
180 ToResolvedValue,
181 ToShmem,
182 ToTyped,
183)]
184#[repr(C, u8)]
185pub enum GenericSVGStrokeDashArray<L> {
186 #[css(comma)]
188 Values(#[css(if_empty = "none", iterable)] crate::OwnedSlice<L>),
189 ContextValue,
191}
192
193pub use self::GenericSVGStrokeDashArray as SVGStrokeDashArray;
194
195#[derive(
198 Animate,
199 Clone,
200 ComputeSquaredDistance,
201 Copy,
202 Debug,
203 MallocSizeOf,
204 PartialEq,
205 Parse,
206 SpecifiedValueInfo,
207 ToAnimatedValue,
208 ToAnimatedZero,
209 ToComputedValue,
210 ToCss,
211 ToResolvedValue,
212 ToShmem,
213 ToTyped,
214)]
215#[repr(C, u8)]
216pub enum GenericSVGOpacity<OpacityType> {
217 Opacity(OpacityType),
219 #[animation(error)]
221 ContextFillOpacity,
222 #[animation(error)]
224 ContextStrokeOpacity,
225}
226
227pub use self::GenericSVGOpacity as SVGOpacity;