Nokia hereby grants to the W3C a perpetual, nonexclusive, royalty-free, world-wide right and license under any Nokia copyrights on this contribution, to copy, publish and distribute the contribution under the W3C document licenses.
Additionally, should the submission be used as a contribution towards a W3C Activity, Nokia grants a right and license of the same scope to any derivative works prepared by the W3C and based on, or incorporating all or part of, the contribution. Nokia further agrees that any derivative works of this contribution prepared by the W3C shall be solely owned by the W3C.
Nokia Corporation agrees to offer W3C members and non-members granting reciprocal terms a non-assignable, non-sublicensable, worldwide and royalty free license to make, have made, use, sell, have sold, offer to sell, import, and distribute and dispose of implementations of any portion of the submission that is subsequently incorporated into a W3C Recommendation. Such license shall extend to all Essential Claims owned or controlled by Nokia Corporation and shall be available as long as the Recommendation is in effect.
Touch screens with directly manipulated user interface have become mainstream in portable devices. Current web technology is specified for mouse use and implementation of direct manipulation is kludgy and non portable at best.
This document describes three new event types to enable direct manipulation of a DOM element. Typically these events are generated as the user does an action or gesture such as "pan", "zoom", or "rotate" requesting transformation of a visual element. As the gestures and actions to transform a visual element vary from device to device, this proposal abstracts them out and provides interface to the actual action the end user is attempting to do.
Example 1.
A box that can be dragged, rotated, and scaled on the screen.
<html> <head> <style> #box { position: absolute; border: 3px solid black; width: 200px; height: 200px; left: 200px; top: 100px; } </style> </head> <body> <div id="box" ontransformactionstart="transformStart(event);" ontransformactionupdate="transformUpdate(event);" ontransformactionend="transformEnd(event);"></div> <script> // Initialize the current transform values var curX = 0; var curY = 0; var curRotation = 0; var curScalefactor = 1.0; var box = document.getElementById("box"); function transformStart(e) { // Prevent browser zoom e.preventDefault(); } function transformUpdate(e) { // Set the new transform box.style.transform = "translate(" + (curX + e.translateX) + "px, " + (curY + e.translateY) + "px) " + "rotate(" + (curRotation + e.rotate) + "rad) " + "scale(" + (curScalefactor * e.scale) + ") "; } function transformEnd(e) { // Update the current transform values curX += e.translateX; curY += e.translateY; curRotation += e.rotate; curScalefactor *= e.scale; } </script> </body> </html>
No security or privacy issues identified.
The following events are defined in this specification
Name | Description | How often? | When? |
transformactionstart | The new transform action starts. | Once | Must be dispatched first. |
transformactionupdate | The transform action continues. | Zero or more | May be dispatched zero or more times after a transformactionstart . |
transformactionend | The transform action ends. | Once | Must be dispatched last. |
User agents must implement these events such that by default they do bubble, and are cancelable.
User agents must ensure that these events trigger event listeners attached on the element nodes for that event on the capture and target phases.
Default action for these events is implementation specific (for example, adjustment of the user agent zoom level.)
These events are in the null namespace. Initialisation method assigns the null namespace automatically.
In the transformactionstart
event, attributes rotate
, translateX
, translateY
, rotateSpeed
, scaleSpeed
, translateSpeedX
, and translateSpeedY
must always have the value zero and attribute scale
must always have the value one.
The user agent must dispatch a transformactionstart
event when the user starts the interaction (for example, touches the screen).
The user agent must dispatch one or more transformactionupdate
events
when the user continues the interaction (for example, moves finger(s) on the touch screen).
When the user end the interfaction (for example, stops touching the screen), the user agent must
dispatch a transformactionend
event.
In short, for the DOM element in question, there must one transformactionstart
event, followed
by zero or more transformactionupdate
, followed by one transformactionend
event.
The user agent must dispatch all transformaction events immediately after related lower level events if such lower level event exists. For example, if the source of transformaction events is a touch screen, the transformaction events must be dispatched immediately after the touch events.
The TransformAction
interface exposes the information in transformactionstart
, transformactionupdate
, and transformactionend
events.
[Supplemental]
interface TransformActionEvent : UIEvent {
readonly attribute long screenX;
readonly attribute long screenY;
readonly attribute long offsetX;
readonly attribute long offsetY;
readonly attribute long clientX;
readonly attribute long clientY;
readonly attribute boolean ctrlKey;
readonly attribute boolean shiftKey;
readonly attribute boolean altKey;
readonly attribute boolean metaKey;
readonly attribute long translateX;
readonly attribute long translateY;
readonly attribute long translateSpeedX;
readonly attribute long translateSpeedY;
readonly attribute float scale;
readonly attribute float scaleSpeed;
readonly attribute float rotate;
readonly attribute float rotateSpeed;
void initTransformActionEvent (in DOMString type, in boolean canBubble, in boolean cancelable, in DOMWindow view, in long screenX, in long screenY, in long clientX, in long clientY, in boolean ctrlKey, in boolean altKey, in boolean shiftKey, in boolean metaKey, in long translateX, in long translateY, in long translateSpeedX, in long translateSpeedY, in float scale, in float scaleSpeed, in float rotate, in float rotateSpeed); };
altKey
of type boolean, readonlyclientX
of type long, readonlyclientY
of type long, readonlyctrlKey
of type boolean, readonlymetaKey
of type boolean, readonlyoffsetX
of type long, readonlyoffsetY
of type long, readonlyrotate
of type float, readonlyRotation angle in radians, increasing angle meaning rotation clockwise.
If just a single finger touches the screen, rotation is 0.
rotateSpeed
of type
float,
readonlyscale
of type float, readonlyScale factor, between 0 and 1.0 for scale down, greater than 1.0 for scale up.
For example 2.5 when the distance of touch points has increased 2.5-fold, i.e. element should be scaled 2.5 times its original size.
If just a single finger touches the screen, scale is 1.0.
scaleSpeed
of type
float, readonlyscreenX
of type long, readonlyscreenY
of type long, readonlyshiftKey
of type boolean, readonlytranslateSpeedX
of type long,
readonlytranslateSpeedY
of type long,
readonlytranslateX
of type
long, readonlyThe horizontal coordinate in client coordinate space that indicates the panning of the element. Translation coordinates are activated even with a single finger.
Translation coordinates are always relative to the start of the touch. Thus there is no need to calculate absolute offsets of elements on the page when moving an element. Translation values can only be added to the starting position of an element.
translateY
of type
long, readonlyThe vertical coordinate in client coordinate space that indicates the panning of the element. Translation coordinates are activated even with a single finger.
Translation coordinates are always relative to the start of the touch. Thus there is no need to calculate absolute offsets of elements on the page when moving an element. Translation values can only be added to the starting position of an element.
initTransformActionEvent
This method is used to initialize the value of a TransformActionEvent object and has the same behavior as Event.initEventNS(), where the value of the namespace parameter is specified as null [D3E].
Parameter | Type | Nullable | Optional | Description |
---|---|---|---|---|
type | DOMString | ? | ? | This must be one of transformactionstart , transformactionupdate , or transformactionend . If it is not one of those values then this specification does not define the resulting event. Refer to the Event.initEvent() method [D3E] for further description of this parameter. |
canBubble | boolean | ? | ? | Specifies Event.bubbles. This parameter overrides the intrinsic bubbling behavior of the event and determines whether the event created will bubble |
cancelable | boolean | ? | ? | Specifies Event.cancelable. This parameter overrides the intrinsic cancel behavior of the event and determines whether the event created is cancelable |
view | DOMWindow | ? | ? | Specifies the DOM window in which the event occurred. |
screenX | long | ? | ? | The horizontal coordinate at which the event occurred relative to the origin of the screen. |
screenY | long | ? | ? | The vertical coordinate at which the event occurred relative to the origin of the screen. |
clientX | long | ? | ? | The horizontal coordinate at which the event occurred relative to the origin of the viewport. |
clientY | long | ? | ? | The vertical coordinate at which the event occurred relative to the origin of the viewport. |
ctrlKey | boolean | ? | ? | Status of the control key during the event. |
altKey | boolean | ? | ? | Status of the shift key during the event. |
shiftKey | boolean | ? | ? | Status of the alt key during the event. |
metaKey | boolean | ? | ? | Status of the meta key during the event. |
translateX | long | ? | ? | The horizontal coordinate in client coordinate space that indicates the panning of the element. |
translateY | long | ? | ? | The vertical coordinate in client coordinate space that indicates the panning of the element. |
translateSpeedX | long | ? | ? | The horizontal panning speed in pixels per seconds in client coordinate space. The user agent should use best effort to approximate the speed. |
translateSpeedY | long | ? | ? | The vertical panning speed in pixels per seconds in client coordinate space. The user agent should use best effort to approximate the speed. |
scale | float | ? | ? | Scale factor, between 0 and 1.0 for scale down, greater than 1.0 scale up. For example 2.5 when the distance of touch points has increased 2.5-fold, i.e. element should be scaled 2.5 times its original size. |
scaleSpeed | float | ? | ? | Speed of scaling in normalized scale factor change per second. The user agent should use best effort to approximate the speed. |
rotate | float | ? | ? | Rotation angle in radians, increasing angle meaning rotation clockwise. |
rotateSpeed | float | ? | ? | Rotation speed in radians per second. The user agent should use best effort to approximate the speed. |
void
No normative references.
No informative references.