Mouse gesture events

  • Revision slug: DOM/Mouse_gesture_events
  • Revision title: Mouse gesture events
  • Revision id: 28831
  • Created:
  • Creator: dflanagan
  • Is current revision? No
  • Comment 27 words added

Revision Content

{{ gecko_minversion_header("1.9.1") }}

{{ non-standard_header() }}

Gecko 1.9.1 added support for several Mozilla-specific DOM events used to handle mouse gestures. These are special movements that can be made with a mouse or trackpad and can be interpreted to perform specific tasks.

Note: These gesture events are available to add-ons and other browser chrome code, but are never sent to regular web page content.
Note: Some operating systems, including Mac OS X and Windows 7, provide default actions when gesture events occur. If you handle a gesture event and wish to prevent the default action from taking place as well, be sure to call the event's preventDefault() method.

Types of gesture events

MozSwipeGesture

The MozSwipeGesture event is sent when the user uses three fingers to "swipe" the trackpad.

MozMagnifyGestureStart

The MozMagnifyGestureStart event is sent when the user begins performing a "pinch" gesture, by using two fingers as the corners of a rectangle and moving them either closer together or farther apart. This is typically used to zoom in and out on content (this is the default behavior in Firefox, for example).

MozMagnifyGestureUpdate

The MozMagnifyGestureUpdate event is sent periodically while processing a magnify gesture, to provide updated status information.  The event's delta value represents the amount by which the gesture has moved since the MozMagnifyGestureStart or MozMagnifyGestureUpdate event.

Note: This event is sent whenever the movement of the user's fingers exceeds the number of pixels indicated by the browser.gesture.pinch.threshold preference.

MozMagnifyGesture

The MozMagnifyGesture event is sent when the user completes a "pinch" gesture. If you only care about the end results of the pinch gesture, you can simply watch for this event; however, if you want to provide feedback during the handling of the gesture, you should also watch the MozMagnifyGestureStart and MozMagnifyGestureUpdate events.

The delta value is the cumulative change over the course of handling the entire sequence of magnify gesture events.

MozRotateGestureStart

The MozRotateGestureStart event is sent when the user begins performing a rotate gesture, by placing two fingers on the trackpad and rotating them around the center of the trackpad. Firefox uses this gesture to move backward and forward through the tabs in the current window.

MozRotateGestureUpdate

The MozRotateGestureUpdate event is sent periodically while processing a rotate gesture, to provide updated status information.  The event's delta value represents the amount by which the gesture has moved since the MozRotateGestureStart or MozRotateGestureUpdate event.

Note: This event is sent whenever the movement of the user's fingers exceeds the number of pixels indicated by the browser.gesture.pinch.threshold preference.

MozRotateGesture

The MozRotateGesture event is sent when the user completes a rotate gesture. If you only care about the end results of the rotate gesture, you can simply watch for this event; however, if you want to provide feedback during the handling of the gesture, you should also watch the MozRotateGestureStart and MozRotateGestureUpdate events.

The delta value is the cumulative change over the course of handling the entire sequence of rotate gesture events.

Event fields

Mouse gesture events have additional fields providing information about the gesture. These are:

direction
The direction in which the swipe moved.
delta
The amount by which the gesture moved; for rotation, this value is in degrees. Positive values are clockwise and negative values are counterclockwise. For magnification, this value is implementation-specific, but the value is positive for zooming in and negative for zooming out.

Direction constants

The direction field in the gesture events can take one of the following values:

SimpleGestureEvent.DIRECTION_LEFT
Leftward swipe.
SimpleGestureEvent.DIRECTION_RIGHT
Rightward swipe.
SimpleGestureEvent.DIRECTION_UP
Upward swipe.
SimpleGestureEvent.DIRECTION_DOWN
Downward swipe.
SimpleGestureEvent.ROTATION_COUNTERCLOCKWISE
Counter-clockwise rotation.
SimpleGestureEvent.ROTATION_CLOCKWISE
Clockwise rotation.

See also

Revision Source

