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