Unverified Commit 7beb09e7 authored by Tong Mu's avatar Tong Mu Committed by GitHub

Redo "Remove pressure customization from some pointer events" (#30874)

* Revert "Revert "Remove pressure customization from some pointer events (#30414)" (#30873)"

This reverts commit f34c2ef0.

* Revert pressure removal of PointerUpEvent

* Replace PR with an issue

* Add tests for fromMouseEvent
parent c8b00a9f
...@@ -337,7 +337,6 @@ class PointerEventConverter { ...@@ -337,7 +337,6 @@ class PointerEventConverter {
position: position, position: position,
buttons: datum.buttons, buttons: datum.buttons,
obscured: datum.obscured, obscured: datum.obscured,
pressure: datum.pressure,
pressureMin: datum.pressureMin, pressureMin: datum.pressureMin,
pressureMax: datum.pressureMax, pressureMax: datum.pressureMax,
distance: datum.distance, distance: datum.distance,
...@@ -364,7 +363,6 @@ class PointerEventConverter { ...@@ -364,7 +363,6 @@ class PointerEventConverter {
position: state.lastPosition, // Change position in Hover position: state.lastPosition, // Change position in Hover
buttons: datum.buttons, buttons: datum.buttons,
obscured: datum.obscured, obscured: datum.obscured,
pressure: datum.pressure,
pressureMin: datum.pressureMin, pressureMin: datum.pressureMin,
pressureMax: datum.pressureMax, pressureMax: datum.pressureMax,
distance: datum.distance, distance: datum.distance,
......
...@@ -372,7 +372,6 @@ class PointerAddedEvent extends PointerEvent { ...@@ -372,7 +372,6 @@ class PointerAddedEvent extends PointerEvent {
int device = 0, int device = 0,
Offset position = Offset.zero, Offset position = Offset.zero,
bool obscured = false, bool obscured = false,
double pressure = 0.0,
double pressureMin = 1.0, double pressureMin = 1.0,
double pressureMax = 1.0, double pressureMax = 1.0,
double distance = 0.0, double distance = 0.0,
...@@ -387,7 +386,7 @@ class PointerAddedEvent extends PointerEvent { ...@@ -387,7 +386,7 @@ class PointerAddedEvent extends PointerEvent {
device: device, device: device,
position: position, position: position,
obscured: obscured, obscured: obscured,
pressure: pressure, pressure: 0.0,
pressureMin: pressureMin, pressureMin: pressureMin,
pressureMax: pressureMax, pressureMax: pressureMax,
distance: distance, distance: distance,
...@@ -412,7 +411,6 @@ class PointerRemovedEvent extends PointerEvent { ...@@ -412,7 +411,6 @@ class PointerRemovedEvent extends PointerEvent {
PointerDeviceKind kind = PointerDeviceKind.touch, PointerDeviceKind kind = PointerDeviceKind.touch,
int device = 0, int device = 0,
bool obscured = false, bool obscured = false,
double pressure = 0.0,
double pressureMin = 1.0, double pressureMin = 1.0,
double pressureMax = 1.0, double pressureMax = 1.0,
double distanceMax = 0.0, double distanceMax = 0.0,
...@@ -424,7 +422,7 @@ class PointerRemovedEvent extends PointerEvent { ...@@ -424,7 +422,7 @@ class PointerRemovedEvent extends PointerEvent {
device: device, device: device,
position: null, position: null,
obscured: obscured, obscured: obscured,
pressure: pressure, pressure: 0.0,
pressureMin: pressureMin, pressureMin: pressureMin,
pressureMax: pressureMax, pressureMax: pressureMax,
distanceMax: distanceMax, distanceMax: distanceMax,
...@@ -455,7 +453,6 @@ class PointerHoverEvent extends PointerEvent { ...@@ -455,7 +453,6 @@ class PointerHoverEvent extends PointerEvent {
Offset delta = Offset.zero, Offset delta = Offset.zero,
int buttons = 0, int buttons = 0,
bool obscured = false, bool obscured = false,
double pressure = 0.0,
double pressureMin = 1.0, double pressureMin = 1.0,
double pressureMax = 1.0, double pressureMax = 1.0,
double distance = 0.0, double distance = 0.0,
...@@ -477,7 +474,7 @@ class PointerHoverEvent extends PointerEvent { ...@@ -477,7 +474,7 @@ class PointerHoverEvent extends PointerEvent {
buttons: buttons, buttons: buttons,
down: false, down: false,
obscured: obscured, obscured: obscured,
pressure: pressure, pressure: 0.0,
pressureMin: pressureMin, pressureMin: pressureMin,
pressureMax: pressureMax, pressureMax: pressureMax,
distance: distance, distance: distance,
...@@ -515,7 +512,6 @@ class PointerEnterEvent extends PointerEvent { ...@@ -515,7 +512,6 @@ class PointerEnterEvent extends PointerEvent {
Offset delta = Offset.zero, Offset delta = Offset.zero,
int buttons = 0, int buttons = 0,
bool obscured = false, bool obscured = false,
double pressure = 0.0,
double pressureMin = 1.0, double pressureMin = 1.0,
double pressureMax = 1.0, double pressureMax = 1.0,
double distance = 0.0, double distance = 0.0,
...@@ -537,7 +533,7 @@ class PointerEnterEvent extends PointerEvent { ...@@ -537,7 +533,7 @@ class PointerEnterEvent extends PointerEvent {
buttons: buttons, buttons: buttons,
down: false, down: false,
obscured: obscured, obscured: obscured,
pressure: pressure, pressure: 0.0,
pressureMin: pressureMin, pressureMin: pressureMin,
pressureMax: pressureMax, pressureMax: pressureMax,
distance: distance, distance: distance,
...@@ -561,16 +557,14 @@ class PointerEnterEvent extends PointerEvent { ...@@ -561,16 +557,14 @@ class PointerEnterEvent extends PointerEvent {
/// Creates an enter event from a [PointerEvent]. /// Creates an enter event from a [PointerEvent].
/// ///
/// This is used by the [MouseTracker] to synthesize enter events. /// This is used by the [MouseTracker] to synthesize enter events.
PointerEnterEvent.fromMouseEvent(PointerEvent event) : super( PointerEnterEvent.fromMouseEvent(PointerEvent event) : this(
timeStamp: event?.timeStamp, timeStamp: event?.timeStamp,
kind: event?.kind, kind: event?.kind,
device: event?.device, device: event?.device,
position: event?.position, position: event?.position,
delta: event?.delta, delta: event?.delta,
buttons: event?.buttons, buttons: event?.buttons,
down: event?.down,
obscured: event?.obscured, obscured: event?.obscured,
pressure: event?.pressure,
pressureMin: event?.pressureMin, pressureMin: event?.pressureMin,
pressureMax: event?.pressureMax, pressureMax: event?.pressureMax,
distance: event?.distance, distance: event?.distance,
...@@ -608,7 +602,6 @@ class PointerExitEvent extends PointerEvent { ...@@ -608,7 +602,6 @@ class PointerExitEvent extends PointerEvent {
Offset delta = Offset.zero, Offset delta = Offset.zero,
int buttons = 0, int buttons = 0,
bool obscured = false, bool obscured = false,
double pressure = 0.0,
double pressureMin = 1.0, double pressureMin = 1.0,
double pressureMax = 1.0, double pressureMax = 1.0,
double distance = 0.0, double distance = 0.0,
...@@ -630,7 +623,7 @@ class PointerExitEvent extends PointerEvent { ...@@ -630,7 +623,7 @@ class PointerExitEvent extends PointerEvent {
buttons: buttons, buttons: buttons,
down: false, down: false,
obscured: obscured, obscured: obscured,
pressure: pressure, pressure: 0.0,
pressureMin: pressureMin, pressureMin: pressureMin,
pressureMax: pressureMax, pressureMax: pressureMax,
distance: distance, distance: distance,
...@@ -654,16 +647,14 @@ class PointerExitEvent extends PointerEvent { ...@@ -654,16 +647,14 @@ class PointerExitEvent extends PointerEvent {
/// Creates an exit event from a [PointerEvent]. /// Creates an exit event from a [PointerEvent].
/// ///
/// This is used by the [MouseTracker] to synthesize exit events. /// This is used by the [MouseTracker] to synthesize exit events.
PointerExitEvent.fromMouseEvent(PointerEvent event) : super( PointerExitEvent.fromMouseEvent(PointerEvent event) : this(
timeStamp: event?.timeStamp, timeStamp: event?.timeStamp,
kind: event?.kind, kind: event?.kind,
device: event?.device, device: event?.device,
position: event?.position, position: event?.position,
delta: event?.delta, delta: event?.delta,
buttons: event?.buttons, buttons: event?.buttons,
down: event?.down,
obscured: event?.obscured, obscured: event?.obscured,
pressure: event?.pressure,
pressureMin: event?.pressureMin, pressureMin: event?.pressureMin,
pressureMax: event?.pressureMax, pressureMax: event?.pressureMax,
distance: event?.distance, distance: event?.distance,
...@@ -800,6 +791,8 @@ class PointerUpEvent extends PointerEvent { ...@@ -800,6 +791,8 @@ class PointerUpEvent extends PointerEvent {
Offset position = Offset.zero, Offset position = Offset.zero,
int buttons = 0, int buttons = 0,
bool obscured = false, bool obscured = false,
// Allow pressure customization here because PointerUpEvent can contain
// non-zero pressure. See https://github.com/flutter/flutter/issues/31340
double pressure = 0.0, double pressure = 0.0,
double pressureMin = 1.0, double pressureMin = 1.0,
double pressureMax = 1.0, double pressureMax = 1.0,
...@@ -908,7 +901,6 @@ class PointerCancelEvent extends PointerEvent { ...@@ -908,7 +901,6 @@ class PointerCancelEvent extends PointerEvent {
Offset position = Offset.zero, Offset position = Offset.zero,
int buttons = 0, int buttons = 0,
bool obscured = false, bool obscured = false,
double pressure = 0.0,
double pressureMin = 1.0, double pressureMin = 1.0,
double pressureMax = 1.0, double pressureMax = 1.0,
double distance = 0.0, double distance = 0.0,
...@@ -929,7 +921,7 @@ class PointerCancelEvent extends PointerEvent { ...@@ -929,7 +921,7 @@ class PointerCancelEvent extends PointerEvent {
buttons: buttons, buttons: buttons,
down: false, down: false,
obscured: obscured, obscured: obscured,
pressure: pressure, pressure: 0.0,
pressureMin: pressureMin, pressureMin: pressureMin,
pressureMax: pressureMax, pressureMax: pressureMax,
distance: distance, distance: distance,
......
...@@ -20,6 +20,83 @@ void main() { ...@@ -20,6 +20,83 @@ void main() {
expect(nthStylusButton(2), kSecondaryStylusButton); expect(nthStylusButton(2), kSecondaryStylusButton);
}); });
group('fromMouseEvent', () {
const PointerEvent hover = PointerHoverEvent(
timeStamp: Duration(days: 1),
kind: PointerDeviceKind.unknown,
device: 10,
position: Offset(101.0, 202.0),
buttons: 7,
obscured: true,
pressureMax: 2.1,
pressureMin: 1.1,
distance: 11,
distanceMax: 110,
size: 11,
radiusMajor: 11,
radiusMinor: 9,
radiusMin: 1.1,
radiusMax: 22,
orientation: 1.1,
tilt: 1.1,
synthesized: true,
);
test('PointerEnterEvent.fromMouseEvent', () {
final PointerEnterEvent event = PointerEnterEvent.fromMouseEvent(hover);
const PointerEnterEvent empty = PointerEnterEvent();
expect(event.timeStamp, hover.timeStamp);
expect(event.pointer, empty.pointer);
expect(event.kind, hover.kind);
expect(event.device, hover.device);
expect(event.position, hover.position);
expect(event.buttons, hover.buttons);
expect(event.down, empty.down);
expect(event.obscured, hover.obscured);
expect(event.pressure, empty.pressure);
expect(event.pressureMin, hover.pressureMin);
expect(event.pressureMax, hover.pressureMax);
expect(event.distance, hover.distance);
expect(event.distanceMax, hover.distanceMax);
expect(event.distanceMax, hover.distanceMax);
expect(event.size, hover.size);
expect(event.radiusMajor, hover.radiusMajor);
expect(event.radiusMinor, hover.radiusMinor);
expect(event.radiusMin, hover.radiusMin);
expect(event.radiusMax, hover.radiusMax);
expect(event.orientation, hover.orientation);
expect(event.tilt, hover.tilt);
expect(event.synthesized, hover.synthesized);
});
test('PointerExitEvent.fromMouseEvent', () {
final PointerExitEvent event = PointerExitEvent.fromMouseEvent(hover);
const PointerExitEvent empty = PointerExitEvent();
expect(event.timeStamp, hover.timeStamp);
expect(event.pointer, empty.pointer);
expect(event.kind, hover.kind);
expect(event.device, hover.device);
expect(event.position, hover.position);
expect(event.buttons, hover.buttons);
expect(event.down, empty.down);
expect(event.obscured, hover.obscured);
expect(event.pressure, empty.pressure);
expect(event.pressureMin, hover.pressureMin);
expect(event.pressureMax, hover.pressureMax);
expect(event.distance, hover.distance);
expect(event.distanceMax, hover.distanceMax);
expect(event.distanceMax, hover.distanceMax);
expect(event.size, hover.size);
expect(event.radiusMajor, hover.radiusMajor);
expect(event.radiusMinor, hover.radiusMinor);
expect(event.radiusMin, hover.radiusMin);
expect(event.radiusMax, hover.radiusMax);
expect(event.orientation, hover.orientation);
expect(event.tilt, hover.tilt);
expect(event.synthesized, hover.synthesized);
});
});
group('Default values of PointerEvents:', () { group('Default values of PointerEvents:', () {
// Some parameters are intentionally set to a non-trivial value. // Some parameters are intentionally set to a non-trivial value.
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment