Derive ToCss for cursor keywords

This commit is contained in:
Anthony Ramine 2017-06-07 21:08:35 +02:00
parent c8c6f3482f
commit d55d726a21
3 changed files with 14 additions and 21 deletions

View file

@ -2853,8 +2853,8 @@ impl ServoComputedValuesCursorUtility for ServoComputedValues {
fn get_cursor(&self, default_cursor: Cursor) -> Option<Cursor> {
match (self.get_pointing().pointer_events, self.get_pointing().cursor) {
(pointer_events::T::none, _) => None,
(pointer_events::T::auto, cursor::Keyword::AutoCursor) => Some(default_cursor),
(pointer_events::T::auto, cursor::Keyword::SpecifiedCursor(cursor)) => Some(cursor),
(pointer_events::T::auto, cursor::Keyword::Auto) => Some(default_cursor),
(pointer_events::T::auto, cursor::Keyword::Cursor(cursor)) => Some(cursor),
}
}
}

View file

@ -4191,8 +4191,8 @@ clip-path
use style_traits::cursor::Cursor;
self.gecko.mCursor = match v.keyword {
Keyword::AutoCursor => structs::NS_STYLE_CURSOR_AUTO,
Keyword::SpecifiedCursor(cursor) => match cursor {
Keyword::Auto => structs::NS_STYLE_CURSOR_AUTO,
Keyword::Cursor(cursor) => match cursor {
Cursor::None => structs::NS_STYLE_CURSOR_NONE,
Cursor::Default => structs::NS_STYLE_CURSOR_DEFAULT,
Cursor::Pointer => structs::NS_STYLE_CURSOR_POINTER,

View file

@ -17,17 +17,19 @@
no_viewport_percentage!(SpecifiedValue);
pub mod computed_value {
#[cfg(feature = "gecko")]
use std::fmt;
use style_traits::cursor::Cursor;
#[cfg(feature = "gecko")]
use style_traits::ToCss;
use style_traits::cursor::Cursor;
#[cfg(feature = "gecko")]
use values::specified::url::SpecifiedUrl;
#[derive(Clone, PartialEq, Copy, Debug)]
#[cfg_attr(feature = "servo", derive(HeapSizeOf))]
#[derive(Clone, Copy, Debug, PartialEq, ToCss)]
pub enum Keyword {
AutoCursor,
SpecifiedCursor(Cursor),
Auto,
Cursor(Cursor),
}
#[cfg(not(feature = "gecko"))]
@ -47,15 +49,6 @@
pub keyword: Keyword,
}
impl ToCss for Keyword {
fn to_css<W>(&self, dest: &mut W) -> fmt::Result where W: fmt::Write {
match *self {
Keyword::AutoCursor => dest.write_str("auto"),
Keyword::SpecifiedCursor(c) => c.to_css(dest),
}
}
}
#[cfg(feature = "gecko")]
impl ToCss for Image {
fn to_css<W>(&self, dest: &mut W) -> fmt::Result where W: fmt::Write {
@ -85,7 +78,7 @@
#[cfg(not(feature = "gecko"))]
#[inline]
pub fn get_initial_value() -> computed_value::T {
computed_value::Keyword::AutoCursor
computed_value::Keyword::Auto
}
#[cfg(feature = "gecko")]
@ -93,7 +86,7 @@
pub fn get_initial_value() -> computed_value::T {
computed_value::T {
images: vec![],
keyword: computed_value::Keyword::AutoCursor
keyword: computed_value::Keyword::Auto
}
}
@ -103,9 +96,9 @@
use style_traits::cursor::Cursor;
let ident = try!(input.expect_ident());
if ident.eq_ignore_ascii_case("auto") {
Ok(computed_value::Keyword::AutoCursor)
Ok(computed_value::Keyword::Auto)
} else {
Cursor::from_css_keyword(&ident).map(computed_value::Keyword::SpecifiedCursor)
Cursor::from_css_keyword(&ident).map(computed_value::Keyword::Cursor)
}
}
}