Roll src/third_party/WebKit d9c6159:8139f33 (svn 201974:201975)
[chromium-blink-merge.git] / ui / events / gesture_detection / motion_event.h
blobab2522643d3633032f5c1612842c5d223a380bb8
1 // Copyright 2014 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 #ifndef UI_EVENTS_GESTURE_DETECTION_MOTION_EVENT_H_
6 #define UI_EVENTS_GESTURE_DETECTION_MOTION_EVENT_H_
8 #include "base/memory/scoped_ptr.h"
9 #include "base/time/time.h"
10 #include "ui/events/gesture_detection/gesture_detection_export.h"
12 namespace ui {
14 // Abstract class for a generic motion-related event, patterned after that
15 // subset of Android's MotionEvent API used in gesture detection.
16 class GESTURE_DETECTION_EXPORT MotionEvent {
17 public:
18 enum Action {
19 ACTION_NONE,
20 ACTION_DOWN,
21 ACTION_UP,
22 ACTION_MOVE,
23 ACTION_CANCEL,
24 ACTION_POINTER_DOWN,
25 ACTION_POINTER_UP,
28 enum ToolType {
29 TOOL_TYPE_UNKNOWN,
30 TOOL_TYPE_FINGER,
31 TOOL_TYPE_STYLUS,
32 TOOL_TYPE_MOUSE,
33 TOOL_TYPE_ERASER
36 enum ButtonType {
37 BUTTON_PRIMARY = 1 << 0,
38 BUTTON_SECONDARY = 1 << 1,
39 BUTTON_TERTIARY = 1 << 2,
40 BUTTON_BACK = 1 << 3,
41 BUTTON_FORWARD = 1 << 4,
44 // The implementer promises that |GetPointerId()| will never exceed
45 // MAX_POINTER_ID.
46 enum { MAX_POINTER_ID = 31, MAX_TOUCH_POINT_COUNT = 16 };
48 virtual ~MotionEvent() {}
50 // An unique identifier this motion event.
51 virtual uint32 GetUniqueEventId() const = 0;
52 virtual Action GetAction() const = 0;
53 // Only valid if |GetAction()| returns ACTION_POINTER_UP or
54 // ACTION_POINTER_DOWN.
55 virtual int GetActionIndex() const = 0;
56 virtual size_t GetPointerCount() const = 0;
57 virtual int GetPointerId(size_t pointer_index) const = 0;
58 virtual float GetX(size_t pointer_index) const = 0;
59 virtual float GetY(size_t pointer_index) const = 0;
60 virtual float GetRawX(size_t pointer_index) const = 0;
61 virtual float GetRawY(size_t pointer_index) const = 0;
62 virtual float GetTouchMajor(size_t pointer_index) const = 0;
63 virtual float GetTouchMinor(size_t pointer_index) const = 0;
64 virtual float GetOrientation(size_t pointer_index) const = 0;
65 virtual float GetPressure(size_t pointer_index) const = 0;
66 virtual ToolType GetToolType(size_t pointer_index) const = 0;
67 virtual int GetButtonState() const = 0;
68 virtual int GetFlags() const = 0;
69 virtual base::TimeTicks GetEventTime() const = 0;
71 // Optional historical data, default implementation provides an empty history.
72 virtual size_t GetHistorySize() const;
73 virtual base::TimeTicks GetHistoricalEventTime(size_t historical_index) const;
74 virtual float GetHistoricalTouchMajor(size_t pointer_index,
75 size_t historical_index) const;
76 virtual float GetHistoricalX(size_t pointer_index,
77 size_t historical_index) const;
78 virtual float GetHistoricalY(size_t pointer_index,
79 size_t historical_index) const;
81 // Get the id of the device which created the event. Currently Aura only.
82 virtual int GetSourceDeviceId(size_t pointer_index) const;
84 // Utility accessor methods for convenience.
85 int GetPointerId() const { return GetPointerId(0); }
86 float GetX() const { return GetX(0); }
87 float GetY() const { return GetY(0); }
88 float GetRawX() const { return GetRawX(0); }
89 float GetRawY() const { return GetRawY(0); }
90 float GetRawOffsetX() const { return GetRawX() - GetX(); }
91 float GetRawOffsetY() const { return GetRawY() - GetY(); }
93 float GetTouchMajor() const { return GetTouchMajor(0); }
94 float GetTouchMinor() const { return GetTouchMinor(0); }
96 // Returns the orientation in radians. The meaning is overloaded:
97 // * For a touch screen or pad, it's the orientation of the major axis
98 // clockwise from vertical. The return value lies in [-PI/2, PI/2].
99 // * For a stylus, it indicates the direction in which the stylus is pointing.
100 // The return value lies in [-PI, PI].
101 float GetOrientation() const { return GetOrientation(0); }
103 float GetPressure() const { return GetPressure(0); }
104 ToolType GetToolType() const { return GetToolType(0); }
106 // O(N) search of pointers (use sparingly!). Returns -1 if |id| nonexistent.
107 int FindPointerIndexOfId(int id) const;
109 // Note that these methods perform shallow copies of the originating events.
110 // They guarantee only that the returned type will reflect the same
111 // data exposed by the MotionEvent interface; no guarantees are made that the
112 // underlying implementation is identical to the source implementation.
113 scoped_ptr<MotionEvent> Clone() const;
114 scoped_ptr<MotionEvent> Cancel() const;
117 } // namespace ui
119 #endif // UI_EVENTS_GESTURE_DETECTION_MOTION_EVENT_H_