diff --git a/engine/src/flutter/lib/ui/hooks.dart b/engine/src/flutter/lib/ui/hooks.dart index 91cdfdb615..089c08380f 100644 --- a/engine/src/flutter/lib/ui/hooks.dart +++ b/engine/src/flutter/lib/ui/hooks.dart @@ -94,14 +94,14 @@ PointerDataPacket _unpackPointerDataPacket(ByteData packet) { const int kBytesPerPointerData = _kPointerDataFieldCount * kStride; final int length = packet.lengthInBytes ~/ kBytesPerPointerData; assert(length * kBytesPerPointerData == packet.lengthInBytes); - List pointers = new List(length); + List data = new List(length); for (int i = 0; i < length; ++i) { int offset = i * _kPointerDataFieldCount; - pointers[i] = new PointerData( + data[i] = new PointerData( timeStamp: new Duration(microseconds: packet.getInt64(kStride * offset++, _kFakeHostEndian)), - pointer: packet.getInt64(kStride * offset++, _kFakeHostEndian), change: PointerChange.values[packet.getInt64(kStride * offset++, _kFakeHostEndian)], kind: PointerDeviceKind.values[packet.getInt64(kStride * offset++, _kFakeHostEndian)], + device: packet.getInt64(kStride * offset++, _kFakeHostEndian), physicalX: packet.getFloat64(kStride * offset++, _kFakeHostEndian), physicalY: packet.getFloat64(kStride * offset++, _kFakeHostEndian), buttons: packet.getInt64(kStride * offset++, _kFakeHostEndian), @@ -120,5 +120,5 @@ PointerDataPacket _unpackPointerDataPacket(ByteData packet) { ); assert(offset == (i + 1) * _kPointerDataFieldCount); } - return new PointerDataPacket(pointers: pointers); + return new PointerDataPacket(data: data); } diff --git a/engine/src/flutter/lib/ui/pointer.dart b/engine/src/flutter/lib/ui/pointer.dart index c71c232ea8..a631a2bc6d 100644 --- a/engine/src/flutter/lib/ui/pointer.dart +++ b/engine/src/flutter/lib/ui/pointer.dart @@ -21,10 +21,15 @@ enum PointerChange { /// detection range or might have been disconnected from the system entirely. remove, + /// The pointer has moved with respect to the device while not in contact with + /// the device. + hover, + /// The pointer has made contact with the device. down, - /// The pointer has moved with respect to the device. + /// The pointer has moved with respect to the device while in contact with the + /// device. move, /// The pointer has stopped making contact with the device. @@ -51,9 +56,9 @@ class PointerData { /// Creates an object that represents the state of a pointer. const PointerData({ this.timeStamp: Duration.ZERO, - this.pointer: 0, this.change: PointerChange.cancel, this.kind: PointerDeviceKind.touch, + this.device: 0, this.physicalX: 0.0, this.physicalY: 0.0, this.buttons: 0, @@ -74,14 +79,15 @@ class PointerData { /// Time of event dispatch, relative to an arbitrary timeline. final Duration timeStamp; - /// Unique identifier for the pointer, potentially reused. - final int pointer; - + /// How the pointer has changed since the last report. final PointerChange change; /// The kind of input device for which the event was generated. final PointerDeviceKind kind; + /// Unique identifier for the pointing device, reused across interactions. + final int device; + /// X coordinate of the position of the pointer, in physical pixels in the /// global coordinate space. final double physicalX; @@ -188,9 +194,9 @@ class PointerData { String toStringFull() { return '$runtimeType(' 'timeStamp: $timeStamp, ' - 'pointer: $pointer, ' - 'change:: $change, ' + 'change: $change, ' 'kind: $kind, ' + 'device: $device, ' 'physicalX: $physicalX, ' 'physicalY: $physicalY, ' 'buttons: $buttons, ' @@ -212,10 +218,10 @@ class PointerData { /// A sequence of reports about the state of pointers. class PointerDataPacket { /// Creates a packet of pointer data reports. - const PointerDataPacket({ this.pointers: const [] }); + const PointerDataPacket({ this.data: const [] }); /// Data about the individual pointers in this packet. /// /// This list might contain multiple pieces of data about the same pointer. - final List pointers; + final List data; } diff --git a/engine/src/flutter/lib/ui/window/pointer_data.h b/engine/src/flutter/lib/ui/window/pointer_data.h index d2da6f7071..6a23c3d689 100644 --- a/engine/src/flutter/lib/ui/window/pointer_data.h +++ b/engine/src/flutter/lib/ui/window/pointer_data.h @@ -16,6 +16,7 @@ struct alignas(8) PointerData { kCancel, kAdd, kRemove, + kHover, kDown, kMove, kUp, @@ -30,9 +31,9 @@ struct alignas(8) PointerData { }; int64_t time_stamp; - int64_t pointer; Change change; DeviceKind kind; + int64_t device; double physical_x; double physical_y; int64_t buttons; diff --git a/engine/src/flutter/shell/platform/android/io/flutter/view/FlutterView.java b/engine/src/flutter/shell/platform/android/io/flutter/view/FlutterView.java index fe8055dc1b..77e534c6fb 100644 --- a/engine/src/flutter/shell/platform/android/io/flutter/view/FlutterView.java +++ b/engine/src/flutter/shell/platform/android/io/flutter/view/FlutterView.java @@ -329,9 +329,9 @@ public class FlutterView extends SurfaceView long timeStamp = event.getEventTime() * 1000; // Convert from milliseconds to microseconds. packet.putLong(timeStamp); // time_stamp - packet.putLong(event.getPointerId(pointerIndex)); // pointer packet.putLong(pointerChange); // change packet.putLong(pointerKind); // kind + packet.putLong(event.getPointerId(pointerIndex)); // device packet.putDouble(event.getX(pointerIndex)); // physical_x packet.putDouble(event.getY(pointerIndex)); // physical_y diff --git a/engine/src/flutter/shell/platform/darwin/desktop/sky_window.mm b/engine/src/flutter/shell/platform/darwin/desktop/sky_window.mm index b43afb1e7f..465b2f5212 100644 --- a/engine/src/flutter/shell/platform/darwin/desktop/sky_window.mm +++ b/engine/src/flutter/shell/platform/darwin/desktop/sky_window.mm @@ -39,6 +39,7 @@ static inline blink::PointerData::Change PointerChangeFromNSEventPhase( @implementation SkyWindow { std::unique_ptr _platformView; + bool _mouseIsDown; } @synthesize renderSurface = _renderSurface; @@ -118,6 +119,25 @@ static inline blink::PointerData::Change PointerChangeFromNSEventPhase( pointer_data.pressure = 1.0; pointer_data.pressure_max = 1.0; + switch (pointer_data.change) { + case blink::PointerData::Change::kDown: + _mouseIsDown = true; + break; + case blink::PointerData::Change::kCancel: + case blink::PointerData::Change::kUp: + _mouseIsDown = false; + break; + case blink::PointerData::Change::kMove: + if (!_mouseIsDown) + pointer_data.change = blink::PointerData::Change::kHover; + break; + case blink::PointerData::Change::kAdd: + case blink::PointerData::Change::kRemove: + case blink::PointerData::Change::kHover: + FTL_DCHECK(!_mouseIsDown); + break; + } + blink::Threads::UI()->PostTask( [ engine = _platformView->engine().GetWeakPtr(), pointer_data ] { if (engine.get()) { diff --git a/engine/src/flutter/shell/platform/darwin/ios/framework/Source/FlutterViewController.mm b/engine/src/flutter/shell/platform/darwin/ios/framework/Source/FlutterViewController.mm index 86cfc9bedf..f609ada227 100644 --- a/engine/src/flutter/shell/platform/darwin/ios/framework/Source/FlutterViewController.mm +++ b/engine/src/flutter/shell/platform/darwin/ios/framework/Source/FlutterViewController.mm @@ -267,21 +267,21 @@ static inline PointerChangeMapperPhase PointerChangePhaseFromUITouchPhase( int i = 0; for (UITouch* touch in touches) { - int touch_identifier = 0; + int device_id = 0; switch (eventTypePhase.second) { case Accessed: - touch_identifier = _touchMapper.identifierOf(touch); + device_id = _touchMapper.identifierOf(touch); break; case Added: - touch_identifier = _touchMapper.registerTouch(touch); + device_id = _touchMapper.registerTouch(touch); break; case Removed: - touch_identifier = _touchMapper.unregisterTouch(touch); + device_id = _touchMapper.unregisterTouch(touch); break; } - DCHECK(touch_identifier != 0); + DCHECK(device_id != 0); CGPoint windowCoordinates = [touch locationInView:nil]; blink::PointerData pointer_data; @@ -291,7 +291,7 @@ static inline PointerChangeMapperPhase PointerChangePhaseFromUITouchPhase( pointer_data.time_stamp = touch.timestamp * kMicrosecondsPerSecond; pointer_data.change = eventTypePhase.first; pointer_data.kind = blink::PointerData::DeviceKind::kTouch; - pointer_data.pointer = touch_identifier; + pointer_data.device = device_id; pointer_data.physical_x = windowCoordinates.x * scale; pointer_data.physical_y = windowCoordinates.y * scale; pointer_data.pressure = 1.0;