| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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_GESTURES_GESTURE_SEQUENCE_H_ | 5 #ifndef UI_EVENTS_GESTURES_GESTURE_SEQUENCE_H_ |
| 6 #define UI_EVENTS_GESTURES_GESTURE_SEQUENCE_H_ | 6 #define UI_EVENTS_GESTURES_GESTURE_SEQUENCE_H_ |
| 7 | 7 |
| 8 #include "base/timer/timer.h" | 8 #include "base/timer/timer.h" |
| 9 #include "ui/events/event_constants.h" | 9 #include "ui/events/event_constants.h" |
| 10 #include "ui/events/gestures/gesture_event_queue.h" |
| 10 #include "ui/events/gestures/gesture_point.h" | 11 #include "ui/events/gestures/gesture_point.h" |
| 11 #include "ui/events/gestures/gesture_recognizer.h" | 12 #include "ui/events/gestures/gesture_recognizer.h" |
| 12 #include "ui/gfx/rect.h" | 13 #include "ui/gfx/rect.h" |
| 13 | 14 |
| 14 namespace ui { | 15 namespace ui { |
| 15 class TouchEvent; | 16 class TouchEvent; |
| 16 class GestureEvent; | 17 class GestureEvent; |
| 17 | 18 |
| 18 // Gesture state. | 19 // Gesture state. |
| 19 enum GestureState { | 20 enum GestureState { |
| 20 GS_NO_GESTURE, | 21 GS_NO_GESTURE, |
| 21 GS_PENDING_SYNTHETIC_CLICK, | 22 GS_PENDING_SYNTHETIC_CLICK, |
| 22 GS_PENDING_SYNTHETIC_CLICK_NO_SCROLL, | 23 GS_PENDING_SYNTHETIC_CLICK_NO_SCROLL, |
| 23 GS_SCROLL, | 24 GS_SCROLL, |
| 24 GS_PINCH, | 25 GS_PINCH, |
| 25 GS_PENDING_TWO_FINGER_TAP, | 26 GS_PENDING_TWO_FINGER_TAP, |
| 26 GS_PENDING_TWO_FINGER_TAP_NO_PINCH, | 27 GS_PENDING_TWO_FINGER_TAP_NO_PINCH, |
| 27 GS_PENDING_PINCH, | 28 GS_PENDING_PINCH, |
| 28 GS_PENDING_PINCH_NO_PINCH, | 29 GS_PENDING_PINCH_NO_PINCH, |
| 29 }; | 30 }; |
| 30 | 31 |
| 31 enum ScrollType { | 32 enum ScrollType { |
| 32 ST_FREE, | 33 ST_FREE, |
| 33 ST_HORIZONTAL, | 34 ST_HORIZONTAL, |
| 34 ST_VERTICAL, | 35 ST_VERTICAL, |
| 35 }; | 36 }; |
| 36 | 37 |
| 37 // Delegates dispatch of gesture events for which the GestureSequence does not | |
| 38 // have enough context to dispatch itself. | |
| 39 class EVENTS_EXPORT GestureSequenceDelegate { | |
| 40 public: | |
| 41 virtual void DispatchPostponedGestureEvent(GestureEvent* event) = 0; | |
| 42 | |
| 43 protected: | |
| 44 virtual ~GestureSequenceDelegate() {} | |
| 45 }; | |
| 46 | |
| 47 // A GestureSequence recognizes gestures from touch sequences. | 38 // A GestureSequence recognizes gestures from touch sequences. |
| 48 class EVENTS_EXPORT GestureSequence { | 39 class EVENTS_EXPORT GestureSequence { |
| 49 public: | 40 public: |
| 50 // Maximum number of points in a single gesture. | 41 // Maximum number of points in a single gesture. |
| 51 static const int kMaxGesturePoints = 12; | 42 static const int kMaxGesturePoints = 12; |
| 52 | 43 |
| 53 explicit GestureSequence(GestureSequenceDelegate* delegate); | 44 explicit GestureSequence(GestureEventQueueTimerInterface* geq_timers); |
| 54 virtual ~GestureSequence(); | 45 virtual ~GestureSequence(); |
| 55 | 46 |
| 56 typedef GestureRecognizer::Gestures Gestures; | 47 typedef GestureRecognizer::Gestures Gestures; |
| 57 | 48 |
| 58 // Invoked for each touch event that could contribute to the current gesture. | 49 // Invoked for each touch event that could contribute to the current gesture. |
| 59 // Returns list of zero or more GestureEvents identified after processing | 50 // Returns list of zero or more GestureEvents identified after processing |
| 60 // TouchEvent. | 51 // TouchEvent. |
| 61 // Caller would be responsible for freeing up Gestures. | 52 // Caller would be responsible for freeing up Gestures. |
| 62 virtual Gestures* ProcessTouchEventForGesture(const TouchEvent& event, | 53 virtual Gestures* ProcessTouchEventForGesture(const TouchEvent& event); |
| 63 EventResult status); | |
| 64 const GesturePoint* points() const { return points_; } | 54 const GesturePoint* points() const { return points_; } |
| 65 int point_count() const { return point_count_; } | 55 int point_count() const { return point_count_; } |
| 66 | 56 |
| 67 const gfx::Point& last_touch_location() const { return last_touch_location_; } | 57 const gfx::Point& last_touch_location() const { return last_touch_location_; } |
| 68 | 58 |
| 69 protected: | 59 protected: |
| 70 virtual base::OneShotTimer<GestureSequence>* CreateTimer(); | 60 virtual base::OneShotTimer<GestureEventQueueTimerInterface>* CreateTimer(); |
| 71 base::OneShotTimer<GestureSequence>* GetLongPressTimer(); | 61 base::OneShotTimer<GestureEventQueueTimerInterface>* GetLongPressTimer(); |
| 72 base::OneShotTimer<GestureSequence>* GetShowPressTimer(); | 62 base::OneShotTimer<GestureEventQueueTimerInterface>* GetShowPressTimer(); |
| 73 | 63 |
| 74 private: | 64 private: |
| 75 // Recreates the axis-aligned bounding box that contains all the touch-points | 65 // Recreates the axis-aligned bounding box that contains all the touch-points |
| 76 // at their most recent position. | 66 // at their most recent position. |
| 77 void RecreateBoundingBox(); | 67 void RecreateBoundingBox(); |
| 78 | 68 |
| 79 void ResetVelocities(); | 69 void ResetVelocities(); |
| 80 | 70 |
| 81 GesturePoint& GesturePointForEvent(const TouchEvent& event); | 71 GesturePoint& GesturePointForEvent(const TouchEvent& event); |
| 82 | 72 |
| (...skipping 18 matching lines...) Expand all Loading... |
| 101 void AppendTapDownGestureEvent(const GesturePoint& point, Gestures* gestures); | 91 void AppendTapDownGestureEvent(const GesturePoint& point, Gestures* gestures); |
| 102 void PrependTapCancelGestureEvent(const GesturePoint& point, | 92 void PrependTapCancelGestureEvent(const GesturePoint& point, |
| 103 Gestures* gestures); | 93 Gestures* gestures); |
| 104 void AppendBeginGestureEvent(const GesturePoint& point, Gestures* gestures); | 94 void AppendBeginGestureEvent(const GesturePoint& point, Gestures* gestures); |
| 105 void AppendEndGestureEvent(const GesturePoint& point, Gestures* gestures); | 95 void AppendEndGestureEvent(const GesturePoint& point, Gestures* gestures); |
| 106 void AppendClickGestureEvent(const GesturePoint& point, | 96 void AppendClickGestureEvent(const GesturePoint& point, |
| 107 int tap_count, | 97 int tap_count, |
| 108 Gestures* gestures); | 98 Gestures* gestures); |
| 109 void AppendDoubleClickGestureEvent(const GesturePoint& point, | 99 void AppendDoubleClickGestureEvent(const GesturePoint& point, |
| 110 Gestures* gestures); | 100 Gestures* gestures); |
| 111 void AppendLongPressGestureEvent(); | 101 void AppendLongPressGestureEvent(const GesturePoint& point, |
| 112 void AppendShowPressGestureEvent(); | 102 Gestures* gestures); |
| 103 void AppendShowPressGestureEvent(const GesturePoint& point, |
| 104 Gestures* gestures); |
| 113 void AppendLongTapGestureEvent(const GesturePoint& point, | 105 void AppendLongTapGestureEvent(const GesturePoint& point, |
| 114 Gestures* gestures); | 106 Gestures* gestures); |
| 115 | 107 |
| 116 // Scroll gestures. | 108 // Scroll gestures. |
| 117 void AppendScrollGestureBegin(const GesturePoint& point, | 109 void AppendScrollGestureBegin(const GesturePoint& point, |
| 118 const gfx::Point& location, | 110 const gfx::Point& location, |
| 119 Gestures* gestures); | 111 Gestures* gestures); |
| 120 void AppendScrollGestureEnd(const GesturePoint& point, | 112 void AppendScrollGestureEnd(const GesturePoint& point, |
| 121 const gfx::Point& location, | 113 const gfx::Point& location, |
| 122 Gestures* gestures, | 114 Gestures* gestures, |
| (...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 219 float pinch_distance_start_; | 211 float pinch_distance_start_; |
| 220 | 212 |
| 221 // This distance is updated after each PINCH_UPDATE. | 213 // This distance is updated after each PINCH_UPDATE. |
| 222 float pinch_distance_current_; | 214 float pinch_distance_current_; |
| 223 | 215 |
| 224 // This is the time when second touch down was received. Used for determining | 216 // This is the time when second touch down was received. Used for determining |
| 225 // if a two finger double tap has happened. | 217 // if a two finger double tap has happened. |
| 226 base::TimeDelta second_touch_time_; | 218 base::TimeDelta second_touch_time_; |
| 227 | 219 |
| 228 ScrollType scroll_type_; | 220 ScrollType scroll_type_; |
| 229 scoped_ptr<base::OneShotTimer<GestureSequence> > long_press_timer_; | 221 scoped_ptr<base::OneShotTimer<GestureEventQueueTimerInterface> > |
| 230 scoped_ptr<base::OneShotTimer<GestureSequence> > show_press_timer_; | 222 long_press_timer_; |
| 223 scoped_ptr<base::OneShotTimer<GestureEventQueueTimerInterface> > |
| 224 show_press_timer_; |
| 231 | 225 |
| 232 GesturePoint points_[kMaxGesturePoints]; | 226 GesturePoint points_[kMaxGesturePoints]; |
| 233 int point_count_; | 227 int point_count_; |
| 234 | 228 |
| 235 // Location of the last touch event. | 229 // Location of the last touch event. |
| 236 gfx::Point last_touch_location_; | 230 gfx::Point last_touch_location_; |
| 237 | 231 |
| 238 GestureSequenceDelegate* delegate_; | 232 GestureEventQueueTimerInterface* geq_timers_; |
| 239 | 233 |
| 240 DISALLOW_COPY_AND_ASSIGN(GestureSequence); | 234 DISALLOW_COPY_AND_ASSIGN(GestureSequence); |
| 241 }; | 235 }; |
| 242 | 236 |
| 243 } // namespace ui | 237 } // namespace ui |
| 244 | 238 |
| 245 #endif // UI_EVENTS_GESTURES_GESTURE_SEQUENCE_H_ | 239 #endif // UI_EVENTS_GESTURES_GESTURE_SEQUENCE_H_ |
| OLD | NEW |