events.dart 72.1 KB
Newer Older
Ian Hickson's avatar
Ian Hickson committed
1
// Copyright 2014 The Flutter Authors. All rights reserved.
Kris Giesing's avatar
Kris Giesing committed
2 3 4
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

5

6
import 'dart:ui' show Offset, PointerDeviceKind;
7

8
import 'package:flutter/foundation.dart';
9
import 'package:vector_math/vector_math_64.dart';
10

11
export 'dart:ui' show Offset, PointerDeviceKind;
12

13 14
/// The bit of [PointerEvent.buttons] that corresponds to a cross-device
/// behavior of "primary operation".
15
///
16
/// More specifically, it includes:
17
///
18 19 20
///  * [kTouchContact]: The pointer contacts the touch screen.
///  * [kStylusContact]: The stylus contacts the screen.
///  * [kPrimaryMouseButton]: The primary mouse button.
21 22 23
///
/// See also:
///
24 25
///  * [kSecondaryButton], which describes a cross-device behavior of
///    "secondary operation".
26 27
///  * [kTertiaryButton], which describes a cross-device behavior of
///    "tertiary operation".
28 29
const int kPrimaryButton = 0x01;

30 31 32 33 34 35
/// The bit of [PointerEvent.buttons] that corresponds to a cross-device
/// behavior of "secondary operation".
///
/// It is equivalent to:
///
///  * [kPrimaryStylusButton]: The stylus contacts the screen.
36
///  * [kSecondaryMouseButton]: The secondary mouse button.
37 38 39 40 41
///
/// See also:
///
///  * [kPrimaryButton], which describes a cross-device behavior of
///    "primary operation".
42 43
///  * [kTertiaryButton], which describes a cross-device behavior of
///    "tertiary operation".
44 45
const int kSecondaryButton = 0x02;

46 47 48 49
/// 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
/// mouse but can be reconfigured to be a different physical button.
50 51 52
///
/// See also:
///
53 54
///  * [kPrimaryButton], which has the same value but describes its cross-device
///    concept.
55
const int kPrimaryMouseButton = kPrimaryButton;
56 57 58 59 60

/// The bit of [PointerEvent.buttons] that corresponds to the secondary mouse button.
///
/// The secondary mouse button is typically the right button on the top of the
/// mouse but can be reconfigured to be a different physical button.
61 62 63 64 65 66
///
/// See also:
///
///  * [kSecondaryButton], which has the same value but describes its cross-device
///    concept.
const int kSecondaryMouseButton = kSecondaryButton;
67

68 69
/// The bit of [PointerEvent.buttons] that corresponds to when a stylus
/// contacting the screen.
70 71 72
///
/// See also:
///
73 74
///  * [kPrimaryButton], which has the same value but describes its cross-device
///    concept.
75 76
const int kStylusContact = kPrimaryButton;

77 78 79 80
/// The bit of [PointerEvent.buttons] that corresponds to the primary stylus button.
///
/// The primary stylus button is typically the top of the stylus and near the
/// tip but can be reconfigured to be a different physical button.
81 82 83 84 85 86
///
/// See also:
///
///  * [kSecondaryButton], which has the same value but describes its cross-device
///    concept.
const int kPrimaryStylusButton = kSecondaryButton;
87

88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105
/// The bit of [PointerEvent.buttons] that corresponds to a cross-device
/// behavior of "tertiary operation".
///
/// It is equivalent to:
///
///  * [kMiddleMouseButton]: The tertiary mouseButton.
///  * [kSecondaryStylusButton]: The secondary button on a stylus. This is considered
///    a tertiary button as the primary button of a stylus already corresponds to a
///    "secondary operation" (where stylus contact is the primary operation).
///
/// See also:
///
///  * [kPrimaryButton], which describes a cross-device behavior of
///    "primary operation".
///  * [kSecondaryButton], which describes a cross-device behavior of
///    "secondary operation".
const int kTertiaryButton = 0x04;

106 107 108 109 110
/// The bit of [PointerEvent.buttons] that corresponds to the middle mouse button.
///
/// The middle mouse button is typically between the left and right buttons on
/// the top of the mouse but can be reconfigured to be a different physical
/// button.
111 112 113 114 115 116
///
/// See also:
///
///  * [kTertiaryButton], which has the same value but describes its cross-device
///    concept.
const int kMiddleMouseButton = kTertiaryButton;
117 118 119

/// The bit of [PointerEvent.buttons] that corresponds to the secondary stylus button.
///
120
/// The secondary stylus button is typically on the end of the stylus farthest
121
/// from the tip but can be reconfigured to be a different physical button.
122 123 124 125 126 127
///
/// See also:
///
///  * [kTertiaryButton], which has the same value but describes its cross-device
///    concept.
const int kSecondaryStylusButton = kTertiaryButton;
128 129 130 131 132

/// The bit of [PointerEvent.buttons] that corresponds to the back mouse button.
///
/// The back mouse button is typically on the left side of the mouse but can be
/// reconfigured to be a different physical button.
133
const int kBackMouseButton = 0x08;
134 135 136 137 138 139 140

/// The bit of [PointerEvent.buttons] that corresponds to the forward mouse button.
///
/// The forward mouse button is typically on the right side of the mouse but can
/// be reconfigured to be a different physical button.
const int kForwardMouseButton = 0x10;

141 142
/// The bit of [PointerEvent.buttons] that corresponds to the pointer contacting
/// a touch screen.
143 144 145
///
/// See also:
///
146 147
///  * [kPrimaryButton], which has the same value but describes its cross-device
///    concept.
148 149
const int kTouchContact = kPrimaryButton;

150 151
/// The bit of [PointerEvent.buttons] that corresponds to the nth mouse button.
///
152 153
/// The `number` argument can be at most 62 in Flutter for mobile and desktop,
/// and at most 32 on Flutter for web.
154 155 156 157 158 159 160 161
///
/// See [kPrimaryMouseButton], [kSecondaryMouseButton], [kMiddleMouseButton],
/// [kBackMouseButton], and [kForwardMouseButton] for semantic names for some
/// mouse buttons.
int nthMouseButton(int number) => (kPrimaryMouseButton << (number - 1)) & kMaxUnsignedSMI;

/// The bit of [PointerEvent.buttons] that corresponds to the nth stylus button.
///
162 163
/// The `number` argument can be at most 62 in Flutter for mobile and desktop,
/// and at most 32 on Flutter for web.
164 165 166 167
///
/// See [kPrimaryStylusButton] and [kSecondaryStylusButton] for semantic names
/// for some stylus buttons.
int nthStylusButton(int number) => (kPrimaryStylusButton << (number - 1)) & kMaxUnsignedSMI;
168

169 170
/// Returns the button of `buttons` with the smallest integer.
///
171
/// The `buttons` parameter is a bit field where each set bit represents a button.
172 173 174 175 176 177 178 179 180 181 182 183 184 185
/// This function returns the set bit closest to the least significant bit.
///
/// It returns zero when `buttons` is zero.
///
/// Example:
///
/// ```dart
///   assert(rightmostButton(0x1) == 0x1);
///   assert(rightmostButton(0x11) == 0x1);
///   assert(rightmostButton(0) == 0);
/// ```
///
/// See also:
///
186
///  * [isSingleButton], which checks if a `buttons` contains exactly one button.
187 188 189 190
int smallestButton(int buttons) => buttons & (-buttons);

/// Returns whether `buttons` contains one and only one button.
///
191
/// The `buttons` parameter is a bit field where each set bit represents a button.
192 193 194 195 196 197 198 199 200 201 202 203 204 205
/// This function returns whether there is only one set bit in the given integer.
///
/// It returns false when `buttons` is zero.
///
/// Example:
///
/// ```dart
///   assert(isSingleButton(0x1) == true);
///   assert(isSingleButton(0x11) == false);
///   assert(isSingleButton(0) == false);
/// ```
///
/// See also:
///
206 207
///  * [smallestButton], which returns the button in a `buttons` bit field with
///    the smallest integer button.
208 209
bool isSingleButton(int buttons) => buttons != 0 && (smallestButton(buttons) == buttons);

Ian Hickson's avatar
Ian Hickson committed
210
/// Base class for touch, stylus, or mouse events.
211 212 213 214 215
///
/// Pointer events operate in the coordinate space of the screen, scaled to
/// logical pixels. Logical pixels approximate a grid with about 38 pixels per
/// centimeter, or 96 pixels per inch.
///
216
/// This allows gestures to be recognized independent of the precise hardware
217 218 219 220 221 222 223 224 225 226 227 228 229 230
/// characteristics of the device. In particular, features such as touch slop
/// (see [kTouchSlop]) can be defined in terms of roughly physical lengths so
/// that the user can shift their finger by the same distance on a high-density
/// display as on a low-resolution device.
///
/// For similar reasons, pointer events are not affected by any transforms in
/// the rendering layer. This means that deltas may need to be scaled before
/// being applied to movement within the rendering. For example, if a scrolling
/// list is shown scaled by 2x, the pointer deltas will have to be scaled by the
/// inverse amount if the list is to appear to scroll with the user's finger.
///
/// See also:
///
///  * [Window.devicePixelRatio], which defines the device's current resolution.
231 232
///  * [Listener], a widget that calls callbacks in response to common pointer
///    events.
233
@immutable
234
abstract class PointerEvent with Diagnosticable {
235 236
  /// Abstract const constructor. This constructor enables subclasses to provide
  /// const constructors so that they can be used in const expressions.
Ian Hickson's avatar
Ian Hickson committed
237
  const PointerEvent({
238
    this.embedderId = 0,
239 240 241 242 243
    this.timeStamp = Duration.zero,
    this.pointer = 0,
    this.kind = PointerDeviceKind.touch,
    this.device = 0,
    this.position = Offset.zero,
244
    Offset? localPosition,
245
    this.delta = Offset.zero,
246
    Offset? localDelta,
247 248 249 250 251 252 253 254
    this.buttons = 0,
    this.down = false,
    this.obscured = false,
    this.pressure = 1.0,
    this.pressureMin = 1.0,
    this.pressureMax = 1.0,
    this.distance = 0.0,
    this.distanceMax = 0.0,
255
    this.size = 0.0,
256 257 258 259 260 261
    this.radiusMajor = 0.0,
    this.radiusMinor = 0.0,
    this.radiusMin = 0.0,
    this.radiusMax = 0.0,
    this.orientation = 0.0,
    this.tilt = 0.0,
262
    this.platformData = 0,
263
    this.synthesized = false,
264 265 266 267 268
    this.transform,
    this.original,
  }) : localPosition = localPosition ?? position,
       localDelta = localDelta ?? delta;

269 270 271 272 273 274 275 276
  /// Unique identifier that ties the [PointerEvent] to the embedder event that created it.
  ///
  /// No two pointer events can have the same [embedderId] on platforms that set it.
  /// This is different from [pointer] identifier - used for hit-testing,
  /// whereas [embedderId] is used to identify the platform event.
  ///
  /// On Android this is ID of the underlying [MotionEvent](https://developer.android.com/reference/android/view/MotionEvent).
  final int embedderId;
277

Ian Hickson's avatar
Ian Hickson committed
278 279 280
  /// Time of event dispatch, relative to an arbitrary timeline.
  final Duration timeStamp;

281 282
  /// Unique identifier for the pointer, not reused. Changes for each new
  /// pointer down event.
Kris Giesing's avatar
Kris Giesing committed
283
  final int pointer;
Ian Hickson's avatar
Ian Hickson committed
284 285 286 287

  /// The kind of input device for which the event was generated.
  final PointerDeviceKind kind;

288 289 290
  /// Unique identifier for the pointing device, reused across interactions.
  final int device;

Ian Hickson's avatar
Ian Hickson committed
291 292
  /// Coordinate of the position of the pointer, in logical pixels in the global
  /// coordinate space.
293 294 295 296 297
  ///
  /// See also:
  ///
  ///  * [localPosition], which is the [position] transformed into the local
  ///    coordinate system of the event receiver.
298
  final Offset position;
Ian Hickson's avatar
Ian Hickson committed
299

300 301 302 303 304 305
  /// The [position] transformed into the event receiver's local coordinate
  /// system according to [transform].
  ///
  /// If this event has not been transformed, [position] is returned as-is.
  /// See also:
  ///
Dan Field's avatar
Dan Field committed
306 307
  ///  * [position], which is the position in the global coordinate system of
  ///    the screen.
308 309
  final Offset localPosition;

Ian Hickson's avatar
Ian Hickson committed
310
  /// Distance in logical pixels that the pointer moved since the last
311
  /// [PointerMoveEvent] or [PointerHoverEvent].
312 313
  ///
  /// This value is always 0.0 for down, up, and cancel events.
314 315 316 317 318
  ///
  /// See also:
  ///
  ///  * [localDelta], which is the [delta] transformed into the local
  ///    coordinate space of the event receiver.
Ian Hickson's avatar
Ian Hickson committed
319 320
  final Offset delta;

321 322 323 324 325 326 327 328 329 330 331
  /// The [delta] transformed into the event receiver's local coordinate
  /// system according to [transform].
  ///
  /// If this event has not been transformed, [delta] is returned as-is.
  ///
  /// See also:
  ///
  ///  * [delta], which is the distance the pointer moved in the global
  ///    coordinate system of the screen.
  final Offset localDelta;

332 333 334 335
  /// Bit field using the *Button constants such as [kPrimaryMouseButton],
  /// [kSecondaryStylusButton], etc.
  ///
  /// For example, if this has the value 6 and the
Ian Hickson's avatar
Ian Hickson committed
336 337
  /// [kind] is [PointerDeviceKind.invertedStylus], then this indicates an
  /// upside-down stylus with both its primary and secondary buttons pressed.
Kris Giesing's avatar
Kris Giesing committed
338
  final int buttons;
Ian Hickson's avatar
Ian Hickson committed
339

340 341 342 343
  /// Set if the pointer is currently down.
  ///
  /// For touch and stylus pointers, this means the object (finger, pen) is in
  /// contact with the input surface. For mice, it means a button is pressed.
Kris Giesing's avatar
Kris Giesing committed
344
  final bool down;
Ian Hickson's avatar
Ian Hickson committed
345

346
  /// Set if an application from a different security domain is in any way
347 348 349
  /// obscuring this application's window.
  ///
  /// This is not currently implemented.
Kris Giesing's avatar
Kris Giesing committed
350
  final bool obscured;
Ian Hickson's avatar
Ian Hickson committed
351

352 353 354 355 356 357
  /// The pressure of the touch.
  ///
  /// This value is 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 that do not
  /// detect pressure (e.g. mice), returns 1.0.
Kris Giesing's avatar
Kris Giesing committed
358
  final double pressure;
Ian Hickson's avatar
Ian Hickson committed
359

360 361 362 363
  /// The minimum value that [pressure] can return for this pointer.
  ///
  /// For devices that do not detect pressure (e.g. mice), returns 1.0.
  /// This will always be a number less than or equal to 1.0.
Kris Giesing's avatar
Kris Giesing committed
364
  final double pressureMin;
Ian Hickson's avatar
Ian Hickson committed
365

366 367 368 369
  /// The maximum value that [pressure] can return for this pointer.
  ///
  /// For devices that do not detect pressure (e.g. mice), returns 1.0.
  /// This will always be a greater than or equal to 1.0.
Kris Giesing's avatar
Kris Giesing committed
370
  final double pressureMax;
Ian Hickson's avatar
Ian Hickson committed
371

372 373 374 375 376
  /// The distance of the detected object from the input surface.
  ///
  /// For instance, this value could be the distance of a stylus or finger
  /// from a touch screen, in arbitrary units on an arbitrary (not necessarily
  /// linear) scale. If the pointer is down, this is 0.0 by definition.
Kris Giesing's avatar
Kris Giesing committed
377
  final double distance;
Ian Hickson's avatar
Ian Hickson committed
378

379 380 381
  /// The minimum value that [distance] can return for this pointer.
  ///
  /// This value is always 0.0.
382
  double get distanceMin => 0.0;
Ian Hickson's avatar
Ian Hickson committed
383

384 385 386 387
  /// The maximum value that [distance] can return for this pointer.
  ///
  /// If this input device cannot detect "hover touch" input events,
  /// then this will be 0.0.
Kris Giesing's avatar
Kris Giesing committed
388
  final double distanceMax;
Ian Hickson's avatar
Ian Hickson committed
389

390 391 392 393 394 395 396 397 398 399 400
  /// The area of the screen being pressed.
  ///
  /// This value is scaled to a range between 0 and 1. It can be used to
  /// determine fat touch events. This value is only set on Android and is
  /// a device specific approximation within the range of detectable values.
  /// So, for example, the value of 0.1 could mean a touch with the tip of
  /// the finger, 0.2 a touch with full finger, and 0.3 the full palm.
  ///
  /// Because this value uses device-specific range and is uncalibrated,
  /// it is of limited use and is primarily retained in order to be able
  /// to reconstruct original pointer events for [AndroidView].
401 402
  final double size;

Ian Hickson's avatar
Ian Hickson committed
403
  /// The radius of the contact ellipse along the major axis, in logical pixels.
Kris Giesing's avatar
Kris Giesing committed
404
  final double radiusMajor;
Ian Hickson's avatar
Ian Hickson committed
405 406

  /// The radius of the contact ellipse along the minor axis, in logical pixels.
Kris Giesing's avatar
Kris Giesing committed
407
  final double radiusMinor;
Ian Hickson's avatar
Ian Hickson committed
408

409
  /// The minimum value that could be reported for [radiusMajor] and [radiusMinor]
Ian Hickson's avatar
Ian Hickson committed
410
  /// for this pointer, in logical pixels.
Kris Giesing's avatar
Kris Giesing committed
411
  final double radiusMin;
Ian Hickson's avatar
Ian Hickson committed
412

413
  /// The maximum value that could be reported for [radiusMajor] and [radiusMinor]
Ian Hickson's avatar
Ian Hickson committed
414
  /// for this pointer, in logical pixels.
Kris Giesing's avatar
Kris Giesing committed
415
  final double radiusMax;
Ian Hickson's avatar
Ian Hickson committed
416

417
  /// The orientation angle of the detected object, in radians.
Ian Hickson's avatar
Ian Hickson committed
418
  ///
419 420 421
  /// For [PointerDeviceKind.touch] events:
  ///
  /// The angle of the contact ellipse, in radians in the range:
Ian Hickson's avatar
Ian Hickson committed
422
  ///
423
  ///     -pi/2 < orientation <= pi/2
Ian Hickson's avatar
Ian Hickson committed
424 425 426 427 428 429 430
  ///
  /// ...giving the angle of the major axis of the ellipse with the y-axis
  /// (negative angles indicating an orientation along the top-left /
  /// bottom-right diagonal, positive angles indicating an orientation along the
  /// top-right / bottom-left diagonal, and zero indicating an orientation
  /// parallel with the y-axis).
  ///
431
  /// For [PointerDeviceKind.stylus] and [PointerDeviceKind.invertedStylus] events:
Ian Hickson's avatar
Ian Hickson committed
432 433 434
  ///
  /// The angle of the stylus, in radians in the range:
  ///
435
  ///     -pi < orientation <= pi
Ian Hickson's avatar
Ian Hickson committed
436 437 438 439 440 441 442 443
  ///
  /// ...giving the angle of the axis of the stylus projected onto the input
  /// surface, relative to the positive y-axis of that surface (thus 0.0
  /// indicates the stylus, if projected onto that surface, would go from the
  /// contact point vertically up in the positive y-axis direction, pi would
  /// indicate that the stylus would go down in the negative y-axis direction;
  /// pi/4 would indicate that the stylus goes up and to the right, -pi/2 would
  /// indicate that the stylus goes to the left, etc).
Kris Giesing's avatar
Kris Giesing committed
444 445
  final double orientation;

446 447 448
  /// The tilt angle of the detected object, in radians.
  ///
  /// For [PointerDeviceKind.stylus] and [PointerDeviceKind.invertedStylus] events:
Ian Hickson's avatar
Ian Hickson committed
449 450 451
  ///
  /// The angle of the stylus, in radians in the range:
  ///
452
  ///     0 <= tilt <= pi/2
Ian Hickson's avatar
Ian Hickson committed
453 454 455 456 457 458
  ///
  /// ...giving the angle of the axis of the stylus, relative to the axis
  /// perpendicular to the input surface (thus 0.0 indicates the stylus is
  /// orthogonal to the plane of the input surface, while pi/2 indicates that
  /// the stylus is flat on that surface).
  final double tilt;
459

460 461 462
  /// Opaque platform-specific data associated with the event.
  final int platformData;

463 464
  /// Set if the event was synthesized by Flutter.
  ///
465
  /// We occasionally synthesize PointerEvents that aren't exact translations
Dan Field's avatar
Dan Field committed
466
  /// of [PointerData] from the engine to cover small cross-OS discrepancies
Ian Hickson's avatar
Ian Hickson committed
467
  /// in pointer behaviors.
468 469
  ///
  /// For instance, on end events, Android always drops any location changes
470
  /// that happened between its reporting intervals when emitting the end events.
471 472 473 474 475 476
  ///
  /// On iOS, minor incorrect location changes from the previous move events
  /// can be reported on end events. We synthesize a [PointerEvent] to cover
  /// the difference between the 2 events in that case.
  final bool synthesized;

477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492
  /// The transformation used to transform this event from the global coordinate
  /// space into the coordinate space of the event receiver.
  ///
  /// This value affects what is returned by [localPosition] and [localDelta].
  /// If this value is null, it is treated as the identity transformation.
  ///
  /// Unlike a paint transform, this transform usually does not contain any
  /// "perspective" components, meaning that the third row and the third column
  /// of the matrix should be equal to "0, 0, 1, 0". This ensures that
  /// [localPosition] describes the point in the local coordinate system of the
  /// event receiver at which the user is actually touching the screen.
  ///
  /// See also:
  ///
  ///  * [transformed], which transforms this event into a different coordinate
  ///    space.
493
  final Matrix4? transform;
494 495 496 497 498 499 500 501 502 503

  /// The original un-transformed [PointerEvent] before any [transform]s were
  /// applied.
  ///
  /// If [transform] is null or the identity transformation this may be null.
  ///
  /// When multiple event receivers in different coordinate spaces receive an
  /// event, they all receive the event transformed to their local coordinate
  /// space. The [original] property can be used to determine if all those
  /// transformed events actually originated from the same pointer interaction.
504
  final PointerEvent? original;
505 506 507 508 509 510 511 512 513 514 515 516 517

  /// Transforms the event from the global coordinate space into the coordinate
  /// space of an event receiver.
  ///
  /// The coordinate space of the event receiver is described by `transform`. A
  /// null value for `transform` is treated as the identity transformation.
  ///
  /// The method may return the same object instance if for example the
  /// transformation has no effect on the event.
  ///
  /// Transforms are not commutative. If this method is called on a
  /// [PointerEvent] that has a non-null [transform] value, that value will be
  /// overridden by the provided `transform`.
518
  PointerEvent transformed(Matrix4? transform);
519

520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549
  /// Creates a copy of event with the specified properties replaced.
  PointerEvent copyWith({
    Duration? timeStamp,
    int? pointer,
    PointerDeviceKind? kind,
    int? device,
    Offset? position,
    Offset? localPosition,
    Offset? delta,
    Offset? localDelta,
    int? buttons,
    bool? obscured,
    double? pressure,
    double? pressureMin,
    double? pressureMax,
    double? distance,
    double? distanceMax,
    double? size,
    double? radiusMajor,
    double? radiusMinor,
    double? radiusMin,
    double? radiusMax,
    double? orientation,
    double? tilt,
    bool? synthesized,
    Matrix4? transform,
    PointerEvent? original,
    int? embedderId,
  });

550
  @override
551 552 553
  void debugFillProperties(DiagnosticPropertiesBuilder properties) {
    super.debugFillProperties(properties);
    properties.add(DiagnosticsProperty<Offset>('position', position));
554
    properties.add(DiagnosticsProperty<Offset>('localPosition', localPosition, defaultValue: position, level: DiagnosticLevel.debug));
555
    properties.add(DiagnosticsProperty<Offset>('delta', delta, defaultValue: Offset.zero, level: DiagnosticLevel.debug));
556
    properties.add(DiagnosticsProperty<Offset>('localDelta', localDelta, defaultValue: delta, level: DiagnosticLevel.debug));
557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578
    properties.add(DiagnosticsProperty<Duration>('timeStamp', timeStamp, defaultValue: Duration.zero, level: DiagnosticLevel.debug));
    properties.add(IntProperty('pointer', pointer, level: DiagnosticLevel.debug));
    properties.add(EnumProperty<PointerDeviceKind>('kind', kind, level: DiagnosticLevel.debug));
    properties.add(IntProperty('device', device, defaultValue: 0, level: DiagnosticLevel.debug));
    properties.add(IntProperty('buttons', buttons, defaultValue: 0, level: DiagnosticLevel.debug));
    properties.add(DiagnosticsProperty<bool>('down', down, level: DiagnosticLevel.debug));
    properties.add(DoubleProperty('pressure', pressure, defaultValue: 1.0, level: DiagnosticLevel.debug));
    properties.add(DoubleProperty('pressureMin', pressureMin, defaultValue: 1.0, level: DiagnosticLevel.debug));
    properties.add(DoubleProperty('pressureMax', pressureMax, defaultValue: 1.0, level: DiagnosticLevel.debug));
    properties.add(DoubleProperty('distance', distance, defaultValue: 0.0, level: DiagnosticLevel.debug));
    properties.add(DoubleProperty('distanceMin', distanceMin, defaultValue: 0.0, level: DiagnosticLevel.debug));
    properties.add(DoubleProperty('distanceMax', distanceMax, defaultValue: 0.0, level: DiagnosticLevel.debug));
    properties.add(DoubleProperty('size', size, defaultValue: 0.0, level: DiagnosticLevel.debug));
    properties.add(DoubleProperty('radiusMajor', radiusMajor, defaultValue: 0.0, level: DiagnosticLevel.debug));
    properties.add(DoubleProperty('radiusMinor', radiusMinor, defaultValue: 0.0, level: DiagnosticLevel.debug));
    properties.add(DoubleProperty('radiusMin', radiusMin, defaultValue: 0.0, level: DiagnosticLevel.debug));
    properties.add(DoubleProperty('radiusMax', radiusMax, defaultValue: 0.0, level: DiagnosticLevel.debug));
    properties.add(DoubleProperty('orientation', orientation, defaultValue: 0.0, level: DiagnosticLevel.debug));
    properties.add(DoubleProperty('tilt', tilt, defaultValue: 0.0, level: DiagnosticLevel.debug));
    properties.add(IntProperty('platformData', platformData, defaultValue: 0, level: DiagnosticLevel.debug));
    properties.add(FlagProperty('obscured', value: obscured, ifTrue: 'obscured', level: DiagnosticLevel.debug));
    properties.add(FlagProperty('synthesized', value: synthesized, ifTrue: 'synthesized', level: DiagnosticLevel.debug));
579
    properties.add(IntProperty('embedderId', embedderId, defaultValue: 0, level: DiagnosticLevel.debug));
580
  }
581

582
  /// Returns a complete textual description of this event.
583
  String toStringFull() {
584
    return toString(minLevel: DiagnosticLevel.fine);
585
  }
586 587 588 589 590 591

  /// Returns the transformation of `position` into the coordinate system
  /// described by `transform`.
  ///
  /// The z-value of `position` is assumed to be 0.0. If `transform` is null,
  /// `position` is returned as-is.
592
  static Offset transformPosition(Matrix4? transform, Offset position) {
593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608
    if (transform == null) {
      return position;
    }
    final Vector3 position3 = Vector3(position.dx, position.dy, 0.0);
    final Vector3 transformed3 = transform.perspectiveTransform(position3);
    return Offset(transformed3.x, transformed3.y);
  }

  /// Transforms `untransformedDelta` into the coordinate system described by
  /// `transform`.
  ///
  /// It uses the provided `untransformedEndPosition` and
  /// `transformedEndPosition` of the provided delta to increase accuracy.
  ///
  /// If `transform` is null, `untransformedDelta` is returned.
  static Offset transformDeltaViaPositions({
609 610 611 612
    required Offset untransformedEndPosition,
    Offset? transformedEndPosition,
    required Offset untransformedDelta,
    required Matrix4? transform,
613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640
  }) {
    if (transform == null) {
      return untransformedDelta;
    }
    // We could transform the delta directly with the transformation matrix.
    // While that is mathematically equivalent, in practice we are seeing a
    // greater precision error with that approach. Instead, we are transforming
    // start and end point of the delta separately and calculate the delta in
    // the new space for greater accuracy.
    transformedEndPosition ??= transformPosition(transform, untransformedEndPosition);
    final Offset transformedStartPosition = transformPosition(transform, untransformedEndPosition - untransformedDelta);
    return transformedEndPosition - transformedStartPosition;
  }

  /// Removes the "perspective" component from `transform`.
  ///
  /// When applying the resulting transform matrix to a point with a
  /// z-coordinate of zero (which is generally assumed for all points
  /// represented by an [Offset]), the other coordinates will get transformed as
  /// before, but the new z-coordinate is going to be zero again. This is
  /// achieved by setting the third column and third row of the matrix to
  /// "0, 0, 1, 0".
  static Matrix4 removePerspectiveTransform(Matrix4 transform) {
    final Vector4 vector = Vector4(0, 0, 1, 0);
    return transform.clone()
      ..setColumn(2, vector)
      ..setRow(2, vector);
  }
641
}
Ian Hickson's avatar
Ian Hickson committed
642

643 644 645 646
/// The device has started tracking the pointer.
///
/// For example, the pointer might be hovering above the device, having not yet
/// made contact with the surface of the device.
Ian Hickson's avatar
Ian Hickson committed
647
class PointerAddedEvent extends PointerEvent {
648 649
  /// Creates a pointer added event.
  ///
650
  /// All of the arguments must be non-null.
Ian Hickson's avatar
Ian Hickson committed
651
  const PointerAddedEvent({
652 653 654 655
    Duration timeStamp = Duration.zero,
    PointerDeviceKind kind = PointerDeviceKind.touch,
    int device = 0,
    Offset position = Offset.zero,
656
    Offset? localPosition,
657 658 659 660 661 662 663 664
    bool obscured = false,
    double pressureMin = 1.0,
    double pressureMax = 1.0,
    double distance = 0.0,
    double distanceMax = 0.0,
    double radiusMin = 0.0,
    double radiusMax = 0.0,
    double orientation = 0.0,
665
    double tilt = 0.0,
666 667
    Matrix4? transform,
    PointerAddedEvent? original,
668
    int embedderId = 0,
Ian Hickson's avatar
Ian Hickson committed
669
  }) : super(
670 671 672 673
         timeStamp: timeStamp,
         kind: kind,
         device: device,
         position: position,
674
         localPosition: localPosition,
675
         obscured: obscured,
676
         pressure: 0.0,
677 678 679 680 681 682 683 684
         pressureMin: pressureMin,
         pressureMax: pressureMax,
         distance: distance,
         distanceMax: distanceMax,
         radiusMin: radiusMin,
         radiusMax: radiusMax,
         orientation: orientation,
         tilt: tilt,
685 686
         transform: transform,
         original: original,
687
         embedderId: embedderId,
688
       );
689 690

  @override
691
  PointerAddedEvent transformed(Matrix4? transform) {
692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710
    if (transform == null || transform == this.transform) {
      return this;
    }
    return PointerAddedEvent(
      timeStamp: timeStamp,
      kind: kind,
      device: device,
      position: position,
      localPosition: PointerEvent.transformPosition(transform, position),
      obscured: obscured,
      pressureMin: pressureMin,
      pressureMax: pressureMax,
      distance: distance,
      distanceMax: distanceMax,
      radiusMin: radiusMin,
      radiusMax: radiusMax,
      orientation: orientation,
      tilt: tilt,
      transform: transform,
711
      original: original as PointerAddedEvent? ?? this,
712
      embedderId: embedderId,
713 714
    );
  }
715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764

