pointer.dart 11.0 KB
Newer Older
M
Michael Goderbauer 已提交
1
// Copyright 2013 The Flutter Authors. All rights reserved.
2 3 4
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

5
// @dart = 2.10
6

A
Adam Barth 已提交
7
part of dart.ui;
8 9 10

/// How the pointer has changed since the last report.
enum PointerChange {
11 12 13
  /// The input from the pointer is no longer directed towards this receiver.
  cancel,

14 15 16 17 18 19 20 21 22 23 24 25
  /// 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.
  add,

  /// 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.
  remove,

26 27 28 29
  /// The pointer has moved with respect to the device while not in contact with
  /// the device.
  hover,

30 31 32
  /// The pointer has made contact with the device.
  down,

33 34
  /// The pointer has moved with respect to the device while in contact with the
  /// device.
35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53
  move,

  /// The pointer has stopped making contact with the device.
  up,
}

/// The kind of pointer device.
enum PointerDeviceKind {
  /// A touch-based pointer device.
  touch,

  /// A mouse-based pointer device.
  mouse,

  /// A pointer device with a stylus.
  stylus,

  /// A pointer device with a stylus that has been inverted.
  invertedStylus,
54 55 56

  /// An unknown pointer device.
  unknown
57 58
}

59
/// The kind of pointer signal event.
60 61 62 63 64 65 66 67 68 69 70
enum PointerSignalKind {
  /// The event is not associated with a pointer signal.
  none,

  /// A pointer-generated scroll (e.g., mouse wheel or trackpad scroll).
  scroll,

  /// An unknown pointer signal kind.
  unknown
}

71 72 73 74
/// Information about the state of a pointer.
class PointerData {
  /// Creates an object that represents the state of a pointer.
  const PointerData({
75
    this.embedderId = 0,
D
Dan Field 已提交
76 77 78
    this.timeStamp = Duration.zero,
    this.change = PointerChange.cancel,
    this.kind = PointerDeviceKind.touch,
79
    this.signalKind,
D
Dan Field 已提交
80
    this.device = 0,
81
    this.pointerIdentifier = 0,
D
Dan Field 已提交
82 83
    this.physicalX = 0.0,
    this.physicalY = 0.0,
84 85
    this.physicalDeltaX = 0.0,
    this.physicalDeltaY = 0.0,
D
Dan Field 已提交
86 87
    this.buttons = 0,
    this.obscured = false,
88
    this.synthesized = false,
D
Dan Field 已提交
89 90 91 92 93 94 95 96 97 98 99 100 101 102 103
    this.pressure = 0.0,
    this.pressureMin = 0.0,
    this.pressureMax = 0.0,
    this.distance = 0.0,
    this.distanceMax = 0.0,
    this.size = 0.0,
    this.radiusMajor = 0.0,
    this.radiusMinor = 0.0,
    this.radiusMin = 0.0,
    this.radiusMax = 0.0,
    this.orientation = 0.0,
    this.tilt = 0.0,
    this.platformData = 0,
    this.scrollDeltaX = 0.0,
    this.scrollDeltaY = 0.0,
104 105
  });

106 107 108 109 110 111 112
  /// Unique identifier that ties the [PointerEvent] to embedder event created it.
  ///
  /// No two pointer events can have the same [embedderId]. This is different from
  /// [pointerIdentifier] - used for hit-testing, whereas [embedderId] is used to
  /// identify the platform event.
  final int embedderId;

113
  /// Time of event dispatch, relative to an arbitrary timeline.
114
  final Duration timeStamp;
115

116
  /// How the pointer has changed since the last report.
117
  final PointerChange change;
118 119

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

122
  /// The kind of signal for a pointer signal event.
123
  final PointerSignalKind? signalKind;
124

125
  /// Unique identifier for the pointing device, reused across interactions.
126
  final int device;
127

128 129 130 131
  /// Unique identifier for the pointer.
  ///
  /// This field changes for each new pointer down event. Framework uses this
  /// identifier to determine hit test result.
132
  final int pointerIdentifier;
133

134 135
  /// X coordinate of the position of the pointer, in physical pixels in the
  /// global coordinate space.
136
  final double physicalX;
137 138 139

  /// Y coordinate of the position of the pointer, in physical pixels in the
  /// global coordinate space.
140
  final double physicalY;
141

142
  /// The distance of pointer movement on X coordinate in physical pixels.
143
  final double physicalDeltaX;
144 145

  /// The distance of pointer movement on Y coordinate in physical pixels.
146
  final double physicalDeltaY;
147

148 149 150 151
  /// Bit field using the *Button constants (primaryMouseButton,
  /// secondaryStylusButton, etc). For example, if this has the value 6 and the
  /// [kind] is [PointerDeviceKind.invertedStylus], then this indicates an
  /// upside-down stylus with both its primary and secondary buttons pressed.
152
  final int buttons;
153 154 155 156

