Auto merge of #18957 - mhaessig:fire-mouse-event-enum, r=jdm

Made fire_mouse_event take an enum for event_name

Added an enum with the mouse event options for `fire_mouse_event` and refactored the `event_name` parameter to take the enum as argument.
I also added two options (Leave and Enter) which are noted as todo in the comments.

- [x] `./mach build -d` does not report any errors
- [X] `./mach test-tidy` does not report any errors
- [X] These Changes fix #18943.
- [X] These changes do not require tests because the issue said a clean build suffices.

<!-- Reviewable:start -->
---
This change is [<img src="https://reviewable.io/review_button.svg" height="34" align="absmiddle" alt="Reviewable"/>](https://reviewable.io/reviews/servo/servo/18957)
<!-- Reviewable:end -->
This commit is contained in:
bors-servo 2017-10-20 22:14:43 -05:00 committed by GitHub
commit 1b08bfc5c0

View file

@ -158,6 +158,22 @@ pub enum TouchEventResult {
Forwarded, Forwarded,
} }
pub enum FireMouseEventType {
Move,
Over,
Out,
}
impl FireMouseEventType {
pub fn as_str(&self) -> &str {
match self {
&FireMouseEventType::Move => "mousemove",
&FireMouseEventType::Over => "mouseout",
&FireMouseEventType::Out => "mouseover",
}
}
}
#[derive(Clone, Copy, Debug, JSTraceable, MallocSizeOf, PartialEq)] #[derive(Clone, Copy, Debug, JSTraceable, MallocSizeOf, PartialEq)]
pub enum IsHTMLDocument { pub enum IsHTMLDocument {
HTMLDocument, HTMLDocument,
@ -1037,13 +1053,13 @@ impl Document {
event.fire(target); event.fire(target);
} }
pub fn fire_mouse_event(&self, client_point: Point2D<f32>, target: &EventTarget, event_name: String) { pub fn fire_mouse_event(&self, client_point: Point2D<f32>, target: &EventTarget, event_name: FireMouseEventType) {
let client_x = client_point.x.to_i32().unwrap_or(0); let client_x = client_point.x.to_i32().unwrap_or(0);
let client_y = client_point.y.to_i32().unwrap_or(0); let client_y = client_point.y.to_i32().unwrap_or(0);
let mouse_event = MouseEvent::new( let mouse_event = MouseEvent::new(
&self.window, &self.window,
DOMString::from(event_name), DOMString::from(event_name.as_str()),
EventBubbles::Bubbles, EventBubbles::Bubbles,
EventCancelable::Cancelable, EventCancelable::Cancelable,
Some(&self.window), Some(&self.window),
@ -1096,7 +1112,7 @@ impl Document {
None => return, None => return,
}; };
self.fire_mouse_event(client_point, new_target.upcast(), "mousemove".to_owned()); self.fire_mouse_event(client_point, new_target.upcast(), FireMouseEventType::Move);
// Nothing more to do here, mousemove is sent, // Nothing more to do here, mousemove is sent,
// and the element under the mouse hasn't changed. // and the element under the mouse hasn't changed.
@ -1125,7 +1141,7 @@ impl Document {
} }
// Remove hover state to old target and its parents // Remove hover state to old target and its parents
self.fire_mouse_event(client_point, old_target.upcast(), "mouseout".to_owned()); self.fire_mouse_event(client_point, old_target.upcast(), FireMouseEventType::Out);
// TODO: Fire mouseleave here only if the old target is // TODO: Fire mouseleave here only if the old target is
// not an ancestor of the new target. // not an ancestor of the new target.
@ -1142,7 +1158,7 @@ impl Document {
element.set_hover_state(true); element.set_hover_state(true);
} }
self.fire_mouse_event(client_point, &new_target.upcast(), "mouseover".to_owned()); self.fire_mouse_event(client_point, &new_target.upcast(), FireMouseEventType::Over);
// TODO: Fire mouseenter here. // TODO: Fire mouseenter here.
} }