aboutsummaryrefslogtreecommitdiffstats
path: root/components/util/cursor.rs
blob: 23ca2c0af4aeb3bea85b0912e6742204530ffab7 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
/* This Source Code Form is subject to the terms of the Mozilla Public
 * License, v. 2.0. If a copy of the MPL was not distributed with this
 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */

//! A list of common mouse cursors per CSS3-UI § 8.1.1.

use cssparser::ToCss;
use std::ascii::AsciiExt;
use text_writer::TextWriter;


macro_rules! define_cursor {
    ($( $css: expr => $variant: ident = $value: expr, )+) => {
        #[deriving(Clone, Copy, PartialEq, Eq, FromPrimitive, Show)]
        #[repr(u8)]
        pub enum Cursor {
            $( $variant = $value ),+
        }

        impl Cursor {
            pub fn from_css_keyword(keyword: &str) -> Result<Cursor, ()> {
                match_ignore_ascii_case! { keyword:
                    $( concat!($css) => Ok(Cursor::$variant) ),+
                    _ => Err(())
                }
            }
        }

        impl ToCss for Cursor {
            fn to_css<W>(&self, dest: &mut W) -> ::text_writer::Result where W: TextWriter {
                match self {
                    $( &Cursor::$variant => dest.write_str($css) ),+
                }
            }
        }
    }
}


define_cursor! {
    "none" => NoCursor = 0,
    "default" => DefaultCursor = 1,
    "pointer" => PointerCursor = 2,
    "context-menu" => ContextMenuCursor = 3,
    "help" => HelpCursor = 4,
    "progress" => ProgressCursor = 5,
    "wait" => WaitCursor = 6,
    "cell" => CellCursor = 7,
    "crosshair" => CrosshairCursor = 8,
    "text" => TextCursor = 9,
    "vertical-text" => VerticalTextCursor = 10,
    "alias" => AliasCursor = 11,
    "copy" => CopyCursor = 12,
    "move" => MoveCursor = 13,
    "no-drop" => NoDropCursor = 14,
    "not-allowed" => NotAllowedCursor = 15,
    "grab" => GrabCursor = 16,
    "grabbing" => GrabbingCursor = 17,
    "e-resize" => EResizeCursor = 18,
    "n-resize" => NResizeCursor = 19,
    "ne-resize" => NeResizeCursor = 20,
    "nw-resize" => NwResizeCursor = 21,
    "s-resize" => SResizeCursor = 22,
    "se-resize" => SeResizeCursor = 23,
    "sw-resize" => SwResizeCursor = 24,
    "w-resize" => WResizeCursor = 25,
    "ew-resize" => EwResizeCursor = 26,
    "ns-resize" => NsResizeCursor = 27,
    "nesw-resize" => NeswResizeCursor = 28,
    "nwse-resize" => NwseResizeCursor = 29,
    "col-resize" => ColResizeCursor = 30,
    "row-resize" => RowResizeCursor = 31,
    "all-scroll" => AllScrollCursor = 32,
    "zoom-in" => ZoomInCursor = 33,
    "zoom-out" => ZoomOutCursor = 34,
}