Chromium Code Reviews| 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 namespace ui { | |
|
jdduke (slow)
2014/05/02 17:56:43
Nit: Line before namespace
tdresser
2014/05/05 15:42:35
Done.
| |
| 18 | |
| 19 // Implementation of MotionEvent which takes a stream of ui::Events. | |
|
jdduke (slow)
2014/05/02 17:56:43
ui::TouchEvents
tdresser
2014/05/05 15:42:35
Done.
| |
| 20 class EVENTS_EXPORT MotionEventUI : public MotionEvent { | |
|
jdduke (slow)
2014/05/02 17:56:43
Would MotionEventAura be more appropriate?
tdresser
2014/05/05 15:42:35
Done.
| |
| 21 public: | |
| 22 MotionEventUI(); | |
| 23 virtual ~MotionEventUI(); | |
| 24 | |
| 25 void OnTouch(const TouchEvent& touch); | |
| 26 | |
| 27 virtual int GetId() const OVERRIDE; | |
|
jdduke (slow)
2014/05/02 17:56:43
// MotionEvent implementation.
tdresser
2014/05/05 15:42:35
Done.
| |
| 28 virtual Action GetAction() const OVERRIDE; | |
| 29 virtual int GetActionIndex() const OVERRIDE; | |
| 30 virtual size_t GetPointerCount() const OVERRIDE; | |
| 31 virtual int GetPointerId(size_t pointer_index) const OVERRIDE; | |
| 32 virtual float GetX(size_t pointer_index) const OVERRIDE; | |
| 33 virtual float GetY(size_t pointer_index) const OVERRIDE; | |
| 34 virtual float GetTouchMajor(size_t pointer_index) const OVERRIDE; | |
| 35 virtual float GetPressure(size_t pointer_index) const OVERRIDE; | |
| 36 virtual base::TimeTicks GetEventTime() const OVERRIDE; | |
| 37 | |
| 38 virtual size_t GetHistorySize() const OVERRIDE; | |
| 39 virtual base::TimeTicks GetHistoricalEventTime(size_t historical_index) const | |
| 40 OVERRIDE; | |
| 41 virtual float GetHistoricalTouchMajor(size_t pointer_index, | |
| 42 size_t historical_index) const OVERRIDE; | |
| 43 virtual float GetHistoricalX(size_t pointer_index, | |
| 44 size_t historical_index) const OVERRIDE; | |
| 45 virtual float GetHistoricalY(size_t pointer_index, | |
| 46 size_t historical_index) const OVERRIDE; | |
| 47 | |
| 48 virtual scoped_ptr<MotionEvent> Clone() const OVERRIDE; | |
| 49 virtual scoped_ptr<MotionEvent> Cancel() const OVERRIDE; | |
| 50 | |
| 51 // We can't cleanup removed touch points immediately upon receipt of a | |
| 52 // TouchCancel or TouchRelease, as the MotionEvent needs to be able to report | |
| 53 // information about those touch events. Once the MotionEvent has been | |
| 54 // processed, call CleanupRemovedTouchPoints to do the required book-keeping. | |
| 55 void CleanupRemovedTouchPoints(const TouchEvent& touch); | |
| 56 | |
| 57 int GetSourceDeviceId(size_t pointer_index) const; | |
| 58 | |
| 59 private: | |
| 60 struct PointData { | |
| 61 float x; | |
|
jdduke (slow)
2014/05/02 17:56:43
Let's give this a default constructor that zero's
tdresser
2014/05/05 15:42:35
Done.
| |
| 62 float y; | |
| 63 int touch_id; | |
| 64 float pressure; | |
| 65 int source_device_id; | |
| 66 float major_radius; | |
| 67 }; | |
| 68 | |
| 69 MotionEventUI( | |
| 70 size_t pointer_count, | |
| 71 const base::TimeDelta& last_touch_time, | |
| 72 Action cached_action, | |
| 73 int cached_action_index, | |
| 74 const PointData (&active_touches)[GestureSequence::kMaxGesturePoints], | |
| 75 const std::map<int, int>& id_to_index); | |
| 76 | |
| 77 void UpdatePointData(const TouchEvent& touch, | |
| 78 MotionEventUI::PointData* point_data); | |
| 79 void AddTouch(const TouchEvent& touch); | |
| 80 void UpdateTouch(const TouchEvent& touch); | |
| 81 void SetCachedAction(const TouchEvent& touch); | |
| 82 | |
| 83 size_t pointer_count_; | |
| 84 base::TimeDelta last_touch_time_; | |
| 85 Action cached_action_; | |
| 86 // The index of the touch responsible for last ACTION_POINTER_DOWN or | |
| 87 // ACTION_POINTER_UP. -1 if no such action has occurred. | |
| 88 int cached_action_index_; | |
| 89 | |
| 90 // We want constant time indexing by pointer_index, and fast indexing by id. | |
| 91 // TODO(tdresser): figure out which constant to use here. | |
| 92 PointData active_touches_[GestureSequence::kMaxGesturePoints]; | |
| 93 std::map<int, int> id_to_index_; | |
|
jdduke (slow)
2014/05/02 17:56:43
Would a base::SmallMap be more appropriate here? D
tdresser
2014/05/05 15:42:35
I switched to iterating through |active_touches_|.
| |
| 94 }; | |
| 95 | |
| 96 } // namespace ui | |
| 97 | |
| 98 #endif // UI_EVENTS_GESTURE_DETECTION_UI_MOTION_EVENT_H_ | |
| OLD | NEW |