File: motion_event.h

package info (click to toggle)
chromium-browser 41.0.2272.118-1
  • links: PTS, VCS
  • area: main
  • in suites: jessie-kfreebsd
  • size: 2,189,132 kB
  • sloc: cpp: 9,691,462; ansic: 3,341,451; python: 712,689; asm: 518,779; xml: 208,926; java: 169,820; sh: 119,353; perl: 68,907; makefile: 28,311; yacc: 13,305; objc: 11,385; tcl: 3,186; cs: 2,225; sql: 2,217; lex: 2,215; lisp: 1,349; pascal: 1,256; awk: 407; ruby: 155; sed: 53; php: 14; exp: 11
file content (113 lines) | stat: -rw-r--r-- 4,278 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
// Copyright 2014 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#ifndef UI_EVENTS_GESTURE_DETECTION_MOTION_EVENT_H_
#define UI_EVENTS_GESTURE_DETECTION_MOTION_EVENT_H_

#include "base/memory/scoped_ptr.h"
#include "base/time/time.h"
#include "ui/events/gesture_detection/gesture_detection_export.h"

namespace ui {

// Abstract class for a generic motion-related event, patterned after that
// subset of Android's MotionEvent API used in gesture detection.
class GESTURE_DETECTION_EXPORT MotionEvent {
 public:
  enum Action {
    ACTION_DOWN,
    ACTION_UP,
    ACTION_MOVE,
    ACTION_CANCEL,
    ACTION_POINTER_DOWN,
    ACTION_POINTER_UP,
  };

  enum ToolType {
    TOOL_TYPE_UNKNOWN,
    TOOL_TYPE_FINGER,
    TOOL_TYPE_STYLUS,
    TOOL_TYPE_MOUSE,
    TOOL_TYPE_ERASER
  };

  enum ButtonType {
    BUTTON_PRIMARY = 1 << 0,
    BUTTON_SECONDARY = 1 << 1,
    BUTTON_TERTIARY = 1 << 2,
    BUTTON_BACK = 1 << 3,
    BUTTON_FORWARD = 1 << 4,
  };

  // The implementer promises that |GetPointerId()| will never exceed
  // MAX_POINTER_ID.
  enum { MAX_POINTER_ID = 31, MAX_TOUCH_POINT_COUNT = 16 };

  virtual ~MotionEvent() {}

  virtual int GetId() const = 0;
  virtual Action GetAction() const = 0;
  // Only valid if |GetAction()| returns ACTION_POINTER_UP or
  // ACTION_POINTER_DOWN.
  virtual int GetActionIndex() const = 0;
  virtual size_t GetPointerCount() const = 0;
  virtual int GetPointerId(size_t pointer_index) const = 0;
  virtual float GetX(size_t pointer_index) const = 0;
  virtual float GetY(size_t pointer_index) const = 0;
  virtual float GetRawX(size_t pointer_index) const = 0;
  virtual float GetRawY(size_t pointer_index) const = 0;
  virtual float GetTouchMajor(size_t pointer_index) const = 0;
  virtual float GetTouchMinor(size_t pointer_index) const = 0;
  virtual float GetOrientation(size_t pointer_index) const = 0;
  virtual float GetPressure(size_t pointer_index) const = 0;
  virtual ToolType GetToolType(size_t pointer_index) const = 0;
  virtual int GetButtonState() const = 0;
  virtual int GetFlags() const = 0;
  virtual base::TimeTicks GetEventTime() const = 0;

  // Optional historical data, default implementation provides an empty history.
  virtual size_t GetHistorySize() const;
  virtual base::TimeTicks GetHistoricalEventTime(size_t historical_index) const;
  virtual float GetHistoricalTouchMajor(size_t pointer_index,
                                        size_t historical_index) const;
  virtual float GetHistoricalX(size_t pointer_index,
                               size_t historical_index) const;
  virtual float GetHistoricalY(size_t pointer_index,
                               size_t historical_index) const;

  // Get the id of the device which created the event. Currently Aura only.
  virtual int GetSourceDeviceId(size_t pointer_index) const;

  // Utility accessor methods for convenience.
  float GetX() const { return GetX(0); }
  float GetY() const { return GetY(0); }
  float GetRawX() const { return GetRawX(0); }
  float GetRawY() const { return GetRawY(0); }
  float GetRawOffsetX() const { return GetRawX() - GetX(); }
  float GetRawOffsetY() const { return GetRawY() - GetY(); }

  float GetTouchMajor() const { return GetTouchMajor(0); }
  float GetTouchMinor() const { return GetTouchMinor(0); }

  // Returns the orientation of the major axis clockwise from vertical, in
  // radians. The return value lies in [-PI/2, PI/2].
  float GetOrientation() const { return GetOrientation(0); }

  float GetPressure() const { return GetPressure(0); }
  ToolType GetToolType() const { return GetToolType(0); }

  // O(N) search of pointers (use sparingly!). Returns -1 if |id| nonexistent.
  int FindPointerIndexOfId(int id) const;

  // Note that these methods perform shallow copies of the originating events.
  // They guarantee only that the returned type will reflect the same
  // data exposed by the MotionEvent interface; no guarantees are made that the
  // underlying implementation is identical to the source implementation.
  scoped_ptr<MotionEvent> Clone() const;
  scoped_ptr<MotionEvent> Cancel() const;
};

}  // namespace ui

#endif  // UI_EVENTS_GESTURE_DETECTION_MOTION_EVENT_H_