  @override
  PointerAddedEvent copyWith({
    Duration? timeStamp,
    int? pointer,
    PointerDeviceKind? kind,
    int? device,
    Offset? position,
    Offset? localPosition,
    Offset? delta,
    Offset? localDelta,
    int? buttons,
    bool? obscured,
    double? pressure,
    double? pressureMin,
    double? pressureMax,
    double? distance,
    double? distanceMax,
    double? size,
    double? radiusMajor,
    double? radiusMinor,
    double? radiusMin,
    double? radiusMax,
    double? orientation,
    double? tilt,
    bool? synthesized,
    Matrix4? transform,
    PointerEvent? original,
    int? embedderId,
  }) {
    return PointerAddedEvent(
      timeStamp: timeStamp ?? this.timeStamp,
      kind: kind ?? this.kind,
      device: device ?? this.device,
      position: position ?? this.position,
      localPosition: localPosition ?? this.localPosition,
      obscured: obscured ?? this.obscured,
      pressureMin: pressureMin ?? this.pressureMin,
      pressureMax: pressureMax ?? this.pressureMax,
      distance: distance ?? this.distance,
      distanceMax: distanceMax ?? this.distanceMax,
      radiusMin: radiusMin ?? this.radiusMin,
      radiusMax: radiusMax ?? this.radiusMax,
      orientation: orientation ?? this.orientation,
      tilt: tilt ?? this.tilt,
      transform: transform ?? this.transform,
      original: original as PointerAddedEvent? ?? this,
      embedderId: embedderId ?? this.embedderId,
    );
  }
Ian Hickson's avatar
Ian Hickson committed
765 766
}

767 768 769 770
/// The device is no longer tracking the pointer.
///
/// For example, the pointer might have drifted out of the device's hover
/// detection range or might have been disconnected from the system entirely.
Ian Hickson's avatar
Ian Hickson committed
771
class PointerRemovedEvent extends PointerEvent {
772 773
  /// Creates a pointer removed event.
  ///
774
  /// All of the arguments must be non-null.
Ian Hickson's avatar
Ian Hickson committed
775
  const PointerRemovedEvent({
776 777 778
    Duration timeStamp = Duration.zero,
    PointerDeviceKind kind = PointerDeviceKind.touch,
    int device = 0,
779
    Offset position = Offset.zero,
780
    Offset? localPosition,
781 782 783 784 785
    bool obscured = false,
    double pressureMin = 1.0,
    double pressureMax = 1.0,
    double distanceMax = 0.0,
    double radiusMin = 0.0,
786
    double radiusMax = 0.0,
787 788
    Matrix4? transform,
    PointerRemovedEvent? original,
789
    int embedderId = 0,
Ian Hickson's avatar
Ian Hickson committed
790
  }) : super(
791 792 793
         timeStamp: timeStamp,
         kind: kind,
         device: device,
794
         position: position,
795
         localPosition: localPosition,
796
         obscured: obscured,
797
         pressure: 0.0,
798 799 800 801 802
         pressureMin: pressureMin,
         pressureMax: pressureMax,
         distanceMax: distanceMax,
         radiusMin: radiusMin,
         radiusMax: radiusMax,
803 804
         transform: transform,
         original: original,
805
         embedderId: embedderId,
806
       );
807 808

  @override
809
  PointerRemovedEvent transformed(Matrix4? transform) {
810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825
    if (transform == null || transform == this.transform) {
      return this;
    }
    return PointerRemovedEvent(
      timeStamp: timeStamp,
      kind: kind,
      device: device,
      position: position,
      localPosition: PointerEvent.transformPosition(transform, position),
      obscured: obscured,
      pressureMin: pressureMin,
      pressureMax: pressureMax,
      distanceMax: distanceMax,
      radiusMin: radiusMin,
      radiusMax: radiusMax,
      transform: transform,
826
      original: original as PointerRemovedEvent? ?? this,
827
      embedderId: embedderId,
828 829
    );
  }
830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876

  @override
  PointerRemovedEvent copyWith({
    Duration? timeStamp,
    int? pointer,
    PointerDeviceKind? kind,
    int? device,
    Offset? position,
    Offset? localPosition,
    Offset? delta,
    Offset? localDelta,
    int? buttons,
    bool? obscured,
    double? pressure,
    double? pressureMin,
    double? pressureMax,
    double? distance,
    double? distanceMax,
    double? size,
    double? radiusMajor,
    double? radiusMinor,
    double? radiusMin,
    double? radiusMax,
    double? orientation,
    double? tilt,
    bool? synthesized,
    Matrix4? transform,
    PointerEvent? original,
    int? embedderId,
  }) {
    return PointerRemovedEvent(
      timeStamp: timeStamp ?? this.timeStamp,
      kind: kind ?? this.kind,
      device: device ?? this.device,
      position: position ?? this.position,
      localPosition: localPosition ?? this.localPosition,
      obscured: obscured ?? this.obscured,
      pressureMin: pressureMin ?? this.pressureMin,
      pressureMax: pressureMax ?? this.pressureMax,
      distanceMax: distanceMax ?? this.distanceMax,
      radiusMin: radiusMin ?? this.radiusMin,
      radiusMax: radiusMax ?? this.radiusMax,
      transform: transform ?? this.transform,
      original: original as PointerRemovedEvent? ?? this,
      embedderId: embedderId ?? this.embedderId,
    );
  }
Ian Hickson's avatar
Ian Hickson committed
877 878
}

879 880 881 882 883
/// The pointer has moved with respect to the device while the pointer is not
/// in contact with the device.
///
/// See also:
///
884 885 886
///  * [PointerEnterEvent], which reports when the pointer has entered an
///    object.
///  * [PointerExitEvent], which reports when the pointer has left an object.
887 888
///  * [PointerMoveEvent], which reports movement while the pointer is in
///    contact with the device.
889 890
///  * [Listener.onPointerHover], which allows callers to be notified of these
///    events in a widget tree.
891 892 893
class PointerHoverEvent extends PointerEvent {
  /// Creates a pointer hover event.
  ///
894
  /// All of the arguments must be non-null.
895
  const PointerHoverEvent({
896 897 898 899
    Duration timeStamp = Duration.zero,
    PointerDeviceKind kind = PointerDeviceKind.touch,
    int device = 0,
    Offset position = Offset.zero,
900
    Offset? localPosition,
901
    Offset delta = Offset.zero,
902
    Offset? localDelta,
903 904 905 906 907 908
    int buttons = 0,
    bool obscured = false,
    double pressureMin = 1.0,
    double pressureMax = 1.0,
    double distance = 0.0,
    double distanceMax = 0.0,
909
    double size = 0.0,
910 911 912 913 914 915 916
    double radiusMajor = 0.0,
    double radiusMinor = 0.0,
    double radiusMin = 0.0,
    double radiusMax = 0.0,
    double orientation = 0.0,
    double tilt = 0.0,
    bool synthesized = false,
917 918
    Matrix4? transform,
    PointerHoverEvent? original,
919
    int embedderId = 0,
920
  }) : super(
921 922 923 924
         timeStamp: timeStamp,
         kind: kind,
         device: device,
         position: position,
925
         localPosition: localPosition,
926
         delta: delta,
927
         localDelta: localDelta,
928 929 930
         buttons: buttons,
         down: false,
         obscured: obscured,
931
         pressure: 0.0,
932 933 934 935 936 937 938 939 940 941 942 943
         pressureMin: pressureMin,
         pressureMax: pressureMax,
         distance: distance,
         distanceMax: distanceMax,
         size: size,
         radiusMajor: radiusMajor,
         radiusMinor: radiusMinor,
         radiusMin: radiusMin,
         radiusMax: radiusMax,
         orientation: orientation,
         tilt: tilt,
         synthesized: synthesized,
944 945
         transform: transform,
         original: original,
946
         embedderId: embedderId,
947
       );
948 949

  @override
950
  PointerHoverEvent transformed(Matrix4? transform) {
951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982
    if (transform == null || transform == this.transform) {
      return this;
    }
    final Offset transformedPosition = PointerEvent.transformPosition(transform, position);
    return PointerHoverEvent(
      timeStamp: timeStamp,
      kind: kind,
      device: device,
      position: position,
      localPosition: transformedPosition,
      delta: delta,
      localDelta: PointerEvent.transformDeltaViaPositions(
        transform: transform,
        untransformedDelta: delta,
        untransformedEndPosition: position,
        transformedEndPosition: transformedPosition,
      ),
      buttons: buttons,
      obscured: obscured,
      pressureMin: pressureMin,
      pressureMax: pressureMax,
      distance: distance,
      distanceMax: distanceMax,
      size: size,
      radiusMajor: radiusMajor,
      radiusMinor: radiusMinor,
      radiusMin: radiusMin,
      radiusMax: radiusMax,
      orientation: orientation,
      tilt: tilt,
      synthesized: synthesized,
      transform: transform,
983
      original: original as PointerHoverEvent? ?? this,
984
      embedderId: embedderId,
985 986
    );
  }
987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043

  @override
  PointerHoverEvent copyWith({
    Duration? timeStamp,
    int? pointer,
    PointerDeviceKind? kind,
    int? device,
    Offset? position,
    Offset? localPosition,
    Offset? delta,
    Offset? localDelta,
    int? buttons,
    bool? obscured,
    double? pressure,
    double? pressureMin,
    double? pressureMax,
    double? distance,
    double? distanceMax,
    double? size,
    double? radiusMajor,
    double? radiusMinor,
    double? radiusMin,
    double? radiusMax,
    double? orientation,
    double? tilt,
    bool? synthesized,
    Matrix4? transform,
    PointerEvent? original,
    int? embedderId,
  }) {
    return PointerHoverEvent(
      timeStamp: timeStamp ?? this.timeStamp,
      kind: kind ?? this.kind,
      device: device ?? this.device,
      position: position ?? this.position,
      localPosition: localPosition ?? this.localPosition,
      delta: delta ?? this.delta,
      localDelta: localDelta ?? this.localDelta,
      buttons: buttons ?? this.buttons,
      obscured: obscured ?? this.obscured,
      pressureMin: pressureMin ?? this.pressureMin,
      pressureMax: pressureMax ?? this.pressureMax,
      distance: distance ?? this.distance,
      distanceMax: distanceMax ?? this.distanceMax,
      size: size ?? this.size,
      radiusMajor: radiusMajor ?? this.radiusMajor,
      radiusMinor: radiusMinor ?? this.radiusMinor,
      radiusMin: radiusMin ?? this.radiusMin,
      radiusMax: radiusMax ?? this.radiusMax,
      orientation: orientation ?? this.orientation,
      tilt: tilt ?? this.tilt,
      synthesized: synthesized ?? this.synthesized,
      transform: transform ?? this.transform,
      original: original as PointerHoverEvent? ?? this,
      embedderId: embedderId ?? this.embedderId,
    );
  }
1044 1045
}

