Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(118)

Side by Side Diff: sky/specs/pointer.md

Issue 872993007: Specs: dartification of pointer and wheel events (Closed) Base URL: https://github.com/domokit/mojo.git@master
Patch Set: Created 5 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « sky/specs/events.md ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 Pointer Events 1 Pointer Events
2 ============== 2 ==============
3 3
4 Scope 4 Scope
5 ----- 5 -----
6 6
7 The following input devices are supported by sky: 7 The following input devices are supported by sky:
8 - fingers on multitouch screens 8 - fingers on multitouch screens
9 - mice, including mouse wheels 9 - mice, including mouse wheels
10 - styluses on screens 10 - styluses on screens
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
52 52
53 Pointers 53 Pointers
54 -------- 54 --------
55 55
56 Each touch or pointer is tracked individually. 56 Each touch or pointer is tracked individually.
57 57
58 New touches and pointers can appear and disappear over time. 58 New touches and pointers can appear and disappear over time.
59 59
60 Each pointer has a list of current targets. 60 Each pointer has a list of current targets.
61 61
62 When a new one enters the system, a non-bubbling 'pointer-added' event 62 When a new one enters the system, a non-bubbling ``PointerAddedEvent``
63 is fired at the application's document, and the pointer's current 63 event is fired at the application's document, and the pointer's
64 targets list is initialised to just that Document object. 64 current targets list is initialised to just that Document object.
65 65
66 When it is removed, a non-bubbling 'pointer-removed' event is fired at 66 When it is removed, a non-bubbling ``PointerRemovedEvent`` event is
67 the application's document and at any other objects in the pointer's 67 fired at the application's document and at any other objects in the
68 current targets list. Currently, at the time of a pointer-removed, the 68 pointer's current targets list. Currently, at the time of a
69 list will always consist of only the document. 69 ``PointerRemoved``, the list will always consist of only the document.
70 70
71 A pointer can be "up" or "down". Initially all pointers are "up". 71 A pointer can be "up" or "down". Initially all pointers are "up".
72 72
73 A pointer switches from "up" to "down" when it is a touch or stylus 73 A pointer switches from "up" to "down" when it is a touch or stylus
74 that is in contact with the display surface, or when it is a mouse 74 that is in contact with the display surface, or when it is a mouse
75 that is being clicked, and from "down" back to "up" when this ends. 75 that is being clicked, and from "down" back to "up" when this ends.
76 (Note that clicking a button on a stylus doesn't change it from up to 76 (Note that clicking a button on a stylus doesn't change it from up to
77 down. A stylus can have a button pressed while "up".) In the case of a 77 down. A stylus can have a button pressed while "up".) In the case of a
78 mouse with multiple buttons, the pointer switches back to "up" only 78 mouse with multiple buttons, the pointer switches back to "up" only
79 when all the buttons have been released. 79 when all the buttons have been released.
80 80
81 When a pointer switches from "up" to "down", the following algorithm 81 When a pointer switches from "up" to "down", the following algorithm
82 is run: 82 is run:
83 83
84 1. Hit test the position of the pointer, let 'node' be the result. 84 1. Hit test the position of the pointer, let 'node' be the result.
85 2. Fire a bubbling pointer-down event at the layoutManager for 85 2. Fire a bubbling ``PointerDownEvent`` event at the layoutManager
86 'node', with an empty array as the default return value. Let 86 for 'node', with an empty array as the default return value. Let
87 'result1' be the returned value. 87 'result1' be the returned value.
88 3. If result1 is not an array of EventTarget objects, set it to the 88 3. If result1 is not an array of EventTarget objects, set it to the
89 empty array and (if this is debug mode) report the issue. 89 empty array and (if this is debug mode) report the issue.
90 4. Fire a bubbling pointer-down event at the Element for 'node', with 90 4. Fire a bubbling ``PointerDownEvent`` event at the Element for
91 an empty array as the default return value. Let 'result2' be the 91 'node', with an empty array as the default return value. Let
92 returned value. 92 'result2' be the returned value.
93 5. If result2 is not an array of EventTarget objects, set it to the 93 5. If result2 is not an array of EventTarget objects, set it to the
94 empty array and (if this is debug mode) report the issue. 94 empty array and (if this is debug mode) report the issue.
95 6. Let result be the concatenation of result1's contents, result2's 95 6. Let result be the concatenation of result1's contents, result2's
96 contents, and the application document. 96 contents, and the application document.
97 7. Let 'result' be this pointer's current targets. 97 7. Let 'result' be this pointer's current targets.
98 98
99 When an object is one of the current targets of a pointer and no other 99 When an object is one of the current targets of a pointer and no other
100 pointers have that object as a current target so far, and either there 100 pointers have that object as a current target so far, and either there
101 are no buttons (touch, stylus) or only the primary button is active 101 are no buttons (touch, stylus) or only the primary button is active
102 (mouse) and this is not an inverted stylus, then that pointer is 102 (mouse) and this is not an inverted stylus, then that pointer is
103 considered the "primary" pointer for that object. The pointer remains 103 considered the "primary" pointer for that object. The pointer remains
104 the primary pointer for that object until the corresponding pointer-up 104 the primary pointer for that object until the corresponding
105 event (even if the buttons change). 105 ``PointerUpEvent`` event (even if the buttons change).
106 106
107 When a pointer moves, a non-bubbling 'pointer-move' event is fired at 107 When a pointer moves, a non-bubbling ``PointerMoveEvent`` event is
108 each of the pointer's current targets in turn (maintaining the order 108 fired at each of the pointer's current targets in turn (maintaining
109 they had in the 'pointer-down' event, if there's more than one). If 109 the order they had in the ``PointerDownEvent`` event, if there's more
110 the return value of a 'pointer-moved' event is 'cancel', and the 110 than one). If the return value of a ``PointerMovedEvent`` event is
111 pointer is currently down, then the pointer is canceled (see below). 111 'cancel', and the pointer is currently down, then the pointer is
112 canceled (see below).
112 113
113 When a pointer's button state changes but this doesn't impact whether 114 When a pointer's button state changes but this doesn't impact whether
114 it is "up" or "down", e.g. when a mouse with a button down gets a 115 it is "up" or "down", e.g. when a mouse with a button down gets a
115 second button down, or when a stylus' buttons change state, but the 116 second button down, or when a stylus' buttons change state, but the
116 pointer doesn't simultaneously move, then a 'pointer-moved' event is 117 pointer doesn't simultaneously move, then a ``PointerMovedEvent``
117 fired anyway, as described above, but with dx=dy=0. 118 event is fired anyway, as described above, but with dx=dy=0.
118 119
119 When a pointer switches from "down" to "up", a non-bubbling 120 When a pointer switches from "down" to "up", a non-bubbling
120 'pointer-up' event is fired at each of the pointer's current targets 121 ``PointerUpEvent`` event is fired at each of the pointer's current
121 in turn (maintaining the order they had in the 'pointer-down' event, 122 targets in turn (maintaining the order they had in the
122 if there's more than one), and then the pointer's current target list 123 ``PointerDownEvent`` event, if there's more than one), and then the
123 is emptied except for the application's document. The buttons exposed 124 pointer's current target list is emptied except for the application's
124 on the 'pointer-up' event are those that were down immediately prior 125 document. The buttons exposed on the ``PointerUpEvent`` event are
125 to the buttons being released. 126 those that were down immediately prior to the buttons being released.
126 127
127 At the time of a 'pointer-up' event, for each object that is a current 128 At the time of a ``PointerUpEvent`` event, for each object that is a
128 target of the pointer, and for which the pointer is considered the 129 current target of the pointer, and for which the pointer is considered
129 "primary" pointer for that object, if there is another pointer that is 130 the "primary" pointer for that object, if there is another pointer
130 already down, which is of the same kind, which also has that object as 131 that is already down, which is of the same kind, which also has that
131 a current target, and that has either no buttons or only its primary 132 object as a current target, and that has either no buttons or only its
132 button active, then that pointer becomes the new "primary" pointer for 133 primary button active, then that pointer becomes the new "primary"
133 that object before the 'pointer-up' event is sent. Otherwise, the 134 pointer for that object before the ``PointerUpEvent`` event is sent.
134 "primary" pointer stops being "primary" just _after_ the 'pointer-up' 135 Otherwise, the "primary" pointer stops being "primary" just _after_
135 event. (This matters for whether the 'primary' field is set.) 136 the ``PointerUpEvent`` event. (This matters for whether the 'primary'
137 field is set.)
136 138
137 When a pointer is canceled, if it is "down", pretend that the pointer 139 When a pointer is canceled, if it is "down", pretend that the pointer
138 moved to "up", sending 'pointer-up' as described above, and entirely 140 moved to "up", sending ``PointerUpEvent`` as described above, and
139 empty its current targets list. AFter the pointer actually switches 141 entirely empty its current targets list. AFter the pointer actually
140 from "down" to "up", replace the current targets list with an object 142 switches from "down" to "up", replace the current targets list with an
141 that only contains the application's document. 143 object that only contains the application's document.
142 144
143 Nothing special happens when a pointer's current target moves in the 145 Nothing special happens when a pointer's current target moves in the
144 DOM. 146 DOM.
145 147
146 The x and y position of an -up or -down event always match those of 148 The x and y position of an -up or -down event always match those of
147 the previous -moved or -added event, so their dx and dy are always 0. 149 the previous -moved or -added event, so their dx and dy are always 0.
148 150
149 Positions are floating point numbers; they can have subpixel values. 151 Positions are floating point numbers; they can have subpixel values.
150 152
151 For each pointer, only a single pointer-added or pointer-removed event 153 For each pointer, only a single ``PointerAddedEvent`` or
152 is fired per frame. If a pointer would have been added and removed in 154 ``PointerRemovedEvent`` event is fired per frame. If a pointer would
153 the same frame, the pointer is ignored, and no events are fired for 155 have been added and removed in the same frame, the pointer is ignored,
154 that pointer. 156 and no events are fired for that pointer.
155 157
156 For each pointer, only a single pointer-down or pointer-up event is 158 For each pointer, only a single ``PointerDownEvent`` or
157 fired per frame, representing the change in state from the last frame, 159 ``PointerUpEvent`` event is fired per frame, representing the change
158 if any. Exactly when the event is fired is up to the implementation 160 in state from the last frame, if any. Exactly when the event is fired
159 and may depend on the hardware. 161 is up to the implementation and may depend on the hardware.
160 162
161 For each pointer, at most two pointer-move events are fired per frame, 163 For each pointer, at most two ``PointerMoveEvent`` events are fired
162 one before the pointer-down or pointer-up event, if any, and one 164 per frame, one before the ``PointerDownEvent`` or ``PointerUpEvent``
163 after. If the pointer didn't change "down" state, then only one 165 event, if any, and one after. If the pointer didn't change "down"
164 pointer-move event is fired. All the actual moves that the pointer 166 state, then only one ``PointerMoveEvent`` event is fired. All the
165 experienced are coallesced into the event. 167 actual moves that the pointer experienced are coallesced into the
168 event.
166 169
167 Example: 170 Example:
168 If a mouse experiences the following events: 171 If a mouse experiences the following events:
169 - move +1, down, move +2, up, move +4, down, move +8 172 - move +1, down, move +2, up, move +4, down, move +8
170 ...the events might be: 173 ...the events might be:
171 - move +7, down, move +8 174 - move +7, down, move +8
172 ...or: 175 ...or:
173 - move +1, down, move +14 176 - move +1, down, move +14
174 177
175 TODO(ianh): expose the unfiltered uncoalesced stream of events for 178 TODO(ianh): expose the unfiltered uncoalesced stream of events for
176 programs that want more precision (e.g. drawing apps) 179 programs that want more precision (e.g. drawing apps)
177 180
178 181
179 These data of all these events is an object with the following fields: 182 These events have the following fields (see below for the class
183 definitions):
180 184
181 pointer: an integer assigned to this touch or pointer when it 185 pointer: an integer assigned to this touch or pointer when it
182 enters the system, never reused, increasing 186 enters the system, never reused, increasing
183 monotonically every time a new value is assigned, 187 monotonically every time a new value is assigned,
184 starting from 1 (if the system gets a new tap every 188 starting from 1 (if the system gets a new tap every
185 microsecond, this will cause a problem after 285 189 microsecond, this will cause a problem after 285
186 years) 190 years)
187 191
188 kind: one of 'touch', 'mouse', 'stylus', 'inverted-stylus' 192 kind: one of 'touch', 'mouse', 'stylus', 'inverted-stylus'
189 193
190 x: x-position relative to the top-left corner of the 194 x: x-position relative to the top-left corner of the
191 surface of the node on which the event was fired 195 surface of the node on which the event was fired
192 196
193 y: y-position relative to the top-left corner of the 197 y: y-position relative to the top-left corner of the
194 surface of the node on which the event was fired 198 surface of the node on which the event was fired
195 199
196 dx: difference in x-position since last pointer-moved 200 dx: difference in x-position since last
197 event 201 ``PointerMovedEvent`` event
198 202
199 dy: difference in y-position since last pointer-moved 203 dy: difference in y-position since last
200 event 204 ``PointerMovedEvent`` event
201 205
202 buttons: a bitfield of the buttons pressed, from the following 206 buttons: a bitfield of the buttons pressed, from the following
203 list: 207 list:
204 208
205 1: primary mouse button (not available on stylus) 209 1: primary mouse button (not available on stylus)
206 210
207 2: secondary mouse button, primary stylus button 211 2: secondary mouse button, primary stylus button
208 212
209 3: middle mouse button, secondary stylus button 213 3: middle mouse button, secondary stylus button
210 214
(...skipping 12 matching lines...) Expand all
223 227
224 note that stylus buttons can be pressed even when the 228 note that stylus buttons can be pressed even when the
225 pointer is not "down" 229 pointer is not "down"
226 230
227 e.g. if the left mouse button and the right mouse 231 e.g. if the left mouse button and the right mouse
228 button are pressed at the same time, the value will 232 button are pressed at the same time, the value will
229 be 3 (bits 1 and 2); if the right mouse button and 233 be 3 (bits 1 and 2); if the right mouse button and
230 the back button are pressed at the same time, the 234 the back button are pressed at the same time, the
231 value will be 10 (bits 2 and 4) 235 value will be 10 (bits 2 and 4)
232 236
233 down: true if the pointer is down (in pointer-down event or 237 down: true if the pointer is down (in ``PointerDownEvent``
234 subsequent pointer-move events); false otherwise (in 238 event or subsequent ``PointerMoveEvent`` events);
235 pointer-added, pointer-up, and pointer-removed 239 false otherwise (in ``PointerAdded``, ``PointerUp``,
236 events, and in pointer-move events that aren't 240 and ``PointerRemovedEvent`` events, and in
237 between pointer-down and pointer-up events) 241 ``PointerMoveEvent`` events that aren't between
242 ``PointerDownEvent`` and ``PointerUpEvent`` events)
238 243
239 primary: true if this is a primary pointer/touch (see above) 244 primary: true if this is a primary pointer/touch (see above)
240 can only be set for pointer-moved and pointer-up 245 can only be set for ``PointerMovedEvent`` and
246 ``PointerUpEvent``
241 247
242 obscured: true if the system was rendering another view on top 248 obscured: true if the system was rendering another view on top
243 of the sky application at the time of the event (this 249 of the sky application at the time of the event (this
244 is intended to enable click-jacking protections) 250 is intended to enable click-jacking protections)
245 251
246 252
247 When down is true: 253 When down is true:
248 254
249 pressure: the pressure of the touch as a number ranging from 255 pressure: the pressure of the touch as a number ranging from
250 0.0, indicating a touch with no discernible pressure, 256 0.0, indicating a touch with no discernible pressure,
(...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after
326 ...giving the angle of the axis of the stylus, 332 ...giving the angle of the axis of the stylus,
327 relative to the axis perpendicular to the screen 333 relative to the axis perpendicular to the screen
328 (thus 0 indicates the stylus is orthogonal to the 334 (thus 0 indicates the stylus is orthogonal to the
329 plane of the screen, while pi/2 indicates that the 335 plane of the screen, while pi/2 indicates that the
330 stylus is flat on the screen) 336 stylus is flat on the screen)
331 337
332 338
333 TODO(ianh): add an API that exposes the currently existing pointers, 339 TODO(ianh): add an API that exposes the currently existing pointers,
334 so that you can determine e.g. if you have a mouse. 340 so that you can determine e.g. if you have a mouse.
335 341
342 Here are the class definitions for pointer events:
336 343
344 ```dart
345 enum PointerKind { touch, mouse, stylus, invertedStylus }
346
347 abstract class PointerEvent extends Event {
348 PointerEvent({ bool bubbles,
349 this.pointer,
350 this.kind,
351 this.x, this.y,
352 this.dx: 0.0, this.dy: 0.0,
353 this.buttons: 0,
354 this.down: false,
355 this.primary: false,
356 this.obscured: false,
357 this.pressure, this.minPressure, this.maxPressure,
358 this.distance, this.minDistance, this.maxDistance,
359 this.radiusMajor, this.radiusMinor, this.minRadius, this.maxRad ius,
360 this.orientation, this.tilt
361 }): super(bubbles: bubbles);
362
363 final int pointer;
364 final PointerKind kind;
365 final double x; // logical pixels
366 final double y; // logical pixels
367 final double dx; // logical pixels
368 final double dy; // logical pixels
369
370 final int buttons; // bit field
371 static const int primaryMouseButton = 0x01;
372 static const int secondaryMouseButton = 0x02;
373 static const int primaryStylusButton = 0x02;
374 static const int middleMouseButton = 0x04;
375 static const int secondaryStylusButton = 0x04;
376 static const int backButton = 0x08;
377 static const int forwardButton = 0x10;
378
379 final bool down;
380 final bool primary;
381 final bool obscured;
382
383 // if down != true, these are all null
384 final double pressure; // normalised, 0.0 means none, 1.0 means "normal"
385 final double minPressure; // 0 <= minPressure <= 1.0
386 final double maxPressure; // maxPressure >= 1.0
387
388 // if kind != touch, stylus, or invertedStylus, these are all null
389 final double distance; // logical pixels
390 final double minDistance; // logical pixels
391 final double maxDistance; // logical pixels
392
393 // if down != true or kind != touch, stylus, or invertedStylus, these are all null
394 final double radiusMajor; // logical pixels
395 final double radiusMinor; // logical pixels
396 final double minRadius; // logical pixels
397 final double maxRadius; // logical pixels
398
399 // if down != true or kind != touch, stylus, or invertedStylus, this is null
400 final double orientation; // radians // meaning is different for touch and sty lus/invertedStylus
401
402 // if kind != stylus or invertedStylus, this is null
403 final double tilt; // radians
404 }
405
406 // the following uses proposed syntax from
407 // https://code.google.com/p/dart/issues/detail?id=22274
408 // to avoid duplicating that entire constructor up there
409
410 class PointerAddedEvent extends Event {
411 PointerAddedEvent = PointerEvent;
412 }
413
414 class PointerRemovedEvent extends Event {
415 PointerRemovedEvent = PointerEvent;
416 }
417
418 class PointerDownEvent extends Event {
419 PointerDownEvent = PointerEvent;
420 }
421
422 class PointerUpEvent extends Event {
423 PointerUpEvent = PointerEvent;
424 }
425
426 class PointerMovedEvent extends Event {
427 PointerMovedEvent = PointerEvent;
428 }
429 ```
337 430
338 Wheel events 431 Wheel events
339 ------------ 432 ------------
340 433
341 When a wheel input device is turned, a 'wheel' event that bubbles is 434 When a wheel input device is turned, a ``WheelEvent`` event that
342 fired at the application's document, with the following fields: 435 bubbles is fired at the application's document, with the following
436 fields:
343 437
344 wheel: an integer assigned to this wheel by the system. The 438 wheel: an integer assigned to this wheel by the system. The
345 same wheel on the same system must always be given 439 same wheel on the same system must always be given
346 the same ID. The primary wheel (e.g. the vertical 440 the same ID. The primary wheel (e.g. the vertical
347 wheel on a mouse) must be given ID 1. 441 wheel on a mouse) must be given ID 1.
348 442
349 delta: an floating point number representing the fraction of 443 delta: an floating point number representing the fraction of
350 the wheel that was turned, with positive numbers 444 the wheel that was turned, with positive numbers
351 representing a downward movement on vertical wheels, 445 representing a downward movement on vertical wheels,
352 rightward movement on horizontal wheels, and a 446 rightward movement on horizontal wheels, and a
353 clockwise movement on wheels with a user-facing side. 447 clockwise movement on wheels with a user-facing side.
354 448
355 Additionally, if the wheel is associated with a pointer (e.g. a mouse 449 Additionally, if the wheel is associated with a pointer (e.g. a mouse
356 wheel), the following fields must be present also: 450 wheel), the following fields must be present also:
357 451
358 pointer: the integer assigned to the pointer in its 452 pointer: the integer assigned to the pointer in its
359 'pointer-add' event (see above). 453 ``PointerAddEvent`` event (see above).
360 454
361 x: x-position relative to the top-left corner of the 455 x: x-position relative to the top-left corner of the
362 display, in global layout coordinates 456 display, in global layout coordinates
363 457
364 y: x-position relative to the top-left corner of the 458 y: x-position relative to the top-left corner of the
365 display, in global layout coordinates 459 display, in global layout coordinates
366 460
367 Note: The only wheels that are supported are mouse wheels and physical 461 Note: The only wheels that are supported are mouse wheels and physical
368 dials. Track balls are not reported as mouse wheels. 462 dials. Track balls are not reported as mouse wheels.
463
464 ```dart
465 abstract class WheelEvent extends Event {
466 PointerEvent({ bool bubbles,
467 this.wheel,
468 this.delta: 0.0,
469 this.pointer,
470 this.x, this.y,
471 }): super(bubbles: bubbles);
472
473 final int wheel;
474 final double delta; // revolutions (or fractions thereof)
475 final int pointer;
476 final double x; // logical pixels
477 final double y; // logical pixels
478 }
479 ```
OLDNEW
« no previous file with comments | « sky/specs/events.md ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698