Unverified Commit 7e96d89a authored by Tong Mu's avatar Tong Mu Committed by GitHub

PointerEvent asserts device kinds (#105987)

parent 54bd6297
...@@ -216,7 +216,6 @@ class PointerEventConverter { ...@@ -216,7 +216,6 @@ class PointerEventConverter {
return PointerPanZoomStartEvent( return PointerPanZoomStartEvent(
timeStamp: timeStamp, timeStamp: timeStamp,
pointer: datum.pointerIdentifier, pointer: datum.pointerIdentifier,
kind: kind,
device: datum.device, device: datum.device,
position: position, position: position,
embedderId: datum.embedderId, embedderId: datum.embedderId,
...@@ -230,7 +229,6 @@ class PointerEventConverter { ...@@ -230,7 +229,6 @@ class PointerEventConverter {
return PointerPanZoomUpdateEvent( return PointerPanZoomUpdateEvent(
timeStamp: timeStamp, timeStamp: timeStamp,
pointer: datum.pointerIdentifier, pointer: datum.pointerIdentifier,
kind: kind,
device: datum.device, device: datum.device,
position: position, position: position,
pan: pan, pan: pan,
...@@ -244,7 +242,6 @@ class PointerEventConverter { ...@@ -244,7 +242,6 @@ class PointerEventConverter {
return PointerPanZoomEndEvent( return PointerPanZoomEndEvent(
timeStamp: timeStamp, timeStamp: timeStamp,
pointer: datum.pointerIdentifier, pointer: datum.pointerIdentifier,
kind: kind,
device: datum.device, device: datum.device,
position: position, position: position,
embedderId: datum.embedderId, embedderId: datum.embedderId,
......
...@@ -1035,7 +1035,10 @@ class PointerHoverEvent extends PointerEvent with _PointerEventDescription, _Cop ...@@ -1035,7 +1035,10 @@ class PointerHoverEvent extends PointerEvent with _PointerEventDescription, _Cop
super.tilt, super.tilt,
super.synthesized, super.synthesized,
super.embedderId, super.embedderId,
}) : super( }) : // Dart doesn't support comparing enums with == in const contexts yet.
// https://github.com/dart-lang/language/issues/1811
assert(!identical(kind, PointerDeviceKind.trackpad)),
super(
down: false, down: false,
pressure: 0.0, pressure: 0.0,
); );
...@@ -1153,7 +1156,8 @@ class PointerEnterEvent extends PointerEvent with _PointerEventDescription, _Cop ...@@ -1153,7 +1156,8 @@ class PointerEnterEvent extends PointerEvent with _PointerEventDescription, _Cop
super.down, super.down,
super.synthesized, super.synthesized,
super.embedderId, super.embedderId,
}) : super( }) : assert(!identical(kind, PointerDeviceKind.trackpad)),
super(
pressure: 0.0, pressure: 0.0,
); );
...@@ -1297,7 +1301,8 @@ class PointerExitEvent extends PointerEvent with _PointerEventDescription, _Copy ...@@ -1297,7 +1301,8 @@ class PointerExitEvent extends PointerEvent with _PointerEventDescription, _Copy
super.down, super.down,
super.synthesized, super.synthesized,
super.embedderId, super.embedderId,
}) : super( }) : assert(!identical(kind, PointerDeviceKind.trackpad)),
super(
pressure: 0.0, pressure: 0.0,
); );
...@@ -1432,7 +1437,8 @@ class PointerDownEvent extends PointerEvent with _PointerEventDescription, _Copy ...@@ -1432,7 +1437,8 @@ class PointerDownEvent extends PointerEvent with _PointerEventDescription, _Copy
super.orientation, super.orientation,
super.tilt, super.tilt,
super.embedderId, super.embedderId,
}) : super( }) : assert(!identical(kind, PointerDeviceKind.trackpad)),
super(
down: true, down: true,
distance: 0.0, distance: 0.0,
); );
...@@ -1548,7 +1554,8 @@ class PointerMoveEvent extends PointerEvent with _PointerEventDescription, _Copy ...@@ -1548,7 +1554,8 @@ class PointerMoveEvent extends PointerEvent with _PointerEventDescription, _Copy
super.platformData, super.platformData,
super.synthesized, super.synthesized,
super.embedderId, super.embedderId,
}) : super( }) : assert(!identical(kind, PointerDeviceKind.trackpad)),
super(
down: true, down: true,
distance: 0.0, distance: 0.0,
); );
...@@ -1662,7 +1669,8 @@ class PointerUpEvent extends PointerEvent with _PointerEventDescription, _CopyPo ...@@ -1662,7 +1669,8 @@ class PointerUpEvent extends PointerEvent with _PointerEventDescription, _CopyPo
super.orientation, super.orientation,
super.tilt, super.tilt,
super.embedderId, super.embedderId,
}) : super( }) : assert(!identical(kind, PointerDeviceKind.trackpad)),
super(
down: false, down: false,
); );
...@@ -1711,7 +1719,7 @@ abstract class PointerSignalEvent extends PointerEvent { ...@@ -1711,7 +1719,7 @@ abstract class PointerSignalEvent extends PointerEvent {
super.device, super.device,
super.position, super.position,
super.embedderId, super.embedderId,
}); }) : assert(!identical(kind, PointerDeviceKind.trackpad));
} }
mixin _CopyPointerScrollEvent on PointerEvent { mixin _CopyPointerScrollEvent on PointerEvent {
...@@ -1849,9 +1857,9 @@ mixin _CopyPointerPanZoomStartEvent on PointerEvent { ...@@ -1849,9 +1857,9 @@ mixin _CopyPointerPanZoomStartEvent on PointerEvent {
bool? synthesized, bool? synthesized,
int? embedderId, int? embedderId,
}) { }) {
assert(kind == null || identical(kind, PointerDeviceKind.trackpad));
return PointerPanZoomStartEvent( return PointerPanZoomStartEvent(
timeStamp: timeStamp ?? this.timeStamp, timeStamp: timeStamp ?? this.timeStamp,
kind: kind ?? this.kind,
device: device ?? this.device, device: device ?? this.device,
position: position ?? this.position, position: position ?? this.position,
embedderId: embedderId ?? this.embedderId, embedderId: embedderId ?? this.embedderId,
...@@ -1871,19 +1879,18 @@ class PointerPanZoomStartEvent extends PointerEvent with _PointerEventDescriptio ...@@ -1871,19 +1879,18 @@ class PointerPanZoomStartEvent extends PointerEvent with _PointerEventDescriptio
/// All of the arguments must be non-null. /// All of the arguments must be non-null.
const PointerPanZoomStartEvent({ const PointerPanZoomStartEvent({
super.timeStamp, super.timeStamp,
super.kind = PointerDeviceKind.mouse,
super.device, super.device,
super.pointer, super.pointer,
super.position, super.position,
super.embedderId, super.embedderId,
super.synthesized, super.synthesized,
}) : assert(timeStamp != null), }) : assert(timeStamp != null),
assert(kind != null),
assert(device != null), assert(device != null),
assert(pointer != null), assert(pointer != null),
assert(position != null), assert(position != null),
assert(embedderId != null), assert(embedderId != null),
assert(synthesized != null); assert(synthesized != null),
super(kind: PointerDeviceKind.trackpad);
@override @override
PointerPanZoomStartEvent transformed(Matrix4? transform) { PointerPanZoomStartEvent transformed(Matrix4? transform) {
...@@ -1953,9 +1960,9 @@ mixin _CopyPointerPanZoomUpdateEvent on PointerEvent { ...@@ -1953,9 +1960,9 @@ mixin _CopyPointerPanZoomUpdateEvent on PointerEvent {
double? scale, double? scale,
double? rotation, double? rotation,
}) { }) {
assert(kind == null || identical(kind, PointerDeviceKind.trackpad));
return PointerPanZoomUpdateEvent( return PointerPanZoomUpdateEvent(
timeStamp: timeStamp ?? this.timeStamp, timeStamp: timeStamp ?? this.timeStamp,
kind: kind ?? this.kind,
device: device ?? this.device, device: device ?? this.device,
position: position ?? this.position, position: position ?? this.position,
embedderId: embedderId ?? this.embedderId, embedderId: embedderId ?? this.embedderId,
...@@ -1979,7 +1986,6 @@ class PointerPanZoomUpdateEvent extends PointerEvent with _PointerEventDescripti ...@@ -1979,7 +1986,6 @@ class PointerPanZoomUpdateEvent extends PointerEvent with _PointerEventDescripti
/// All of the arguments must be non-null. /// All of the arguments must be non-null.
const PointerPanZoomUpdateEvent({ const PointerPanZoomUpdateEvent({
super.timeStamp, super.timeStamp,
super.kind = PointerDeviceKind.mouse,
super.device, super.device,
super.pointer, super.pointer,
super.position, super.position,
...@@ -1990,7 +1996,6 @@ class PointerPanZoomUpdateEvent extends PointerEvent with _PointerEventDescripti ...@@ -1990,7 +1996,6 @@ class PointerPanZoomUpdateEvent extends PointerEvent with _PointerEventDescripti
this.rotation = 0.0, this.rotation = 0.0,
super.synthesized, super.synthesized,
}) : assert(timeStamp != null), }) : assert(timeStamp != null),
assert(kind != null),
assert(device != null), assert(device != null),
assert(pointer != null), assert(pointer != null),
assert(position != null), assert(position != null),
...@@ -1999,7 +2004,9 @@ class PointerPanZoomUpdateEvent extends PointerEvent with _PointerEventDescripti ...@@ -1999,7 +2004,9 @@ class PointerPanZoomUpdateEvent extends PointerEvent with _PointerEventDescripti
assert(panDelta != null), assert(panDelta != null),
assert(scale != null), assert(scale != null),
assert(rotation != null), assert(rotation != null),
assert(synthesized != null); assert(synthesized != null),
super(kind: PointerDeviceKind.trackpad);
@override @override
final Offset pan; final Offset pan;
@override @override
...@@ -2085,9 +2092,9 @@ mixin _CopyPointerPanZoomEndEvent on PointerEvent { ...@@ -2085,9 +2092,9 @@ mixin _CopyPointerPanZoomEndEvent on PointerEvent {
bool? synthesized, bool? synthesized,
int? embedderId, int? embedderId,
}) { }) {
assert(kind == null || identical(kind, PointerDeviceKind.trackpad));
return PointerPanZoomEndEvent( return PointerPanZoomEndEvent(
timeStamp: timeStamp ?? this.timeStamp, timeStamp: timeStamp ?? this.timeStamp,
kind: kind ?? this.kind,
device: device ?? this.device, device: device ?? this.device,
position: position ?? this.position, position: position ?? this.position,
embedderId: embedderId ?? this.embedderId, embedderId: embedderId ?? this.embedderId,
...@@ -2107,19 +2114,18 @@ class PointerPanZoomEndEvent extends PointerEvent with _PointerEventDescription, ...@@ -2107,19 +2114,18 @@ class PointerPanZoomEndEvent extends PointerEvent with _PointerEventDescription,
/// All of the arguments must be non-null. /// All of the arguments must be non-null.
const PointerPanZoomEndEvent({ const PointerPanZoomEndEvent({
super.timeStamp, super.timeStamp,
super.kind = PointerDeviceKind.mouse,
super.device, super.device,
super.pointer, super.pointer,
super.position, super.position,
super.embedderId, super.embedderId,
super.synthesized, super.synthesized,
}) : assert(timeStamp != null), }) : assert(timeStamp != null),
assert(kind != null),
assert(device != null), assert(device != null),
assert(pointer != null), assert(pointer != null),
assert(position != null), assert(position != null),
assert(embedderId != null), assert(embedderId != null),
assert(synthesized != null); assert(synthesized != null),
super(kind: PointerDeviceKind.trackpad);
@override @override
PointerPanZoomEndEvent transformed(Matrix4? transform) { PointerPanZoomEndEvent transformed(Matrix4? transform) {
...@@ -2224,7 +2230,8 @@ class PointerCancelEvent extends PointerEvent with _PointerEventDescription, _Co ...@@ -2224,7 +2230,8 @@ class PointerCancelEvent extends PointerEvent with _PointerEventDescription, _Co
super.orientation, super.orientation,
super.tilt, super.tilt,
super.embedderId, super.embedderId,
}) : super( }) : assert(!identical(kind, PointerDeviceKind.trackpad)),
super(
down: false, down: false,
pressure: 0.0, pressure: 0.0,
); );
......
...@@ -1507,7 +1507,7 @@ void main() { ...@@ -1507,7 +1507,7 @@ void main() {
didEndPan = true; didEndPan = true;
}; };
final TestPointer pointer = TestPointer(2); final TestPointer pointer = TestPointer(2, PointerDeviceKind.trackpad);
final PointerPanZoomStartEvent start = pointer.panZoomStart(const Offset(10.0, 10.0)); final PointerPanZoomStartEvent start = pointer.panZoomStart(const Offset(10.0, 10.0));
pan.addPointerPanZoom(start); pan.addPointerPanZoom(start);
competingPan.addPointerPanZoom(start); competingPan.addPointerPanZoom(start);
...@@ -1564,7 +1564,7 @@ void main() { ...@@ -1564,7 +1564,7 @@ void main() {
didEndPan = true; didEndPan = true;
}; };
final TestPointer panZoomPointer = TestPointer(2); final TestPointer panZoomPointer = TestPointer(2, PointerDeviceKind.trackpad);
final TestPointer touchPointer = TestPointer(3); final TestPointer touchPointer = TestPointer(3);
final PointerPanZoomStartEvent start = panZoomPointer.panZoomStart(const Offset(10.0, 10.0)); final PointerPanZoomStartEvent start = panZoomPointer.panZoomStart(const Offset(10.0, 10.0));
pan.addPointerPanZoom(start); pan.addPointerPanZoom(start);
...@@ -1641,7 +1641,7 @@ testGesture('Touch drags should allow pointer pan/zooms to join them', (GestureT ...@@ -1641,7 +1641,7 @@ testGesture('Touch drags should allow pointer pan/zooms to join them', (GestureT
didEndPan = true; didEndPan = true;
}; };
final TestPointer panZoomPointer = TestPointer(2); final TestPointer panZoomPointer = TestPointer(2, PointerDeviceKind.trackpad);
final TestPointer touchPointer = TestPointer(3); final TestPointer touchPointer = TestPointer(3);
final PointerDownEvent touchDown = touchPointer.down(const Offset(20.0, 20.0)); final PointerDownEvent touchDown = touchPointer.down(const Offset(20.0, 20.0));
pan.addPointer(touchDown); pan.addPointer(touchDown);
......
...@@ -732,7 +732,7 @@ void main() { ...@@ -732,7 +732,7 @@ void main() {
didEndScale = true; didEndScale = true;
}; };
final TestPointer pointer1 = TestPointer(2); final TestPointer pointer1 = TestPointer(2, PointerDeviceKind.trackpad);
final PointerPanZoomStartEvent start = pointer1.panZoomStart(Offset.zero); final PointerPanZoomStartEvent start = pointer1.panZoomStart(Offset.zero);
scale.addPointerPanZoom(start); scale.addPointerPanZoom(start);
...@@ -836,7 +836,7 @@ void main() { ...@@ -836,7 +836,7 @@ void main() {
final TestPointer touchPointer1 = TestPointer(2); final TestPointer touchPointer1 = TestPointer(2);
final TestPointer touchPointer2 = TestPointer(3); final TestPointer touchPointer2 = TestPointer(3);
final TestPointer panZoomPointer = TestPointer(4); final TestPointer panZoomPointer = TestPointer(4, PointerDeviceKind.trackpad);
final PointerPanZoomStartEvent panZoomStart = panZoomPointer.panZoomStart(Offset.zero); final PointerPanZoomStartEvent panZoomStart = panZoomPointer.panZoomStart(Offset.zero);
scale.addPointerPanZoom(panZoomStart); scale.addPointerPanZoom(panZoomStart);
...@@ -985,7 +985,7 @@ void main() { ...@@ -985,7 +985,7 @@ void main() {
drag.onStart = (DragStartDetails details) { log.add('drag-start'); }; drag.onStart = (DragStartDetails details) { log.add('drag-start'); };
drag.onEnd = (DragEndDetails details) { log.add('drag-end'); }; drag.onEnd = (DragEndDetails details) { log.add('drag-end'); };
final TestPointer pointer1 = TestPointer(2); final TestPointer pointer1 = TestPointer(2, PointerDeviceKind.trackpad);
final PointerPanZoomStartEvent down = pointer1.panZoomStart(const Offset(10.0, 10.0)); final PointerPanZoomStartEvent down = pointer1.panZoomStart(const Offset(10.0, 10.0));
scale.addPointerPanZoom(down); scale.addPointerPanZoom(down);
...@@ -1004,7 +1004,7 @@ void main() { ...@@ -1004,7 +1004,7 @@ void main() {
expect(log, equals(<String>['scale-start', 'scale-update'])); expect(log, equals(<String>['scale-start', 'scale-update']));
log.clear(); log.clear();
final TestPointer pointer2 = TestPointer(3); final TestPointer pointer2 = TestPointer(3, PointerDeviceKind.trackpad);
final PointerPanZoomStartEvent down2 = pointer2.panZoomStart(const Offset(10.0, 20.0)); final PointerPanZoomStartEvent down2 = pointer2.panZoomStart(const Offset(10.0, 20.0));
scale.addPointerPanZoom(down2); scale.addPointerPanZoom(down2);
drag.addPointerPanZoom(down2); drag.addPointerPanZoom(down2);
...@@ -1033,7 +1033,7 @@ void main() { ...@@ -1033,7 +1033,7 @@ void main() {
// TODO(ianh): https://github.com/flutter/flutter/issues/11384 // TODO(ianh): https://github.com/flutter/flutter/issues/11384
// In this case, we move fast, so that the scale wins. If we moved slowly, // In this case, we move fast, so that the scale wins. If we moved slowly,
// the horizontal drag would win, since it was added first. // the horizontal drag would win, since it was added first.
final TestPointer pointer3 = TestPointer(4); final TestPointer pointer3 = TestPointer(4, PointerDeviceKind.trackpad);
final PointerPanZoomStartEvent down3 = pointer3.panZoomStart(const Offset(30.0, 30.0)); final PointerPanZoomStartEvent down3 = pointer3.panZoomStart(const Offset(30.0, 30.0));
scale.addPointerPanZoom(down3); scale.addPointerPanZoom(down3);
drag.addPointerPanZoom(down3); drag.addPointerPanZoom(down3);
...@@ -1084,7 +1084,7 @@ void main() { ...@@ -1084,7 +1084,7 @@ void main() {
didEndScale = true; didEndScale = true;
}; };
final TestPointer pointer1 = TestPointer(2); final TestPointer pointer1 = TestPointer(2, PointerDeviceKind.trackpad);
final PointerPanZoomStartEvent start = pointer1.panZoomStart(Offset.zero); final PointerPanZoomStartEvent start = pointer1.panZoomStart(Offset.zero);
scale.addPointerPanZoom(start); scale.addPointerPanZoom(start);
......
...@@ -314,12 +314,12 @@ class TestPointer { ...@@ -314,12 +314,12 @@ class TestPointer {
Duration timeStamp = Duration.zero Duration timeStamp = Duration.zero
}) { }) {
assert(!isPanZoomActive); assert(!isPanZoomActive);
assert(kind == PointerDeviceKind.trackpad);
_location = location; _location = location;
_pan = Offset.zero; _pan = Offset.zero;
_isPanZoomActive = true; _isPanZoomActive = true;
return PointerPanZoomStartEvent( return PointerPanZoomStartEvent(
timeStamp: timeStamp, timeStamp: timeStamp,
kind: kind,
device: _device, device: _device,
pointer: pointer, pointer: pointer,
position: location, position: location,
...@@ -341,12 +341,12 @@ class TestPointer { ...@@ -341,12 +341,12 @@ class TestPointer {
Duration timeStamp = Duration.zero, Duration timeStamp = Duration.zero,
}) { }) {
assert(isPanZoomActive); assert(isPanZoomActive);
assert(kind == PointerDeviceKind.trackpad);
_location = location; _location = location;
final Offset panDelta = pan - _pan!; final Offset panDelta = pan - _pan!;
_pan = pan; _pan = pan;
return PointerPanZoomUpdateEvent( return PointerPanZoomUpdateEvent(
timeStamp: timeStamp, timeStamp: timeStamp,
kind: kind,
device: _device, device: _device,
pointer: pointer, pointer: pointer,
position: location, position: location,
...@@ -366,11 +366,11 @@ class TestPointer { ...@@ -366,11 +366,11 @@ class TestPointer {
Duration timeStamp = Duration.zero Duration timeStamp = Duration.zero
}) { }) {
assert(isPanZoomActive); assert(isPanZoomActive);
assert(kind == PointerDeviceKind.trackpad);
_isPanZoomActive = false; _isPanZoomActive = false;
_pan = null; _pan = null;
return PointerPanZoomEndEvent( return PointerPanZoomEndEvent(
timeStamp: timeStamp, timeStamp: timeStamp,
kind: kind,
device: _device, device: _device,
pointer: pointer, pointer: pointer,
position: location!, position: location!,
......
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