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)]
94pub struct BoolInteger(pub bool);
95
96impl BoolInteger {
97 #[inline]
99 pub fn zero() -> Self {
100 Self(false)
101 }
102}
103
104impl Parse for BoolInteger {
105 fn parse<'i, 't>(
106 _context: &ParserContext,
107 input: &mut Parser<'i, 't>,
108 ) -> Result<Self, ParseError<'i>> {
109 match input.expect_integer()? {
111 0 => Ok(Self(false)),
112 1 => Ok(Self(true)),
113 _ => Err(input.new_custom_error(StyleParseErrorKind::UnspecifiedError)),
114 }
115 }
116}
117
118impl ToCss for BoolInteger {
119 fn to_css<W>(&self, dest: &mut CssWriter<W>) -> fmt::Result
120 where
121 W: Write,
122 {
123 dest.write_str(if self.0 { "1" } else { "0" })
124 }
125}
126
127pub type ScrollbarColor = generics::ScrollbarColor<Color>;
129
130impl Parse for ScrollbarColor {
131 fn parse<'i, 't>(
132 context: &ParserContext,
133 input: &mut Parser<'i, 't>,
134 ) -> Result<Self, ParseError<'i>> {
135 if input.try_parse(|i| i.expect_ident_matching("auto")).is_ok() {
136 return Ok(generics::ScrollbarColor::Auto);
137 }
138 Ok(generics::ScrollbarColor::Colors {
139 thumb: Color::parse(context, input)?,
140 track: Color::parse(context, input)?,
141 })
142 }
143}
144
145#[allow(missing_docs)]
149#[derive(
150 Clone,
151 Copy,
152 Debug,
153 Eq,
154 MallocSizeOf,
155 Parse,
156 PartialEq,
157 SpecifiedValueInfo,
158 ToComputedValue,
159 ToCss,
160 ToResolvedValue,
161 ToShmem,
162 ToTyped,
163)]
164#[repr(u8)]
165pub enum UserSelect {
166 Auto,
167 Text,
168 #[parse(aliases = "-moz-none")]
169 None,
170 All,
172}
173
174#[allow(missing_docs)]
178#[derive(
179 Clone,
180 Copy,
181 Debug,
182 Eq,
183 FromPrimitive,
184 MallocSizeOf,
185 Parse,
186 PartialEq,
187 SpecifiedValueInfo,
188 ToComputedValue,
189 ToCss,
190 ToResolvedValue,
191 ToShmem,
192)]
193#[repr(u8)]
194pub enum CursorKind {
195 None,
196 Default,
197 Pointer,
198 ContextMenu,
199 Help,
200 Progress,
201 Wait,
202 Cell,
203 Crosshair,
204 Text,
205 VerticalText,
206 Alias,
207 Copy,
208 Move,
209 NoDrop,
210 NotAllowed,
211 #[parse(aliases = "-moz-grab")]
212 Grab,
213 #[parse(aliases = "-moz-grabbing")]
214 Grabbing,
215 EResize,
216 NResize,
217 NeResize,
218 NwResize,
219 SResize,
220 SeResize,
221 SwResize,
222 WResize,
223 EwResize,
224 NsResize,
225 NeswResize,
226 NwseResize,
227 ColResize,
228 RowResize,
229 AllScroll,
230 #[parse(aliases = "-moz-zoom-in")]
231 ZoomIn,
232 #[parse(aliases = "-moz-zoom-out")]
233 ZoomOut,
234 Auto,
235}
236
237#[derive(
239 Clone,
240 Copy,
241 Debug,
242 Eq,
243 FromPrimitive,
244 MallocSizeOf,
245 Parse,
246 PartialEq,
247 SpecifiedValueInfo,
248 ToComputedValue,
249 ToCss,
250 ToResolvedValue,
251 ToShmem,
252 ToTyped,
253)]
254#[repr(u8)]
255pub enum MozTheme {
256 Auto,
258 NonNative,
260}
261
262#[allow(missing_docs)]
265#[derive(
266 Clone,
267 Copy,
268 Debug,
269 Eq,
270 FromPrimitive,
271 MallocSizeOf,
272 Parse,
273 PartialEq,
274 SpecifiedValueInfo,
275 ToComputedValue,
276 ToCss,
277 ToResolvedValue,
278 ToShmem,
279 ToTyped,
280)]
281#[repr(u8)]
282pub enum PointerEvents {
283 Auto,
284 None,
285 #[cfg(feature = "gecko")]
286 Visiblepainted,
287 #[cfg(feature = "gecko")]
288 Visiblefill,
289 #[cfg(feature = "gecko")]
290 Visiblestroke,
291 #[cfg(feature = "gecko")]
292 Visible,
293 #[cfg(feature = "gecko")]
294 Painted,
295 #[cfg(feature = "gecko")]
296 Fill,
297 #[cfg(feature = "gecko")]
298 Stroke,
299 #[cfg(feature = "gecko")]
300 All,
301}
302
303#[allow(missing_docs)]
306#[derive(
307 Clone,
308 Copy,
309 Debug,
310 Eq,
311 FromPrimitive,
312 MallocSizeOf,
313 Parse,
314 PartialEq,
315 SpecifiedValueInfo,
316 ToComputedValue,
317 ToCss,
318 ToResolvedValue,
319 ToShmem,
320 ToTyped,
321)]
322#[repr(u8)]
323pub enum Inert {
324 None,
325 Inert,
326}
327
328#[allow(missing_docs)]
331#[derive(
332 Clone,
333 Copy,
334 Debug,
335 Eq,
336 FromPrimitive,
337 MallocSizeOf,
338 Parse,
339 PartialEq,
340 SpecifiedValueInfo,
341 ToComputedValue,
342 ToCss,
343 ToResolvedValue,
344 ToShmem,
345 ToTyped,
346)]
347#[repr(u8)]
348pub enum UserFocus {
349 Normal,
350 None,
351 Ignore,
352}