From dd791f36aca8fc6f13d6e2fa60f20d4ebea89825 Mon Sep 17 00:00:00 2001 From: Stanislav Baranov Date: Fri, 26 Oct 2018 09:39:10 -0700 Subject: [PATCH] Propagate pointer size from Android MotionEvent (#6662) --- lib/ui/hooks.dart | 3 ++- lib/ui/pointer.dart | 10 ++++++++++ lib/ui/window/pointer_data.cc | 2 +- lib/ui/window/pointer_data.h | 1 + .../platform/android/io/flutter/view/FlutterView.java | 4 +++- 5 files changed, 17 insertions(+), 3 deletions(-) diff --git a/lib/ui/hooks.dart b/lib/ui/hooks.dart index d3d81b7f3cc7d..dcd8d6d093c5a 100644 --- a/lib/ui/hooks.dart +++ b/lib/ui/hooks.dart @@ -196,7 +196,7 @@ void _invoke3(void callback(A1 a1, A2 a2, A3 a3), Zone zone, A1 arg1 // // * pointer_data.cc // * FlutterView.java -const int _kPointerDataFieldCount = 19; +const int _kPointerDataFieldCount = 20; PointerDataPacket _unpackPointerDataPacket(ByteData packet) { const int kStride = Int64List.bytesPerElement; @@ -220,6 +220,7 @@ PointerDataPacket _unpackPointerDataPacket(ByteData packet) { pressureMax: packet.getFloat64(kStride * offset++, _kFakeHostEndian), distance: packet.getFloat64(kStride * offset++, _kFakeHostEndian), distanceMax: packet.getFloat64(kStride * offset++, _kFakeHostEndian), + size: packet.getFloat64(kStride * offset++, _kFakeHostEndian), radiusMajor: packet.getFloat64(kStride * offset++, _kFakeHostEndian), radiusMinor: packet.getFloat64(kStride * offset++, _kFakeHostEndian), radiusMin: packet.getFloat64(kStride * offset++, _kFakeHostEndian), diff --git a/lib/ui/pointer.dart b/lib/ui/pointer.dart index 98a4f92385e95..a55086ece63f0 100644 --- a/lib/ui/pointer.dart +++ b/lib/ui/pointer.dart @@ -71,6 +71,7 @@ class PointerData { this.pressureMax: 0.0, this.distance: 0.0, this.distanceMax: 0.0, + this.size: 0.0, this.radiusMajor: 0.0, this.radiusMinor: 0.0, this.radiusMin: 0.0, @@ -137,6 +138,14 @@ class PointerData { /// 0.0. final double distanceMax; + /// The area of the screen being pressed, scaled to a value between 0 and 1. + /// The value of size can be used to determine fat touch events. This value + /// is only set on Android, and is a device specific approximation within + /// the range of detectable values. So, for example, the value of 0.1 could + /// mean a touch with the tip of the finger, 0.2 a touch with full finger, + /// and 0.3 the full palm. + final double size; + /// The radius of the contact ellipse along the major axis, in logical pixels. final double radiusMajor; @@ -208,6 +217,7 @@ class PointerData { 'pressureMax: $pressureMax, ' 'distance: $distance, ' 'distanceMax: $distanceMax, ' + 'size: $size, ' 'radiusMajor: $radiusMajor, ' 'radiusMinor: $radiusMinor, ' 'radiusMin: $radiusMin, ' diff --git a/lib/ui/window/pointer_data.cc b/lib/ui/window/pointer_data.cc index c85a1a50b8e72..e657460cf293a 100644 --- a/lib/ui/window/pointer_data.cc +++ b/lib/ui/window/pointer_data.cc @@ -9,7 +9,7 @@ namespace blink { // If this value changes, update the pointer data unpacking code in hooks.dart. -static constexpr int kPointerDataFieldCount = 19; +static constexpr int kPointerDataFieldCount = 20; static_assert(sizeof(PointerData) == sizeof(int64_t) * kPointerDataFieldCount, "PointerData has the wrong size"); diff --git a/lib/ui/window/pointer_data.h b/lib/ui/window/pointer_data.h index 6a23c3d689d2e..1d7fe09cea7a8 100644 --- a/lib/ui/window/pointer_data.h +++ b/lib/ui/window/pointer_data.h @@ -43,6 +43,7 @@ struct alignas(8) PointerData { double pressure_max; double distance; double distance_max; + double size; double radius_major; double radius_minor; double radius_min; diff --git a/shell/platform/android/io/flutter/view/FlutterView.java b/shell/platform/android/io/flutter/view/FlutterView.java index eadd2247f8d83..a2c12cc78543d 100644 --- a/shell/platform/android/io/flutter/view/FlutterView.java +++ b/shell/platform/android/io/flutter/view/FlutterView.java @@ -488,6 +488,8 @@ private void addPointerForIndex(MotionEvent event, int pointerIndex, ByteBuffer packet.putDouble(0.0); // distance_max } + packet.putDouble(event.getSize(pointerIndex)); // size + packet.putDouble(event.getToolMajor(pointerIndex)); // radius_major packet.putDouble(event.getToolMinor(pointerIndex)); // radius_minor @@ -519,7 +521,7 @@ public boolean onTouchEvent(MotionEvent event) { } // These values must match the unpacking code in hooks.dart. - final int kPointerDataFieldCount = 19; + final int kPointerDataFieldCount = 20; final int kBytePerField = 8; int pointerCount = event.getPointerCount();