Skip to content

Commit

Permalink
Propagate pointer size from Android MotionEvent (flutter#6662)
Browse files Browse the repository at this point in the history
  • Loading branch information
sbaranov authored Oct 26, 2018
1 parent 270b02b commit dd791f3
Show file tree
Hide file tree
Showing 5 changed files with 17 additions and 3 deletions.
3 changes: 2 additions & 1 deletion lib/ui/hooks.dart
Original file line number Diff line number Diff line change
Expand Up @@ -196,7 +196,7 @@ void _invoke3<A1, A2, A3>(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;
Expand All @@ -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),
Expand Down
10 changes: 10 additions & 0 deletions lib/ui/pointer.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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;

Expand Down Expand Up @@ -208,6 +217,7 @@ class PointerData {
'pressureMax: $pressureMax, '
'distance: $distance, '
'distanceMax: $distanceMax, '
'size: $size, '
'radiusMajor: $radiusMajor, '
'radiusMinor: $radiusMinor, '
'radiusMin: $radiusMin, '
Expand Down
2 changes: 1 addition & 1 deletion lib/ui/window/pointer_data.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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");
Expand Down
1 change: 1 addition & 0 deletions lib/ui/window/pointer_data.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
4 changes: 3 additions & 1 deletion shell/platform/android/io/flutter/view/FlutterView.java
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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();
Expand Down

0 comments on commit dd791f3

Please sign in to comment.