1use crate::derives::*;
8use crate::parser::{Parse, ParserContext};
9use crate::values::generics::ui as generics;
10use crate::values::specified::color::Color;
11use crate::values::specified::image::Image;
12use crate::values::specified::Number;
13use cssparser::Parser;
14use std::fmt::{self, Write};
15use style_traits::{
16 CssWriter, KeywordsCollectFn, ParseError, SpecifiedValueInfo, StyleParseErrorKind, ToCss,
17};
18
19pub type Cursor = generics::GenericCursor<CursorImage>;
21
22pub type CursorImage = generics::GenericCursorImage<Image, Number>;
24
25impl Parse for Cursor {
26 fn parse<'i, 't>(
28 context: &ParserContext,
29 input: &mut Parser<'i, 't>,
30 ) -> Result<Self, ParseError<'i>> {
31 let mut images = vec![];
32 loop {
33 match input.try_parse(|input| CursorImage::parse(context, input)) {
34 Ok(image) => images.push(image),
35 Err(_) => break,
36 }
37 input.expect_comma()?;
38 }
39 Ok(Self {
40 images: images.into(),
41 keyword: CursorKind::parse(input)?,
42 })
43 }
44}
45
46impl Parse for CursorImage {
47 fn parse<'i, 't>(
48 context: &ParserContext,
49 input: &mut Parser<'i, 't>,
50 ) -> Result<Self, ParseError<'i>> {
51 use crate::Zero;
52
53 let image = Image::parse_only_url(context, input)?;
54 let mut has_hotspot = false;
55 let mut hotspot_x = Number::zero();
56 let mut hotspot_y = Number::zero();
57
58 if let Ok(x) = input.try_parse(|input| Number::parse(context, input)) {
59 has_hotspot = true;
60 hotspot_x = x;
61 hotspot_y = Number::parse(context, input)?;
62 }
63
64 Ok(Self {
65 image,
66 has_hotspot,
67 hotspot_x,
68 hotspot_y,
69 })
70 }
71}
72
73impl SpecifiedValueInfo for CursorImage {
76 fn collect_completion_keywords(f: KeywordsCollectFn) {
77 f(&["url", "image-set"]);
78 }
79}
80#[derive(
82 Clone,
83 Copy,
84 Debug,
85 MallocSizeOf,
86 PartialEq,
87 SpecifiedValueInfo,
88 ToComputedValue,
89 ToResolvedValue,
90 ToShmem,
91 ToTyped,
92)]
93#[repr(transparent)]
94#[typed(todo_derive_fields)]
95pub struct BoolInteger(pub bool);
96
97impl BoolInteger {
98 #[inline]
100 pub fn zero() -> Self {
101 Self(false)
102 }
103}
104
105impl Parse for BoolInteger {
106 fn parse<'i, 't>(
107 _context: &ParserContext,
108 input: &mut Parser<'i, 't>,
109 ) -> Result<Self, ParseError<'i>> {
110 match input.expect_integer()? {
112 0 => Ok(Self(false)),
113 1 => Ok(Self(true)),
114 _ => Err(input.new_custom_error(StyleParseErrorKind::UnspecifiedError)),
115 }
116 }
117}
118
119impl ToCss for BoolInteger {
120 fn to_css<W>(&self, dest: &mut CssWriter<W>) -> fmt::Result
121 where
122 W: Write,
123 {
124 dest.write_str(if self.0 { "1" } else { "0" })
125 }
126}
127
128pub type ScrollbarColor = generics::ScrollbarColor<Color>;
130
131impl Parse for ScrollbarColor {
132 fn parse<'i, 't>(
133 context: &ParserContext,
134 input: &mut Parser<'i, 't>,
135 ) -> Result<Self, ParseError<'i>> {
136 if input.try_parse(|i| i.expect_ident_matching("auto")).is_ok() {
137 return Ok(generics::ScrollbarColor::Auto);
138 }
139 Ok(generics::ScrollbarColor::Colors {
140 thumb: Color::parse(context, input)?,
141 track: Color::parse(context, input)?,
142 })
143 }
144}
145
146#[allow(missing_docs)]
150#[derive(
151 Clone,
152 Copy,
153 Debug,
154 Eq,
155 MallocSizeOf,
156 Parse,
157 PartialEq,
158 SpecifiedValueInfo,
159 ToComputedValue,
160 ToCss,
161 ToResolvedValue,
162 ToShmem,
163 ToTyped,
164)]
165#[repr(u8)]
166pub enum UserSelect {
167 Auto,
168 Text,
169 #[parse(aliases = "-moz-none")]
170 None,
171 All,
173}
174
175#[allow(missing_docs)]
179#[derive(
180 Clone,
181 Copy,
182 Debug,
183 Eq,
184 FromPrimitive,
185 MallocSizeOf,
186 Parse,
187 PartialEq,
188 SpecifiedValueInfo,
189 ToComputedValue,
190 ToCss,
191 ToResolvedValue,
192 ToShmem,
193 ToTyped,
194)]
195#[repr(u8)]
196pub enum CursorKind {
197 None,
198 Default,
199 Pointer,
200 ContextMenu,
201 Help,
202 Progress,
203 Wait,
204 Cell,
205 Crosshair,
206 Text,
207 VerticalText,
208 Alias,
209 Copy,
210 Move,
211 NoDrop,
212 NotAllowed,
213 #[parse(aliases = "-moz-grab")]
214 Grab,
215 #[parse(aliases = "-moz-grabbing")]
216 Grabbing,
217 EResize,
218 NResize,
219 NeResize,
220 NwResize,
221 SResize,
222 SeResize,
223 SwResize,
224 WResize,
225 EwResize,
226 NsResize,
227 NeswResize,
228 NwseResize,
229 ColResize,
230 RowResize,
231 AllScroll,
232 #[parse(aliases = "-moz-zoom-in")]
233 ZoomIn,
234 #[parse(aliases = "-moz-zoom-out")]
235 ZoomOut,
236 Auto,
237}
238
239#[derive(
241 Clone,
242 Copy,
243 Debug,
244 Eq,
245 FromPrimitive,
246 MallocSizeOf,
247 Parse,
248 PartialEq,
249 SpecifiedValueInfo,
250 ToComputedValue,
251 ToCss,
252 ToResolvedValue,
253 ToShmem,
254 ToTyped,
255)]
256#[repr(u8)]
257pub enum MozTheme {
258 Auto,
260 NonNative,
262}
263
264#[allow(missing_docs)]
267#[derive(
268 Clone,
269 Copy,
270 Debug,
271 Eq,
272 FromPrimitive,
273 MallocSizeOf,
274 Parse,
275 PartialEq,
276 SpecifiedValueInfo,
277 ToComputedValue,
278 ToCss,
279 ToResolvedValue,
280 ToShmem,
281 ToTyped,
282)]
283#[repr(u8)]
284pub enum PointerEvents {
285 Auto,
286 None,
287 #[cfg(feature = "gecko")]
288 Visiblepainted,
289 #[cfg(feature = "gecko")]
290 Visiblefill,
291 #[cfg(feature = "gecko")]
292 Visiblestroke,
293 #[cfg(feature = "gecko")]
294 Visible,
295 #[cfg(feature = "gecko")]
296 Painted,
297 #[cfg(feature = "gecko")]
298 Fill,
299 #[cfg(feature = "gecko")]
300 Stroke,
301 #[cfg(feature = "gecko")]
302 All,
303}
304
305#[allow(missing_docs)]
308#[derive(
309 Clone,
310 Copy,
311 Debug,
312 Eq,
313 FromPrimitive,
314 MallocSizeOf,
315 Parse,
316 PartialEq,
317 SpecifiedValueInfo,
318 ToComputedValue,
319 ToCss,
320 ToResolvedValue,
321 ToShmem,
322 ToTyped,
323)]
324#[repr(u8)]
325pub enum Inert {
326 None,
327 Inert,
328}
329
330#[allow(missing_docs)]
333#[derive(
334 Clone,
335 Copy,
336 Debug,
337 Eq,
338 FromPrimitive,
339 MallocSizeOf,
340 Parse,
341 PartialEq,
342 SpecifiedValueInfo,
343 ToComputedValue,
344 ToCss,
345 ToResolvedValue,
346 ToShmem,
347 ToTyped,
348)]
349#[repr(u8)]
350pub enum UserFocus {
351 Normal,
352 None,
353 Ignore,
354}