Merge Chromium + Blink git repositories
[chromium-blink-merge.git] / ui / events / gesture_detection / motion_event_generic.h
blob2a9a606b44d3c66057f40ae44ee1c590c69f4f44
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_UI_MOTION_EVENT_GENERIC_H_
6 #define UI_EVENTS_GESTURE_DETECTION_UI_MOTION_EVENT_GENERIC_H_
8 #include "base/basictypes.h"
9 #include "base/containers/stack_container.h"
10 #include "base/memory/scoped_vector.h"
11 #include "ui/events/gesture_detection/gesture_detection_export.h"
12 #include "ui/events/gesture_detection/motion_event.h"
14 namespace ui {
16 struct GESTURE_DETECTION_EXPORT PointerProperties {
17 PointerProperties();
18 PointerProperties(float x, float y, float touch_major);
19 PointerProperties(const MotionEvent& event, size_t pointer_index);
21 // Sets |touch_major|, |touch_minor|, and |orientation| from the given radius
22 // and rotation angle (in degrees).
23 void SetAxesAndOrientation(float radius_x,
24 float radius_y,
25 float rotation_angle_degree);
27 int id;
28 MotionEvent::ToolType tool_type;
29 float x;
30 float y;
31 float raw_x;
32 float raw_y;
33 float pressure;
34 float touch_major;
35 float touch_minor;
36 float orientation;
37 // source_device_id is only used on Aura.
38 int source_device_id;
41 // A generic MotionEvent implementation.
42 class GESTURE_DETECTION_EXPORT MotionEventGeneric : public MotionEvent {
43 public:
44 MotionEventGeneric(Action action,
45 base::TimeTicks event_time,
46 const PointerProperties& pointer);
47 MotionEventGeneric(const MotionEventGeneric& other);
49 ~MotionEventGeneric() override;
51 // MotionEvent implementation.
52 uint32 GetUniqueEventId() const override;
53 Action GetAction() const override;
54 int GetActionIndex() const override;
55 size_t GetPointerCount() const override;
56 int GetPointerId(size_t pointer_index) const override;
57 float GetX(size_t pointer_index) const override;
58 float GetY(size_t pointer_index) const override;
59 float GetRawX(size_t pointer_index) const override;
60 float GetRawY(size_t pointer_index) const override;
61 float GetTouchMajor(size_t pointer_index) const override;
62 float GetTouchMinor(size_t pointer_index) const override;
63 float GetOrientation(size_t pointer_index) const override;
64 float GetPressure(size_t pointer_index) const override;
65 ToolType GetToolType(size_t pointer_index) const override;
66 int GetButtonState() const override;
67 int GetFlags() const override;
68 base::TimeTicks GetEventTime() const override;
69 size_t GetHistorySize() const override;
70 base::TimeTicks GetHistoricalEventTime(
71 size_t historical_index) const override;
72 float GetHistoricalTouchMajor(size_t pointer_index,
73 size_t historical_index) const override;
74 float GetHistoricalX(size_t pointer_index,
75 size_t historical_index) const override;
76 float GetHistoricalY(size_t pointer_index,
77 size_t historical_index) const override;
79 // Adds |pointer| to the set of pointers returning the index it was added at.
80 size_t PushPointer(const PointerProperties& pointer);
82 // Removes the PointerProperties at |index|.
83 void RemovePointerAt(size_t index);
85 PointerProperties& pointer(size_t index) { return pointers_[index]; }
86 const PointerProperties& pointer(size_t index) const {
87 return pointers_[index];
90 // Add an event to the history. |this| and |event| must have the same pointer
91 // count and must both have an action of ACTION_MOVE.
92 void PushHistoricalEvent(scoped_ptr<MotionEvent> event);
94 void set_action(Action action) { action_ = action; }
95 void set_event_time(base::TimeTicks event_time) { event_time_ = event_time; }
96 void set_unique_event_id(uint32 unique_event_id) {
97 unique_event_id_ = unique_event_id;
99 void set_action_index(int action_index) { action_index_ = action_index; }
100 void set_button_state(int button_state) { button_state_ = button_state; }
101 void set_flags(int flags) { flags_ = flags; }
103 static scoped_ptr<MotionEventGeneric> CloneEvent(const MotionEvent& event);
104 static scoped_ptr<MotionEventGeneric> CancelEvent(const MotionEvent& event);
106 protected:
107 MotionEventGeneric();
108 MotionEventGeneric(const MotionEvent& event, bool with_history);
109 MotionEventGeneric& operator=(const MotionEventGeneric& other);
111 void PopPointer();
113 private:
114 enum { kTypicalMaxPointerCount = 5 };
116 Action action_;
117 base::TimeTicks event_time_;
118 uint32 unique_event_id_;
119 int action_index_;
120 int button_state_;
121 int flags_;
122 base::StackVector<PointerProperties, kTypicalMaxPointerCount> pointers_;
123 ScopedVector<MotionEvent> historical_events_;
126 } // namespace ui
128 #endif // UI_EVENTS_GESTURE_DETECTION_UI_MOTION_EVENT_GENERIC_H_