  /// Set if an application from a different security domain is in any way
  /// obscuring this application's window. (Aspirational; not currently
  /// implemented.)
157
  final bool obscured;
158

159 160 161 162 163 164
  /// Set if this pointer data was synthesized by pointer data packet converter.
  /// pointer data packet converter will synthesize additional pointer datas if
  /// the input sequence of pointer data is illegal.
  ///
  /// For example, a down pointer data will be synthesized if the converter receives
  /// a move pointer data while the pointer is not previously down.
165
  final bool synthesized;
166

167 168 169 170
  /// The pressure of the touch as 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.
171
  final double pressure;
172 173 174 175

  /// 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.
176
  final double pressureMin;
177 178 179 180

  /// 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.
181
  final double pressureMax;
182 183 184 185 186

  /// The distance of the detected object from the input surface (e.g. 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.
187
  final double distance;
188 189 190 191

  /// The maximum value that a distance can return for this pointer. If this
  /// input device cannot detect "hover touch" input events, then this will be
  /// 0.0.
192
  final double distanceMax;
193

194 195 196 197 198 199
  /// The area of the screen being pressed, scaled to a value between 0 and 1.
  /// The value of size 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.
200
  final double size;
201

202
  /// The radius of the contact ellipse along the major axis, in logical pixels.
203
  final double radiusMajor;
204 205

  /// The radius of the contact ellipse along the minor axis, in logical pixels.
206
  final double radiusMinor;
207 208 209

  /// The minimum value that could be reported for radiusMajor and radiusMinor
  /// for this pointer, in logical pixels.
210
  final double radiusMin;
211 212 213

  /// The minimum value that could be reported for radiusMajor and radiusMinor
  /// for this pointer, in logical pixels.
214
  final double radiusMax;
215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240

  /// For PointerDeviceKind.touch events:
  ///
  /// The angle of the contact ellipse, in radius in the range:
  ///
  ///    -pi/2 < orientation <= pi/2
  ///
  /// ...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).
  ///
  /// For PointerDeviceKind.stylus and PointerDeviceKind.invertedStylus events:
  ///
  /// The angle of the stylus, in radians in the range:
  ///
  ///    -pi < orientation <= pi
  ///
  /// ...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).
241
  final double orientation;
242 243 244 245 246 247 248 249 250 251 252

  /// For PointerDeviceKind.stylus and PointerDeviceKind.invertedStylus events:
  ///
  /// The angle of the stylus, in radians in the range:
  ///
  ///    0 <= tilt <= pi/2
  ///
  /// ...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).
253
  final double tilt;
254

255
  /// Opaque platform-specific data associated with the event.
256
  final int platformData;
257

258 259 260
  /// For events with signalKind of PointerSignalKind.scroll:
  ///
  /// The amount to scroll in the x direction, in physical pixels.
261
  final double scrollDeltaX;
262 263 264 265

  /// For events with signalKind of PointerSignalKind.scroll:
  ///
  /// The amount to scroll in the y direction, in physical pixels.
266
  final double scrollDeltaY;
267

268
  @override
269
  String toString() => 'PointerData(x: $physicalX, y: $physicalY)';
270 271 272 273

  /// Returns a complete textual description of the information in this object.
  String toStringFull() {
    return '$runtimeType('
274
             'embedderId: $embedderId, '
275
             'timeStamp: $timeStamp, '
276
             'change: $change, '
277
             'kind: $kind, '
278
             'signalKind: $signalKind, '
279
             'device: $device, '
280
             'pointerIdentifier: $pointerIdentifier, '
281 282
             'physicalX: $physicalX, '
             'physicalY: $physicalY, '
283 284
             'physicalDeltaX: $physicalDeltaX, '
             'physicalDeltaY: $physicalDeltaY, '
285
             'buttons: $buttons, '
286
             'synthesized: $synthesized, '
287 288 289 290 291
             'pressure: $pressure, '
             'pressureMin: $pressureMin, '
             'pressureMax: $pressureMax, '
             'distance: $distance, '
             'distanceMax: $distanceMax, '
292
             'size: $size, '
293 294 295 296 297
             'radiusMajor: $radiusMajor, '
             'radiusMinor: $radiusMinor, '
             'radiusMin: $radiusMin, '
             'radiusMax: $radiusMax, '
             'orientation: $orientation, '
298
             'tilt: $tilt, '
299 300 301
             'platformData: $platformData, '
             'scrollDeltaX: $scrollDeltaX, '
             'scrollDeltaY: $scrollDeltaY'
302 303 304 305 306 307 308
           ')';
  }
}

/// A sequence of reports about the state of pointers.
class PointerDataPacket {
  /// Creates a packet of pointer data reports.
309
  const PointerDataPacket({ this.data = const <PointerData>[] }) : assert(data != null); // ignore: unnecessary_null_comparison
310 311 312 313

  /// Data about the individual pointers in this packet.
  ///
  /// This list might contain multiple pieces of data about the same pointer.
314
  final List<PointerData> data;
315
}