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