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