stdweb/webapi/events/
mouse.rs

1use webcore::value::Reference;
2use webcore::try_from::TryInto;
3use webapi::event_target::EventTarget;
4use webapi::event::{IEvent, IUiEvent, UiEvent, Event};
5use webapi::events::keyboard::{ModifierKey, get_event_modifier_state};
6
7/// The `IMouseEvent` interface represents events that occur due to the user
8/// interacting with a pointing device (such as a mouse).
9///
10/// [(JavaScript docs)](https://developer.mozilla.org/en-US/docs/Web/API/MouseEvent)
11// https://w3c.github.io/uievents/#mouseevent
12pub trait IMouseEvent: IUiEvent {
13    /// Returns whether the Alt key was down when this event was fired.
14    ///
15    /// [(JavaScript docs)](https://developer.mozilla.org/en-US/docs/Web/API/MouseEvent/altKey)
16    // https://w3c.github.io/uievents/#ref-for-dom-mouseevent-altkey-1
17    #[inline]
18    fn alt_key( &self ) -> bool {
19        js!(
20            return @{self.as_ref()}.altKey;
21        ).try_into().unwrap()
22    }
23
24    /// Indicates the mouse button that fired this event.
25    ///
26    /// [(JavaScript docs)](https://developer.mozilla.org/en-US/docs/Web/API/MouseEvent/button)
27    // https://w3c.github.io/uievents/#ref-for-dom-mouseevent-button-1
28    fn button( &self ) -> MouseButton {
29        match js!(
30            return @{self.as_ref()}.button;
31        ).try_into().unwrap() {
32            0 => MouseButton::Left,
33            1 => MouseButton::Wheel,
34            2 => MouseButton::Right,
35            3 => MouseButton::Button4,
36            4 => MouseButton::Button5,
37            _ => unreachable!("Unexpected MouseEvent.button value"),
38        }
39    }
40
41    /// Indicates which mouse buttons were down when this event was fired.
42    ///
43    /// [(JavaScript docs)](https://developer.mozilla.org/en-US/docs/Web/API/MouseEvent/buttons)
44    // https://w3c.github.io/uievents/#ref-for-dom-mouseevent-buttons-1
45    fn buttons( &self ) -> MouseButtonsState {
46        MouseButtonsState(
47            js!(
48                return @{self.as_ref()}.buttons;
49            ).try_into().unwrap()
50        )
51    }
52
53    /// Returns the X position in the application's client area where this event occured.
54    ///
55    /// [(JavaScript docs)](https://developer.mozilla.org/en-US/docs/Web/API/MouseEvent/clientX)
56    // https://w3c.github.io/uievents/#ref-for-dom-mouseevent-clientx-2
57    #[inline]
58    fn client_x( &self ) -> i32 {
59        js!(
60            return @{self.as_ref()}.clientX;
61        ).try_into().unwrap()
62    }
63
64    /// Returns the Y position in the application's client area where this event occured.
65    ///
66    /// [(JavaScript docs)](https://developer.mozilla.org/en-US/docs/Web/API/MouseEvent/clientY)
67    // https://w3c.github.io/uievents/#ref-for-dom-mouseevent-clienty-2
68    #[inline]
69    fn client_y( &self ) -> i32 {
70        js!(
71            return @{self.as_ref()}.clientY;
72        ).try_into().unwrap()
73    }
74
75    /// Returns the X position on the target element where this event occured.
76    ///
77    /// [(JavaScript docs)](https://developer.mozilla.org/en-US/docs/Web/API/MouseEvent/offsetX)
78    // https://drafts.csswg.org/cssom-view/#ref-for-dom-mouseevent-offsetx
79    #[inline]
80    fn offset_x( &self ) -> f64 {
81        js!(
82            return @{self.as_ref()}.offsetX;
83        ).try_into().unwrap()
84    }
85
86    /// Returns the Y position on the target element where this event occured.
87    ///
88    /// [(JavaScript docs)](https://developer.mozilla.org/en-US/docs/Web/API/MouseEvent/offsetY)
89    // https://drafts.csswg.org/cssom-view/#ref-for-dom-mouseevent-offsety
90    #[inline]
91    fn offset_y( &self ) -> f64 {
92        js!(
93            return @{self.as_ref()}.offsetY;
94        ).try_into().unwrap()
95    }
96
97    /// Indicates whether the Ctrl key was down when this event fired.
98    ///
99    /// [(JavaScript docs)](https://developer.mozilla.org/en-US/docs/Web/API/MouseEvent/ctrlKey)
100    // https://w3c.github.io/uievents/#ref-for-dom-mouseevent-ctrlkey-1
101    #[inline]
102    fn ctrl_key( &self ) -> bool {
103        js!(
104            return @{self.as_ref()}.ctrlKey;
105        ).try_into().unwrap()
106    }
107
108    /// Returns the current state of the specified modifier key.
109    ///
110    /// [(JavaScript docs)](https://developer.mozilla.org/en-US/docs/Web/API/MouseEvent/getModifierState)
111    // https://w3c.github.io/uievents/#ref-for-dom-mouseevent-getmodifierstate-2
112    #[inline]
113    fn get_modifier_state( &self, key: ModifierKey ) -> bool {
114        get_event_modifier_state( self, key )
115    }
116
117    /// Indicates whether the Meta key was down when this event fired.
118    ///
119    /// [(JavaScript docs)](https://developer.mozilla.org/en-US/docs/Web/API/MouseEvent/metaKey)
120    // https://w3c.github.io/uievents/#ref-for-dom-mouseevent-metakey-1
121    #[inline]
122    fn meta_key( &self ) -> bool {
123        js!(
124            return @{self.as_ref()}.metaKey;
125        ).try_into().unwrap()
126    }
127
128    /// Returns the change in X coordinate of the pointer between this event and the previous
129    /// MouseMove event.
130    ///
131    /// [(JavaScript docs)](https://developer.mozilla.org/en-US/docs/Web/API/MouseEvent/movementX)
132    // https://w3c.github.io/pointerlock/#extensions-to-the-mouseevent-interface
133    #[inline]
134    fn movement_x( &self ) -> i32 {
135        js!(
136            return @{self.as_ref()}.movementX;
137        ).try_into().unwrap()
138    }
139
140    /// Returns the change in Y coordinate of the pointer between this event and the previous
141    /// MouseMove event.
142    ///
143    /// [(JavaScript docs)](https://developer.mozilla.org/en-US/docs/Web/API/MouseEvent/movementX)
144    // https://w3c.github.io/pointerlock/#extensions-to-the-mouseevent-interface
145    #[inline]
146    fn movement_y( &self ) -> i32 {
147        js!(
148            return @{self.as_ref()}.movementY;
149        ).try_into().unwrap()
150    }
151
152    /// Returns the ID of the hit region affected by the event.
153    ///
154    /// [(JavaScript docs)](https://developer.mozilla.org/en-US/docs/Web/API/MouseEvent/region)
155    #[inline]
156    fn region( &self ) -> Option< String > {
157        js!(
158            return @{self.as_ref()}.region;
159        ).try_into().ok()
160    }
161
162    /// Returns the secondary target of this event, if any.
163    ///
164    /// [(JavaScript docs)](https://developer.mozilla.org/en-US/docs/Web/API/MouseEvent/relatedTarget)
165    // https://w3c.github.io/uievents/#ref-for-dom-mouseevent-relatedtarget-1
166    #[inline]
167    fn related_target( &self ) -> Option< EventTarget > {
168        js!(
169            return @{self.as_ref()}.relatedTarget;
170        ).try_into().ok()
171    }
172
173    /// Returns the X position of the pointer in screen coordinates.
174    ///
175    /// [(JavaScript docs)](https://developer.mozilla.org/en-US/docs/Web/API/MouseEvent/screenX)
176    // https://w3c.github.io/uievents/#ref-for-dom-mouseevent-screenx-1
177    #[inline]
178    fn screen_x( &self ) -> i32 {
179        js!(
180            return @{self.as_ref()}.screenX;
181        ).try_into().unwrap()
182    }
183
184    /// Returns the Y position of the pointer in screen coordinates.
185    ///
186    /// [(JavaScript docs)](https://developer.mozilla.org/en-US/docs/Web/API/MouseEvent/screenY)
187    // https://w3c.github.io/uievents/#ref-for-dom-mouseevent-screeny-1
188    #[inline]
189    fn screen_y( &self ) -> i32 {
190        js!(
191            return @{self.as_ref()}.screenY;
192        ).try_into().unwrap()
193    }
194
195    /// Indicates whether the Shift key was down when this event was fired.
196    ///
197    /// [(JavaScript docs)](https://developer.mozilla.org/en-US/docs/Web/API/MouseEvent/shiftKey)
198    // https://w3c.github.io/uievents/#ref-for-dom-mouseevent-shiftkey-1
199    #[inline]
200    fn shift_key( &self ) -> bool {
201        js!(
202            return @{self.as_ref()}.shiftKey;
203        ).try_into().unwrap()
204    }
205}
206
207/// Represents buttons on a mouse during mouse events.
208#[derive(Clone, Copy, Debug, PartialEq, Eq)]
209pub enum MouseButton {
210    /// The left mouse button.
211    Left,
212    /// The mouse wheel/middle mouse button.
213    Wheel,
214    /// The right mouse button.
215    Right,
216    /// The fourth mouse button (browser back).
217    Button4,
218    /// The fifth mouse button (browser forward).
219    Button5,
220    // /// The sixth mouse button, or the Pen Eraser button
221    //TODO: Eraser,
222}
223
224/// Represents the state of mouse buttons in a `MouseEvent`.
225#[derive(Copy, Clone, Debug, PartialEq, Eq)]
226pub struct MouseButtonsState(u8);
227
228impl MouseButtonsState {
229    /// Check if a [MouseButton](enum.MouseButton.html) is currently pressed
230    pub fn is_down(&self, button: MouseButton) -> bool {
231        match button {
232            MouseButton::Left => self.0 & 0b1 != 0,
233            MouseButton::Right => self.0 & 0b10 != 0,
234            MouseButton::Wheel => self.0 & 0b100 != 0,
235            MouseButton::Button4 => self.0 & 0b1000 != 0,
236            MouseButton::Button5 => self.0 & 0b1_0000 != 0,
237        }
238    }
239}
240
241/// A reference to a JavaScript object which implements the [IMouseEvent](trait.IMouseEvent.html)
242/// interface.
243///
244/// [(JavaScript docs)](https://developer.mozilla.org/en-US/docs/Web/API/MouseEvent)
245// https://w3c.github.io/uievents/#mouseevent
246#[derive(Clone, Debug, PartialEq, Eq, ReferenceType)]
247#[reference(instance_of = "MouseEvent")]
248#[reference(subclass_of(Event, UiEvent))]
249pub struct MouseEvent( Reference );
250
251impl IEvent for MouseEvent {}
252impl IUiEvent for MouseEvent {}
253impl IMouseEvent for MouseEvent {}
254
255/// The `ClickEvent` is fired when a pointing device button (usually a
256/// mouse's primary button) is pressed and released on a single element.
257///
258/// [(JavaScript docs)](https://developer.mozilla.org/en-US/docs/Web/Events/click)
259// https://w3c.github.io/uievents/#event-type-click
260#[derive(Clone, Debug, PartialEq, Eq, ReferenceType)]
261#[reference(instance_of = "MouseEvent")]
262#[reference(event = "click")]
263#[reference(subclass_of(Event, UiEvent, MouseEvent))]
264pub struct ClickEvent( Reference );
265
266impl IEvent for ClickEvent {}
267impl IUiEvent for ClickEvent {}
268impl IMouseEvent for ClickEvent {}
269
270/// The `AuxClickEvent` event is fired when a non-primary pointing device button
271/// (e.g. any non-left mouse button) has been pressed and released on an element.
272///
273/// [(JavaScript docs)](https://developer.mozilla.org/en-US/docs/Web/Events/auxclick)
274// https://w3c.github.io/uievents/#event-type-auxclick
275#[derive(Clone, Debug, PartialEq, Eq, ReferenceType)]
276#[reference(instance_of = "MouseEvent")]
277#[reference(event = "auxclick")]
278#[reference(subclass_of(Event, UiEvent, MouseEvent))]
279pub struct AuxClickEvent( Reference );
280
281impl IEvent for AuxClickEvent {}
282impl IUiEvent for AuxClickEvent {}
283impl IMouseEvent for AuxClickEvent {}
284
285/// The `ContextMenuEvent` event is fired when the right button of the mouse is clicked
286/// (before the context menu is displayed), or when the context menu key is pressed.
287///
288/// [(JavaScript docs)](https://developer.mozilla.org/en-US/docs/Web/Events/contextmenu)
289// https://html.spec.whatwg.org/#event-contextmenu
290#[derive(Clone, Debug, PartialEq, Eq, ReferenceType)]
291#[reference(instance_of = "MouseEvent")]
292#[reference(event = "contextmenu")]
293#[reference(subclass_of(Event, UiEvent, MouseEvent))]
294pub struct ContextMenuEvent( Reference );
295
296impl IEvent for ContextMenuEvent {}
297impl IUiEvent for ContextMenuEvent {}
298impl IMouseEvent for ContextMenuEvent {}
299
300/// The `DoubleClickEvent` is fired when a pointing device button
301/// (usually a mouse's primary button) is clicked twice on a single
302/// element.
303///
304/// [(JavaScript docs)](https://developer.mozilla.org/en-US/docs/Web/Events/dblclick)
305// https://w3c.github.io/uievents/#event-type-dblclick
306#[derive(Clone, Debug, PartialEq, Eq, ReferenceType)]
307#[reference(instance_of = "MouseEvent")]
308#[reference(event = "dblclick")]
309#[reference(subclass_of(Event, UiEvent, MouseEvent))]
310pub struct DoubleClickEvent( Reference );
311
312impl IEvent for DoubleClickEvent {}
313impl IUiEvent for DoubleClickEvent {}
314impl IMouseEvent for DoubleClickEvent {}
315
316/// The `MouseDownEvent` is fired when a pointing device button is pressed on
317/// an element.
318///
319/// [(JavaScript docs)](https://developer.mozilla.org/en-US/docs/Web/Events/mousedown)
320// https://w3c.github.io/uievents/#event-type-mousedown
321#[derive(Clone, Debug, PartialEq, Eq, ReferenceType)]
322#[reference(instance_of = "MouseEvent")]
323#[reference(event = "mousedown")]
324#[reference(subclass_of(Event, UiEvent, MouseEvent))]
325pub struct MouseDownEvent( Reference );
326
327impl IEvent for MouseDownEvent {}
328impl IUiEvent for MouseDownEvent {}
329impl IMouseEvent for MouseDownEvent {}
330
331/// The `MouseUpEvent` is fired when a pointing device button is released
332/// over an element.
333///
334/// [(JavaScript docs)](https://developer.mozilla.org/en-US/docs/Web/Events/mouseup)
335// https://w3c.github.io/uievents/#event-type-mouseup
336#[derive(Clone, Debug, PartialEq, Eq, ReferenceType)]
337#[reference(instance_of = "MouseEvent")]
338#[reference(event = "mouseup")]
339#[reference(subclass_of(Event, UiEvent, MouseEvent))]
340pub struct MouseUpEvent( Reference );
341
342impl IEvent for MouseUpEvent {}
343impl IUiEvent for MouseUpEvent {}
344impl IMouseEvent for MouseUpEvent {}
345
346/// The `MouseMoveEvent` is fired when a pointing device (usually a mouse)
347/// is moved while over an element.
348///
349/// [(JavaScript docs)](https://developer.mozilla.org/en-US/docs/Web/Events/mousemove)
350// https://w3c.github.io/uievents/#event-type-mousemove
351#[derive(Clone, Debug, PartialEq, Eq, ReferenceType)]
352#[reference(instance_of = "MouseEvent")]
353#[reference(event = "mousemove")]
354#[reference(subclass_of(Event, UiEvent, MouseEvent))]
355pub struct MouseMoveEvent( Reference );
356
357impl IEvent for MouseMoveEvent {}
358impl IUiEvent for MouseMoveEvent {}
359impl IMouseEvent for MouseMoveEvent {}
360
361/// The `MouseOverEvent` is fired when a pointing device (usually a mouse)
362/// is moved onto the element that has the listener attached or onto one of its children.
363///
364/// [(JavaScript docs)](https://developer.mozilla.org/en-US/docs/Web/Events/mouseover)
365// https://w3c.github.io/uievents/#event-type-mouseover
366#[derive(Clone, Debug, PartialEq, Eq, ReferenceType)]
367#[reference(instance_of = "MouseEvent")]
368#[reference(event = "mouseover")]
369#[reference(subclass_of(Event, UiEvent, MouseEvent))]
370pub struct MouseOverEvent( Reference );
371
372impl IEvent for MouseOverEvent {}
373impl IUiEvent for MouseOverEvent {}
374impl IMouseEvent for MouseOverEvent {}
375
376/// The `MouseOutEvent` is fired when a pointing device (usually a mouse)
377/// is moved off the element that has the listener attached or off one of its children.
378///
379/// [(JavaScript docs)](https://developer.mozilla.org/en-US/docs/Web/Events/mouseout)
380// https://w3c.github.io/uievents/#event-type-mouseout
381#[derive(Clone, Debug, PartialEq, Eq, ReferenceType)]
382#[reference(instance_of = "MouseEvent")]
383#[reference(event = "mouseout")]
384#[reference(subclass_of(Event, UiEvent, MouseEvent))]
385pub struct MouseOutEvent( Reference );
386
387impl IEvent for MouseOutEvent {}
388impl IUiEvent for MouseOutEvent {}
389impl IMouseEvent for MouseOutEvent {}
390
391/// The `MouseEnterEvent` is fired when a pointing device (usually a mouse)
392/// is moved over the element that has the listener attached.
393///
394/// [(JavaScript docs)](https://developer.mozilla.org/en-US/docs/Web/Events/mouseenter)
395// https://w3c.github.io/uievents/#event-type-mouseenter
396#[derive(Clone, Debug, PartialEq, Eq, ReferenceType)]
397#[reference(instance_of = "MouseEvent")]
398#[reference(event = "mouseenter")]
399#[reference(subclass_of(Event, UiEvent, MouseEvent))]
400pub struct MouseEnterEvent( Reference );
401
402impl IEvent for MouseEnterEvent {}
403impl IUiEvent for MouseEnterEvent {}
404impl IMouseEvent for MouseEnterEvent {}
405
406/// The `MouseLeaveEvent` is fired when a pointing device (usually a mouse)
407/// is moved out of an element that has the listener attached to it.
408///
409/// [(JavaScript docs)](https://developer.mozilla.org/en-US/docs/Web/Events/mouseleave)
410// https://w3c.github.io/uievents/#event-type-mouseleave
411#[derive(Clone, Debug, PartialEq, Eq, ReferenceType)]
412#[reference(instance_of = "MouseEvent")]
413#[reference(event = "mouseleave")]
414#[reference(subclass_of(Event, UiEvent, MouseEvent))]
415pub struct MouseLeaveEvent( Reference );
416
417impl IEvent for MouseLeaveEvent {}
418impl IUiEvent for MouseLeaveEvent {}
419impl IMouseEvent for MouseLeaveEvent {}
420
421/// The `MouseWheelEvent` is fired when a pointing device's wheel button (usually a mousewheel)
422/// is rotated over the element that has the listener attached.
423///
424/// [(JavaScript docs)](https://developer.mozilla.org/en-US/docs/Web/Events/wheel)
425// https://w3c.github.io/uievents/#event-type-wheel
426#[derive(Clone, Debug, PartialEq, Eq, ReferenceType)]
427#[reference(instance_of = "MouseEvent")]
428#[reference(event = "wheel")]
429#[reference(subclass_of(Event, UiEvent, MouseEvent))]
430pub struct MouseWheelEvent( Reference );
431
432impl IEvent for MouseWheelEvent {}
433impl IUiEvent for MouseWheelEvent {}
434impl IMouseEvent for MouseWheelEvent {}
435
436impl MouseWheelEvent {
437    /// The change in X of the wheel
438    ///
439    /// [(Javascript docs)](https://developer.mozilla.org/en-US/docs/Web/API/WheelEvent/deltaX)
440    // https://w3c.github.io/uievents/#dom-wheelevent-deltax
441    pub fn delta_x(&self) -> f64 {
442        js! (
443            return @{self}.deltaX;
444        ).try_into().unwrap()
445    }
446
447    /// The change in Y of the wheel
448    ///
449    /// [(Javascript docs)](https://developer.mozilla.org/en-US/docs/Web/API/WheelEvent/deltaY)
450    // https://w3c.github.io/uievents/#dom-wheelevent-deltay
451    pub fn delta_y(&self) -> f64 {
452        js! (
453            return @{self}.deltaY;
454        ).try_into().unwrap()
455    }
456
457    /// The change in Z of the wheel
458    ///
459    /// [(Javascript docs)](https://developer.mozilla.org/en-US/docs/Web/API/WheelEvent/deltaZ)
460    // https://w3c.github.io/uievents/#dom-wheelevent-deltaz
461    pub fn delta_z(&self) -> f64 {
462        js! (
463            return @{self}.deltaZ;
464        ).try_into().unwrap()
465    }
466
467    /// The unit of measure of change
468    ///
469    /// [(JavaScript docs)](https://developer.mozilla.org/en-US/docs/Web/API/WheelEvent/deltaMode)
470    // https://w3c.github.io/uievents/#dom-wheelevent-deltamode
471    pub fn delta_mode(&self) -> MouseWheelDeltaMode {
472        let mode: u32 = js! (
473            return @{self}.deltaMode;
474        ).try_into().unwrap();
475        match mode {
476            0 => MouseWheelDeltaMode::Pixel,
477            1 => MouseWheelDeltaMode::Line,
478            2 => MouseWheelDeltaMode::Page,
479            _ => unreachable!()
480        }
481    }
482}
483
484/// What unit of measure the mouse wheel delta is in
485///
486/// [(JavaScipt docs)](https://developer.mozilla.org/en-US/docs/Web/API/WheelEvent/deltaMode)
487#[derive(Clone, Copy, Debug, PartialEq, Eq)]
488pub enum MouseWheelDeltaMode {
489    /// The unit of measurement for the delta is pixels
490    // https://w3c.github.io/uievents/#dom-wheelevent-dom_delta_pixel
491    Pixel,
492    /// The unit of measurement for the delta is lines
493    // https://w3c.github.io/uievents/#dom-wheelevent-dom_delta_line
494    Line,
495     /// The unit of measurement for the delta is pages
496    // https://w3c.github.io/uievents/#dom-wheelevent-dom_delta_page
497    Page
498}
499
500#[cfg(all(test, feature = "web_test"))]
501mod tests {
502    use super::*;
503    use webapi::event::ConcreteEvent;
504
505    #[test]
506    fn test_mouse_event() {
507        let event: MouseEvent = js!(
508            return new MouseEvent(
509                @{ClickEvent::EVENT_TYPE},
510                {
511                    altKey: false,
512                    button: 2,
513                    buttons: 6,
514                    clientX: 3,
515                    clientY: 4,
516                    ctrlKey: true,
517                    metaKey: false,
518                    screenX: 1,
519                    screenY: 2,
520                    shiftKey: true
521                }
522            );
523        ).try_into().unwrap();
524        assert_eq!( event.event_type(), ClickEvent::EVENT_TYPE );
525        assert_eq!( event.alt_key(), false );
526        assert_eq!( event.button(), MouseButton::Right );
527        assert!( !event.buttons().is_down( MouseButton::Left ) );
528        assert!( event.buttons().is_down( MouseButton::Right ) );
529        assert!( event.buttons().is_down( MouseButton::Wheel ) );
530        assert_eq!( event.client_x(), 3 );
531        assert_eq!( event.client_y(), 4 );
532        assert!( event.ctrl_key() );
533        assert!( !event.get_modifier_state( ModifierKey::Alt ) );
534        assert!( event.get_modifier_state( ModifierKey::Ctrl ) );
535        assert!( event.get_modifier_state( ModifierKey::Shift ) );
536        assert!( !event.meta_key() );
537        assert_eq!( event.movement_x(), 0 );
538        assert_eq!( event.movement_y(), 0 );
539        assert!( event.region().is_none() );
540        assert!( event.related_target().is_none() );
541        assert_eq!( event.screen_x(), 1 );
542        assert_eq!( event.screen_y(), 2 );
543        assert!( event.shift_key() );
544    }
545
546    #[test]
547    fn test_click_event() {
548        let event: ClickEvent = js!(
549            return new MouseEvent( @{ClickEvent::EVENT_TYPE} );
550        ).try_into().unwrap();
551        assert_eq!( event.event_type(), ClickEvent::EVENT_TYPE );
552    }
553
554    #[test]
555    fn test_aux_click_event() {
556        let event: AuxClickEvent = js!(
557            return new MouseEvent( @{AuxClickEvent::EVENT_TYPE} );
558        ).try_into()
559            .unwrap();
560        assert_eq!( event.event_type(), AuxClickEvent::EVENT_TYPE );
561    }
562
563    #[test]
564    fn test_context_menu_event() {
565        let event: ContextMenuEvent = js!(
566            return new MouseEvent( @{ContextMenuEvent::EVENT_TYPE} );
567        ).try_into().unwrap();
568        assert_eq!( event.event_type(), ContextMenuEvent::EVENT_TYPE );
569    }
570
571    #[test]
572    fn test_double_click_event() {
573        let event: DoubleClickEvent = js!(
574            return new MouseEvent( @{DoubleClickEvent::EVENT_TYPE} );
575        ).try_into().unwrap();
576        assert_eq!( event.event_type(), DoubleClickEvent::EVENT_TYPE );
577    }
578
579    #[test]
580    fn test_mouse_down_event() {
581        let event: MouseDownEvent = js!(
582            return new MouseEvent( @{MouseDownEvent::EVENT_TYPE} );
583        ).try_into().unwrap();
584        assert_eq!( event.event_type(), MouseDownEvent::EVENT_TYPE );
585    }
586
587    #[test]
588    fn test_mouse_up_event() {
589        let event: MouseUpEvent = js!(
590            return new MouseEvent( @{MouseUpEvent::EVENT_TYPE} );
591        ).try_into().unwrap();
592        assert_eq!( event.event_type(), MouseUpEvent::EVENT_TYPE );
593    }
594
595    #[test]
596    fn test_mouse_move_event() {
597        let event: MouseMoveEvent = js!(
598            return new MouseEvent( @{MouseMoveEvent::EVENT_TYPE} );
599        ).try_into().unwrap();
600        assert_eq!( event.event_type(), MouseMoveEvent::EVENT_TYPE );
601    }
602
603    #[test]
604    fn test_mouse_over_event() {
605        let event: MouseOverEvent = js!(
606            return new MouseEvent( @{MouseOverEvent::EVENT_TYPE} );
607        ).try_into().unwrap();
608        assert_eq!( event.event_type(), MouseOverEvent::EVENT_TYPE );
609    }
610
611    #[test]
612    fn test_mouse_out_event() {
613        let event: MouseOutEvent = js!(
614            return new MouseEvent( @{MouseOutEvent::EVENT_TYPE} );
615        ).try_into().unwrap();
616        assert_eq!( event.event_type(), MouseOutEvent::EVENT_TYPE );
617    }
618
619    #[test]
620    fn test_mouse_enter_event() {
621        let event: MouseEnterEvent = js!(
622            return new MouseEvent( @{MouseEnterEvent::EVENT_TYPE} );
623        ).try_into()
624            .unwrap();
625        assert_eq!( event.event_type(), MouseEnterEvent::EVENT_TYPE );
626    }
627
628    #[test]
629    fn test_mouse_leave_event() {
630        let event: MouseLeaveEvent = js!(
631            return new MouseEvent( @{MouseLeaveEvent::EVENT_TYPE} );
632        ).try_into()
633            .unwrap();
634        assert_eq!( event.event_type(), MouseLeaveEvent::EVENT_TYPE );
635    }
636
637    #[test]
638    fn test_mouse_wheel_event() {
639        let event: MouseWheelEvent = js!(
640            return new MouseEvent( @{MouseWheelEvent::EVENT_TYPE} );
641        ).try_into()
642            .unwrap();
643        assert_eq!( event.event_type(), MouseWheelEvent::EVENT_TYPE );
644    }
645}