Unverified Commit a5061bf9 authored by Bernardo Ferrari's avatar Bernardo Ferrari Committed by GitHub

Fix GestureRecognizer allowedButtonsFilter. (#122227)

parent 4792f39d
...@@ -250,9 +250,10 @@ class LongPressGestureRecognizer extends PrimaryPointerGestureRecognizer { ...@@ -250,9 +250,10 @@ class LongPressGestureRecognizer extends PrimaryPointerGestureRecognizer {
super.postAcceptSlopTolerance = null, super.postAcceptSlopTolerance = null,
super.supportedDevices, super.supportedDevices,
super.debugOwner, super.debugOwner,
super.allowedButtonsFilter = _defaultButtonAcceptBehavior, AllowedButtonsFilter? allowedButtonsFilter,
}) : super( }) : super(
deadline: duration ?? kLongPressTimeout, deadline: duration ?? kLongPressTimeout,
allowedButtonsFilter: allowedButtonsFilter ?? _defaultButtonAcceptBehavior,
); );
bool _longPressAccepted = false; bool _longPressAccepted = false;
......
...@@ -78,8 +78,8 @@ abstract class DragGestureRecognizer extends OneSequenceGestureRecognizer { ...@@ -78,8 +78,8 @@ abstract class DragGestureRecognizer extends OneSequenceGestureRecognizer {
this.dragStartBehavior = DragStartBehavior.start, this.dragStartBehavior = DragStartBehavior.start,
this.velocityTrackerBuilder = _defaultBuilder, this.velocityTrackerBuilder = _defaultBuilder,
super.supportedDevices, super.supportedDevices,
super.allowedButtonsFilter = _defaultButtonAcceptBehavior, AllowedButtonsFilter? allowedButtonsFilter,
}); }) : super(allowedButtonsFilter: allowedButtonsFilter ?? _defaultButtonAcceptBehavior);
static VelocityTracker _defaultBuilder(PointerEvent event) => VelocityTracker.withKind(event.kind); static VelocityTracker _defaultBuilder(PointerEvent event) => VelocityTracker.withKind(event.kind);
......
...@@ -216,8 +216,8 @@ abstract class MultiDragGestureRecognizer extends GestureRecognizer { ...@@ -216,8 +216,8 @@ abstract class MultiDragGestureRecognizer extends GestureRecognizer {
MultiDragGestureRecognizer({ MultiDragGestureRecognizer({
required super.debugOwner, required super.debugOwner,
super.supportedDevices, super.supportedDevices,
super.allowedButtonsFilter = _defaultButtonAcceptBehavior, AllowedButtonsFilter? allowedButtonsFilter,
}); }) : super(allowedButtonsFilter: allowedButtonsFilter ?? _defaultButtonAcceptBehavior);
// Accept the input if, and only if, [kPrimaryButton] is pressed. // Accept the input if, and only if, [kPrimaryButton] is pressed.
static bool _defaultButtonAcceptBehavior(int buttons) => buttons == kPrimaryButton; static bool _defaultButtonAcceptBehavior(int buttons) => buttons == kPrimaryButton;
......
...@@ -119,8 +119,8 @@ class DoubleTapGestureRecognizer extends GestureRecognizer { ...@@ -119,8 +119,8 @@ class DoubleTapGestureRecognizer extends GestureRecognizer {
DoubleTapGestureRecognizer({ DoubleTapGestureRecognizer({
super.debugOwner, super.debugOwner,
super.supportedDevices, super.supportedDevices,
super.allowedButtonsFilter = _defaultButtonAcceptBehavior, AllowedButtonsFilter? allowedButtonsFilter,
}); }) : super(allowedButtonsFilter: allowedButtonsFilter ?? _defaultButtonAcceptBehavior);
// The default value for [allowedButtonsFilter]. // The default value for [allowedButtonsFilter].
// Accept the input if, and only if, [kPrimaryButton] is pressed. // Accept the input if, and only if, [kPrimaryButton] is pressed.
......
...@@ -90,4 +90,25 @@ void main() { ...@@ -90,4 +90,25 @@ void main() {
expect(didStartDrag, isFalse); expect(didStartDrag, isFalse);
drag.dispose(); drag.dispose();
}); });
test('allowedButtonsFilter should work the same when null or not specified', () {
// Regression test for https://github.com/flutter/flutter/pull/122227
final ImmediateMultiDragGestureRecognizer recognizer1 = ImmediateMultiDragGestureRecognizer();
// ignore: avoid_redundant_argument_values
final ImmediateMultiDragGestureRecognizer recognizer2 = ImmediateMultiDragGestureRecognizer(allowedButtonsFilter: null);
// We want to test _allowedButtonsFilter, which is called in this method.
const PointerDownEvent allowedPointer = PointerDownEvent(timeStamp: Duration(days: 10));
// ignore: invalid_use_of_protected_member
expect(recognizer1.isPointerAllowed(allowedPointer), true);
// ignore: invalid_use_of_protected_member
expect(recognizer2.isPointerAllowed(allowedPointer), true);
const PointerDownEvent rejectedPointer = PointerDownEvent(timeStamp: Duration(days: 10), buttons: kMiddleMouseButton);
// ignore: invalid_use_of_protected_member
expect(recognizer1.isPointerAllowed(rejectedPointer), false);
// ignore: invalid_use_of_protected_member
expect(recognizer2.isPointerAllowed(rejectedPointer), false);
});
} }
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