Commit 0f70464e authored by Jason Simmons's avatar Jason Simmons

Treat pointer cancel events similarly to pointer up events (#3242)

parent c49d291f
......@@ -61,14 +61,14 @@ abstract class Gesturer extends BindingBase implements HitTestTarget, HitTestabl
HitTestResult result = new HitTestResult();
hitTest(result, event.position);
_hitTests[event.pointer] = result;
} else if (event is! PointerUpEvent) {
} else if (event is! PointerUpEvent && event is! PointerCancelEvent) {
assert(event.down == _hitTests.containsKey(event.pointer));
if (!event.down)
return; // we currently ignore add, remove, and hover move events
}
assert(_hitTests[event.pointer] != null);
dispatchEvent(event, _hitTests[event.pointer]);
if (event is PointerUpEvent) {
if (event is PointerUpEvent || event is PointerCancelEvent) {
assert(_hitTests.containsKey(event.pointer));
_hitTests.remove(event.pointer);
}
......
// Copyright 2016 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
import 'dart:ui' as ui;
import 'package:flutter/gestures.dart';
import 'package:flutter/services.dart';
import 'package:mojo/bindings.dart' as mojo_bindings;
import 'package:sky_services/pointer/pointer.mojom.dart';
import 'package:test/test.dart';
typedef void HandleEventCallback(PointerEvent event);
class TestGestureFlutterBinding extends BindingBase with Gesturer {
HandleEventCallback callback;
@override
void handleEvent(PointerEvent event, HitTestEntry entry) {
if (callback != null)
callback(event);
super.handleEvent(event, entry);
}
}
TestGestureFlutterBinding _binding = new TestGestureFlutterBinding();
void ensureTestGesturer() {
if (_binding == null)
_binding = new TestGestureFlutterBinding();
assert(Gesturer.instance != null);
}
void main() {
setUp(ensureTestGesturer);
test('Pointer tap events', () {
mojo_bindings.Encoder encoder = new mojo_bindings.Encoder();
PointerPacket packet = new PointerPacket();
packet.pointers = <Pointer>[new Pointer(), new Pointer()];
packet.pointers[0].type = PointerType.down;
packet.pointers[0].kind = PointerKind.touch;
packet.pointers[1].type = PointerType.up;
packet.pointers[1].kind = PointerKind.touch;
packet.encode(encoder);
List<PointerEvent> events = <PointerEvent>[];
_binding.callback = (PointerEvent event) => events.add(event);
ui.window.onPointerPacket(encoder.message.buffer);
expect(events[0].runtimeType, equals(PointerDownEvent));
expect(events[1].runtimeType, equals(PointerUpEvent));
});
test('Pointer cancel events', () {
mojo_bindings.Encoder encoder = new mojo_bindings.Encoder();
PointerPacket packet = new PointerPacket();
packet.pointers = <Pointer>[new Pointer(), new Pointer()];
packet.pointers[0].type = PointerType.down;
packet.pointers[0].kind = PointerKind.touch;
packet.pointers[1].type = PointerType.cancel;
packet.pointers[1].kind = PointerKind.touch;
packet.encode(encoder);
List<PointerEvent> events = <PointerEvent>[];
_binding.callback = (PointerEvent event) => events.add(event);
ui.window.onPointerPacket(encoder.message.buffer);
expect(events[0].runtimeType, equals(PointerDownEvent));
expect(events[1].runtimeType, equals(PointerCancelEvent));
});
}
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