flutter/packages/unit/test/engine/mock_events.dart
2015-10-13 15:16:04 -07:00

63 lines
1.2 KiB
Dart

import 'dart:ui' as ui;
import 'package:flutter/gestures.dart';
export 'dart:ui' show Point;
class TestPointer {
TestPointer([ this.pointer = 1 ]);
int pointer;
bool isDown = false;
ui.Point location;
PointerInputEvent down([ui.Point newLocation = ui.Point.origin ]) {
assert(!isDown);
isDown = true;
location = newLocation;
return new PointerInputEvent(
type: 'pointerdown',
pointer: pointer,
x: location.x,
y: location.y
);
}
PointerInputEvent move([ui.Point newLocation = ui.Point.origin ]) {
assert(isDown);
ui.Offset delta = newLocation - location;
location = newLocation;
return new PointerInputEvent(
type: 'pointermove',
pointer: pointer,
x: newLocation.x,
y: newLocation.y,
dx: delta.dx,
dy: delta.dy
);
}
PointerInputEvent up() {
assert(isDown);
isDown = false;
return new PointerInputEvent(
type: 'pointerup',
pointer: pointer,
x: location.x,
y: location.y
);
}
PointerInputEvent cancel() {
assert(isDown);
isDown = false;
return new PointerInputEvent(
type: 'pointercancel',
pointer: pointer,
x: location.x,
y: location.y
);
}
}