1use crate::derives::*;
8use crate::parser::{Parse, ParserContext};
9use crate::values::generics::ui as generics;
10use crate::values::specified::Number;
11use crate::values::specified::color::Color;
12use crate::values::specified::image::Image;
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(context: &ParserContext, input: &mut Parser) -> Result<Self, ParseError> {
28 let mut images = vec![];
29 loop {
30 match input.try_parse(|input| CursorImage::parse(context, input)) {
31 Ok(image) => images.push(image),
32 Err(_) => break,
33 }
34 input.expect_comma()?;
35 }
36 Ok(Self {
37 images: images.into(),
38 keyword: CursorKind::parse(input)?,
39 })
40 }
41}
42
43impl Parse for CursorImage {
44 fn parse(context: &ParserContext, input: &mut Parser) -> Result<Self, ParseError> {
45 use crate::Zero;
46
47 let image = Image::parse_only_url(context, input)?;
48 let mut has_hotspot = false;
49 let mut hotspot_x = Number::zero();
50 let mut hotspot_y = Number::zero();
51
52 if let Ok(x) = input.try_parse(|input| Number::parse(context, input)) {
53 has_hotspot = true;
54 hotspot_x = x;
55 hotspot_y = Number::parse(context, input)?;
56 }
57
58 Ok(Self {
59 image,
60 has_hotspot,
61 hotspot_x,
62 hotspot_y,
63 })
64 }
65}
66
67impl SpecifiedValueInfo for CursorImage {
70 fn collect_completion_keywords(f: KeywordsCollectFn) {
71 f(&["url", "image-set"]);
72 }
73}
74#[derive(
76 Clone,
77 Copy,
78 Debug,
79 MallocSizeOf,
80 PartialEq,
81 SpecifiedValueInfo,
82 ToComputedValue,
83 ToResolvedValue,
84 ToShmem,
85 ToTyped,
86)]
87#[repr(transparent)]
88#[typed(todo_derive_fields)]
89pub struct BoolInteger(pub bool);
90
91impl BoolInteger {
92 #[inline]
94 pub fn zero() -> Self {
95 Self(false)
96 }
97}
98
99impl Parse for BoolInteger {
100 fn parse(_context: &ParserContext, input: &mut Parser) -> Result<Self, ParseError> {
101 match input.expect_integer()? {
103 0 => Ok(Self(false)),
104 1 => Ok(Self(true)),
105 _ => Err(ParseError::custom(StyleParseErrorKind::UnspecifiedError)),
106 }
107 }
108}
109
110impl ToCss for BoolInteger {
111 fn to_css<W>(&self, dest: &mut CssWriter<W>) -> fmt::Result
112 where
113 W: Write,
114 {
115 dest.write_str(if self.0 { "1" } else { "0" })
116 }
117}
118
119pub type ScrollbarColor = generics::ScrollbarColor<Color>;
121
122impl Parse for ScrollbarColor {
123 fn parse(context: &ParserContext, input: &mut Parser) -> Result<Self, ParseError> {
124 if input.try_parse(|i| i.expect_ident_matching("auto")).is_ok() {
125 return Ok(generics::ScrollbarColor::Auto);
126 }
127 Ok(generics::ScrollbarColor::Colors {
128 thumb: Color::parse(context, input)?,
129 track: Color::parse(context, input)?,
130 })
131 }
132}
133
134#[allow(missing_docs)]
138#[derive(
139 Clone,
140 Copy,
141 Debug,
142 Eq,
143 MallocSizeOf,
144 Parse,
145 PartialEq,
146 SpecifiedValueInfo,
147 ToComputedValue,
148 ToCss,
149 ToResolvedValue,
150 ToShmem,
151 ToTyped,
152)]
153#[repr(u8)]
154pub enum UserSelect {
155 Auto,
156 Text,
157 #[parse(aliases = "-moz-none")]
158 None,
159 #[cfg(feature = "servo")]
160 Contain,
161 All,
163}
164
165#[allow(missing_docs)]
169#[derive(
170 Clone,
171 Copy,
172 Debug,
173 Eq,
174 FromPrimitive,
175 MallocSizeOf,
176 Parse,
177 PartialEq,
178 SpecifiedValueInfo,
179 ToComputedValue,
180 ToCss,
181 ToResolvedValue,
182 ToShmem,
183 ToTyped,
184)]
185#[repr(u8)]
186pub enum CursorKind {
187 None,
188 Default,
189 Pointer,
190 ContextMenu,
191 Help,
192 Progress,
193 Wait,
194 Cell,
195 Crosshair,
196 Text,
197 VerticalText,
198 Alias,
199 Copy,
200 Move,
201 NoDrop,
202 NotAllowed,
203 #[parse(aliases = "-moz-grab")]
204 Grab,
205 #[parse(aliases = "-moz-grabbing")]
206 Grabbing,
207 EResize,
208 NResize,
209 NeResize,
210 NwResize,
211 SResize,
212 SeResize,
213 SwResize,
214 WResize,
215 EwResize,
216 NsResize,
217 NeswResize,
218 NwseResize,
219 ColResize,
220 RowResize,
221 AllScroll,
222 #[parse(aliases = "-moz-zoom-in")]
223 ZoomIn,
224 #[parse(aliases = "-moz-zoom-out")]
225 ZoomOut,
226 Auto,
227}
228
229#[derive(
231 Clone,
232 Copy,
233 Debug,
234 Eq,
235 FromPrimitive,
236 MallocSizeOf,
237 Parse,
238 PartialEq,
239 SpecifiedValueInfo,
240 ToComputedValue,
241 ToCss,
242 ToResolvedValue,
243 ToShmem,
244 ToTyped,
245)]
246#[repr(u8)]
247pub enum MozTheme {
248 Auto,
250 NonNative,
252}
253
254fn svg_pointer_events_enabled(_: &ParserContext) -> bool {
255 crate::pref!("layout.css.svg-properties.enabled", gecko = true)
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 ToTyped,
276)]
277#[repr(u8)]
278pub enum PointerEvents {
279 Auto,
280 None,
281 #[parse(condition = "svg_pointer_events_enabled")]
282 Visiblepainted,
283 #[parse(condition = "svg_pointer_events_enabled")]
284 Visiblefill,
285 #[parse(condition = "svg_pointer_events_enabled")]
286 Visiblestroke,
287 #[parse(condition = "svg_pointer_events_enabled")]
288 Visible,
289 #[parse(condition = "svg_pointer_events_enabled")]
290 Painted,
291 #[parse(condition = "svg_pointer_events_enabled")]
292 Fill,
293 #[parse(condition = "svg_pointer_events_enabled")]
294 Stroke,
295 #[parse(condition = "svg_pointer_events_enabled")]
296 All,
297}
298
299#[allow(missing_docs)]
302#[derive(
303 Clone,
304 Copy,
305 Debug,
306 Eq,
307 FromPrimitive,
308 MallocSizeOf,
309 Parse,
310 PartialEq,
311 SpecifiedValueInfo,
312 ToComputedValue,
313 ToCss,
314 ToResolvedValue,
315 ToShmem,
316 ToTyped,
317)]
318#[repr(u8)]
319pub enum Inert {
320 None,
321 Inert,
322}
323
324#[allow(missing_docs)]
327#[derive(
328 Clone,
329 Copy,
330 Debug,
331 Eq,
332 FromPrimitive,
333 MallocSizeOf,
334 Parse,
335 PartialEq,
336 SpecifiedValueInfo,
337 ToComputedValue,
338 ToCss,
339 ToResolvedValue,
340 ToShmem,
341 ToTyped,
342)]
343#[repr(u8)]
344pub enum Interactivity {
345 Auto,
346 Inert,
347}
348
349#[allow(missing_docs)]
352#[derive(
353 Clone,
354 Copy,
355 Debug,
356 Eq,
357 FromPrimitive,
358 MallocSizeOf,
359 Parse,
360 PartialEq,
361 SpecifiedValueInfo,
362 ToComputedValue,
363 ToCss,
364 ToResolvedValue,
365 ToShmem,
366 ToTyped,
367)]
368#[repr(u8)]
369pub enum UserFocus {
370 Normal,
371 None,
372 Ignore,
373}
374
375#[allow(missing_docs)]
377#[derive(
378 Clone,
379 Copy,
380 Debug,
381 Deserialize,
382 Eq,
383 FromPrimitive,
384 Hash,
385 MallocSizeOf,
386 Parse,
387 PartialEq,
388 Serialize,
389 SpecifiedValueInfo,
390 ToComputedValue,
391 ToCss,
392 ToResolvedValue,
393 ToShmem,
394 ToTyped,
395)]
396#[repr(u8)]
397pub enum ImeMode {
398 Auto,
399 Normal,
400 Active,
401 Disabled,
402 Inactive,
403}
404
405#[allow(missing_docs)]
407#[derive(
408 Clone,
409 Copy,
410 Debug,
411 Deserialize,
412 Eq,
413 FromPrimitive,
414 Hash,
415 MallocSizeOf,
416 Parse,
417 PartialEq,
418 Serialize,
419 SpecifiedValueInfo,
420 ToComputedValue,
421 ToCss,
422 ToResolvedValue,
423 ToShmem,
424 ToTyped,
425)]
426#[repr(u8)]
427pub enum ScrollbarWidth {
428 Auto,
429 Thin,
430 None,
431}
432
433#[allow(missing_docs)]
435#[derive(
436 Clone,
437 Copy,
438 Debug,
439 Deserialize,
440 Eq,
441 FromPrimitive,
442 Hash,
443 MallocSizeOf,
444 Parse,
445 PartialEq,
446 Serialize,
447 SpecifiedValueInfo,
448 ToComputedValue,
449 ToCss,
450 ToResolvedValue,
451 ToShmem,
452 ToTyped,
453)]
454#[repr(u8)]
455pub enum WindowDragging {
456 Default,
457 Drag,
458 NoDrag,
459}
460
461#[allow(missing_docs)]
463#[derive(
464 Clone,
465 Copy,
466 Debug,
467 Deserialize,
468 Eq,
469 FromPrimitive,
470 Hash,
471 MallocSizeOf,
472 Parse,
473 PartialEq,
474 Serialize,
475 SpecifiedValueInfo,
476 ToComputedValue,
477 ToCss,
478 ToResolvedValue,
479 ToShmem,
480 ToTyped,
481)]
482#[repr(u8)]
483pub enum WindowShadow {
484 Auto,
485 None,
486}
487
488#[allow(missing_docs)]
490#[derive(
491 Clone,
492 Copy,
493 Debug,
494 Deserialize,
495 Eq,
496 FromPrimitive,
497 Hash,
498 MallocSizeOf,
499 Parse,
500 PartialEq,
501 Serialize,
502 SpecifiedValueInfo,
503 ToComputedValue,
504 ToCss,
505 ToResolvedValue,
506 ToShmem,
507 ToTyped,
508)]
509#[repr(u8)]
510pub enum FieldSizing {
511 Fixed,
512 Content,
513}