OLD | NEW |
(Empty) | |
| 1 // Copyright 2013 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_GESTURES_GESTURE_EVENT_QUEUE_H_ |
| 6 #define UI_EVENTS_GESTURES_GESTURE_EVENT_QUEUE_H_ |
| 7 |
| 8 #include <list> |
| 9 #include <set> |
| 10 |
| 11 #include "base/basictypes.h" |
| 12 #include "base/memory/scoped_ptr.h" |
| 13 #include "base/memory/scoped_vector.h" |
| 14 #include "ui/events/event.h" |
| 15 #include "ui/events/gestures/touch_point_state.h" |
| 16 |
| 17 namespace ui { |
| 18 class TouchEvent; |
| 19 |
| 20 class GestureEventQueueDelegate { |
| 21 public: |
| 22 virtual ~GestureEventQueueDelegate() {}; |
| 23 virtual void DispatchGestureEvent(GestureEvent* event) = 0; |
| 24 }; |
| 25 |
| 26 class GestureEventQueueTimerInterface { |
| 27 public: |
| 28 virtual void TimerFired() = 0; |
| 29 virtual void TimerCancelled() = 0; |
| 30 }; |
| 31 |
| 32 // A GestureEventQueue consumes a stream of gestures, and a stream of touch |
| 33 // acks. It sends the |GestureEventQueueDelegate| a filtered stream of gestures, |
| 34 // with some gestures removed due to touches having been consumed. |
| 35 class EVENTS_EXPORT GestureEventQueue : public GestureEventQueueTimerInterface { |
| 36 public: |
| 37 GestureEventQueue(GestureEventQueueDelegate* geqd); |
| 38 virtual ~GestureEventQueue(); |
| 39 |
| 40 void OnTouchEvent(const TouchEvent& event); |
| 41 |
| 42 void OnTouchEventAck(const TouchEvent& event, |
| 43 EventResult result); |
| 44 |
| 45 // Takes ownership of event. |
| 46 void QueueGestureEvent(GestureEvent* event, |
| 47 TouchPointState::RequiresAck requires_ack); |
| 48 |
| 49 virtual void TimerFired() OVERRIDE; |
| 50 virtual void TimerCancelled() OVERRIDE; |
| 51 |
| 52 protected: |
| 53 void QueueGestureEvent( |
| 54 GestureEvent* event, |
| 55 std::vector<TouchPointState*>& touch_point_states); |
| 56 |
| 57 class GestureWithState { |
| 58 public: |
| 59 // Clears touch_point_states, and takes ownership of its members. |
| 60 GestureWithState(GestureEvent* event, |
| 61 std::vector<TouchPointState*>& touch_point_states); |
| 62 ~GestureWithState(); |
| 63 GestureEvent* event() { return event_.get(); } |
| 64 std::vector<TouchPointState*>& touch_point_states() { |
| 65 return touch_point_states_.get(); |
| 66 } |
| 67 |
| 68 private: |
| 69 scoped_ptr<GestureEvent> event_; |
| 70 ScopedVector<TouchPointState> touch_point_states_; |
| 71 DISALLOW_COPY_AND_ASSIGN(GestureWithState); |
| 72 }; |
| 73 |
| 74 typedef ScopedVector<GestureWithState> Sequence; |
| 75 // sequences_ owns all of the TouchPointState objects keeping tracking of |
| 76 // which acks a given event depends on. |
| 77 std::list<Sequence*> sequences_; |
| 78 |
| 79 private: |
| 80 void SendGestureEvent(GestureEvent* event); |
| 81 |
| 82 // Returns true if we've seen unconsumed acks in the current sequence for |
| 83 // every touch contributing to |gesture_touches|. |
| 84 bool CanSend(const std::vector<TouchPointState*>& gesture_touches) const; |
| 85 |
| 86 // Returns true if we've seen consumed acks in the current sequence for any |
| 87 // touch contributing to |gesture_touches|. |
| 88 bool CanDelete(const std::vector<TouchPointState*>& gesture_touches) const; |
| 89 |
| 90 void SendAckedEvents(); |
| 91 void DeleteConsumedEvents(); |
| 92 void RemoveEmptyFirstSequence(); |
| 93 |
| 94 ScopedVector<TouchPointState> touch_point_states_; |
| 95 ScopedVector<TouchPointState> acked_touch_point_states_; |
| 96 ScopedVector<TouchPointState> consumed_touch_point_states_; |
| 97 GestureEventQueueDelegate* gesture_event_queue_delegate_; |
| 98 |
| 99 DISALLOW_COPY_AND_ASSIGN(GestureEventQueue); |
| 100 }; |
| 101 |
| 102 } // namespace ui |
| 103 |
| 104 #endif // UI_EVENTS_GESTURES_GESTURE_EVENT_QUEUE_H_ |
OLD | NEW |