1046 1047
/// The pointer has moved with respect to the device while the pointer is or is
/// not in contact with the device, and it has entered a target object.
1048 1049 1050 1051 1052 1053 1054 1055
///
/// See also:
///
///  * [PointerHoverEvent], which reports when the pointer has moved while
///    within an object.
///  * [PointerExitEvent], which reports when the pointer has left an object.
///  * [PointerMoveEvent], which reports movement while the pointer is in
///    contact with the device.
1056
///  * [MouseRegion.onEnter], which allows callers to be notified of these
1057
///    events in a widget tree.
1058 1059 1060 1061 1062 1063 1064 1065 1066
class PointerEnterEvent extends PointerEvent {
  /// Creates a pointer enter event.
  ///
  /// All of the arguments must be non-null.
  const PointerEnterEvent({
    Duration timeStamp = Duration.zero,
    PointerDeviceKind kind = PointerDeviceKind.touch,
    int device = 0,
    Offset position = Offset.zero,
1067
    Offset? localPosition,
1068
    Offset delta = Offset.zero,
1069
    Offset? localDelta,
1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082
    int buttons = 0,
    bool obscured = false,
    double pressureMin = 1.0,
    double pressureMax = 1.0,
    double distance = 0.0,
    double distanceMax = 0.0,
    double size = 0.0,
    double radiusMajor = 0.0,
    double radiusMinor = 0.0,
    double radiusMin = 0.0,
    double radiusMax = 0.0,
    double orientation = 0.0,
    double tilt = 0.0,
1083
    bool down = false,
1084
    bool synthesized = false,
1085 1086
    Matrix4? transform,
    PointerEnterEvent? original,
1087
    int embedderId = 0,
1088
  }) : super(
1089 1090 1091 1092
         timeStamp: timeStamp,
         kind: kind,
         device: device,
         position: position,
1093
         localPosition: localPosition,
1094
         delta: delta,
1095
         localDelta: localDelta,
1096
         buttons: buttons,
1097
         down: down,
1098
         obscured: obscured,
1099
         pressure: 0.0,
1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111
         pressureMin: pressureMin,
         pressureMax: pressureMax,
         distance: distance,
         distanceMax: distanceMax,
         size: size,
         radiusMajor: radiusMajor,
         radiusMinor: radiusMinor,
         radiusMin: radiusMin,
         radiusMax: radiusMax,
         orientation: orientation,
         tilt: tilt,
         synthesized: synthesized,
1112 1113
         transform: transform,
         original: original,
1114
         embedderId: embedderId,
1115
       );
1116 1117 1118

  /// Creates an enter event from a [PointerHoverEvent].
  ///
1119
  /// Deprecated. Please use [PointerEnterEvent.fromMouseEvent] instead.
1120 1121 1122 1123
  @Deprecated(
    'Use PointerEnterEvent.fromMouseEvent instead. '
    'This feature was deprecated after v1.4.3.'
  )
1124 1125 1126 1127 1128
  PointerEnterEvent.fromHoverEvent(PointerHoverEvent event) : this.fromMouseEvent(event);

  /// Creates an enter event from a [PointerEvent].
  ///
  /// This is used by the [MouseTracker] to synthesize enter events.
1129
  PointerEnterEvent.fromMouseEvent(PointerEvent event) : this(
1130 1131 1132 1133 1134 1135 1136 1137 1138 1139 1140 1141 1142 1143 1144 1145 1146 1147 1148 1149 1150 1151 1152
    timeStamp: event.timeStamp,
    kind: event.kind,
    device: event.device,
    position: event.position,
    localPosition: event.localPosition,
    delta: event.delta,
    localDelta: event.localDelta,
    buttons: event.buttons,
    obscured: event.obscured,
    pressureMin: event.pressureMin,
    pressureMax: event.pressureMax,
    distance: event.distance,
    distanceMax: event.distanceMax,
    size: event.size,
    radiusMajor: event.radiusMajor,
    radiusMinor: event.radiusMinor,
    radiusMin: event.radiusMin,
    radiusMax: event.radiusMax,
    orientation: event.orientation,
    tilt: event.tilt,
    down: event.down,
    synthesized: event.synthesized,
    transform: event.transform,
1153
    original: null,
1154
  );
1155 1156

  @override
1157
  PointerEnterEvent transformed(Matrix4? transform) {
1158 1159 1160 1161 1162 1163 1164 1165 1166 1167 1168 1169 1170 1171 1172 1173 1174 1175 1176 1177 1178 1179 1180 1181 1182 1183 1184 1185 1186 1187
    if (transform == null || transform == this.transform) {
      return this;
    }
    final Offset transformedPosition = PointerEvent.transformPosition(transform, position);
    return PointerEnterEvent(
      timeStamp: timeStamp,
      kind: kind,
      device: device,
      position: position,
      localPosition: transformedPosition,
      delta: delta,
      localDelta: PointerEvent.transformDeltaViaPositions(
        transform: transform,
        untransformedDelta: delta,
        untransformedEndPosition: position,
        transformedEndPosition: transformedPosition,
      ),
      buttons: buttons,
      obscured: obscured,
      pressureMin: pressureMin,
      pressureMax: pressureMax,
      distance: distance,
      distanceMax: distanceMax,
      size: size,
      radiusMajor: radiusMajor,
      radiusMinor: radiusMinor,
      radiusMin: radiusMin,
      radiusMax: radiusMax,
      orientation: orientation,
      tilt: tilt,
1188
      down: down,
1189 1190
      synthesized: synthesized,
      transform: transform,
1191
      original: original as PointerEnterEvent? ?? this,
1192
      embedderId: embedderId,
1193 1194
    );
  }
1195 1196 1197 1198 1199 1200 1201 1202 1203 1204 1205 1206 1207 1208 1209 1210 1211 1212 1213 1214 1215 1216 1217 1218 1219 1220 1221 1222 1223 1224 1225 1226 1227 1228 1229 1230 1231 1232 1233 1234 1235 1236 1237 1238 1239 1240 1241 1242 1243 1244 1245 1246 1247 1248 1249 1250 1251

  @override
  PointerEnterEvent copyWith({
    Duration? timeStamp,
    int? pointer,
    PointerDeviceKind? kind,
    int? device,
    Offset? position,
    Offset? localPosition,
    Offset? delta,
    Offset? localDelta,
    int? buttons,
    bool? obscured,
    double? pressure,
    double? pressureMin,
    double? pressureMax,
    double? distance,
    double? distanceMax,
    double? size,
    double? radiusMajor,
    double? radiusMinor,
    double? radiusMin,
    double? radiusMax,
    double? orientation,
    double? tilt,
    bool? synthesized,
    Matrix4? transform,
    PointerEvent? original,
    int? embedderId,
  }) {
    return PointerEnterEvent(
      timeStamp: timeStamp ?? this.timeStamp,
      kind: kind ?? this.kind,
      device: device ?? this.device,
      position: position ?? this.position,
      localPosition: localPosition ?? this.localPosition,
      delta: delta ?? this.delta,
      localDelta: localDelta ?? this.localDelta,
      buttons: buttons ?? this.buttons,
      obscured: obscured ?? this.obscured,
      pressureMin: pressureMin ?? this.pressureMin,
      pressureMax: pressureMax ?? this.pressureMax,
      distance: distance ?? this.distance,
      distanceMax: distanceMax ?? this.distanceMax,
      size: size ?? this.size,
      radiusMajor: radiusMajor ?? this.radiusMajor,
      radiusMinor: radiusMinor ?? this.radiusMinor,
      radiusMin: radiusMin ?? this.radiusMin,
      radiusMax: radiusMax ?? this.radiusMax,
      orientation: orientation ?? this.orientation,
      tilt: tilt ?? this.tilt,
      synthesized: synthesized ?? this.synthesized,
      transform: transform ?? this.transform,
      original: original as PointerEnterEvent? ?? this,
      embedderId: embedderId ?? this.embedderId,
    );
  }
1252 1253
}

1254 1255
/// The pointer has moved with respect to the device while the pointer is or is
/// not in contact with the device, and entered a target object.
1256 1257 1258 1259 1260 1261 1262 1263
///
/// See also:
///
///  * [PointerHoverEvent], which reports when the pointer has moved while
///    within an object.
///  * [PointerEnterEvent], which reports when the pointer has entered an object.
///  * [PointerMoveEvent], which reports movement while the pointer is in
///    contact with the device.
1264
///  * [MouseRegion.onExit], which allows callers to be notified of these
1265
///    events in a widget tree.
1266 1267 1268 1269 1270 1271 1272 1273 1274
class PointerExitEvent extends PointerEvent {
  /// Creates a pointer exit event.
  ///
  /// All of the arguments must be non-null.
  const PointerExitEvent({
    Duration timeStamp = Duration.zero,
    PointerDeviceKind kind = PointerDeviceKind.touch,
    int device = 0,
    Offset position = Offset.zero,
1275
    Offset? localPosition,
1276
    Offset delta = Offset.zero,
1277
    Offset? localDelta,
1278 1279 1280 1281 1282 1283 1284 1285 1286 1287 1288 1289 1290
    int buttons = 0,
    bool obscured = false,
    double pressureMin = 1.0,
    double pressureMax = 1.0,
    double distance = 0.0,
    double distanceMax = 0.0,
    double size = 0.0,
    double radiusMajor = 0.0,
    double radiusMinor = 0.0,
    double radiusMin = 0.0,
    double radiusMax = 0.0,
    double orientation = 0.0,
    double tilt = 0.0,
1291
    bool down = false,
1292
    bool synthesized = false,
1293 1294
    Matrix4? transform,
    PointerExitEvent? original,
1295
    int embedderId = 0,
1296
  }) : super(
1297 1298 1299 1300
         timeStamp: timeStamp,
         kind: kind,
         device: device,
         position: position,
1301
         localPosition: localPosition,
1302
         delta: delta,
1303
         localDelta: localDelta,
1304
         buttons: buttons,
1305
         down: down,
1306
         obscured: obscured,
1307
         pressure: 0.0,
1308 1309 1310 1311 1312 1313 1314 1315 1316 1317 1318 1319
         pressureMin: pressureMin,
         pressureMax: pressureMax,
         distance: distance,
         distanceMax: distanceMax,
         size: size,
         radiusMajor: radiusMajor,
         radiusMinor: radiusMinor,
         radiusMin: radiusMin,
         radiusMax: radiusMax,
         orientation: orientation,
         tilt: tilt,
         synthesized: synthesized,
1320 1321
         transform: transform,
         original: original,
1322
         embedderId: embedderId,
1323
       );
1324 1325 1326

  /// Creates an exit event from a [PointerHoverEvent].
  ///
1327
  /// Deprecated. Please use [PointerExitEvent.fromMouseEvent] instead.
1328 1329 1330 1331
  @Deprecated(
    'Use PointerExitEvent.fromMouseEvent instead. '
    'This feature was deprecated after v1.4.3.'
  )
1332 1333 1334 1335 1336
  PointerExitEvent.fromHoverEvent(PointerHoverEvent event) : this.fromMouseEvent(event);

  /// Creates an exit event from a [PointerEvent].
  ///
  /// This is used by the [MouseTracker] to synthesize exit events.
1337
  PointerExitEvent.fromMouseEvent(PointerEvent event) : this(
1338 1339 1340 1341 1342 1343 1344 1345 1346 1347 1348 1349 1350 1351 1352 1353 1354 1355 1356 1357 1358 1359 1360
    timeStamp: event.timeStamp,
    kind: event.kind,
    device: event.device,
    position: event.position,
    localPosition: event.localPosition,
    delta: event.delta,
    localDelta: event.localDelta,
    buttons: event.buttons,
    obscured: event.obscured,
    pressureMin: event.pressureMin,
    pressureMax: event.pressureMax,
    distance: event.distance,
    distanceMax: event.distanceMax,
    size: event.size,
    radiusMajor: event.radiusMajor,
    radiusMinor: event.radiusMinor,
    radiusMin: event.radiusMin,
    radiusMax: event.radiusMax,
    orientation: event.orientation,
    tilt: event.tilt,
    down: event.down,
    synthesized: event.synthesized,
    transform: event.transform,
1361
    original: null,
1362
  );
1363 1364

