| Index: sky/specs/gestures.md
|
| diff --git a/sky/specs/gestures.md b/sky/specs/gestures.md
|
| index 3f7028bc1265674ef6fb0ef018b4f118cc410e22..ee216fdfbecb7cdb7cb40402db69bc03ea826a31 100644
|
| --- a/sky/specs/gestures.md
|
| +++ b/sky/specs/gestures.md
|
| @@ -12,16 +12,16 @@ abstract class GestureEvent extends Event {
|
| }
|
|
|
| class GestureState {
|
| - bool cancel = true; // if true, then cancel the gesture at this point
|
| - bool capture = false; // (for PointerDownEvent) if true, then this pointer is relevant
|
| - bool choose = false; // if true, the gesture thinks that other gestures should give up
|
| - bool finished = true; // if true, we're ready for the next gesture to start
|
| + @nonnull bool cancel = true; // if true, then cancel the gesture at this point
|
| + @nonnull bool capture = false; // (for PointerDownEvent) if true, then this pointer is relevant
|
| + @nonnull bool choose = false; // if true, the gesture thinks that other gestures should give up
|
| + @nonnull bool finished = true; // if true, we're ready for the next gesture to start
|
| // choose and cancel are mutually exclusive
|
| }
|
|
|
| class BufferedEvent {
|
| const BufferedEvent(this.event, this.coallesceGroup);
|
| - final GestureEvent event;
|
| + final @nonnull GestureEvent event;
|
| final int coallesceGroup;
|
| }
|
|
|
| @@ -31,7 +31,7 @@ abstract class Gesture extends EventTarget {
|
| event is PointerMovedEvent ||
|
| event is PointerUpEvent).listen(_handler);
|
| }
|
| - final EventTarget target;
|
| + final @nonnull EventTarget target;
|
|
|
| bool _ready = true; // last event, we were finished
|
| bool get ready => _ready;
|
| @@ -46,9 +46,9 @@ abstract class Gesture extends EventTarget {
|
| // (active && !chosen) means we're collecting events until no other
|
| // gesture is valid, or until we take command
|
|
|
| - GestureState processEvent(PointerEvent event);
|
| + @nonnull GestureState processEvent(@nonnull PointerEvent event);
|
|
|
| - List<BufferedEvent> _eventBuffer;
|
| + List<@nonnull BufferedEvent> _eventBuffer;
|
|
|
| void choose() {
|
| // called by GestureManager
|
| @@ -62,9 +62,8 @@ abstract class Gesture extends EventTarget {
|
| // while we are doing this
|
| var events = _eventBuffer;
|
| _eventBuffer = null;
|
| - for (var item in events) {
|
| + for (var item in events)
|
| dispatchEvent(item.event);
|
| - }
|
| }
|
| }
|
|
|
| @@ -77,9 +76,9 @@ abstract class Gesture extends EventTarget {
|
| }
|
|
|
| // for use by subclasses only
|
| - void sendEvent(GestureEvent event,
|
| + void sendEvent(@nonnull GestureEvent event,
|
| { int coallesceGroup, // when queuing events, only the last event with each group is kept
|
| - bool prechoose: false // if true, event should just be sent right away, not queued
|
| + @nonnull bool prechoose: false // if true, event should just be sent right away, not queued
|
| }) {
|
| assert(_active == true);
|
| assert(coallesceGroup == null || prechoose == false);
|
| @@ -95,7 +94,7 @@ abstract class Gesture extends EventTarget {
|
| }
|
| }
|
|
|
| - void _handler(event) {
|
| + void _handler(@nonnull Event event) {
|
| bool wasActive = _active;
|
| if (_ready) {
|
| // reset the state to start a new gesture
|
| @@ -163,19 +162,19 @@ class PointerState {
|
| factory PointerState.clone(PointerState source) {
|
| return new PointerState(gestures: source.gestures, chosen: source.chosen);
|
| }
|
| - List<Gesture> gestures;
|
| - bool chosen = false;
|
| + @nonnull List<@nonnull Gesture> gestures;
|
| + @nonnull bool chosen = false;
|
| }
|
|
|
| class GestureManager {
|
| GestureManager(this.target) {
|
| target.events.where((event) => event is PointerDownEvent).listen(_handler);
|
| }
|
| - final EventTarget target; // usually the ApplicationDocument object
|
| + final @nonnull EventTarget target; // usually the ApplicationDocument object
|
|
|
| - Map<int, PointerState> _pointers = new SplayTreeMap<int, PointerState>();
|
| + Map<@nonnull int, @nonnull PointerState> _pointers = new SplayTreeMap<int, PointerState>();
|
|
|
| - void addGesture(PointerEvent event, Gesture gesture) {
|
| + void addGesture(@nonnull PointerEvent event, @nonnull Gesture gesture) {
|
| assert(gesture.active);
|
| var pointer = event.pointer;
|
| if (_pointers.containsKey(pointer)) {
|
| @@ -191,17 +190,17 @@ class GestureManager {
|
| }
|
| }
|
|
|
| - void cancelGesture(Gesture gesture) {
|
| + void cancelGesture(@nonnull Gesture gesture) {
|
| _pointers.forEach((index, pointerState) => pointerState.gestures.remove(gesture));
|
| gesture.cancel();
|
| // get a static copy of the _pointers keys, so we can remove them safely
|
| var activePointers = new List<int>.from(_pointers.keys);
|
| // now walk our lists, removing pointers that are obsolete, and choosing
|
| // gestures from pointers that have only one outstanding gesture
|
| - for (var index = 0; index < activePointers.length; index += 1) {
|
| - var pointerState = _pointers[activePointers[index]];
|
| + for (var pointer in activePointers) {
|
| + var pointerState = _pointers[pointer];
|
| if (pointerState.gestures.length == 0) {
|
| - _pointers.remove(activePointers[index]);
|
| + _pointers.remove(pointer);
|
| } else {
|
| if (pointerState.gestures.length == 1 && pointerState.chosen) {
|
| pointerState.chosen = true;
|
| @@ -211,12 +210,12 @@ class GestureManager {
|
| }
|
| }
|
|
|
| - void chooseGesture(Gesture gesture) {
|
| + void chooseGesture(@nonnull Gesture gesture) {
|
| if (!gesture.active)
|
| // this could happen e.g. if two gestures simultaneously add
|
| // themselves and chose themselves for the same PointerDownEvent
|
| return;
|
| - List<Gesture> losers = new List<Gesture>();
|
| + @nonnull List<@nonnull Gesture> losers = new List<@nonnull Gesture>();
|
| _pointers.values
|
| .where((pointerState) => pointerState.gestures.contains(gesture))
|
| .forEach((pointerState) {
|
| @@ -236,13 +235,13 @@ class GestureManager {
|
| gesture.choose();
|
| }
|
|
|
| - PointerState getActiveGestures(int pointer) {
|
| + @nonnull PointerState getActiveGestures(@nonnull int pointer) {
|
| if (_pointers.containsKey(pointer) && _pointers[pointer].gestures.length > 0)
|
| return new PointerState.clone(_pointers[pointer]);
|
| return new PointerState();
|
| }
|
|
|
| - void _handler(PointerDownEvent event) {
|
| + void _handler(@nonnull PointerDownEvent event) {
|
| var pointer = event.pointer;
|
| if (_pointers.containsKey(pointer)) {
|
| var pointerState = _pointers[pointer];
|
|
|