Unverified Commit 0fb6a050 authored by Tong Mu's avatar Tong Mu Committed by GitHub

PointerDownEvent and PointerMoveEvent default `buttons` to 1 (#30579)

* Down and Move have default buttons = kPrimary.
parent 3c605d45
...@@ -8,20 +8,30 @@ import 'package:flutter/foundation.dart'; ...@@ -8,20 +8,30 @@ import 'package:flutter/foundation.dart';
export 'dart:ui' show Offset, PointerDeviceKind; export 'dart:ui' show Offset, PointerDeviceKind;
/// The bit of [PointerEvent.buttons] that corresponds to a unified behavior of /// The bit of [PointerEvent.buttons] that corresponds to the "primary
/// "basic operation". /// action" on any device.
/// ///
/// It is equivalent to: /// More specifially,
/// ///
/// * [kTouchContact]: The pointer contacts the touch screen. /// * For touch screen, it's when the pointer contacts the screen.
/// * [kStylusContact]: The stylus contacts the screen. /// * For stylus and inverted stylus, it's when the pen contacts the screen.
/// * [kPrimaryMouseButton]: The primary mouse button. /// * For mouse, it's when the primary button is pressed.
///
/// See also:
///
/// * [kTouchContact]: an alias of this constant when used by touch screen.
/// * [kStylusContact]: an alias of this constant when used by stylus.
/// * [kPrimaryMouseButton]: an alias of this constant when used by mouse.
const int kPrimaryButton = 0x01; const int kPrimaryButton = 0x01;
/// The bit of [PointerEvent.buttons] that corresponds to the primary mouse button. /// The bit of [PointerEvent.buttons] that corresponds to the primary mouse button.
/// ///
/// The primary mouse button is typically the left button on the top of the /// The primary mouse button is typically the left button on the top of the
/// mouse but can be reconfigured to be a different physical button. /// mouse but can be reconfigured to be a different physical button.
///
/// See also:
///
/// * [kTouchContact]: an alias of this constant when used by touch screen.
const int kPrimaryMouseButton = kPrimaryButton; const int kPrimaryMouseButton = kPrimaryButton;
/// The bit of [PointerEvent.buttons] that corresponds to the secondary mouse button. /// The bit of [PointerEvent.buttons] that corresponds to the secondary mouse button.
...@@ -32,6 +42,10 @@ const int kSecondaryMouseButton = 0x02; ...@@ -32,6 +42,10 @@ const int kSecondaryMouseButton = 0x02;
/// The bit of [PointerEvent.buttons] that corresponds to when a stylus /// The bit of [PointerEvent.buttons] that corresponds to when a stylus
/// contacting the screen. /// contacting the screen.
///
/// See also:
///
/// * [kPrimaryButton]: an alias of this constant for any device.
const int kStylusContact = kPrimaryButton; const int kStylusContact = kPrimaryButton;
/// The bit of [PointerEvent.buttons] that corresponds to the primary stylus button. /// The bit of [PointerEvent.buttons] that corresponds to the primary stylus button.
...@@ -67,6 +81,10 @@ const int kForwardMouseButton = 0x10; ...@@ -67,6 +81,10 @@ const int kForwardMouseButton = 0x10;
/// The bit of [PointerEvent.buttons] that corresponds to the pointer contacting /// The bit of [PointerEvent.buttons] that corresponds to the pointer contacting
/// a touch screen. /// a touch screen.
///
/// See also:
///
/// * [kPrimaryButton]: an alias of this constant for any device.
const int kTouchContact = kPrimaryButton; const int kTouchContact = kPrimaryButton;
/// The bit of [PointerEvent.buttons] that corresponds to the nth mouse button. /// The bit of [PointerEvent.buttons] that corresponds to the nth mouse button.
...@@ -672,7 +690,7 @@ class PointerDownEvent extends PointerEvent { ...@@ -672,7 +690,7 @@ class PointerDownEvent extends PointerEvent {
PointerDeviceKind kind = PointerDeviceKind.touch, PointerDeviceKind kind = PointerDeviceKind.touch,
int device = 0, int device = 0,
Offset position = Offset.zero, Offset position = Offset.zero,
int buttons = 0, int buttons = kPrimaryButton,
bool obscured = false, bool obscured = false,
double pressure = 1.0, double pressure = 1.0,
double pressureMin = 1.0, double pressureMin = 1.0,
...@@ -727,7 +745,7 @@ class PointerMoveEvent extends PointerEvent { ...@@ -727,7 +745,7 @@ class PointerMoveEvent extends PointerEvent {
int device = 0, int device = 0,
Offset position = Offset.zero, Offset position = Offset.zero,
Offset delta = Offset.zero, Offset delta = Offset.zero,
int buttons = 0, int buttons = kPrimaryButton,
bool obscured = false, bool obscured = false,
double pressure = 1.0, double pressure = 1.0,
double pressureMin = 1.0, double pressureMin = 1.0,
......
...@@ -19,4 +19,18 @@ void main() { ...@@ -19,4 +19,18 @@ void main() {
expect(nthMouseButton(2), kSecondaryMouseButton); expect(nthMouseButton(2), kSecondaryMouseButton);
expect(nthStylusButton(2), kSecondaryStylusButton); expect(nthStylusButton(2), kSecondaryStylusButton);
}); });
group('Default values of PointerEvents:', () {
// Some parameters are intentionally set to a non-trivial value.
test('PointerDownEvent', () {
const PointerDownEvent event = PointerDownEvent();
expect(event.buttons, kPrimaryButton);
});
test('PointerMoveEvent', () {
const PointerMoveEvent event = PointerMoveEvent();
expect(event.buttons, kPrimaryButton);
});
});
} }
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