  @override
1365
  PointerExitEvent transformed(Matrix4? transform) {
1366 1367 1368 1369 1370 1371 1372 1373 1374 1375 1376 1377 1378 1379 1380 1381 1382 1383 1384 1385 1386 1387 1388 1389 1390 1391 1392 1393 1394 1395
    if (transform == null || transform == this.transform) {
      return this;
    }
    final Offset transformedPosition = PointerEvent.transformPosition(transform, position);
    return PointerExitEvent(
      timeStamp: timeStamp,
      kind: kind,
      device: device,
      position: position,
      localPosition: transformedPosition,
      delta: delta,
      localDelta: PointerEvent.transformDeltaViaPositions(
        transform: transform,
        untransformedDelta: delta,
        untransformedEndPosition: position,
        transformedEndPosition: transformedPosition,
      ),
      buttons: buttons,
      obscured: obscured,
      pressureMin: pressureMin,
      pressureMax: pressureMax,
      distance: distance,
      distanceMax: distanceMax,
      size: size,
      radiusMajor: radiusMajor,
      radiusMinor: radiusMinor,
      radiusMin: radiusMin,
      radiusMax: radiusMax,
      orientation: orientation,
      tilt: tilt,
1396
      down: down,
1397 1398
      synthesized: synthesized,
      transform: transform,
1399
      original: original as PointerExitEvent? ?? this,
1400
      embedderId: embedderId,
1401 1402
    );
  }
1403 1404 1405 1406 1407 1408 1409 1410 1411 1412 1413 1414 1415 1416 1417 1418 1419 1420 1421 1422 1423 1424 1425 1426 1427 1428 1429 1430 1431 1432 1433 1434 1435 1436 1437 1438 1439 1440 1441 1442 1443 1444 1445 1446 1447 1448 1449 1450 1451 1452 1453 1454 1455 1456 1457 1458 1459

  @override
  PointerExitEvent copyWith({
    Duration? timeStamp,
    int? pointer,
    PointerDeviceKind? kind,
    int? device,
    Offset? position,
    Offset? localPosition,
    Offset? delta,
    Offset? localDelta,
    int? buttons,
    bool? obscured,
    double? pressure,
    double? pressureMin,
    double? pressureMax,
    double? distance,
    double? distanceMax,
    double? size,
    double? radiusMajor,
    double? radiusMinor,
    double? radiusMin,
    double? radiusMax,
    double? orientation,
    double? tilt,
    bool? synthesized,
    Matrix4? transform,
    PointerEvent? original,
    int? embedderId,
  }) {
    return PointerExitEvent(
      timeStamp: timeStamp ?? this.timeStamp,
      kind: kind ?? this.kind,
      device: device ?? this.device,
      position: position ?? this.position,
      localPosition: localPosition ?? this.localPosition,
      delta: delta ?? this.delta,
      localDelta: localDelta ?? this.localDelta,
      buttons: buttons ?? this.buttons,
      obscured: obscured ?? this.obscured,
      pressureMin: pressureMin ?? this.pressureMin,
      pressureMax: pressureMax ?? this.pressureMax,
      distance: distance ?? this.distance,
      distanceMax: distanceMax ?? this.distanceMax,
      size: size ?? this.size,
      radiusMajor: radiusMajor ?? this.radiusMajor,
      radiusMinor: radiusMinor ?? this.radiusMinor,
      radiusMin: radiusMin ?? this.radiusMin,
      radiusMax: radiusMax ?? this.radiusMax,
      orientation: orientation ?? this.orientation,
      tilt: tilt ?? this.tilt,
      synthesized: synthesized ?? this.synthesized,
      transform: transform ?? this.transform,
      original: original as PointerExitEvent? ?? this,
      embedderId: embedderId ?? this.embedderId,
    );
  }
1460 1461
}

1462
/// The pointer has made contact with the device.
1463 1464 1465 1466 1467
///
/// See also:
///
///  * [Listener.onPointerDown], which allows callers to be notified of these
///    events in a widget tree.
Ian Hickson's avatar
Ian Hickson committed
1468
class PointerDownEvent extends PointerEvent {
1469 1470
  /// Creates a pointer down event.
  ///
1471
  /// All of the arguments must be non-null.
Ian Hickson's avatar
Ian Hickson committed
1472
  const PointerDownEvent({
1473 1474 1475 1476 1477
    Duration timeStamp = Duration.zero,
    int pointer = 0,
    PointerDeviceKind kind = PointerDeviceKind.touch,
    int device = 0,
    Offset position = Offset.zero,
1478
    Offset? localPosition,
1479
    int buttons = kPrimaryButton,
1480 1481 1482 1483 1484
    bool obscured = false,
    double pressure = 1.0,
    double pressureMin = 1.0,
    double pressureMax = 1.0,
    double distanceMax = 0.0,
1485
    double size = 0.0,
1486 1487 1488 1489 1490
    double radiusMajor = 0.0,
    double radiusMinor = 0.0,
    double radiusMin = 0.0,
    double radiusMax = 0.0,
    double orientation = 0.0,
1491
    double tilt = 0.0,
1492 1493
    Matrix4? transform,
    PointerDownEvent? original,
1494
    int embedderId = 0,
Ian Hickson's avatar
Ian Hickson committed
1495
  }) : super(
1496 1497 1498 1499 1500
         timeStamp: timeStamp,
         pointer: pointer,
         kind: kind,
         device: device,
         position: position,
1501
         localPosition: localPosition,
1502 1503 1504 1505 1506 1507 1508 1509 1510 1511 1512 1513 1514 1515 1516
         buttons: buttons,
         down: true,
         obscured: obscured,
         pressure: pressure,
         pressureMin: pressureMin,
         pressureMax: pressureMax,
         distance: 0.0,
         distanceMax: distanceMax,
         size: size,
         radiusMajor: radiusMajor,
         radiusMinor: radiusMinor,
         radiusMin: radiusMin,
         radiusMax: radiusMax,
         orientation: orientation,
         tilt: tilt,
1517 1518
         transform: transform,
         original: original,
1519
         embedderId: embedderId,
1520
       );
1521 1522

  @override
1523
  PointerDownEvent transformed(Matrix4? transform) {
1524 1525 1526 1527 1528 1529 1530 1531 1532 1533 1534 1535 1536 1537 1538 1539 1540 1541 1542 1543 1544 1545 1546 1547
    if (transform == null || transform == this.transform) {
      return this;
    }
    return PointerDownEvent(
      timeStamp: timeStamp,
      pointer: pointer,
      kind: kind,
      device: device,
      position: position,
      localPosition: PointerEvent.transformPosition(transform, position),
      buttons: buttons,
      obscured: obscured,
      pressure: pressure,
      pressureMin: pressureMin,
      pressureMax: pressureMax,
      distanceMax: distanceMax,
      size: size,
      radiusMajor: radiusMajor,
      radiusMinor: radiusMinor,
      radiusMin: radiusMin,
      radiusMax: radiusMax,
      orientation: orientation,
      tilt: tilt,
      transform: transform,
1548
      original: original as PointerDownEvent? ?? this,
1549
      embedderId: embedderId,
1550 1551
    );
  }
1552 1553 1554 1555 1556 1557 1558 1559 1560 1561 1562 1563 1564 1565 1566 1567 1568 1569 1570 1571 1572 1573 1574 1575 1576 1577 1578 1579 1580 1581 1582 1583 1584 1585 1586 1587 1588 1589 1590 1591 1592 1593 1594 1595 1596 1597 1598 1599 1600 1601 1602 1603 1604 1605 1606

  @override
  PointerDownEvent copyWith({
    Duration? timeStamp,
    int? pointer,
    PointerDeviceKind? kind,
    int? device,
    Offset? position,
    Offset? localPosition,
    Offset? delta,
    Offset? localDelta,
    int? buttons,
    bool? obscured,
    double? pressure,
    double? pressureMin,
    double? pressureMax,
    double? distance,
    double? distanceMax,
    double? size,
    double? radiusMajor,
    double? radiusMinor,
    double? radiusMin,
    double? radiusMax,
    double? orientation,
    double? tilt,
    bool? synthesized,
    Matrix4? transform,
    PointerEvent? original,
    int? embedderId,
  }) {
    return PointerDownEvent(
      timeStamp: timeStamp ?? this.timeStamp,
      pointer: pointer ?? this.pointer,
      kind: kind ?? this.kind,
      device: device ?? this.device,
      position: position ?? this.position,
      localPosition: localPosition ?? this.localPosition,
      buttons: buttons ?? this.buttons,
      obscured: obscured ?? this.obscured,
      pressure: pressure ?? this.pressure,
      pressureMin: pressureMin ?? this.pressureMin,
      pressureMax: pressureMax ?? this.pressureMax,
      distanceMax: distanceMax ?? this.distanceMax,
      size: size ?? this.size,
      radiusMajor: radiusMajor ?? this.radiusMajor,
      radiusMinor: radiusMinor ?? this.radiusMinor,
      radiusMin: radiusMin ?? this.radiusMin,
      radiusMax: radiusMax ?? this.radiusMax,
      orientation: orientation ?? this.orientation,
      tilt: tilt ?? this.tilt,
      transform: transform ?? this.transform,
      original: original as PointerDownEvent? ?? this,
      embedderId: embedderId ?? this.embedderId,
    );
  }
Ian Hickson's avatar
Ian Hickson committed
1607 1608
}

