| OLD | NEW |
| 1 Gestures | 1 Gestures |
| 2 ======== | 2 ======== |
| 3 | 3 |
| 4 ```dart | 4 ```dart |
| 5 SKY MODULE | 5 SKY MODULE |
| 6 <!-- part of dart:sky --> | 6 <!-- part of dart:sky --> |
| 7 | 7 |
| 8 <script> | 8 <script> |
| 9 abstract class GestureEvent extends Event { | 9 abstract class GestureEvent extends Event { |
| 10 Gesture _gesture; | 10 Gesture _gesture; |
| (...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 105 } | 105 } |
| 106 GestureState returnValue = processEvent(event); | 106 GestureState returnValue = processEvent(event); |
| 107 if (returnValue.capture) { | 107 if (returnValue.capture) { |
| 108 assert(event is PointerDownEvent); | 108 assert(event is PointerDownEvent); |
| 109 if (event is PointerDownEvent) | 109 if (event is PointerDownEvent) |
| 110 event.result.add(this); | 110 event.result.add(this); |
| 111 } | 111 } |
| 112 if (returnValue.cancel) { | 112 if (returnValue.cancel) { |
| 113 assert(returnValue.choose == false); | 113 assert(returnValue.choose == false); |
| 114 if (wasActive) | 114 if (wasActive) |
| 115 module.application.cancelGesture(this); | 115 module.application.gestureManager.cancelGesture(this); |
| 116 // if we never became active, then we never called addGesture() below | 116 // if we never became active, then we never called addGesture() below |
| 117 _active = false; | 117 _active = false; |
| 118 } else if (active == true) { | 118 } else if (active == true) { |
| 119 if (wasActive == false || event is PointerDownEvent) | 119 if (wasActive == false || event is PointerDownEvent) |
| 120 module.application.addGesture(event, this); | 120 module.application.gestureManager.addGesture(event, this); |
| 121 if (returnValue.choose == true) | 121 if (returnValue.choose == true) |
| 122 module.application.chooseGesture(this); | 122 module.application.gestureManager.chooseGesture(this); |
| 123 } | 123 } |
| 124 _ready = returnValue.finished; | 124 _ready = returnValue.finished; |
| 125 } | 125 } |
| 126 } | 126 } |
| 127 | 127 |
| 128 /* |
| 128 ``` | 129 ``` |
| 129 Subclasses should override ``processEvent()``: | 130 Subclasses should override ``processEvent()``: |
| 130 - as the events are received, they get examined to see if they | 131 - as the events are received, they get examined to see if they |
| 131 fit the pattern for the gesture; if they do, then return an | 132 fit the pattern for the gesture; if they do, then return an |
| 132 object with valid=true; if more events for this gesture could | 133 object with valid=true; if more events for this gesture could |
| 133 still come in, return finished=false. | 134 still come in, return finished=false. |
| 134 - if you returned valid=false finished=false, then the next call | 135 - if you returned valid=false finished=false, then the next call |
| 135 to this must not return valid=true | 136 to this must not return valid=true |
| 136 - doing anything with the event or target other than reading | 137 - doing anything with the event or target other than reading |
| 137 state is a contract violation | 138 state is a contract violation |
| 138 - you are allowed to call sendEvent() at any time during a | 139 - you are allowed to call sendEvent() at any time during a |
| 139 processEventInternal() call, or after a call to | 140 processEvent() call, or after a call to processEvent(), assuming |
| 140 processEventInternal(), assuming that the last such call returned | 141 that the last such call returned valid=true, until the next call to |
| 141 valid=true, until the next call to processEventInternal() or | 142 processEvent() or cancel(). |
| 142 cancel(). | |
| 143 - set forceChoose=true on the return value if you are confident | 143 - set forceChoose=true on the return value if you are confident |
| 144 that this is the gesture the user meant, even if it's possible | 144 that this is the gesture the user meant, even if it's possible |
| 145 that another gesture is still claiming it's valid (e.g. a long | 145 that another gesture is still claiming it's valid (e.g. a long |
| 146 press might forceChoose to override a scroll, if the user | 146 press might forceChoose to override a scroll, if the user |
| 147 hasn't moved for a while) | 147 hasn't moved for a while) |
| 148 - if you send events, you can set prechoose=true to send the | 148 - if you send events, you can set prechoose=true to send the |
| 149 event even before the gesture has been chosen | 149 event even before the gesture has been chosen |
| 150 - if you send prechoose events, make sure to send corresponding | 150 - if you send prechoose events, make sure to send corresponding |
| 151 "cancel" events if cancel() is called | 151 "cancel" events if cancel() is called |
| 152 | 152 |
| 153 ```dart | 153 ```dart |
| 154 */ |
| 154 | 155 |
| 155 class PointerState { | 156 class PointerState { |
| 156 PointerState({this.gestures, this.chosen}) { | 157 PointerState({this.gestures, this.chosen}) { |
| 157 if (gestures == null) | 158 if (gestures == null) |
| 158 gestures = new List<Gesture>(); | 159 gestures = new List<Gesture>(); |
| 159 } | 160 } |
| 160 factory PointerState.clone(PointerState source) { | 161 factory PointerState.clone(PointerState source) { |
| 161 return new PointerState(gestures: source.gestures, chosen: source.chosen); | 162 return new PointerState(gestures: source.gestures, chosen: source.chosen); |
| 162 } | 163 } |
| 163 List<Gesture> gestures; | 164 List<Gesture> gestures; |
| (...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 244 if (_pointers.containsKey(pointer)) { | 245 if (_pointers.containsKey(pointer)) { |
| 245 var pointerState = _pointers[pointer]; | 246 var pointerState = _pointers[pointer]; |
| 246 if ((!pointerState.chosen) && (pointerState.gestures.length == 1)) { | 247 if ((!pointerState.chosen) && (pointerState.gestures.length == 1)) { |
| 247 pointerState.chosen = true; | 248 pointerState.chosen = true; |
| 248 pointerState.gestures[0].choose(); | 249 pointerState.gestures[0].choose(); |
| 249 } | 250 } |
| 250 } | 251 } |
| 251 } | 252 } |
| 252 | 253 |
| 253 } | 254 } |
| 255 /* |
| 254 </script> | 256 </script> |
| 255 ``` | 257 ``` |
| 256 | 258 |
| 257 Gestures defined in the framework | 259 Gestures defined in the framework |
| 258 --------------------------------- | 260 --------------------------------- |
| 259 | 261 |
| 260 ```dart | 262 ```dart |
| 261 SKY MODULE | 263 SKY MODULE |
| 262 <!-- not in dart:sky --> | 264 <!-- not in dart:sky --> |
| 263 <!-- note: this hasn't been dartified yet --> | 265 <!-- note: this hasn't been dartified yet --> |
| 264 | 266 |
| 265 <script> | 267 <script> |
| 268 */ |
| 266 class TapGesture extends Gesture { | 269 class TapGesture extends Gesture { |
| 270 TapGesture = Gesture; |
| 267 | 271 |
| 268 // internal state: | 272 // internal state: |
| 269 // Integer numButtons = 0; | 273 // Integer numButtons = 0; |
| 270 // Boolean primaryDown = false; | 274 // Boolean primaryDown = false; |
| 271 | 275 |
| 272 virtual GestureState processEvent(Event event); | 276 GestureState processEvent(Event event); |
| 273 // - let returnValue = { finished = false } | 277 // - let returnValue = { finished = false } |
| 274 // - if the event is a pointer-down: | 278 // - if the event is a pointer-down: |
| 275 // - increment this.numButtons | 279 // - increment this.numButtons |
| 276 // - set returnValue.capture = true | 280 // - set returnValue.capture = true |
| 277 // - otherwise if it is a pointer-up: | 281 // - otherwise if it is a pointer-up: |
| 278 // - assert: this.numButtons > 0 | 282 // - assert: this.numButtons > 0 |
| 279 // - decrement this.numButtons | 283 // - decrement this.numButtons |
| 280 // - if numButtons == 0: | 284 // - if numButtons == 0: |
| 281 // - set returnValue.finished = true | 285 // - set returnValue.finished = true |
| 282 // - if this.ready == false and this.active == false: | 286 // - if this.ready == false and this.active == false: |
| (...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 327 // - set returnValue.cancel = false | 331 // - set returnValue.cancel = false |
| 328 // - return returnValue | 332 // - return returnValue |
| 329 // - otherwise: | 333 // - otherwise: |
| 330 // - // this is the 'up' of some bogus secondary press | 334 // - // this is the 'up' of some bogus secondary press |
| 331 // // ignore it, but continue listening for our primary up if necessar
y | 335 // // ignore it, but continue listening for our primary up if necessar
y |
| 332 // - if this.primaryDown == true and this.active == true: | 336 // - if this.primaryDown == true and this.active == true: |
| 333 // - set returnValue.cancel = false | 337 // - set returnValue.cancel = false |
| 334 // - return returnValue | 338 // - return returnValue |
| 335 } | 339 } |
| 336 | 340 |
| 337 class LongPressGesture : Gesture { | 341 class LongPressGesture extends Gesture { |
| 338 GestureState processEvent(EventTarget target, Event event); | 342 LongPressGesture = Gesture; |
| 343 |
| 344 GestureState processEvent(PointerEvent event); |
| 339 // long-tap-start: sent when the primary pointer goes down | 345 // long-tap-start: sent when the primary pointer goes down |
| 340 // long-tap-cancel: sent when cancel()ed or finger goes out of bounding box | 346 // long-tap-cancel: sent when cancel()ed or finger goes out of bounding box |
| 341 // long-tap: sent when the primary pointer is released | 347 // long-tap: sent when the primary pointer is released |
| 342 } | 348 } |
| 343 | 349 |
| 344 class DoubleTapGesture : Gesture { | 350 class DoubleTapGesture extends Gesture { |
| 345 GestureState processEvent(EventTarget target, Event event); | 351 DoubleTapGesture = Gesture; |
| 352 |
| 353 GestureState processEvent(PointerEvent event); |
| 346 // double-tap-start: sent when the primary pointer goes down the first time | 354 // double-tap-start: sent when the primary pointer goes down the first time |
| 347 // double-tap-cancel: sent when cancel()ed or finger goes out of bounding box,
or it times out | 355 // double-tap-cancel: sent when cancel()ed or finger goes out of bounding box,
or it times out |
| 348 // double-tap: sent when the primary pointer is released the second time withi
n the timeout | 356 // double-tap: sent when the primary pointer is released the second time withi
n the timeout |
| 349 } | 357 } |
| 350 | 358 |
| 351 | 359 |
| 352 abstract class ScrollGesture : Gesture { | 360 abstract class ScrollGesture extends Gesture { |
| 353 GestureState processEvent(EventTarget target, Event event); | 361 ScrollGesture = Gesture; |
| 362 |
| 363 GestureState processEvent(PointerEvent event); |
| 354 // this fires the following events (inertia is a boolean, delta is a float): | 364 // this fires the following events (inertia is a boolean, delta is a float): |
| 355 // scroll-start, with field inertia=false, delta=0; prechoose=true | 365 // scroll-start, with field inertia=false, delta=0; prechoose=true |
| 356 // scroll, with fields inertia (is this a simulated scroll from inertia or a
real scroll?), delta (number of pixels to scroll); prechoose=true | 366 // scroll, with fields inertia (is this a simulated scroll from inertia or a
real scroll?), delta (number of pixels to scroll); prechoose=true |
| 357 // scroll-end, with field inertia (same), delta=0; prechoose=true | 367 // scroll-end, with field inertia (same), delta=0; prechoose=true |
| 358 // scroll-start is fired right away | 368 // scroll-start is fired right away |
| 359 // scroll is sent whenever the primary pointer moves while down | 369 // scroll is sent whenever the primary pointer moves while down |
| 360 // scroll is also sent after the pointer goes back up, based on inertia | 370 // scroll is also sent after the pointer goes back up, based on inertia |
| 361 // scroll-end is sent after the pointer goes back up once the scroll reaches d
elta=0 | 371 // scroll-end is sent after the pointer goes back up once the scroll reaches d
elta=0 |
| 362 // scroll-end is also sent when the gesture is canceled or reset | 372 // scroll-end is also sent when the gesture is canceled or reset |
| 363 // processEvent() returns: | 373 // processEvent() returns: |
| 364 // - cancel=false pretty much always so long as there's a primary touch (e.g.
not for a right-click) | 374 // - cancel=false pretty much always so long as there's a primary touch (e.g.
not for a right-click) |
| 365 // - chose=true when you travel a certain distance | 375 // - chose=true when you travel a certain distance |
| 366 // - finished=true when the primary pointer goes up | 376 // - finished=true when the primary pointer goes up |
| 367 } | 377 } |
| 368 | 378 |
| 369 class HorizontalScrollGesture : ScrollGesture { } | 379 class HorizontalScrollGesture extends ScrollGesture { |
| 370 // a ScrollGesture giving x-axis scrolling | 380 // a ScrollGesture giving x-axis scrolling |
| 381 HorizontalScrollGesture = ScrollGesture; |
| 382 } |
| 371 | 383 |
| 372 class VerticalScrollGesture : ScrollGesture { } | 384 class VerticalScrollGesture extends ScrollGesture { |
| 373 // a ScrollGesture giving y-axis scrolling | 385 // a ScrollGesture giving y-axis scrolling |
| 386 VerticalScrollGesture = ScrollGesture; |
| 387 } |
| 374 | 388 |
| 375 | 389 |
| 376 class PanGesture : Gesture { | 390 class PanGesture extends Gesture { |
| 391 PanGesture = Gesture; |
| 377 // similar to ScrollGesture, but with two axes | 392 // similar to ScrollGesture, but with two axes |
| 378 // pan-start, pan, pan-end | 393 // pan-start, pan, pan-end |
| 379 // events have inertia (boolean), dx (float), dy (float) | 394 // events have inertia (boolean), dx (float), dy (float) |
| 380 } | 395 } |
| 381 | 396 |
| 382 | 397 |
| 383 abstract class ZoomGesture : Gesture { | 398 abstract class ZoomGesture extends Gesture { |
| 384 GestureState processEvent(EventTarget target, Event event); | 399 ZoomGesture = Gesture; |
| 400 |
| 401 GestureState processEvent(PointerEvent event); |
| 385 // zoom-start: sent when we could start zooming (e.g. for pinch-zoom, when two
fingers hit the glass) (prechoose) | 402 // zoom-start: sent when we could start zooming (e.g. for pinch-zoom, when two
fingers hit the glass) (prechoose) |
| 386 // zoom-end: sent when cancel()ed after zoom-start, or when the fingers are li
fted (prechoose) | 403 // zoom-end: sent when cancel()ed after zoom-start, or when the fingers are li
fted (prechoose) |
| 387 // zoom, with a 'scale' attribute, whose value is a multiple of the scale fact
or at zoom-start | 404 // zoom, with a 'scale' attribute, whose value is a multiple of the scale fact
or at zoom-start |
| 388 // e.g. if the user zooms to 2x, you'd get a bunch of 'zoom' events like scale
=1.0, scale=1.17, ... scale=1.91, scale=2.0 | 405 // e.g. if the user zooms to 2x, you'd get a bunch of 'zoom' events like scale
=1.0, scale=1.17, ... scale=1.91, scale=2.0 |
| 389 } | 406 } |
| 390 | 407 |
| 391 class PinchZoomGesture : ZoomGesture { | 408 class PinchZoomGesture extends ZoomGesture { |
| 409 PinchZoomGesture = ZoomGesture; |
| 392 // a ZoomGesture for two-finger-pinch gesture | 410 // a ZoomGesture for two-finger-pinch gesture |
| 393 // zoom is prechoose | 411 // zoom is prechoose |
| 394 } | 412 } |
| 395 | 413 |
| 396 class DoubleTapZoomGesture : ZoomGesture { | 414 class DoubleTapZoomGesture extends ZoomGesture { |
| 415 DoubleTapZoomGesture = ZoomGesture; |
| 397 // a ZoomGesture for the double-tap-slide gesture | 416 // a ZoomGesture for the double-tap-slide gesture |
| 398 // when the slide starts, forceChoose | 417 // when the slide starts, forceChoose |
| 399 } | 418 } |
| 400 | 419 |
| 401 | 420 |
| 402 class PanAndZoomGesture : Gesture { | 421 class PanAndZoomGesture extends Gesture { |
| 403 GestureState processEvent(EventTarget target, Event event); | 422 PanAndZoomGesture = Gesture; |
| 423 |
| 424 GestureState processEvent(PointerEvent event); |
| 404 // manipulate-start (prechoose) | 425 // manipulate-start (prechoose) |
| 405 // manipulate: (prechoose) | 426 // manipulate: (prechoose) |
| 406 // panX, panY: pixels | 427 // panX, panY: pixels |
| 407 // scaleX, scaleY: a multiplier of the scale at manipulate-start | 428 // scaleX, scaleY: a multiplier of the scale at manipulate-start |
| 408 // rotation: turns | 429 // rotation: turns |
| 409 // manipulate-end (prechoose) | 430 // manipulate-end (prechoose) |
| 410 } | 431 } |
| 411 | 432 |
| 412 | 433 |
| 413 abstract class FlingGesture : Gesture { | 434 abstract class FlingGesture extends Gesture { |
| 414 GestureState processEvent(EventTarget target, Event event); | 435 FlingGesture = Gesture; |
| 436 |
| 437 GestureState processEvent(PointerEvent event); |
| 415 // fling-start: when the gesture begins (prechoose) | 438 // fling-start: when the gesture begins (prechoose) |
| 416 // fling-move: while the user is directly dragging the element (has delta attr
ibute with the distance from fling-start) (prechoose) | 439 // fling-move: while the user is directly dragging the element (has delta attr
ibute with the distance from fling-start) (prechoose) |
| 417 // fling: the user has released the pointer and the decision is it was in fact
flung | 440 // fling: the user has released the pointer and the decision is it was in fact
flung |
| 418 // fling-cancel: cancel(), or the user has released the pointer and the decisi
on is it was not flung (prechoose) | 441 // fling-cancel: cancel(), or the user has released the pointer and the decisi
on is it was not flung (prechoose) |
| 419 // fling-end: cancel(), or after fling or fling-cancel (prechoose) | 442 // fling-end: cancel(), or after fling or fling-cancel (prechoose) |
| 420 } | 443 } |
| 421 | 444 |
| 422 class FlingLeftGesture : FlingGesture { } | 445 class FlingLeftGesture extends FlingGesture { |
| 423 class FlingRightGesture : FlingGesture { } | 446 FlingLeftGesture = FlingGesture; |
| 424 class FlingUpGesture : FlingGesture { } | 447 } |
| 425 class FlingDownGesture : FlingGesture { } | 448 class FlingRightGesture extends FlingGesture { |
| 426 | 449 FlingRightGesture = FlingGesture; |
| 450 } |
| 451 class FlingUpGesture extends FlingGesture { |
| 452 FlingUpGesture = FlingGesture; |
| 453 } |
| 454 class FlingDownGesture extends FlingGesture { |
| 455 FlingDownGesture = FlingGesture; |
| 456 } |
| 427 </script> | 457 </script> |
| 428 ``` | 458 ``` |
| OLD | NEW |