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 {
super.postAcceptSlopTolerance = null,
super.supportedDevices,
super.debugOwner,
super.allowedButtonsFilter = _defaultButtonAcceptBehavior,
AllowedButtonsFilter? allowedButtonsFilter,
}) : super(
deadline: duration ?? kLongPressTimeout,
allowedButtonsFilter: allowedButtonsFilter ?? _defaultButtonAcceptBehavior,
);
bool _longPressAccepted = false;
......
......@@ -78,8 +78,8 @@ abstract class DragGestureRecognizer extends OneSequenceGestureRecognizer {
this.dragStartBehavior = DragStartBehavior.start,
this.velocityTrackerBuilder = _defaultBuilder,
super.supportedDevices,
super.allowedButtonsFilter = _defaultButtonAcceptBehavior,
});
AllowedButtonsFilter? allowedButtonsFilter,
}) : super(allowedButtonsFilter: allowedButtonsFilter ?? _defaultButtonAcceptBehavior);
static VelocityTracker _defaultBuilder(PointerEvent event) => VelocityTracker.withKind(event.kind);
......
......@@ -216,8 +216,8 @@ abstract class MultiDragGestureRecognizer extends GestureRecognizer {
MultiDragGestureRecognizer({
required super.debugOwner,
super.supportedDevices,
super.allowedButtonsFilter = _defaultButtonAcceptBehavior,
});
AllowedButtonsFilter? allowedButtonsFilter,
}) : super(allowedButtonsFilter: allowedButtonsFilter ?? _defaultButtonAcceptBehavior);
// Accept the input if, and only if, [kPrimaryButton] is pressed.
static bool _defaultButtonAcceptBehavior(int buttons) => buttons == kPrimaryButton;
......
......@@ -119,8 +119,8 @@ class DoubleTapGestureRecognizer extends GestureRecognizer {
DoubleTapGestureRecognizer({
super.debugOwner,
super.supportedDevices,
super.allowedButtonsFilter = _defaultButtonAcceptBehavior,
});
AllowedButtonsFilter? allowedButtonsFilter,
}) : super(allowedButtonsFilter: allowedButtonsFilter ?? _defaultButtonAcceptBehavior);
// The default value for [allowedButtonsFilter].
// Accept the input if, and only if, [kPrimaryButton] is pressed.
......
......@@ -90,4 +90,25 @@ void main() {
expect(didStartDrag, isFalse);
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