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