Skip to content

Commit

Permalink
make cursor animatable
Browse files Browse the repository at this point in the history
  • Loading branch information
dadaa committed Jul 20, 2017
1 parent e8b11d2 commit f01ad20
Show file tree
Hide file tree
Showing 2 changed files with 77 additions and 1 deletion.
76 changes: 76 additions & 0 deletions components/style/properties/gecko.mako.rs
Expand Up @@ -4669,6 +4669,17 @@ clip-path
// background-image to a url() value, since only properties in reset structs
// are re-used from the applicable declaration cache, and the Pointing struct
// is an inherited struct.

match v.images[i].hotspot {
Some((x, y)) => {
self.gecko.mCursorImages[i].mHaveHotspot = true;
self.gecko.mCursorImages[i].mHotspotX = x;
self.gecko.mCursorImages[i].mHotspotY = y;
},
_ => {
self.gecko.mCursorImages[i].mHaveHotspot = false;
}
}
}
}

Expand All @@ -4679,6 +4690,71 @@ clip-path
}
}

pub fn clone_cursor(&self) -> longhands::cursor::computed_value::T {
use properties::longhands::cursor::computed_value::{Keyword, Image};
use style_traits::cursor::Cursor;
use values::specified::url::SpecifiedUrl;

let keyword = match self.gecko.mCursor as u32 {
structs::NS_STYLE_CURSOR_AUTO => Keyword::Auto,
structs::NS_STYLE_CURSOR_NONE => Keyword::Cursor(Cursor::None),
structs::NS_STYLE_CURSOR_DEFAULT => Keyword::Cursor(Cursor::Default),
structs::NS_STYLE_CURSOR_POINTER => Keyword::Cursor(Cursor::Pointer),
structs::NS_STYLE_CURSOR_CONTEXT_MENU => Keyword::Cursor(Cursor::ContextMenu),
structs::NS_STYLE_CURSOR_HELP => Keyword::Cursor(Cursor::Help),
structs::NS_STYLE_CURSOR_SPINNING => Keyword::Cursor(Cursor::Progress),
structs::NS_STYLE_CURSOR_WAIT => Keyword::Cursor(Cursor::Wait),
structs::NS_STYLE_CURSOR_CELL => Keyword::Cursor(Cursor::Cell),
structs::NS_STYLE_CURSOR_CROSSHAIR => Keyword::Cursor(Cursor::Crosshair),
structs::NS_STYLE_CURSOR_TEXT => Keyword::Cursor(Cursor::Text),
structs::NS_STYLE_CURSOR_VERTICAL_TEXT => Keyword::Cursor(Cursor::VerticalText),
structs::NS_STYLE_CURSOR_ALIAS => Keyword::Cursor(Cursor::Alias),
structs::NS_STYLE_CURSOR_COPY => Keyword::Cursor(Cursor::Copy),
structs::NS_STYLE_CURSOR_MOVE => Keyword::Cursor(Cursor::Move),
structs::NS_STYLE_CURSOR_NO_DROP => Keyword::Cursor(Cursor::NoDrop),
structs::NS_STYLE_CURSOR_NOT_ALLOWED => Keyword::Cursor(Cursor::NotAllowed),
structs::NS_STYLE_CURSOR_GRAB => Keyword::Cursor(Cursor::Grab),
structs::NS_STYLE_CURSOR_GRABBING => Keyword::Cursor(Cursor::Grabbing),
structs::NS_STYLE_CURSOR_E_RESIZE => Keyword::Cursor(Cursor::EResize),
structs::NS_STYLE_CURSOR_N_RESIZE => Keyword::Cursor(Cursor::NResize),
structs::NS_STYLE_CURSOR_NE_RESIZE => Keyword::Cursor(Cursor::NeResize),
structs::NS_STYLE_CURSOR_NW_RESIZE => Keyword::Cursor(Cursor::NwResize),
structs::NS_STYLE_CURSOR_S_RESIZE => Keyword::Cursor(Cursor::SResize),
structs::NS_STYLE_CURSOR_SE_RESIZE => Keyword::Cursor(Cursor::SeResize),
structs::NS_STYLE_CURSOR_SW_RESIZE => Keyword::Cursor(Cursor::SwResize),
structs::NS_STYLE_CURSOR_W_RESIZE => Keyword::Cursor(Cursor::WResize),
structs::NS_STYLE_CURSOR_EW_RESIZE => Keyword::Cursor(Cursor::EwResize),
structs::NS_STYLE_CURSOR_NS_RESIZE => Keyword::Cursor(Cursor::NsResize),
structs::NS_STYLE_CURSOR_NESW_RESIZE => Keyword::Cursor(Cursor::NeswResize),
structs::NS_STYLE_CURSOR_NWSE_RESIZE => Keyword::Cursor(Cursor::NwseResize),
structs::NS_STYLE_CURSOR_COL_RESIZE => Keyword::Cursor(Cursor::ColResize),
structs::NS_STYLE_CURSOR_ROW_RESIZE => Keyword::Cursor(Cursor::RowResize),
structs::NS_STYLE_CURSOR_ALL_SCROLL => Keyword::Cursor(Cursor::AllScroll),
structs::NS_STYLE_CURSOR_ZOOM_IN => Keyword::Cursor(Cursor::ZoomIn),
structs::NS_STYLE_CURSOR_ZOOM_OUT => Keyword::Cursor(Cursor::ZoomOut),
x => panic!("Found unexpected value in style struct for cursor property: {:?}", x),
};

let images = self.gecko.mCursorImages.iter().map(|gecko_cursor_image| {
let url = unsafe {
let gecko_image_request = gecko_cursor_image.mImage.mRawPtr.as_ref().unwrap();
SpecifiedUrl::from_image_request(&gecko_image_request)
.expect("mCursorImages.mImage could not convert to SpecifiedUrl")
};

let hotspot =
if gecko_cursor_image.mHaveHotspot {
Some((gecko_cursor_image.mHotspotX, gecko_cursor_image.mHotspotY))
} else {
None
};

Image { url, hotspot }
}).collect();

longhands::cursor::computed_value::T { images, keyword }
}

<%call expr="impl_color('caret_color', 'mCaretColor', need_clone=True)"></%call>
</%self:impl_trait>

Expand Down
2 changes: 1 addition & 1 deletion components/style/properties/longhand/pointing.mako.rs
Expand Up @@ -6,7 +6,7 @@

<% data.new_style_struct("Pointing", inherited=True, gecko_name="UserInterface") %>

<%helpers:longhand name="cursor" boxed="${product == 'gecko'}" animation_value_type="none"
<%helpers:longhand name="cursor" boxed="${product == 'gecko'}" animation_value_type="discrete"
spec="https://drafts.csswg.org/css-ui/#cursor">
pub use self::computed_value::T as SpecifiedValue;
use values::computed::ComputedValueAsSpecified;
Expand Down

0 comments on commit f01ad20

Please sign in to comment.