| OLD | NEW |
| (Empty) |
| 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 | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 #ifndef CONTENT_BROWSER_RENDERER_HOST_TOUCH_EVENT_QUEUE_H_ | |
| 6 #define CONTENT_BROWSER_RENDERER_HOST_TOUCH_EVENT_QUEUE_H_ | |
| 7 | |
| 8 #include <deque> | |
| 9 #include <map> | |
| 10 | |
| 11 #include "base/basictypes.h" | |
| 12 #include "content/common/content_export.h" | |
| 13 #include "content/port/browser/event_with_latency_info.h" | |
| 14 #include "content/port/common/input_event_ack_state.h" | |
| 15 #include "third_party/WebKit/public/web/WebInputEvent.h" | |
| 16 | |
| 17 namespace content { | |
| 18 | |
| 19 class CoalescedWebTouchEvent; | |
| 20 | |
| 21 // Interface with which TouchEventQueue can forward touch events, and dispatch | |
| 22 // touch event responses. | |
| 23 class TouchEventQueueClient { | |
| 24 public: | |
| 25 virtual ~TouchEventQueueClient() {} | |
| 26 | |
| 27 virtual void SendTouchEventImmediately( | |
| 28 const TouchEventWithLatencyInfo& event) = 0; | |
| 29 | |
| 30 virtual void OnTouchEventAck( | |
| 31 const TouchEventWithLatencyInfo& event, | |
| 32 InputEventAckState ack_result) = 0; | |
| 33 }; | |
| 34 | |
| 35 // A queue for throttling and coalescing touch-events. | |
| 36 class TouchEventQueue { | |
| 37 public: | |
| 38 | |
| 39 // The |client| must outlive the TouchEventQueue. | |
| 40 explicit TouchEventQueue(TouchEventQueueClient* client); | |
| 41 virtual ~TouchEventQueue(); | |
| 42 | |
| 43 // Adds an event to the queue. The event may be coalesced with previously | |
| 44 // queued events (e.g. consecutive touch-move events can be coalesced into a | |
| 45 // single touch-move event). The event may also be immediately forwarded to | |
| 46 // the renderer (e.g. when there are no other queued touch event). | |
| 47 void QueueEvent(const TouchEventWithLatencyInfo& event); | |
| 48 | |
| 49 // Notifies the queue that a touch-event has been processed by the renderer. | |
| 50 // At this point, the queue may send one or more gesture events and/or | |
| 51 // additional queued touch-events to the renderer. | |
| 52 void ProcessTouchAck(InputEventAckState ack_result); | |
| 53 | |
| 54 // Empties the queue of touch events. This may result in any number of gesture | |
| 55 // events being sent to the renderer. | |
| 56 void FlushQueue(); | |
| 57 | |
| 58 // Returns whether the event-queue is empty. | |
| 59 bool empty() const WARN_UNUSED_RESULT { | |
| 60 return touch_queue_.empty(); | |
| 61 } | |
| 62 | |
| 63 private: | |
| 64 friend class MockRenderWidgetHost; | |
| 65 | |
| 66 CONTENT_EXPORT size_t GetQueueSize() const; | |
| 67 CONTENT_EXPORT const TouchEventWithLatencyInfo& GetLatestEvent() const; | |
| 68 | |
| 69 // Pops the touch-event from the top of the queue and sends it to the | |
| 70 // TouchEventQueueClient. This reduces the size of the queue by one. | |
| 71 void PopTouchEventWithAck(InputEventAckState ack_result); | |
| 72 | |
| 73 bool ShouldForwardToRenderer(const WebKit::WebTouchEvent& event) const; | |
| 74 | |
| 75 // Handles touch event forwarding and ack'ed event dispatch. | |
| 76 TouchEventQueueClient* client_; | |
| 77 | |
| 78 typedef std::deque<CoalescedWebTouchEvent*> TouchQueue; | |
| 79 TouchQueue touch_queue_; | |
| 80 | |
| 81 // Maintain the ACK status for each touch point. | |
| 82 typedef std::map<int, InputEventAckState> TouchPointAckStates; | |
| 83 TouchPointAckStates touch_ack_states_; | |
| 84 | |
| 85 // Used to defer touch forwarding when ack dispatch triggers |QueueEvent()|. | |
| 86 bool dispatching_touch_ack_; | |
| 87 | |
| 88 DISALLOW_COPY_AND_ASSIGN(TouchEventQueue); | |
| 89 }; | |
| 90 | |
| 91 } // namespace content | |
| 92 | |
| 93 #endif // CONTENT_BROWSER_RENDERER_HOST_TOUCH_EVENT_QUEUE_H_ | |
| OLD | NEW |