1use crate::values::animated::ToAnimatedZero;
8use crate::values::generics::position::{GenericPosition, GenericPositionOrAuto};
9use crate::values::specified::motion::CoordBox;
10use serde::Deserializer;
11use std::fmt::{self, Write};
12use style_traits::{CssWriter, ToCss};
13
14#[allow(missing_docs)]
18#[derive(
19 Animate,
20 Clone,
21 ComputeSquaredDistance,
22 Copy,
23 Debug,
24 Deserialize,
25 MallocSizeOf,
26 Parse,
27 PartialEq,
28 Serialize,
29 SpecifiedValueInfo,
30 ToAnimatedValue,
31 ToComputedValue,
32 ToCss,
33 ToResolvedValue,
34 ToShmem,
35)]
36#[repr(u8)]
37pub enum RaySize {
38 ClosestSide,
39 ClosestCorner,
40 FarthestSide,
41 FarthestCorner,
42 Sides,
43}
44
45#[derive(
49 Animate,
50 Clone,
51 ComputeSquaredDistance,
52 Debug,
53 Deserialize,
54 MallocSizeOf,
55 PartialEq,
56 Serialize,
57 SpecifiedValueInfo,
58 ToAnimatedValue,
59 ToComputedValue,
60 ToResolvedValue,
61 ToShmem,
62)]
63#[repr(C)]
64pub struct GenericRayFunction<Angle, Position> {
65 pub angle: Angle,
68 pub size: RaySize,
71 #[animation(constant)]
74 pub contain: bool,
75 pub position: GenericPositionOrAuto<Position>,
77}
78
79pub use self::GenericRayFunction as RayFunction;
80
81impl<Angle, Position> ToCss for RayFunction<Angle, Position>
82where
83 Angle: ToCss,
84 Position: ToCss,
85{
86 fn to_css<W>(&self, dest: &mut CssWriter<W>) -> fmt::Result
87 where
88 W: Write,
89 {
90 self.angle.to_css(dest)?;
91
92 if !matches!(self.size, RaySize::ClosestSide) {
93 dest.write_char(' ')?;
94 self.size.to_css(dest)?;
95 }
96
97 if self.contain {
98 dest.write_str(" contain")?;
99 }
100
101 if !matches!(self.position, GenericPositionOrAuto::Auto) {
102 dest.write_str(" at ")?;
103 self.position.to_css(dest)?;
104 }
105
106 Ok(())
107 }
108}
109
110fn deserialize_url<'de, D, T>(_deserializer: D) -> Result<T, D::Error>
118where
119 D: Deserializer<'de>,
120{
121 use crate::serde::de::Error;
122 Err(<D as Deserializer>::Error::custom(
124 "we don't support the deserializing for url",
125 ))
126}
127
128#[derive(
133 Animate,
134 Clone,
135 ComputeSquaredDistance,
136 Debug,
137 Deserialize,
138 MallocSizeOf,
139 PartialEq,
140 Serialize,
141 SpecifiedValueInfo,
142 ToAnimatedValue,
143 ToComputedValue,
144 ToCss,
145 ToResolvedValue,
146 ToShmem,
147)]
148#[animation(no_bound(U))]
149#[repr(C, u8)]
150pub enum GenericOffsetPathFunction<Shapes, RayFunction, U> {
151 #[css(function)]
154 Ray(RayFunction),
155 #[animation(error)]
158 #[serde(deserialize_with = "deserialize_url")]
159 #[serde(skip_serializing)]
160 Url(U),
161 Shape(Shapes),
163}
164
165pub use self::GenericOffsetPathFunction as OffsetPathFunction;
166
167#[derive(
172 Animate,
173 Clone,
174 ComputeSquaredDistance,
175 Debug,
176 Deserialize,
177 MallocSizeOf,
178 PartialEq,
179 Serialize,
180 SpecifiedValueInfo,
181 ToAnimatedValue,
182 ToComputedValue,
183 ToCss,
184 ToResolvedValue,
185 ToShmem,
186 ToTyped,
187)]
188#[repr(C, u8)]
189pub enum GenericOffsetPath<Function> {
190 OffsetPath {
192 path: Box<Function>,
195 #[css(skip_if = "CoordBox::is_default")]
197 coord_box: CoordBox,
198 },
199 CoordBox(CoordBox),
203 #[animation(error)]
205 None,
206}
207
208pub use self::GenericOffsetPath as OffsetPath;
209
210impl<Function> OffsetPath<Function> {
211 #[inline]
213 pub fn none() -> Self {
214 OffsetPath::None
215 }
216}
217
218impl<Function> ToAnimatedZero for OffsetPath<Function> {
219 #[inline]
220 fn to_animated_zero(&self) -> Result<Self, ()> {
221 Err(())
222 }
223}
224
225#[derive(
230 Animate,
231 Clone,
232 ComputeSquaredDistance,
233 Copy,
234 Debug,
235 Deserialize,
236 MallocSizeOf,
237 Parse,
238 PartialEq,
239 Serialize,
240 SpecifiedValueInfo,
241 ToAnimatedValue,
242 ToAnimatedZero,
243 ToComputedValue,
244 ToCss,
245 ToResolvedValue,
246 ToShmem,
247 ToTyped,
248)]
249#[repr(C, u8)]
250pub enum GenericOffsetPosition<H, V> {
251 Normal,
253 Auto,
255 Position(
258 #[css(field_bound)]
259 #[parse(field_bound)]
260 GenericPosition<H, V>,
261 ),
262}
263
264pub use self::GenericOffsetPosition as OffsetPosition;
265
266impl<H, V> OffsetPosition<H, V> {
267 #[inline]
269 pub fn normal() -> Self {
270 Self::Normal
271 }
272}