1609 1610 1611 1612 1613 1614 1615
/// The pointer has moved with respect to the device while the pointer is in
/// contact with the device.
///
/// See also:
///
///  * [PointerHoverEvent], which reports movement while the pointer is not in
///    contact with the device.
1616 1617
///  * [Listener.onPointerMove], which allows callers to be notified of these
///    events in a widget tree.
Ian Hickson's avatar
Ian Hickson committed
1618
class PointerMoveEvent extends PointerEvent {
1619 1620
  /// Creates a pointer move event.
  ///
1621
  /// All of the arguments must be non-null.
Ian Hickson's avatar
Ian Hickson committed
1622
  const PointerMoveEvent({
1623 1624 1625 1626 1627
    Duration timeStamp = Duration.zero,
    int pointer = 0,
    PointerDeviceKind kind = PointerDeviceKind.touch,
    int device = 0,
    Offset position = Offset.zero,
1628
    Offset? localPosition,
1629
    Offset delta = Offset.zero,
1630
    Offset? localDelta,
1631
    int buttons = kPrimaryButton,
1632 1633 1634 1635 1636
    bool obscured = false,
    double pressure = 1.0,
    double pressureMin = 1.0,
    double pressureMax = 1.0,
    double distanceMax = 0.0,
1637
    double size = 0.0,
1638 1639 1640 1641 1642 1643
    double radiusMajor = 0.0,
    double radiusMinor = 0.0,
    double radiusMin = 0.0,
    double radiusMax = 0.0,
    double orientation = 0.0,
    double tilt = 0.0,
1644
    int platformData = 0,
1645
    bool synthesized = false,
1646 1647
    Matrix4? transform,
    PointerMoveEvent? original,
1648
    int embedderId = 0,
Ian Hickson's avatar
Ian Hickson committed
1649
  }) : super(
1650 1651 1652 1653 1654
         timeStamp: timeStamp,
         pointer: pointer,
         kind: kind,
         device: device,
         position: position,
1655
         localPosition: localPosition,
1656
         delta: delta,
1657
         localDelta: localDelta,
1658 1659 1660 1661 1662 1663 1664 1665 1666 1667 1668 1669 1670 1671 1672 1673 1674
         buttons: buttons,
         down: true,
         obscured: obscured,
         pressure: pressure,
         pressureMin: pressureMin,
         pressureMax: pressureMax,
         distance: 0.0,
         distanceMax: distanceMax,
         size: size,
         radiusMajor: radiusMajor,
         radiusMinor: radiusMinor,
         radiusMin: radiusMin,
         radiusMax: radiusMax,
         orientation: orientation,
         tilt: tilt,
         platformData: platformData,
         synthesized: synthesized,
1675 1676
         transform: transform,
         original: original,
1677
         embedderId: embedderId,
1678
       );
1679 1680

  @override
1681
  PointerMoveEvent transformed(Matrix4? transform) {
1682 1683 1684 1685 1686 1687 1688 1689 1690 1691 1692 1693 1694 1695 1696 1697 1698 1699 1700 1701 1702 1703 1704 1705 1706 1707 1708 1709 1710 1711 1712 1713 1714 1715 1716
    if (transform == null || transform == this.transform) {
      return this;
    }
    final Offset transformedPosition = PointerEvent.transformPosition(transform, position);

    return PointerMoveEvent(
      timeStamp: timeStamp,
      pointer: pointer,
      kind: kind,
      device: device,
      position: position,
      localPosition: transformedPosition,
      delta: delta,
      localDelta: PointerEvent.transformDeltaViaPositions(
        transform: transform,
        untransformedDelta: delta,
        untransformedEndPosition: position,
        transformedEndPosition: transformedPosition,
      ),
      buttons: buttons,
      obscured: obscured,
      pressure: pressure,
      pressureMin: pressureMin,
      pressureMax: pressureMax,
      distanceMax: distanceMax,
      size: size,
      radiusMajor: radiusMajor,
      radiusMinor: radiusMinor,
      radiusMin: radiusMin,
      radiusMax: radiusMax,
      orientation: orientation,
      tilt: tilt,
      platformData: platformData,
      synthesized: synthesized,
      transform: transform,
1717
      original: original as PointerMoveEvent? ?? this,
1718
      embedderId: embedderId,
1719 1720
    );
  }
1721 1722 1723 1724 1725 1726 1727 1728 1729 1730 1731 1732 1733 1734 1735 1736 1737 1738 1739 1740 1741 1742 1743 1744 1745 1746 1747 1748 1749 1750 1751 1752 1753 1754 1755 1756 1757 1758 1759 1760 1761 1762 1763 1764 1765 1766 1767 1768 1769 1770 1771 1772 1773 1774 1775 1776 1777 1778

  @override
  PointerMoveEvent copyWith({
    Duration? timeStamp,
    int? pointer,
    PointerDeviceKind? kind,
    int? device,
    Offset? position,
    Offset? localPosition,
    Offset? delta,
    Offset? localDelta,
    int? buttons,
    bool? obscured,
    double? pressure,
    double? pressureMin,
    double? pressureMax,
    double? distance,
    double? distanceMax,
    double? size,
    double? radiusMajor,
    double? radiusMinor,
    double? radiusMin,
    double? radiusMax,
    double? orientation,
    double? tilt,
    bool? synthesized,
    Matrix4? transform,
    PointerEvent? original,
    int? embedderId,
  }) {
    return PointerMoveEvent(
      timeStamp: timeStamp ?? this.timeStamp,
      pointer: pointer ?? this.pointer,
      kind: kind ?? this.kind,
      device: device ?? this.device,
      position: position ?? this.position,
      localPosition: localPosition ?? this.localPosition,
      delta: delta ?? this.delta,
      localDelta: localDelta ?? this.localDelta,
      buttons: buttons ?? this.buttons,
      obscured: obscured ?? this.obscured,
      pressure: pressure ?? this.pressure,
      pressureMin: pressureMin ?? this.pressureMin,
      pressureMax: pressureMax ?? this.pressureMax,
      distanceMax: distanceMax ?? this.distanceMax,
      size: size ?? this.size,
      radiusMajor: radiusMajor ?? this.radiusMajor,
      radiusMinor: radiusMinor ?? this.radiusMinor,
      radiusMin: radiusMin ?? this.radiusMin,
      radiusMax: radiusMax ?? this.radiusMax,
      orientation: orientation ?? this.orientation,
      tilt: tilt ?? this.tilt,
      synthesized: synthesized ?? this.synthesized,
      transform: transform ?? this.transform,
      original: original as PointerMoveEvent? ?? this,
      embedderId: embedderId ?? this.embedderId,
    );
  }
Ian Hickson's avatar
Ian Hickson committed
1779 1780
}

1781
/// The pointer has stopped making contact with the device.
1782 1783 1784 1785 1786
///
/// See also:
///
///  * [Listener.onPointerUp], which allows callers to be notified of these
///    events in a widget tree.
Ian Hickson's avatar
Ian Hickson committed
1787
class PointerUpEvent extends PointerEvent {
1788 1789
  /// Creates a pointer up event.
  ///
1790
  /// All of the arguments must be non-null.
Ian Hickson's avatar
Ian Hickson committed
1791
  const PointerUpEvent({
1792 1793 1794 1795 1796
    Duration timeStamp = Duration.zero,
    int pointer = 0,
    PointerDeviceKind kind = PointerDeviceKind.touch,
    int device = 0,
    Offset position = Offset.zero,
1797
    Offset? localPosition,
1798 1799
    int buttons = 0,
    bool obscured = false,
1800 1801
    // Allow pressure customization here because PointerUpEvent can contain
    // non-zero pressure. See https://github.com/flutter/flutter/issues/31340
1802
    double pressure = 0.0,
1803 1804 1805 1806
    double pressureMin = 1.0,
    double pressureMax = 1.0,
    double distance = 0.0,
    double distanceMax = 0.0,
1807
    double size = 0.0,
1808 1809
    double radiusMajor = 0.0,
    double radiusMinor = 0.0,
1810 1811 1812
    double radiusMin = 0.0,
    double radiusMax = 0.0,
    double orientation = 0.0,
1813
    double tilt = 0.0,
1814 1815
    Matrix4? transform,
    PointerUpEvent? original,
1816
    int embedderId = 0,
Ian Hickson's avatar
Ian Hickson committed
1817
  }) : super(
1818 1819 1820 1821 1822
         timeStamp: timeStamp,
         pointer: pointer,
         kind: kind,
         device: device,
         position: position,
1823
         localPosition: localPosition,
1824 1825 1826
         buttons: buttons,
         down: false,
         obscured: obscured,
1827
         pressure: pressure,
1828 1829 1830 1831 1832 1833 1834 1835 1836 1837 1838
         pressureMin: pressureMin,
         pressureMax: pressureMax,
         distance: distance,
         distanceMax: distanceMax,
         size: size,
         radiusMajor: radiusMajor,
         radiusMinor: radiusMinor,
         radiusMin: radiusMin,
         radiusMax: radiusMax,
         orientation: orientation,
         tilt: tilt,
1839 1840
         transform: transform,
         original: original,
1841
         embedderId: embedderId,
1842
       );
1843 1844

  @override
1845
  PointerUpEvent transformed(Matrix4? transform) {
1846 1847 1848 1849 1850 1851 1852 1853 1854 1855 1856 1857 1858 1859 1860 1861 1862 1863 1864 1865 1866 1867 1868 1869 1870
    if (transform == null || transform == this.transform) {
      return this;
    }
    return PointerUpEvent(
      timeStamp: timeStamp,
      pointer: pointer,
      kind: kind,
      device: device,
      position: position,
      localPosition: PointerEvent.transformPosition(transform, position),
      buttons: buttons,
      obscured: obscured,
      pressure: pressure,
      pressureMin: pressureMin,
      pressureMax: pressureMax,
      distance: distance,
      distanceMax: distanceMax,
      size: size,
      radiusMajor: radiusMajor,
      radiusMinor: radiusMinor,
      radiusMin: radiusMin,
      radiusMax: radiusMax,
      orientation: orientation,
      tilt: tilt,
      transform: transform,
1871
      original: original as PointerUpEvent? ?? this,
1872
      embedderId: embedderId,
1873 1874
    );
  }
1875 1876 1877 1878 1879 1880 1881 1882 1883 1884 1885 1886 1887 1888 1889 1890 1891 1892 1893 1894 1895 1896 1897 1898 1899 1900 1901 1902 1903 1904 1905 1906 1907 1908 1909 1910 1911 1912 1913 1914 1915 1916 1917 1918 1919 1920 1921 1922 1923 1924 1925 1926 1927 1928 1929 1930

  @override
  PointerUpEvent copyWith({
    Duration? timeStamp,
    int? pointer,
    PointerDeviceKind? kind,
    int? device,
    Offset? position,
    Offset? localPosition,
    Offset? delta,
    Offset? localDelta,
    int? buttons,
    bool? obscured,
    double? pressure,
    double? pressureMin,
    double? pressureMax,
    double? distance,
    double? distanceMax,
    double? size,
    double? radiusMajor,
    double? radiusMinor,
    double? radiusMin,
    double? radiusMax,
    double? orientation,
    double? tilt,
    bool? synthesized,
    Matrix4? transform,
    PointerEvent? original,
    int? embedderId,
  }) {
    return PointerUpEvent(
      timeStamp: timeStamp ?? this.timeStamp,
      pointer: pointer ?? this.pointer,
      kind: kind ?? this.kind,
      device: device ?? this.device,
      position: position ?? this.position,
      localPosition: localPosition ?? this.localPosition,
      buttons: buttons ?? this.buttons,
      obscured: obscured ?? this.obscured,
      pressure: pressure ?? this.pressure,
      pressureMin: pressureMin ?? this.pressureMin,
      pressureMax: pressureMax ?? this.pressureMax,
      distance: distance ?? this.distance,
      distanceMax: distanceMax ?? this.distanceMax,
      size: size ?? this.size,
      radiusMajor: radiusMajor ?? this.radiusMajor,
      radiusMinor: radiusMinor ?? this.radiusMinor,
      radiusMin: radiusMin ?? this.radiusMin,
      radiusMax: radiusMax ?? this.radiusMax,
      orientation: orientation ?? this.orientation,
      tilt: tilt ?? this.tilt,
      transform: transform ?? this.transform,
      original: original as PointerUpEvent? ?? this,
      embedderId: embedderId ?? this.embedderId,
    );
  }
Ian Hickson's avatar
Ian Hickson committed
1931 1932
}

