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.
5 #ifndef CONTENT_BROWSER_RENDERER_HOST_TOUCH_EVENT_QUEUE_H_
6 #define CONTENT_BROWSER_RENDERER_HOST_TOUCH_EVENT_QUEUE_H_
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"
19 class CoalescedWebTouchEvent
;
20 class MockRenderWidgetHost
;
21 class RenderWidgetHostImpl
;
23 // A queue for throttling and coalescing touch-events.
24 class TouchEventQueue
{
26 explicit TouchEventQueue(RenderWidgetHostImpl
* host
);
27 virtual ~TouchEventQueue();
29 // Adds an event to the queue. The event may be coalesced with previously
30 // queued events (e.g. consecutive touch-move events can be coalesced into a
31 // single touch-move event). The event may also be immediately forwarded to
32 // the renderer (e.g. when there are no other queued touch event).
33 void QueueEvent(const TouchEventWithLatencyInfo
& event
);
35 // Notifies the queue that a touch-event has been processed by the renderer.
36 // At this point, the queue may send one or more gesture events and/or
37 // additional queued touch-events to the renderer.
38 void ProcessTouchAck(InputEventAckState ack_result
);
40 // Empties the queue of touch events. This may result in any number of gesture
41 // events being sent to the renderer.
44 // Resets all internal state. This does not trigger any touch or gesture
48 // Returns whether the event-queue is empty.
49 bool empty() const WARN_UNUSED_RESULT
{
50 return touch_queue_
.empty();
54 friend class MockRenderWidgetHost
;
56 CONTENT_EXPORT
size_t GetQueueSize() const;
57 CONTENT_EXPORT
const TouchEventWithLatencyInfo
& GetLatestEvent() const;
59 // Pops the touch-event from the top of the queue and sends it to the
60 // RenderWidgetHostView. This reduces the size of the queue by one.
61 void PopTouchEventToView(InputEventAckState ack_result
);
63 bool ShouldForwardToRenderer(const WebKit::WebTouchEvent
& event
) const;
65 // The RenderWidgetHost that owns this event-queue.
66 RenderWidgetHostImpl
* render_widget_host_
;
68 typedef std::deque
<CoalescedWebTouchEvent
*> TouchQueue
;
69 TouchQueue touch_queue_
;
71 // Maintain the ACK status for each touch point.
72 typedef std::map
<int, InputEventAckState
> TouchPointAckStates
;
73 TouchPointAckStates touch_ack_states_
;
75 DISALLOW_COPY_AND_ASSIGN(TouchEventQueue
);
78 } // namespace content
80 #endif // CONTENT_BROWSER_RENDERER_HOST_TOUCH_EVENT_QUEUE_H_