| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #ifndef UI_EVENTS_GESTURE_DETECTION_UI_MOTION_EVENT_GENERIC_H_ | 5 #ifndef UI_EVENTS_GESTURE_DETECTION_UI_MOTION_EVENT_GENERIC_H_ |
| 6 #define UI_EVENTS_GESTURE_DETECTION_UI_MOTION_EVENT_GENERIC_H_ | 6 #define UI_EVENTS_GESTURE_DETECTION_UI_MOTION_EVENT_GENERIC_H_ |
| 7 | 7 |
| 8 #include "base/basictypes.h" | 8 #include "base/basictypes.h" |
| 9 #include "base/containers/stack_container.h" | 9 #include "base/containers/stack_container.h" |
| 10 #include "base/memory/scoped_vector.h" |
| 10 #include "ui/events/gesture_detection/gesture_detection_export.h" | 11 #include "ui/events/gesture_detection/gesture_detection_export.h" |
| 11 #include "ui/events/gesture_detection/motion_event.h" | 12 #include "ui/events/gesture_detection/motion_event.h" |
| 12 | 13 |
| 13 namespace ui { | 14 namespace ui { |
| 14 | 15 |
| 15 struct GESTURE_DETECTION_EXPORT PointerProperties { | 16 struct GESTURE_DETECTION_EXPORT PointerProperties { |
| 16 PointerProperties(); | 17 PointerProperties(); |
| 17 PointerProperties(float x, float y); | 18 PointerProperties(float x, float y, float touch_major); |
| 19 PointerProperties(const MotionEvent& event, size_t pointer_index); |
| 20 |
| 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); |
| 18 | 26 |
| 19 int id; | 27 int id; |
| 20 MotionEvent::ToolType tool_type; | 28 MotionEvent::ToolType tool_type; |
| 21 float x; | 29 float x; |
| 22 float y; | 30 float y; |
| 23 float raw_x; | 31 float raw_x; |
| 24 float raw_y; | 32 float raw_y; |
| 25 float pressure; | 33 float pressure; |
| 26 float touch_major; | 34 float touch_major; |
| 27 float touch_minor; | 35 float touch_minor; |
| 28 float orientation; | 36 float orientation; |
| 37 // source_device_id is only used on Aura. |
| 38 int source_device_id; |
| 29 }; | 39 }; |
| 30 | 40 |
| 31 // A generic MotionEvent implementation. | 41 // A generic MotionEvent implementation. |
| 32 class GESTURE_DETECTION_EXPORT MotionEventGeneric : public MotionEvent { | 42 class GESTURE_DETECTION_EXPORT MotionEventGeneric : public MotionEvent { |
| 33 public: | 43 public: |
| 34 MotionEventGeneric(Action action, | 44 MotionEventGeneric(Action action, |
| 35 base::TimeTicks event_time, | 45 base::TimeTicks event_time, |
| 36 const PointerProperties& pointer); | 46 const PointerProperties& pointer); |
| 37 MotionEventGeneric(const MotionEventGeneric& other); | 47 MotionEventGeneric(const MotionEventGeneric& other); |
| 38 | 48 |
| 39 ~MotionEventGeneric() override; | 49 ~MotionEventGeneric() override; |
| 40 | 50 |
| 41 // MotionEvent implementation. | 51 // MotionEvent implementation. |
| 42 int GetId() const override; | 52 uint32 GetUniqueEventId() const override; |
| 43 Action GetAction() const override; | 53 Action GetAction() const override; |
| 44 int GetActionIndex() const override; | 54 int GetActionIndex() const override; |
| 45 size_t GetPointerCount() const override; | 55 size_t GetPointerCount() const override; |
| 46 int GetPointerId(size_t pointer_index) const override; | 56 int GetPointerId(size_t pointer_index) const override; |
| 47 float GetX(size_t pointer_index) const override; | 57 float GetX(size_t pointer_index) const override; |
| 48 float GetY(size_t pointer_index) const override; | 58 float GetY(size_t pointer_index) const override; |
| 49 float GetRawX(size_t pointer_index) const override; | 59 float GetRawX(size_t pointer_index) const override; |
| 50 float GetRawY(size_t pointer_index) const override; | 60 float GetRawY(size_t pointer_index) const override; |
| 51 float GetTouchMajor(size_t pointer_index) const override; | 61 float GetTouchMajor(size_t pointer_index) const override; |
| 52 float GetTouchMinor(size_t pointer_index) const override; | 62 float GetTouchMinor(size_t pointer_index) const override; |
| 53 float GetOrientation(size_t pointer_index) const override; | 63 float GetOrientation(size_t pointer_index) const override; |
| 54 float GetPressure(size_t pointer_index) const override; | 64 float GetPressure(size_t pointer_index) const override; |
| 55 ToolType GetToolType(size_t pointer_index) const override; | 65 ToolType GetToolType(size_t pointer_index) const override; |
| 56 int GetButtonState() const override; | 66 int GetButtonState() const override; |
| 57 int GetFlags() const override; | 67 int GetFlags() const override; |
| 58 base::TimeTicks GetEventTime() const override; | 68 base::TimeTicks GetEventTime() const override; |
| 59 scoped_ptr<MotionEvent> Clone() const override; | 69 size_t GetHistorySize() const override; |
| 60 scoped_ptr<MotionEvent> Cancel() 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; |
| 61 | 78 |
| 62 void PushPointer(const PointerProperties& pointer); | 79 // Adds |pointer| to the set of pointers returning the index it was added at. |
| 80 size_t PushPointer(const PointerProperties& pointer); |
| 63 | 81 |
| 64 void set_action(Action action) { action_ = action; } | 82 // Removes the PointerProperties at |index|. |
| 65 void set_event_time(base::TimeTicks event_time) { event_time_ = event_time; } | 83 void RemovePointerAt(size_t index); |
| 66 void set_id(int id) { id_ = id; } | |
| 67 void set_action_index(int action_index) { action_index_ = action_index; } | |
| 68 void set_button_state(int button_state) { button_state_ = button_state; } | |
| 69 void set_flags(int flags) { flags_ = flags; } | |
| 70 | |
| 71 protected: | |
| 72 MotionEventGeneric(); | |
| 73 | |
| 74 void PopPointer(); | |
| 75 | 84 |
| 76 PointerProperties& pointer(size_t index) { return pointers_[index]; } | 85 PointerProperties& pointer(size_t index) { return pointers_[index]; } |
| 77 const PointerProperties& pointer(size_t index) const { | 86 const PointerProperties& pointer(size_t index) const { |
| 78 return pointers_[index]; | 87 return pointers_[index]; |
| 79 } | 88 } |
| 80 | 89 |
| 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); |
| 93 |
| 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; |
| 98 } |
| 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; } |
| 102 |
| 103 static scoped_ptr<MotionEventGeneric> CloneEvent(const MotionEvent& event); |
| 104 static scoped_ptr<MotionEventGeneric> CancelEvent(const MotionEvent& event); |
| 105 |
| 106 protected: |
| 107 MotionEventGeneric(); |
| 108 MotionEventGeneric(const MotionEvent& event, bool with_history); |
| 109 MotionEventGeneric& operator=(const MotionEventGeneric& other); |
| 110 |
| 111 void PopPointer(); |
| 112 |
| 81 private: | 113 private: |
| 82 enum { kTypicalMaxPointerCount = 5 }; | 114 enum { kTypicalMaxPointerCount = 5 }; |
| 83 | 115 |
| 84 Action action_; | 116 Action action_; |
| 85 base::TimeTicks event_time_; | 117 base::TimeTicks event_time_; |
| 86 int id_; | 118 uint32 unique_event_id_; |
| 87 int action_index_; | 119 int action_index_; |
| 88 int button_state_; | 120 int button_state_; |
| 89 int flags_; | 121 int flags_; |
| 90 base::StackVector<PointerProperties, kTypicalMaxPointerCount> pointers_; | 122 base::StackVector<PointerProperties, kTypicalMaxPointerCount> pointers_; |
| 123 ScopedVector<MotionEvent> historical_events_; |
| 91 }; | 124 }; |
| 92 | 125 |
| 93 } // namespace ui | 126 } // namespace ui |
| 94 | 127 |
| 95 #endif // UI_EVENTS_GESTURE_DETECTION_UI_MOTION_EVENT_GENERIC_H_ | 128 #endif // UI_EVENTS_GESTURE_DETECTION_UI_MOTION_EVENT_GENERIC_H_ |
| OLD | NEW |