Commit 04ee7133 authored by Hixie's avatar Hixie

Minor cleanup in tap.dart

parent c5a966c5
...@@ -3,7 +3,7 @@ ...@@ -3,7 +3,7 @@
// found in the LICENSE file. // found in the LICENSE file.
import 'dart:async'; import 'dart:async';
import 'dart:ui' as ui; import 'dart:ui' show Point, Offset;
import 'arena.dart'; import 'arena.dart';
import 'constants.dart'; import 'constants.dart';
...@@ -11,8 +11,8 @@ import 'events.dart'; ...@@ -11,8 +11,8 @@ import 'events.dart';
import 'pointer_router.dart'; import 'pointer_router.dart';
import 'recognizer.dart'; import 'recognizer.dart';
typedef void GestureTapDownCallback(ui.Point globalPosition); typedef void GestureTapDownCallback(Point globalPosition);
typedef void GestureTapUpCallback(ui.Point globalPosition); typedef void GestureTapUpCallback(Point globalPosition);
typedef void GestureTapCallback(); typedef void GestureTapCallback();
typedef void GestureTapCancelCallback(); typedef void GestureTapCancelCallback();
...@@ -99,15 +99,15 @@ class _TapTracker { ...@@ -99,15 +99,15 @@ class _TapTracker {
_TapTracker({ PointerInputEvent event, this.entry }) _TapTracker({ PointerInputEvent event, this.entry })
: pointer = event.pointer, : pointer = event.pointer,
_initialPosition = event.position, _initialPosition = event.position {
_isTrackingPointer = false {
assert(event.type == 'pointerdown'); assert(event.type == 'pointerdown');
} }
final int pointer; final int pointer;
GestureArenaEntry entry; final GestureArenaEntry entry;
ui.Point _initialPosition; final Point _initialPosition;
bool _isTrackingPointer;
bool _isTrackingPointer = false;
void startTrackingPointer(PointerRouter router, PointerRoute route) { void startTrackingPointer(PointerRouter router, PointerRoute route) {
if (!_isTrackingPointer) { if (!_isTrackingPointer) {
...@@ -124,7 +124,7 @@ class _TapTracker { ...@@ -124,7 +124,7 @@ class _TapTracker {
} }
bool isWithinTolerance(PointerInputEvent event, double tolerance) { bool isWithinTolerance(PointerInputEvent event, double tolerance) {
ui.Offset offset = event.position - _initialPosition; Offset offset = event.position - _initialPosition;
return offset.distance <= tolerance; return offset.distance <= tolerance;
} }
...@@ -135,21 +135,23 @@ enum _TapResolution { ...@@ -135,21 +135,23 @@ enum _TapResolution {
cancel cancel
} }
/// TapGesture represents a full gesture resulting from a single tap /// TapGesture represents a full gesture resulting from a single tap sequence,
/// sequence. Tap gestures are passive, meaning that they will not /// as part of a [MultiTapGestureRecognizer]. Tap gestures are passive, meaning
/// pre-empt any other arena member in play. /// that they will not preempt any other arena member in play.
class _TapGesture extends _TapTracker { class _TapGesture extends _TapTracker {
_TapGesture({ this.gestureRecognizer, PointerInputEvent event }) _TapGesture({
: super(event: event) { MultiTapGestureRecognizer gestureRecognizer,
entry = GestureArena.instance.add(event.pointer, gestureRecognizer); PointerInputEvent event
}) : gestureRecognizer = gestureRecognizer,
super(event: event, entry: GestureArena.instance.add(event.pointer, gestureRecognizer)) {
startTrackingPointer(gestureRecognizer.router, handleEvent); startTrackingPointer(gestureRecognizer.router, handleEvent);
} }
final MultiTapGestureRecognizer gestureRecognizer; final MultiTapGestureRecognizer gestureRecognizer;
bool _wonArena = false; bool _wonArena = false;
ui.Point _finalPosition; Point _finalPosition;
void handleEvent(PointerInputEvent event) { void handleEvent(PointerInputEvent event) {
assert(event.pointer == pointer); assert(event.pointer == pointer);
...@@ -231,7 +233,7 @@ class MultiTapGestureRecognizer extends GestureArenaMember { ...@@ -231,7 +233,7 @@ class MultiTapGestureRecognizer extends GestureArenaMember {
_gestureMap[pointer]?.reject(); _gestureMap[pointer]?.reject();
} }
void _resolveTap(int pointer, _TapResolution resolution, ui.Point globalPosition) { void _resolveTap(int pointer, _TapResolution resolution, Point globalPosition) {
_gestureMap.remove(pointer); _gestureMap.remove(pointer);
if (resolution == _TapResolution.tap) { if (resolution == _TapResolution.tap) {
if (onTapUp != null) if (onTapUp != null)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment