aboutsummaryrefslogtreecommitdiffstats
path: root/components/script
diff options
context:
space:
mode:
authorbors-servo <lbergstrom+bors@mozilla.com>2017-10-20 22:14:43 -0500
committerGitHub <noreply@github.com>2017-10-20 22:14:43 -0500
commit1b08bfc5c0f49dabf205c9f3c32d35c21ea0042c (patch)
tree84c7e8048d3858ce9cbdea17838872108a996995 /components/script
parenta71470abe5b8b4b5c14183c6e8bf7e4eefd5c5a7 (diff)
parent78583ee3398a5b207f67ce72c32cbe59dfb71072 (diff)
downloadservo-1b08bfc5c0f49dabf205c9f3c32d35c21ea0042c.tar.gz
servo-1b08bfc5c0f49dabf205c9f3c32d35c21ea0042c.zip
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 -->
Diffstat (limited to 'components/script')
-rw-r--r--components/script/dom/document.rs26
1 files changed, 21 insertions, 5 deletions
diff --git a/components/script/dom/document.rs b/components/script/dom/document.rs
index 2e018bd62f5..3edd2fdc737 100644
--- a/components/script/dom/document.rs
+++ b/components/script/dom/document.rs
@@ -158,6 +158,22 @@ pub enum TouchEventResult {
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)]
pub enum IsHTMLDocument {
HTMLDocument,
@@ -1037,13 +1053,13 @@ impl Document {
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_y = client_point.y.to_i32().unwrap_or(0);
let mouse_event = MouseEvent::new(
&self.window,
- DOMString::from(event_name),
+ DOMString::from(event_name.as_str()),
EventBubbles::Bubbles,
EventCancelable::Cancelable,
Some(&self.window),
@@ -1096,7 +1112,7 @@ impl Document {
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,
// and the element under the mouse hasn't changed.
@@ -1125,7 +1141,7 @@ impl Document {
}
// 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
// not an ancestor of the new target.
@@ -1142,7 +1158,7 @@ impl Document {
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.
}