<p>{{ gecko_minversion_header("1.9.1") }}</p>
<p>{{ non-standard_header() }}</p>
<p>Gecko 1.9.1 added support for several Mozilla-specific DOM events used to handle mouse gestures. These are special movements that can be made with a mouse or trackpad and can be interpreted to perform specific tasks.</p>
<div class="note"><strong>Note:</strong> These gesture events are available to add-ons and other browser chrome code, but are never sent to regular web page content.</div>
<div class="note"><strong>Note:</strong> Some operating systems, including Mac OS X and Windows 7, provide default actions when gesture events occur. If you handle a gesture event and wish to prevent the default action from taking place as well, be sure to call the event's <a class="internal" href="/en/DOM/event.preventDefault" title="En/DOM/Event.preventDefault"><code>preventDefault()</code></a> method.</div>
<h2 id="Types_of_gesture_events">Types of gesture events</h2>
<h3 id="MozSwipeGesture">MozSwipeGesture</h3>
<p>The <code>MozSwipeGesture</code> event is sent when the user uses three fingers to "swipe" the trackpad.</p>
<h3 id="MozMagnifyGestureStart">MozMagnifyGestureStart</h3>
<p>The <code>MozMagnifyGestureStart</code> event is sent when the user begins performing a "pinch" gesture, by using two fingers as the corners of a rectangle and moving them either closer together or farther apart. This is typically used to zoom in and out on content (this is the default behavior in Firefox, for example).</p>
<h3 id="MozMagnifyGestureUpdate">MozMagnifyGestureUpdate</h3>
<p>The <code>MozMagnifyGestureUpdate</code> event is sent periodically while processing a magnify gesture, to provide updated status information.  The event's <code>delta</code> value represents the amount by which the gesture has moved since the <code>MozMagnifyGestureStart</code> or <code>MozMagnifyGestureUpdate</code> event.</p>
<div class="note"><strong>Note:</strong> This event is sent whenever the movement of the user's fingers exceeds the number of pixels indicated by the <code>browser.gesture.pinch.threshold</code> preference.</div>
<h3 id="MozMagnifyGesture">MozMagnifyGesture</h3>
<p>The <code>MozMagnifyGesture</code> event is sent when the user completes a "pinch" gesture. If you only care about the end results of the pinch gesture, you can simply watch for this event; however, if you want to provide feedback during the handling of the gesture, you should also watch the <code>MozMagnifyGestureStart</code> and <code>MozMagnifyGestureUpdate</code> events.</p>
<p>The <code>delta</code> value is the cumulative change over the course of handling the entire sequence of magnify gesture events.</p>
<h3 id="MozRotateGestureStart">MozRotateGestureStart</h3>
<p>The <code>MozRotateGestureStart</code> event is sent when the user begins performing a rotate gesture, by placing two fingers on the trackpad and rotating them around the center of the trackpad. Firefox uses this gesture to move backward and forward through the tabs in the current window.</p>
<h3 id="MozRotateGestureUpdate">MozRotateGestureUpdate</h3>
<p>The <code>MozRotateGestureUpdate</code> event is sent periodically while processing a rotate gesture, to provide updated status information.  The event's <code>delta</code> value represents the amount by which the gesture has moved since the <code>MozRotateGestureStart</code> or <code>MozRotateGestureUpdate</code> event.</p>
<div class="note"><strong>Note:</strong> This event is sent whenever the movement of the user's fingers exceeds the number of pixels indicated by the <code>browser.gesture.pinch.threshold</code> preference.</div>
<h3 id="MozRotateGesture">MozRotateGesture</h3>
<p>The <code>MozRotateGesture</code> event is sent when the user completes a rotate gesture. If you only care about the end results of the rotate gesture, you can simply watch for this event; however, if you want to provide feedback during the handling of the gesture, you should also watch the <code>MozRotateGestureStart</code> and <code>MozRotateGestureUpdate</code> events.</p>
<p>The <code>delta</code> value is the cumulative change over the course of handling the entire sequence of rotate gesture events.</p>
<h2 id="Event_fields">Event fields</h2>
<p>Mouse gesture events have additional fields providing information about the gesture. These are:</p>
<dl> <dt><code>direction</code></dt> <dd>The direction in which the swipe moved.</dd> <dt><code>delta</code></dt> <dd>The amount by which the gesture moved; for rotation, this value is in degrees. Positive values are clockwise and negative values are counterclockwise. For magnification, this value is implementation-specific, but the value is positive for zooming in and negative for zooming out.</dd>
</dl>
<h2 id="Direction_constants">Direction constants</h2>
<p>The direction field in the gesture events can take one of the following values:</p>
<dl> <dt><code>SimpleGestureEvent.DIRECTION_LEFT</code></dt> <dd>Leftward swipe.</dd> <dt><code>SimpleGestureEvent.DIRECTION_RIGHT</code></dt> <dd>Rightward swipe.</dd> <dt><code>SimpleGestureEvent.DIRECTION_UP</code></dt> <dd>Upward swipe.</dd> <dt><code>SimpleGestureEvent.DIRECTION_DOWN</code></dt> <dd>Downward swipe.</dd> <dt><code>SimpleGestureEvent.ROTATION_COUNTERCLOCKWISE</code></dt> <dd>Counter-clockwise rotation.</dd> <dt><code>SimpleGestureEvent.ROTATION_CLOCKWISE</code></dt> <dd>Clockwise rotation.</dd>
</dl>
<h2 id="See_also">See also</h2>
<ul> <li><a class="internal" href="/en/DOM/event" title="En/DOM/Event"><code>event</code></a></li> <li>Other <a href="/en/Gecko-Specific_DOM_Events" title="en/Gecko-Specific_DOM_Events">Gecko-Specific DOM Events</a></li> <li>{{ interface("nsIDOMSimpleGestureEvent") }}</li>
</ul>
Revert to this revision