Skip to content

Commit

Permalink
Moves pointer event sanitizing to engine. (#13697)
Browse files Browse the repository at this point in the history
* Moves pointer event sanitizing to engine

* fix comment format

* fix formatting

* addressing comment

* fix format

* fix format

* addressing comment
  • Loading branch information
chunhtai committed Nov 19, 2019
1 parent f4fba66 commit 132d38c
Show file tree
Hide file tree
Showing 19 changed files with 1,212 additions and 16 deletions.
3 changes: 3 additions & 0 deletions ci/licenses_golden/licenses_flutter
Original file line number Diff line number Diff line change
Expand Up @@ -344,6 +344,9 @@ FILE: ../../../flutter/lib/ui/window/pointer_data.cc
FILE: ../../../flutter/lib/ui/window/pointer_data.h
FILE: ../../../flutter/lib/ui/window/pointer_data_packet.cc
FILE: ../../../flutter/lib/ui/window/pointer_data_packet.h
FILE: ../../../flutter/lib/ui/window/pointer_data_packet_converter.cc
FILE: ../../../flutter/lib/ui/window/pointer_data_packet_converter.h
FILE: ../../../flutter/lib/ui/window/pointer_data_packet_converter_unittests.cc
FILE: ../../../flutter/lib/ui/window/viewport_metrics.cc
FILE: ../../../flutter/lib/ui/window/viewport_metrics.h
FILE: ../../../flutter/lib/ui/window/window.cc
Expand Down
3 changes: 3 additions & 0 deletions lib/ui/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,8 @@ source_set("ui") {
"window/pointer_data.h",
"window/pointer_data_packet.cc",
"window/pointer_data_packet.h",
"window/pointer_data_packet_converter.cc",
"window/pointer_data_packet_converter.h",
"window/viewport_metrics.cc",
"window/viewport_metrics.h",
"window/window.cc",
Expand Down Expand Up @@ -161,6 +163,7 @@ if (current_toolchain == host_toolchain) {

sources = [
"painting/image_decoder_unittests.cc",
"window/pointer_data_packet_converter_unittests.cc",
]

deps = [
Expand Down
9 changes: 7 additions & 2 deletions lib/ui/hooks.dart
Original file line number Diff line number Diff line change
Expand Up @@ -308,8 +308,9 @@ void _invoke3<A1, A2, A3>(void callback(A1 a1, A2 a2, A3 a3), Zone zone, A1 arg1
// If this value changes, update the encoding code in the following files:
//
// * pointer_data.cc
// * FlutterView.java
const int _kPointerDataFieldCount = 24;
// * pointers.dart
// * AndroidTouchProcessor.java
const int _kPointerDataFieldCount = 28;

PointerDataPacket _unpackPointerDataPacket(ByteData packet) {
const int kStride = Int64List.bytesPerElement;
Expand All @@ -325,10 +326,14 @@ PointerDataPacket _unpackPointerDataPacket(ByteData packet) {
kind: PointerDeviceKind.values[packet.getInt64(kStride * offset++, _kFakeHostEndian)],
signalKind: PointerSignalKind.values[packet.getInt64(kStride * offset++, _kFakeHostEndian)],
device: packet.getInt64(kStride * offset++, _kFakeHostEndian),
pointerIdentifier: packet.getInt64(kStride * offset++, _kFakeHostEndian),
physicalX: packet.getFloat64(kStride * offset++, _kFakeHostEndian),
physicalY: packet.getFloat64(kStride * offset++, _kFakeHostEndian),
physicalDeltaX: packet.getFloat64(kStride * offset++, _kFakeHostEndian),
physicalDeltaY: packet.getFloat64(kStride * offset++, _kFakeHostEndian),
buttons: packet.getInt64(kStride * offset++, _kFakeHostEndian),
obscured: packet.getInt64(kStride * offset++, _kFakeHostEndian) != 0,
synthesized: packet.getInt64(kStride * offset++, _kFakeHostEndian) != 0,
pressure: packet.getFloat64(kStride * offset++, _kFakeHostEndian),
pressureMin: packet.getFloat64(kStride * offset++, _kFakeHostEndian),
pressureMax: packet.getFloat64(kStride * offset++, _kFakeHostEndian),
Expand Down
28 changes: 28 additions & 0 deletions lib/ui/pointer.dart
Original file line number Diff line number Diff line change
Expand Up @@ -75,10 +75,14 @@ class PointerData {
this.kind = PointerDeviceKind.touch,
this.signalKind,
this.device = 0,
this.pointerIdentifier = 0,
this.physicalX = 0.0,
this.physicalY = 0.0,
this.physicalDeltaX = 0.0,
this.physicalDeltaY = 0.0,
this.buttons = 0,
this.obscured = false,
this.synthesized = false,
this.pressure = 0.0,
this.pressureMin = 0.0,
this.pressureMax = 0.0,
Expand Down Expand Up @@ -111,6 +115,12 @@ class PointerData {
/// Unique identifier for the pointing device, reused across interactions.
final int device;

/// Unique identifier for the pointer.
///
/// This field changes for each new pointer down event. Framework uses this
/// identifier to determine hit test result.
final int pointerIdentifier;

/// X coordinate of the position of the pointer, in physical pixels in the
/// global coordinate space.
final double physicalX;
Expand All @@ -119,6 +129,12 @@ class PointerData {
/// global coordinate space.
final double physicalY;

/// The distance of pointer movement on X coordinate in physical pixels.
final double physicalDeltaX;

/// The distance of pointer movement on Y coordinate in physical pixels.
final double physicalDeltaY;

/// Bit field using the *Button constants (primaryMouseButton,
/// secondaryStylusButton, etc). For example, if this has the value 6 and the
/// [kind] is [PointerDeviceKind.invertedStylus], then this indicates an
Expand All @@ -130,6 +146,14 @@ class PointerData {
/// implemented.)
final bool obscured;

/// Set if this pointer data was synthesized by pointer data packet converter.
/// pointer data packet converter will synthesize additional pointer datas if
/// the input sequence of pointer data is illegal.
///
/// For example, a down pointer data will be synthesized if the converter receives
/// a move pointer data while the pointer is not previously down.
final bool synthesized;

/// The pressure of the touch as a number ranging from 0.0, indicating a touch
/// with no discernible pressure, to 1.0, indicating a touch with "normal"
/// pressure, and possibly beyond, indicating a stronger touch. For devices
Expand Down Expand Up @@ -242,9 +266,13 @@ class PointerData {
'kind: $kind, '
'signalKind: $signalKind, '
'device: $device, '
'pointerIdentifier: $pointerIdentifier, '
'physicalX: $physicalX, '
'physicalY: $physicalY, '
'physicalDeltaX: $physicalDeltaX, '
'physicalDeltaY: $physicalDeltaY, '
'buttons: $buttons, '
'synthesized: $synthesized, '
'pressure: $pressure, '
'pressureMin: $pressureMin, '
'pressureMax: $pressureMax, '
Expand Down
5 changes: 1 addition & 4 deletions lib/ui/window/pointer_data.cc
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,7 @@

namespace flutter {

// If this value changes, update the pointer data unpacking code in hooks.dart.
static constexpr int kPointerDataFieldCount = 24;

static_assert(sizeof(PointerData) == sizeof(int64_t) * kPointerDataFieldCount,
static_assert(sizeof(PointerData) == kBytesPerField * kPointerDataFieldCount,
"PointerData has the wrong size");

void PointerData::Clear() {
Expand Down
7 changes: 7 additions & 0 deletions lib/ui/window/pointer_data.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,9 @@

namespace flutter {

// If this value changes, update the pointer data unpacking code in hooks.dart.
static constexpr int kPointerDataFieldCount = 28;
static constexpr int kBytesPerField = sizeof(int64_t);
// Must match the button constants in events.dart.
enum PointerButtonMouse : int64_t {
kPointerButtonMousePrimary = 1 << 0,
Expand Down Expand Up @@ -60,10 +63,14 @@ struct alignas(8) PointerData {
DeviceKind kind;
SignalKind signal_kind;
int64_t device;
int64_t pointer_identifier;
double physical_x;
double physical_y;
double physical_delta_x;
double physical_delta_y;
int64_t buttons;
int64_t obscured;
int64_t synthesized;
double pressure;
double pressure_min;
double pressure_max;
Expand Down

0 comments on commit 132d38c

Please sign in to comment.