1933 1934 1935 1936 1937
/// An event that corresponds to a discrete pointer signal.
///
/// Pointer signals are events that originate from the pointer but don't change
/// the state of the pointer itself, and are discrete rather than needing to be
/// interpreted in the context of a series of events.
1938 1939 1940 1941 1942
///
/// See also:
///
///  * [Listener.onPointerSignal], which allows callers to be notified of these
///    events in a widget tree.
1943 1944 1945 1946 1947 1948 1949 1950 1951
abstract class PointerSignalEvent extends PointerEvent {
  /// Abstract const constructor. This constructor enables subclasses to provide
  /// const constructors so that they can be used in const expressions.
  const PointerSignalEvent({
    Duration timeStamp = Duration.zero,
    int pointer = 0,
    PointerDeviceKind kind = PointerDeviceKind.mouse,
    int device = 0,
    Offset position = Offset.zero,
1952 1953 1954
    Offset? localPosition,
    Matrix4? transform,
    PointerSignalEvent? original,
1955
    int embedderId = 0,
1956
  }) : super(
1957 1958 1959 1960 1961
         timeStamp: timeStamp,
         pointer: pointer,
         kind: kind,
         device: device,
         position: position,
1962 1963 1964
         localPosition: localPosition,
         transform: transform,
         original: original,
1965
         embedderId: embedderId,
1966
       );
1967 1968 1969 1970 1971 1972
}

/// The pointer issued a scroll event.
///
/// Scrolling the scroll wheel on a mouse is an example of an event that
/// would create a [PointerScrollEvent].
1973 1974 1975 1976 1977
///
/// See also:
///
///  * [Listener.onPointerSignal], which allows callers to be notified of these
///    events in a widget tree.
1978 1979 1980 1981 1982 1983 1984 1985 1986
class PointerScrollEvent extends PointerSignalEvent {
  /// Creates a pointer scroll event.
  ///
  /// All of the arguments must be non-null.
  const PointerScrollEvent({
    Duration timeStamp = Duration.zero,
    PointerDeviceKind kind = PointerDeviceKind.mouse,
    int device = 0,
    Offset position = Offset.zero,
1987
    Offset? localPosition,
1988
    this.scrollDelta = Offset.zero,
1989 1990
    Matrix4? transform,
    PointerScrollEvent? original,
1991
    int embedderId = 0,
1992 1993 1994 1995 1996 1997
  }) : assert(timeStamp != null),
       assert(kind != null),
       assert(device != null),
       assert(position != null),
       assert(scrollDelta != null),
       super(
1998 1999 2000 2001
         timeStamp: timeStamp,
         kind: kind,
         device: device,
         position: position,
2002 2003 2004
         localPosition: localPosition,
         transform: transform,
         original: original,
2005
         embedderId: embedderId,
2006
       );
2007 2008 2009 2010

  /// The amount to scroll, in logical pixels.
  final Offset scrollDelta;

2011
  @override
2012
  PointerScrollEvent transformed(Matrix4? transform) {
2013 2014 2015 2016 2017 2018 2019 2020 2021 2022 2023
    if (transform == null || transform == this.transform) {
      return this;
    }
    return PointerScrollEvent(
      timeStamp: timeStamp,
      kind: kind,
      device: device,
      position: position,
      localPosition: PointerEvent.transformPosition(transform, position),
      scrollDelta: scrollDelta,
      transform: transform,
2024
      original: original as PointerScrollEvent? ?? this,
2025
      embedderId: embedderId,
2026 2027 2028
    );
  }

2029 2030 2031 2032 2033 2034 2035 2036 2037 2038 2039 2040 2041 2042 2043 2044 2045 2046 2047 2048 2049 2050 2051 2052 2053 2054 2055 2056 2057 2058 2059 2060 2061 2062 2063 2064 2065 2066 2067 2068 2069 2070
  @override
  PointerScrollEvent copyWith({
    Duration? timeStamp,
    int? pointer,
    PointerDeviceKind? kind,
    int? device,
    Offset? position,
    Offset? localPosition,
    Offset? delta,
    Offset? localDelta,
    int? buttons,
    bool? obscured,
    double? pressure,
    double? pressureMin,
    double? pressureMax,
    double? distance,
    double? distanceMax,
    double? size,
    double? radiusMajor,
    double? radiusMinor,
    double? radiusMin,
    double? radiusMax,
    double? orientation,
    double? tilt,
    bool? synthesized,
    Matrix4? transform,
    PointerEvent? original,
    int? embedderId,
  }) {
    return PointerScrollEvent(
      timeStamp: timeStamp ?? this.timeStamp,
      kind: kind ?? this.kind,
      device: device ?? this.device,
      position: position ?? this.position,
      localPosition: localPosition ?? this.localPosition,
      scrollDelta: scrollDelta,
      transform: transform ?? this.transform,
      original: original as PointerScrollEvent? ?? this,
      embedderId: embedderId ?? this.embedderId,
    );
  }

2071 2072 2073 2074 2075 2076 2077
  @override
  void debugFillProperties(DiagnosticPropertiesBuilder properties) {
    super.debugFillProperties(properties);
    properties.add(DiagnosticsProperty<Offset>('scrollDelta', scrollDelta));
  }
}

2078
/// The input from the pointer is no longer directed towards this receiver.
2079 2080 2081 2082 2083
///
/// See also:
///
///  * [Listener.onPointerCancel], which allows callers to be notified of these
///    events in a widget tree.
Ian Hickson's avatar
Ian Hickson committed
2084
class PointerCancelEvent extends PointerEvent {
2085 2086
  /// Creates a pointer cancel event.
  ///
2087
  /// All of the arguments must be non-null.
Ian Hickson's avatar
Ian Hickson committed
2088
  const PointerCancelEvent({
2089 2090 2091 2092 2093
    Duration timeStamp = Duration.zero,
    int pointer = 0,
    PointerDeviceKind kind = PointerDeviceKind.touch,
    int device = 0,
    Offset position = Offset.zero,
2094
    Offset? localPosition,
2095 2096 2097 2098 2099 2100
    int buttons = 0,
    bool obscured = false,
    double pressureMin = 1.0,
    double pressureMax = 1.0,
    double distance = 0.0,
    double distanceMax = 0.0,
2101
    double size = 0.0,
2102 2103
    double radiusMajor = 0.0,
    double radiusMinor = 0.0,
2104 2105 2106
    double radiusMin = 0.0,
    double radiusMax = 0.0,
    double orientation = 0.0,
2107
    double tilt = 0.0,
2108 2109
    Matrix4? transform,
    PointerCancelEvent? original,
2110
    int embedderId = 0,
Ian Hickson's avatar
Ian Hickson committed
2111
  }) : super(
2112 2113 2114 2115 2116
         timeStamp: timeStamp,
         pointer: pointer,
         kind: kind,
         device: device,
         position: position,
2117
         localPosition: localPosition,
2118 2119 2120
         buttons: buttons,
         down: false,
         obscured: obscured,
2121
         pressure: 0.0,
2122 2123 2124 2125 2126 2127 2128 2129 2130 2131 2132
         pressureMin: pressureMin,
         pressureMax: pressureMax,
         distance: distance,
         distanceMax: distanceMax,
         size: size,
         radiusMajor: radiusMajor,
         radiusMinor: radiusMinor,
         radiusMin: radiusMin,
         radiusMax: radiusMax,
         orientation: orientation,
         tilt: tilt,
2133 2134
         transform: transform,
         original: original,
2135
         embedderId: embedderId,
2136
       );
2137 2138

  @override
2139
  PointerCancelEvent transformed(Matrix4? transform) {
2140 2141 2142 2143 2144 2145 2146 2147 2148 2149 2150 2151 2152 2153 2154 2155 2156 2157 2158 2159 2160 2161 2162 2163
    if (transform == null || transform == this.transform) {
      return this;
    }
    return PointerCancelEvent(
      timeStamp: timeStamp,
      pointer: pointer,
      kind: kind,
      device: device,
      position: position,
      localPosition: PointerEvent.transformPosition(transform, position),
      buttons: buttons,
      obscured: obscured,
      pressureMin: pressureMin,
      pressureMax: pressureMax,
      distance: distance,
      distanceMax: distanceMax,
      size: size,
      radiusMajor: radiusMajor,
      radiusMinor: radiusMinor,
      radiusMin: radiusMin,
      radiusMax: radiusMax,
      orientation: orientation,
      tilt: tilt,
      transform: transform,
2164
      original: original as PointerCancelEvent? ?? this,
2165
      embedderId: embedderId,
2166 2167
    );
  }
2168 2169 2170 2171 2172 2173 2174 2175 2176 2177 2178 2179 2180 2181 2182 2183 2184 2185 2186 2187 2188 2189 2190 2191 2192 2193 2194 2195 2196 2197 2198 2199 2200 2201 2202 2203 2204 2205 2206 2207 2208 2209 2210 2211 2212 2213 2214 2215 2216 2217 2218 2219 2220 2221 2222

  @override
  PointerCancelEvent copyWith({
    Duration? timeStamp,
    int? pointer,
    PointerDeviceKind? kind,
    int? device,
    Offset? position,
    Offset? localPosition,
    Offset? delta,
    Offset? localDelta,
    int? buttons,
    bool? obscured,
    double? pressure,
    double? pressureMin,
    double? pressureMax,
    double? distance,
    double? distanceMax,
    double? size,
    double? radiusMajor,
    double? radiusMinor,
    double? radiusMin,
    double? radiusMax,
    double? orientation,
    double? tilt,
    bool? synthesized,
    Matrix4? transform,
    PointerEvent? original,
    int? embedderId,
  }) {
    return PointerCancelEvent(
      timeStamp: timeStamp ?? this.timeStamp,
      pointer: pointer ?? this.pointer,
      kind: kind ?? this.kind,
      device: device ?? this.device,
      position: position ?? this.position,
      localPosition: localPosition ?? this.localPosition,
      buttons: buttons ?? this.buttons,
      obscured: obscured ?? this.obscured,
      pressureMin: pressureMin ?? this.pressureMin,
      pressureMax: pressureMax ?? this.pressureMax,
      distance: distance ?? this.distance,
      distanceMax: distanceMax ?? this.distanceMax,
      size: size ?? this.size,
      radiusMajor: radiusMajor ?? this.radiusMajor,
      radiusMinor: radiusMinor ?? this.radiusMinor,
      radiusMin: radiusMin ?? this.radiusMin,
      radiusMax: radiusMax ?? this.radiusMax,
      orientation: orientation ?? this.orientation,
      tilt: tilt ?? this.tilt,
      transform: transform ?? this.transform,
      original: original as PointerCancelEvent? ?? this,
      embedderId: embedderId ?? this.embedderId,
    );
  }
Ian Hickson's avatar
Ian Hickson committed
2223
}