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)]
187#[repr(C, u8)]
188pub enum GenericOffsetPath<Function> {
189 OffsetPath {
191 path: Box<Function>,
194 #[css(skip_if = "CoordBox::is_default")]
196 coord_box: CoordBox,
197 },
198 CoordBox(CoordBox),
202 #[animation(error)]
204 None,
205}
206
207pub use self::GenericOffsetPath as OffsetPath;
208
209impl<Function> OffsetPath<Function> {
210 #[inline]
212 pub fn none() -> Self {
213 OffsetPath::None
214 }
215}
216
217impl<Function> ToAnimatedZero for OffsetPath<Function> {
218 #[inline]
219 fn to_animated_zero(&self) -> Result<Self, ()> {
220 Err(())
221 }
222}
223
224#[derive(
229 Animate,
230 Clone,
231 ComputeSquaredDistance,
232 Copy,
233 Debug,
234 Deserialize,
235 MallocSizeOf,
236 Parse,
237 PartialEq,
238 Serialize,
239 SpecifiedValueInfo,
240 ToAnimatedValue,
241 ToAnimatedZero,
242 ToComputedValue,
243 ToCss,
244 ToResolvedValue,
245 ToShmem,
246)]
247#[repr(C, u8)]
248pub enum GenericOffsetPosition<H, V> {
249 Normal,
251 Auto,
253 Position(
256 #[css(field_bound)]
257 #[parse(field_bound)]
258 GenericPosition<H, V>,
259 ),
260}
261
262pub use self::GenericOffsetPosition as OffsetPosition;
263
264impl<H, V> OffsetPosition<H, V> {
265 #[inline]
267 pub fn normal() -> Self {
268 Self::Normal
269 }
270}