mirror of
https://github.com/servo/servo.git
synced 2025-08-04 13:10:20 +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
|
@ -159,40 +159,21 @@ pub mod longhands {
|
||||||
|
|
||||||
<%def name="single_keyword_computed(name, values, experimental=False)">
|
<%def name="single_keyword_computed(name, values, experimental=False)">
|
||||||
<%self:single_component_value name="${name}" experimental="${experimental}">
|
<%self:single_component_value name="${name}" experimental="${experimental}">
|
||||||
|
pub use self::computed_value::T as SpecifiedValue;
|
||||||
${caller.body()}
|
${caller.body()}
|
||||||
pub mod computed_value {
|
pub mod computed_value {
|
||||||
use std::fmt;
|
define_css_keyword_enum! { T:
|
||||||
#[allow(non_camel_case_types)]
|
|
||||||
#[deriving(PartialEq, Clone, FromPrimitive)]
|
|
||||||
pub enum T {
|
|
||||||
% for value in values.split():
|
% for value in values.split():
|
||||||
${to_rust_ident(value)},
|
"${value}" => ${to_rust_ident(value)},
|
||||||
% endfor
|
|
||||||
}
|
|
||||||
impl fmt::Show for T {
|
|
||||||
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
|
||||||
match self {
|
|
||||||
% for value in values.split():
|
|
||||||
&T::${to_rust_ident(value)} => write!(f, "${value}"),
|
|
||||||
% endfor
|
% endfor
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
}
|
|
||||||
pub type SpecifiedValue = computed_value::T;
|
|
||||||
#[inline] pub fn get_initial_value() -> computed_value::T {
|
#[inline] pub fn get_initial_value() -> computed_value::T {
|
||||||
T::${to_rust_ident(values.split()[0])}
|
T::${to_rust_ident(values.split()[0])}
|
||||||
}
|
}
|
||||||
pub fn from_component_value(v: &ComponentValue, _base_url: &Url)
|
pub fn from_component_value(v: &ComponentValue, _base_url: &Url)
|
||||||
-> Result<SpecifiedValue, ()> {
|
-> Result<SpecifiedValue, ()> {
|
||||||
get_ident_lower(v).and_then(|keyword| {
|
computed_value::T::parse(v)
|
||||||
match keyword.as_slice() {
|
|
||||||
% for value in values.split():
|
|
||||||
"${value}" => Ok(T::${to_rust_ident(value)}),
|
|
||||||
% endfor
|
|
||||||
_ => Err(()),
|
|
||||||
}
|
|
||||||
})
|
|
||||||
}
|
}
|
||||||
</%self:single_component_value>
|
</%self:single_component_value>
|
||||||
</%def>
|
</%def>
|
||||||
|
@ -1550,111 +1531,13 @@ pub mod longhands {
|
||||||
pub fn from_component_value(value: &ComponentValue, _: &Url)
|
pub fn from_component_value(value: &ComponentValue, _: &Url)
|
||||||
-> Result<SpecifiedValue,()> {
|
-> Result<SpecifiedValue,()> {
|
||||||
match value {
|
match value {
|
||||||
&Ident(ref value) if value.eq_ignore_ascii_case("auto") => Ok(T::AutoCursor),
|
&Ident(ref ident) => {
|
||||||
&Ident(ref value) if value.eq_ignore_ascii_case("none") => {
|
if ident.eq_ignore_ascii_case("auto") {
|
||||||
Ok(T::SpecifiedCursor(util_cursor::NoCursor))
|
Ok(T::AutoCursor)
|
||||||
|
} else {
|
||||||
|
util_cursor::Cursor::from_css_keyword(ident.as_slice())
|
||||||
|
.map(T::SpecifiedCursor)
|
||||||
}
|
}
|
||||||
&Ident(ref value) if value.eq_ignore_ascii_case("default") => {
|
|
||||||
Ok(T::SpecifiedCursor(util_cursor::DefaultCursor))
|
|
||||||
}
|
|
||||||
&Ident(ref value) if value.eq_ignore_ascii_case("pointer") => {
|
|
||||||
Ok(T::SpecifiedCursor(util_cursor::PointerCursor))
|
|
||||||
}
|
|
||||||
&Ident(ref value) if value.eq_ignore_ascii_case("context-menu") => {
|
|
||||||
Ok(T::SpecifiedCursor(util_cursor::ContextMenuCursor))
|
|
||||||
}
|
|
||||||
&Ident(ref value) if value.eq_ignore_ascii_case("help") => {
|
|
||||||
Ok(T::SpecifiedCursor(util_cursor::HelpCursor))
|
|
||||||
}
|
|
||||||
&Ident(ref value) if value.eq_ignore_ascii_case("progress") => {
|
|
||||||
Ok(T::SpecifiedCursor(util_cursor::ProgressCursor))
|
|
||||||
}
|
|
||||||
&Ident(ref value) if value.eq_ignore_ascii_case("wait") => {
|
|
||||||
Ok(T::SpecifiedCursor(util_cursor::WaitCursor))
|
|
||||||
}
|
|
||||||
&Ident(ref value) if value.eq_ignore_ascii_case("cell") => {
|
|
||||||
Ok(T::SpecifiedCursor(util_cursor::CellCursor))
|
|
||||||
}
|
|
||||||
&Ident(ref value) if value.eq_ignore_ascii_case("crosshair") => {
|
|
||||||
Ok(T::SpecifiedCursor(util_cursor::CrosshairCursor))
|
|
||||||
}
|
|
||||||
&Ident(ref value) if value.eq_ignore_ascii_case("text") => {
|
|
||||||
Ok(T::SpecifiedCursor(util_cursor::TextCursor))
|
|
||||||
}
|
|
||||||
&Ident(ref value) if value.eq_ignore_ascii_case("vertical-text") => {
|
|
||||||
Ok(T::SpecifiedCursor(util_cursor::VerticalTextCursor))
|
|
||||||
}
|
|
||||||
&Ident(ref value) if value.eq_ignore_ascii_case("alias") => {
|
|
||||||
Ok(T::SpecifiedCursor(util_cursor::AliasCursor))
|
|
||||||
}
|
|
||||||
&Ident(ref value) if value.eq_ignore_ascii_case("copy") => {
|
|
||||||
Ok(T::SpecifiedCursor(util_cursor::CopyCursor))
|
|
||||||
}
|
|
||||||
&Ident(ref value) if value.eq_ignore_ascii_case("move") => {
|
|
||||||
Ok(T::SpecifiedCursor(util_cursor::MoveCursor))
|
|
||||||
}
|
|
||||||
&Ident(ref value) if value.eq_ignore_ascii_case("no-drop") => {
|
|
||||||
Ok(T::SpecifiedCursor(util_cursor::NoDropCursor))
|
|
||||||
}
|
|
||||||
&Ident(ref value) if value.eq_ignore_ascii_case("not-allowed") => {
|
|
||||||
Ok(T::SpecifiedCursor(util_cursor::NotAllowedCursor))
|
|
||||||
}
|
|
||||||
&Ident(ref value) if value.eq_ignore_ascii_case("grab") => {
|
|
||||||
Ok(T::SpecifiedCursor(util_cursor::GrabCursor))
|
|
||||||
}
|
|
||||||
&Ident(ref value) if value.eq_ignore_ascii_case("grabbing") => {
|
|
||||||
Ok(T::SpecifiedCursor(util_cursor::GrabbingCursor))
|
|
||||||
}
|
|
||||||
&Ident(ref value) if value.eq_ignore_ascii_case("e-resize") => {
|
|
||||||
Ok(T::SpecifiedCursor(util_cursor::EResizeCursor))
|
|
||||||
}
|
|
||||||
&Ident(ref value) if value.eq_ignore_ascii_case("n-resize") => {
|
|
||||||
Ok(T::SpecifiedCursor(util_cursor::NResizeCursor))
|
|
||||||
}
|
|
||||||
&Ident(ref value) if value.eq_ignore_ascii_case("ne-resize") => {
|
|
||||||
Ok(T::SpecifiedCursor(util_cursor::NeResizeCursor))
|
|
||||||
}
|
|
||||||
&Ident(ref value) if value.eq_ignore_ascii_case("nw-resize") => {
|
|
||||||
Ok(T::SpecifiedCursor(util_cursor::NwResizeCursor))
|
|
||||||
}
|
|
||||||
&Ident(ref value) if value.eq_ignore_ascii_case("s-resize") => {
|
|
||||||
Ok(T::SpecifiedCursor(util_cursor::SResizeCursor))
|
|
||||||
}
|
|
||||||
&Ident(ref value) if value.eq_ignore_ascii_case("se-resize") => {
|
|
||||||
Ok(T::SpecifiedCursor(util_cursor::SeResizeCursor))
|
|
||||||
}
|
|
||||||
&Ident(ref value) if value.eq_ignore_ascii_case("sw-resize") => {
|
|
||||||
Ok(T::SpecifiedCursor(util_cursor::SwResizeCursor))
|
|
||||||
}
|
|
||||||
&Ident(ref value) if value.eq_ignore_ascii_case("w-resize") => {
|
|
||||||
Ok(T::SpecifiedCursor(util_cursor::WResizeCursor))
|
|
||||||
}
|
|
||||||
&Ident(ref value) if value.eq_ignore_ascii_case("ew-resize") => {
|
|
||||||
Ok(T::SpecifiedCursor(util_cursor::EwResizeCursor))
|
|
||||||
}
|
|
||||||
&Ident(ref value) if value.eq_ignore_ascii_case("ns-resize") => {
|
|
||||||
Ok(T::SpecifiedCursor(util_cursor::NsResizeCursor))
|
|
||||||
}
|
|
||||||
&Ident(ref value) if value.eq_ignore_ascii_case("nesw-resize") => {
|
|
||||||
Ok(T::SpecifiedCursor(util_cursor::NeswResizeCursor))
|
|
||||||
}
|
|
||||||
&Ident(ref value) if value.eq_ignore_ascii_case("nwse-resize") => {
|
|
||||||
Ok(T::SpecifiedCursor(util_cursor::NwseResizeCursor))
|
|
||||||
}
|
|
||||||
&Ident(ref value) if value.eq_ignore_ascii_case("col-resize") => {
|
|
||||||
Ok(T::SpecifiedCursor(util_cursor::ColResizeCursor))
|
|
||||||
}
|
|
||||||
&Ident(ref value) if value.eq_ignore_ascii_case("row-resize") => {
|
|
||||||
Ok(T::SpecifiedCursor(util_cursor::RowResizeCursor))
|
|
||||||
}
|
|
||||||
&Ident(ref value) if value.eq_ignore_ascii_case("all-scroll") => {
|
|
||||||
Ok(T::SpecifiedCursor(util_cursor::AllScrollCursor))
|
|
||||||
}
|
|
||||||
&Ident(ref value) if value.eq_ignore_ascii_case("zoom-in") => {
|
|
||||||
Ok(T::SpecifiedCursor(util_cursor::ZoomInCursor))
|
|
||||||
}
|
|
||||||
&Ident(ref value) if value.eq_ignore_ascii_case("zoom-out") => {
|
|
||||||
Ok(T::SpecifiedCursor(util_cursor::ZoomOutCursor))
|
|
||||||
}
|
}
|
||||||
_ => Err(())
|
_ => Err(())
|
||||||
}
|
}
|
||||||
|
|
|
@ -4,43 +4,73 @@
|
||||||
|
|
||||||
//! A list of common mouse cursors per CSS3-UI § 8.1.1.
|
//! A list of common mouse cursors per CSS3-UI § 8.1.1.
|
||||||
|
|
||||||
#[deriving(Clone, PartialEq, FromPrimitive, Show)]
|
use cssparser::ToCss;
|
||||||
#[repr(u8)]
|
use std::ascii::AsciiExt;
|
||||||
pub enum Cursor {
|
use text_writer::TextWriter;
|
||||||
NoCursor = 0,
|
|
||||||
DefaultCursor = 1,
|
|
||||||
PointerCursor = 2,
|
macro_rules! define_cursor {
|
||||||
ContextMenuCursor = 3,
|
($( $css: expr => $variant: ident = $value: expr, )+) => {
|
||||||
HelpCursor = 4,
|
#[deriving(Clone, PartialEq, Eq, FromPrimitive, Show)]
|
||||||
ProgressCursor = 5,
|
#[repr(u8)]
|
||||||
WaitCursor = 6,
|
pub enum Cursor {
|
||||||
CellCursor = 7,
|
$( $variant = $value ),+
|
||||||
CrosshairCursor = 8,
|
}
|
||||||
TextCursor = 9,
|
|
||||||
VerticalTextCursor = 10,
|
impl Cursor {
|
||||||
AliasCursor = 11,
|
pub fn from_css_keyword(keyword: &str) -> Result<Cursor, ()> {
|
||||||
CopyCursor = 12,
|
match keyword.to_ascii_lower().as_slice() {
|
||||||
MoveCursor = 13,
|
$( concat!($css) => Ok(Cursor::$variant), )+
|
||||||
NoDropCursor = 14,
|
_ => Err(())
|
||||||
NotAllowedCursor = 15,
|
}
|
||||||
GrabCursor = 16,
|
}
|
||||||
GrabbingCursor = 17,
|
}
|
||||||
EResizeCursor = 18,
|
|
||||||
NResizeCursor = 19,
|
impl ToCss for Cursor {
|
||||||
NeResizeCursor = 20,
|
fn to_css<W>(&self, dest: &mut W) -> ::text_writer::Result where W: TextWriter {
|
||||||
NwResizeCursor = 21,
|
match self {
|
||||||
SResizeCursor = 22,
|
$( &Cursor::$variant => dest.write_str($css) ),+
|
||||||
SeResizeCursor = 23,
|
}
|
||||||
SwResizeCursor = 24,
|
}
|
||||||
WResizeCursor = 25,
|
}
|
||||||
EwResizeCursor = 26,
|
}
|
||||||
NsResizeCursor = 27,
|
|
||||||
NeswResizeCursor = 28,
|
|
||||||
NwseResizeCursor = 29,
|
|
||||||
ColResizeCursor = 30,
|
|
||||||
RowResizeCursor = 31,
|
|
||||||
AllScrollCursor = 32,
|
|
||||||
ZoomInCursor = 33,
|
|
||||||
ZoomOutCursor = 34,
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
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,
|
||||||
|
}
|
||||||
|
|
|
@ -26,6 +26,7 @@ extern crate sync;
|
||||||
#[cfg(target_os="macos")]
|
#[cfg(target_os="macos")]
|
||||||
extern crate task_info;
|
extern crate task_info;
|
||||||
extern crate "time" as std_time;
|
extern crate "time" as std_time;
|
||||||
|
extern crate text_writer;
|
||||||
extern crate string_cache;
|
extern crate string_cache;
|
||||||
extern crate unicode;
|
extern crate unicode;
|
||||||
extern crate url;
|
extern crate url;
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue