mirror of
https://github.com/servo/servo.git
synced 2025-08-05 05:30:08 +01:00
Implement ToCss for Cursor and de-duplicate variants and string values.
This commit is contained in:
parent
45a08c94a4
commit
8be85c5e6b
3 changed files with 80 additions and 166 deletions
|
@ -4,43 +4,73 @@
|
|||
|
||||
//! A list of common mouse cursors per CSS3-UI § 8.1.1.
|
||||
|
||||
#[deriving(Clone, PartialEq, FromPrimitive, Show)]
|
||||
#[repr(u8)]
|
||||
pub enum Cursor {
|
||||
NoCursor = 0,
|
||||
DefaultCursor = 1,
|
||||
PointerCursor = 2,
|
||||
ContextMenuCursor = 3,
|
||||
HelpCursor = 4,
|
||||
ProgressCursor = 5,
|
||||
WaitCursor = 6,
|
||||
CellCursor = 7,
|
||||
CrosshairCursor = 8,
|
||||
TextCursor = 9,
|
||||
VerticalTextCursor = 10,
|
||||
AliasCursor = 11,
|
||||
CopyCursor = 12,
|
||||
MoveCursor = 13,
|
||||
NoDropCursor = 14,
|
||||
NotAllowedCursor = 15,
|
||||
GrabCursor = 16,
|
||||
GrabbingCursor = 17,
|
||||
EResizeCursor = 18,
|
||||
NResizeCursor = 19,
|
||||
NeResizeCursor = 20,
|
||||
NwResizeCursor = 21,
|
||||
SResizeCursor = 22,
|
||||
SeResizeCursor = 23,
|
||||
SwResizeCursor = 24,
|
||||
WResizeCursor = 25,
|
||||
EwResizeCursor = 26,
|
||||
NsResizeCursor = 27,
|
||||
NeswResizeCursor = 28,
|
||||
NwseResizeCursor = 29,
|
||||
ColResizeCursor = 30,
|
||||
RowResizeCursor = 31,
|
||||
AllScrollCursor = 32,
|
||||
ZoomInCursor = 33,
|
||||
ZoomOutCursor = 34,
|
||||
use cssparser::ToCss;
|
||||
use std::ascii::AsciiExt;
|
||||
use text_writer::TextWriter;
|
||||
|
||||
|
||||
macro_rules! define_cursor {
|
||||
($( $css: expr => $variant: ident = $value: expr, )+) => {
|
||||
#[deriving(Clone, PartialEq, Eq, FromPrimitive, Show)]
|
||||
#[repr(u8)]
|
||||
pub enum Cursor {
|
||||
$( $variant = $value ),+
|
||||
}
|
||||
|
||||
impl Cursor {
|
||||
pub fn from_css_keyword(keyword: &str) -> Result<Cursor, ()> {
|
||||
match keyword.to_ascii_lower().as_slice() {
|
||||
$( 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,
|
||||
"defalut" => 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,
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue