Skip to content

Commit

Permalink
Propagate pointer size from Android MotionEvent. (#23536)
Browse files Browse the repository at this point in the history
  • Loading branch information
sbaranov authored Oct 26, 2018
1 parent 709f54f commit c7b10a2
Show file tree
Hide file tree
Showing 5 changed files with 31 additions and 12 deletions.
2 changes: 1 addition & 1 deletion bin/internal/engine.version
Original file line number Diff line number Diff line change
@@ -1 +1 @@
9c46333e143bb7f0823358811da8ee96e1c13e55
dd791f36aca8fc6f13d6e2fa60f20d4ebea89825
Original file line number Diff line number Diff line change
Expand Up @@ -122,11 +122,7 @@ void diffPointerCoordsList(StringBuffer diffBuffer,

void diffPointerCoords(Map<String, dynamic> expected,
Map<String, dynamic> actual, int pointerIdx, StringBuffer diffBuffer) {
diffMaps(expected, actual, diffBuffer,
messagePrefix: '[pointerCoord $pointerIdx] ',
excludeKeys: <String>[
'size', // Currently the framework doesn't get the size from the engine.
]);
diffMaps(expected, actual, diffBuffer, messagePrefix: '[pointerCoord $pointerIdx] ');
}

void diffMaps(
Expand Down
8 changes: 8 additions & 0 deletions packages/flutter/lib/src/gestures/converter.dart
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,7 @@ class PointerEventConverter {
pressureMax: datum.pressureMax,
distance: datum.distance,
distanceMax: datum.distanceMax,
size: datum.size,
radiusMajor: radiusMajor,
radiusMinor: radiusMinor,
radiusMin: radiusMin,
Expand Down Expand Up @@ -176,6 +177,7 @@ class PointerEventConverter {
pressureMax: datum.pressureMax,
distance: datum.distance,
distanceMax: datum.distanceMax,
size: datum.size,
radiusMajor: radiusMajor,
radiusMinor: radiusMinor,
radiusMin: radiusMin,
Expand All @@ -200,6 +202,7 @@ class PointerEventConverter {
pressureMin: datum.pressureMin,
pressureMax: datum.pressureMax,
distanceMax: datum.distanceMax,
size: datum.size,
radiusMajor: radiusMajor,
radiusMinor: radiusMinor,
radiusMin: radiusMin,
Expand Down Expand Up @@ -230,6 +233,7 @@ class PointerEventConverter {
pressureMin: datum.pressureMin,
pressureMax: datum.pressureMax,
distanceMax: datum.distanceMax,
size: datum.size,
radiusMajor: radiusMajor,
radiusMinor: radiusMinor,
radiusMin: radiusMin,
Expand Down Expand Up @@ -264,6 +268,7 @@ class PointerEventConverter {
pressureMin: datum.pressureMin,
pressureMax: datum.pressureMax,
distanceMax: datum.distanceMax,
size: datum.size,
radiusMajor: radiusMajor,
radiusMinor: radiusMinor,
radiusMin: radiusMin,
Expand All @@ -290,6 +295,7 @@ class PointerEventConverter {
pressureMax: datum.pressureMax,
distance: datum.distance,
distanceMax: datum.distanceMax,
size: datum.size,
radiusMajor: radiusMajor,
radiusMinor: radiusMinor,
radiusMin: radiusMin,
Expand All @@ -310,6 +316,7 @@ class PointerEventConverter {
pressureMax: datum.pressureMax,
distance: datum.distance,
distanceMax: datum.distanceMax,
size: datum.size,
radiusMajor: radiusMajor,
radiusMinor: radiusMinor,
radiusMin: radiusMin,
Expand All @@ -335,6 +342,7 @@ class PointerEventConverter {
pressureMax: datum.pressureMax,
distance: datum.distance,
distanceMax: datum.distanceMax,
size: datum.size,
radiusMajor: radiusMajor,
radiusMinor: radiusMinor,
radiusMin: radiusMin,
Expand Down
20 changes: 20 additions & 0 deletions packages/flutter/lib/src/gestures/events.dart
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,7 @@ abstract class PointerEvent {
this.pressureMax = 1.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 @@ -183,6 +184,14 @@ abstract class PointerEvent {
/// 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 @@ -269,6 +278,7 @@ abstract class PointerEvent {
'distance: $distance, '
'distanceMin: $distanceMin, '
'distanceMax: $distanceMax, '
'size: $size, '
'radiusMajor: $radiusMajor, '
'radiusMinor: $radiusMinor, '
'radiusMin: $radiusMin, '
Expand Down Expand Up @@ -374,6 +384,7 @@ class PointerHoverEvent extends PointerEvent {
double pressureMax = 1.0,
double distance = 0.0,
double distanceMax = 0.0,
double size = 0.0,
double radiusMajor = 0.0,
double radiusMinor = 0.0,
double radiusMin = 0.0,
Expand All @@ -394,6 +405,7 @@ class PointerHoverEvent extends PointerEvent {
pressureMax: pressureMax,
distance: distance,
distanceMax: distanceMax,
size: size,
radiusMajor: radiusMajor,
radiusMinor: radiusMinor,
radiusMin: radiusMin,
Expand Down Expand Up @@ -421,6 +433,7 @@ class PointerDownEvent extends PointerEvent {
double pressureMin = 1.0,
double pressureMax = 1.0,
double distanceMax = 0.0,
double size = 0.0,
double radiusMajor = 0.0,
double radiusMinor = 0.0,
double radiusMin = 0.0,
Expand All @@ -441,6 +454,7 @@ class PointerDownEvent extends PointerEvent {
pressureMax: pressureMax,
distance: 0.0,
distanceMax: distanceMax,
size: size,
radiusMajor: radiusMajor,
radiusMinor: radiusMinor,
radiusMin: radiusMin,
Expand Down Expand Up @@ -474,6 +488,7 @@ class PointerMoveEvent extends PointerEvent {
double pressureMin = 1.0,
double pressureMax = 1.0,
double distanceMax = 0.0,
double size = 0.0,
double radiusMajor = 0.0,
double radiusMinor = 0.0,
double radiusMin = 0.0,
Expand All @@ -496,6 +511,7 @@ class PointerMoveEvent extends PointerEvent {
pressureMax: pressureMax,
distance: 0.0,
distanceMax: distanceMax,
size: size,
radiusMajor: radiusMajor,
radiusMinor: radiusMinor,
radiusMin: radiusMin,
Expand Down Expand Up @@ -524,6 +540,7 @@ class PointerUpEvent extends PointerEvent {
double pressureMax = 1.0,
double distance = 0.0,
double distanceMax = 0.0,
double size = 0.0,
double radiusMajor = 0.0,
double radiusMinor = 0.0,
double radiusMin = 0.0,
Expand All @@ -544,6 +561,7 @@ class PointerUpEvent extends PointerEvent {
pressureMax: pressureMax,
distance: distance,
distanceMax: distanceMax,
size: size,
radiusMajor: radiusMajor,
radiusMinor: radiusMinor,
radiusMin: radiusMin,
Expand All @@ -570,6 +588,7 @@ class PointerCancelEvent extends PointerEvent {
double pressureMax = 1.0,
double distance = 0.0,
double distanceMax = 0.0,
double size = 0.0,
double radiusMajor = 0.0,
double radiusMinor = 0.0,
double radiusMin = 0.0,
Expand All @@ -589,6 +608,7 @@ class PointerCancelEvent extends PointerEvent {
pressureMax: pressureMax,
distance: distance,
distanceMax: distanceMax,
size: size,
radiusMajor: radiusMajor,
radiusMinor: radiusMinor,
radiusMin: radiusMin,
Expand Down
7 changes: 1 addition & 6 deletions packages/flutter/lib/src/rendering/platform_view.dart
Original file line number Diff line number Diff line change
Expand Up @@ -422,12 +422,7 @@ class _MotionEventsDispatcher {
return AndroidPointerCoords(
orientation: event.orientation,
pressure: event.pressure,
// Currently the engine omits the pointer size, for now I'm fixing this to 0.33 which is roughly
// what I typically see on Android.
//
// TODO(amirh): Use the original pointer's size.
// https://github.com/flutter/flutter/issues/20300
size: 0.333,
size: event.size,
toolMajor: event.radiusMajor,
toolMinor: event.radiusMinor,
touchMajor: event.radiusMajor,
Expand Down

0 comments on commit c7b10a2

Please sign in to comment.