-
Notifications
You must be signed in to change notification settings - Fork 161
Add PointerEvent and related event handlers. #317
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 3 commits
5283d61
34aa7c4
099013f
621e15c
ae4d798
950e9c1
d3b6a46
1077dee
2f84610
220c0ee
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -1443,6 +1443,107 @@ class MouseEvent extends UIEvent with ModifierKeyEvent { | |
def getModifierState(keyArg: String): Boolean = js.native | ||
} | ||
|
||
/** | ||
* Most of today's web content assumes the user's pointing device will be a mouse. | ||
* However, since many devices support other types of pointing input devices, | ||
* such as pen/stylus and touch surfaces, extensions to the existing pointing device event models | ||
* are needed and pointer events address that need. | ||
* | ||
* Pointer events are DOM events that are fired for a pointing device. | ||
* They are designed to create a single DOM event model to handle pointing input devices such as a mouse, | ||
* pen/stylus or touch (such as one or more fingers). | ||
* The pointer is a hardware-agnostic device that can target a specific set of screen coordinates. | ||
* Having a single event model for pointers can simplify creating Web sites and applications | ||
* and provide a good user experience regardless of the user's hardware. | ||
* However, for scenarios when device-specific handling is desired, | ||
* pointer events defines a property to inspect the device type which produced the event. | ||
* | ||
* The events needed to handle generic pointer input are analogous to mouse events | ||
* (mousedown/pointerdown, mousemove/pointermove, etc.). | ||
* Consequently, pointer event types are intentionally similar to mouse event types. | ||
* Additionally, a pointer event contains the usual properties present in mouse events | ||
* (client coordinates, target element, button states, etc.) | ||
* in addition to new properties for other forms of input: pressure, contact geometry, tilt, etc. | ||
* In fact, the PointerEvent interface inherits all of the MouseEvent's properties thus facilitating | ||
* migrating content from mouse events to pointer events. | ||
*/ | ||
@js.native | ||
@JSGlobal | ||
class PointerEvent extends MouseEvent { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The constructor should take a
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I added the necessary Init trait and constructor parameters. |
||
|
||
/** | ||
* A unique identifier for the pointer causing the event. | ||
* | ||
* MDN | ||
*/ | ||
def pointerId: Int = js.native | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. https://www.w3.org/TR/pointerevents/#pointerevent-interface says that There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I changed it accordingly. |
||
|
||
/** | ||
* The width (magnitude on the X axis), in CSS pixels, of the contact geometry of the pointer. | ||
* | ||
* MDN | ||
*/ | ||
def width: Double = js.native | ||
|
||
/** | ||
* The height (magnitude on the Y axis), in CSS pixels, of the contact geometry of the pointer. | ||
* | ||
* MDN | ||
*/ | ||
def height: Double = js.native | ||
|
||
/** | ||
* The normalized pressure of the pointer input in the range of 0 to 1, | ||
* where 0 and 1 represent the minimum and maximum pressure the hardware is capable of detecting, respectively. | ||
* | ||
* MDN | ||
*/ | ||
def pressure: Double = js.native | ||
|
||
/** | ||
* The plane angle (in degrees, in the range of -90 to 90) between the Y-Z plane and the | ||
* plane containing both the transducer (e.g. pen stylus) axis and the Y axis. | ||
* | ||
* MDN | ||
*/ | ||
def tiltX: Double = js.native | ||
|
||
/** | ||
* The plane angle (in degrees, in the range of -90 to 90) between the X-Z plane and the | ||
* plane containing both the transducer (e.g. pen stylus) axis and the X axis. | ||
* | ||
* MDN | ||
*/ | ||
def tiltY: Double = js.native | ||
|
||
/** | ||
* Indicates the device type that caused the event (mouse, pen, touch, etc.) | ||
* | ||
* MDN | ||
*/ | ||
def pointerType: String = js.native | ||
|
||
/** | ||
* Indicates if the pointer represents the primary pointer of this pointer type. | ||
* | ||
* In some scenarios there may be multiple pointers (for example a device with both a touchscreen and a mouse) | ||
* or a pointer supports multiple contact points (for example a touchscreen that supports multiple finger touches). | ||
* The application can use the isPrimary property to identify a master pointer | ||
* among the set of active pointers for each pointer type. | ||
* If an application only wants to support a primary pointer, | ||
* it can ignore all pointer events that are not primary. | ||
* | ||
* For mouse there is only one pointer, so it will always be the primary pointer. | ||
* For touch input, a pointer is considered primary if the user touched the screen | ||
* when there were no other active touches. | ||
* For pen and stylus input, a pointer is considered primary if the user's pen | ||
* initially contacted the screenwhen there were no other active pens contacting the screen. | ||
* | ||
* MDN | ||
*/ | ||
def isPrimary: Boolean = js.native | ||
} | ||
|
||
/** | ||
* The TextMetrics interface represents the dimension of a text in the canvas, as | ||
* created by the CanvasRenderingContext2D.measureText() method. | ||
|
@@ -2374,6 +2475,84 @@ class Window | |
* MDN | ||
*/ | ||
def devicePixelRatio: Double = js.native | ||
|
||
/** | ||
* fired when a pointing device is moved into an element's hit test boundaries. | ||
* | ||
* MDN | ||
*/ | ||
var onpointerover: js.Function1[PointerEvent, _] = js.native | ||
|
||
/** | ||
* fired when a pointing device is moved into the hit test boundaries of an element | ||
* or one of its descendants, including as a result of a pointerdown event | ||
* from a device that does not support hover (see pointerdown). | ||
* | ||
* MDN | ||
*/ | ||
var onpointerenter: js.Function1[PointerEvent, _] = js.native | ||
|
||
/** | ||
* fired when a pointer becomes active. | ||
* | ||
* MDN | ||
*/ | ||
var onpointerdown: js.Function1[PointerEvent, _] = js.native | ||
|
||
/** | ||
* fired when a pointer changes coordinates. | ||
* | ||
* MDN | ||
*/ | ||
var onpointermove: js.Function1[PointerEvent, _] = js.native | ||
|
||
/** | ||
* fired when a pointer is no longer active. | ||
* | ||
* MDN | ||
*/ | ||
var onpointerup: js.Function1[PointerEvent, _] = js.native | ||
|
||
/** | ||
* a browser fires this event if it concludes the pointer will no longer be able | ||
* to generate events (for example the related device is deactived). | ||
* | ||
* MDN | ||
*/ | ||
var onpointercancel: js.Function1[PointerEvent, _] = js.native | ||
|
||
/** | ||
* fired for several reasons including: pointing device is moved out of | ||
* the hit test boundaries of an element; | ||
* firing the pointerup event for a device that does not support hover (see pointerup); | ||
* after firing the pointercancel event (see pointercancel); | ||
* when a pen stylus leaves the hover range detectable by the digitizer. | ||
* | ||
* MDN | ||
*/ | ||
var onpointerout: js.Function1[PointerEvent, _] = js.native | ||
|
||
/** | ||
* fired when a pointing device is moved out of the hit test boundaries of an element. | ||
* For pen devices, this event is fired when the stylus leaves the hover range detectable by the digitizer. | ||
* | ||
* MDN | ||
*/ | ||
var onpointerleave: js.Function1[PointerEvent, _] = js.native | ||
|
||
/** | ||
* fired when an element receives pointer capture. | ||
* | ||
* MDN | ||
*/ | ||
var gotpointercapture: js.Function1[PointerEvent, _] = js.native | ||
|
||
/** | ||
* Fired after pointer capture is released for a pointer. | ||
* | ||
* MDN | ||
*/ | ||
var lostpointercapture: js.Function1[PointerEvent, _] = js.native | ||
} | ||
|
||
/** | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could you confirm that you are the original author of this documentation text?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It is the documentation found on MDN. I added credit below (that must have slipped through).
MDN documents are licensed under the Creative Commons license found here: https://github.com/mdn/mdn/blob/master/LICENSE