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