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)]
64#[typed(todo_derive_fields)]
65pub struct GenericSVGPaint<Color, Url> {
66 pub kind: GenericSVGPaintKind<Color, Url>,
68 pub fallback: GenericSVGPaintFallback<Color>,
70}
71
72pub use self::GenericSVGPaint as SVGPaint;
73
74impl<C, U> Default for SVGPaint<C, U> {
75 fn default() -> Self {
76 Self {
77 kind: SVGPaintKind::None,
78 fallback: SVGPaintFallback::Unset,
79 }
80 }
81}
82
83#[derive(
88 Animate,
89 Clone,
90 ComputeSquaredDistance,
91 Debug,
92 MallocSizeOf,
93 PartialEq,
94 Parse,
95 SpecifiedValueInfo,
96 ToAnimatedValue,
97 ToAnimatedZero,
98 ToComputedValue,
99 ToCss,
100 ToResolvedValue,
101 ToShmem,
102)]
103#[animation(no_bound(U))]
104#[repr(C, u8)]
105pub enum GenericSVGPaintKind<C, U> {
106 #[animation(error)]
108 None,
109 Color(C),
111 #[animation(error)]
113 PaintServer(U),
114 ContextFill,
116 ContextStroke,
118}
119
120pub use self::GenericSVGPaintKind as SVGPaintKind;
121
122impl<C: Parse, U: Parse> Parse for SVGPaint<C, U> {
123 fn parse<'i, 't>(
124 context: &ParserContext,
125 input: &mut Parser<'i, 't>,
126 ) -> Result<Self, ParseError<'i>> {
127 let kind = SVGPaintKind::parse(context, input)?;
128 if matches!(kind, SVGPaintKind::None | SVGPaintKind::Color(..)) {
129 return Ok(SVGPaint {
130 kind,
131 fallback: SVGPaintFallback::Unset,
132 });
133 }
134 let fallback = input
135 .try_parse(|i| SVGPaintFallback::parse(context, i))
136 .unwrap_or(SVGPaintFallback::Unset);
137 Ok(SVGPaint { kind, fallback })
138 }
139}
140
141#[derive(
143 Animate,
144 Clone,
145 ComputeSquaredDistance,
146 Copy,
147 Debug,
148 MallocSizeOf,
149 PartialEq,
150 SpecifiedValueInfo,
151 ToAnimatedValue,
152 ToAnimatedZero,
153 ToComputedValue,
154 ToCss,
155 ToResolvedValue,
156 ToShmem,
157 ToTyped,
158)]
159#[repr(C, u8)]
160pub enum GenericSVGLength<L> {
161 LengthPercentage(L),
163 #[animation(error)]
165 ContextValue,
166}
167
168pub use self::GenericSVGLength as SVGLength;
169
170#[derive(
172 Clone,
173 Debug,
174 MallocSizeOf,
175 PartialEq,
176 SpecifiedValueInfo,
177 ToAnimatedValue,
178 ToAnimatedZero,
179 ToComputedValue,
180 ToCss,
181 ToResolvedValue,
182 ToShmem,
183 ToTyped,
184)]
185#[repr(C, u8)]
186pub enum GenericSVGStrokeDashArray<L> {
187 #[css(comma)]
189 #[typed(no_multiple_values)]
190 Values(#[css(if_empty = "none", iterable)] crate::OwnedSlice<L>),
191 ContextValue,
193}
194
195pub use self::GenericSVGStrokeDashArray as SVGStrokeDashArray;
196
197#[derive(
200 Animate,
201 Clone,
202 ComputeSquaredDistance,
203 Copy,
204 Debug,
205 MallocSizeOf,
206 PartialEq,
207 Parse,
208 SpecifiedValueInfo,
209 ToAnimatedValue,
210 ToAnimatedZero,
211 ToComputedValue,
212 ToCss,
213 ToResolvedValue,
214 ToShmem,
215 ToTyped,
216)]
217#[repr(C, u8)]
218pub enum GenericSVGOpacity<OpacityType> {
219 Opacity(OpacityType),
221 #[animation(error)]
223 ContextFillOpacity,
224 #[animation(error)]
226 ContextStrokeOpacity,
227}
228
229pub use self::GenericSVGOpacity as SVGOpacity;