OLD | NEW |
---|---|
(Empty) | |
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. | |
4 | |
5 #ifndef UI_EVENTS_GESTURE_DETECTION_UI_MOTION_EVENT_H_ | |
6 #define UI_EVENTS_GESTURE_DETECTION_UI_MOTION_EVENT_H_ | |
7 | |
8 #include "ui/events/gesture_detection/motion_event.h" | |
9 | |
10 #include <map> | |
11 | |
12 #include "base/memory/scoped_ptr.h" | |
13 #include "base/time/time.h" | |
14 #include "ui/events/event.h" | |
15 #include "ui/events/events_export.h" | |
16 #include "ui/events/gestures/gesture_sequence.h" | |
17 | |
18 namespace ui { | |
19 | |
20 // Implementation of MotionEvent which takes a stream of ui::TouchEvents. | |
21 class EVENTS_EXPORT MotionEventAura : public MotionEvent { | |
22 public: | |
23 MotionEventAura(); | |
24 virtual ~MotionEventAura(); | |
25 | |
26 void OnTouch(const TouchEvent& touch); | |
27 | |
28 // MotionEvent implementation. | |
29 virtual int GetId() const OVERRIDE; | |
30 virtual Action GetAction() const OVERRIDE; | |
31 virtual int GetActionIndex() const OVERRIDE; | |
32 virtual size_t GetPointerCount() const OVERRIDE; | |
33 virtual int GetPointerId(size_t pointer_index) const OVERRIDE; | |
34 virtual float GetX(size_t pointer_index) const OVERRIDE; | |
35 virtual float GetY(size_t pointer_index) const OVERRIDE; | |
36 virtual float GetTouchMajor(size_t pointer_index) const OVERRIDE; | |
37 virtual float GetPressure(size_t pointer_index) const OVERRIDE; | |
38 virtual base::TimeTicks GetEventTime() const OVERRIDE; | |
39 | |
40 virtual size_t GetHistorySize() const OVERRIDE; | |
41 virtual base::TimeTicks GetHistoricalEventTime(size_t historical_index) const | |
42 OVERRIDE; | |
43 virtual float GetHistoricalTouchMajor(size_t pointer_index, | |
44 size_t historical_index) const OVERRIDE; | |
45 virtual float GetHistoricalX(size_t pointer_index, | |
46 size_t historical_index) const OVERRIDE; | |
47 virtual float GetHistoricalY(size_t pointer_index, | |
48 size_t historical_index) const OVERRIDE; | |
49 | |
50 virtual scoped_ptr<MotionEvent> Clone() const OVERRIDE; | |
51 virtual scoped_ptr<MotionEvent> Cancel() const OVERRIDE; | |
52 | |
53 int GetSourceDeviceId(size_t pointer_index) const; | |
54 | |
55 // We can't cleanup removed touch points immediately upon receipt of a | |
56 // TouchCancel or TouchRelease, as the MotionEvent needs to be able to report | |
57 // information about those touch events. Once the MotionEvent has been | |
58 // processed, we call CleanupRemovedTouchPoints to do the required | |
59 // book-keeping. | |
60 void CleanupRemovedTouchPoints(const TouchEvent& event); | |
61 | |
62 private: | |
63 struct PointData { | |
64 PointData(); | |
65 float x; | |
66 float y; | |
67 int touch_id; | |
68 float pressure; | |
69 int source_device_id; | |
70 float major_radius; | |
71 }; | |
72 | |
73 MotionEventAura( | |
74 size_t pointer_count, | |
75 const base::TimeTicks& last_touch_time, | |
76 Action cached_action, | |
77 int cached_action_index, | |
78 const PointData (&active_touches)[GestureSequence::kMaxGesturePoints]); | |
79 | |
80 static PointData GetPointDataFromTouchEvent(const TouchEvent& touch); | |
81 void AddTouch(const TouchEvent& touch); | |
82 void UpdateTouch(const TouchEvent& touch); | |
83 void UpdateCachedAction(const TouchEvent& touch); | |
84 const size_t GetIndexFromId(int id); | |
jdduke (slow)
2014/05/05 17:52:48
Sorry, I should have been more clear, this should
tdresser
2014/05/05 18:11:18
Pffft, that should not have required additional cl
| |
85 | |
86 size_t pointer_count_; | |
87 base::TimeTicks last_touch_time_; | |
88 Action cached_action_; | |
89 // The index of the touch responsible for last ACTION_POINTER_DOWN or | |
90 // ACTION_POINTER_UP. -1 if no such action has occurred. | |
91 int cached_action_index_; | |
92 | |
93 // We want constant time indexing by pointer_index, and fast indexing by id. | |
94 // TODO(tdresser): figure out which constant to use here. | |
95 PointData active_touches_[GestureSequence::kMaxGesturePoints]; | |
96 }; | |
97 | |
98 } // namespace ui | |
99 | |
100 #endif // UI_EVENTS_GESTURE_DETECTION_UI_MOTION_EVENT_H_ | |
OLD | NEW |