Chromium Code Reviews| Index: content/browser/renderer_host/input/buffered_input_router.h |
| diff --git a/content/browser/renderer_host/input/buffered_input_router.h b/content/browser/renderer_host/input/buffered_input_router.h |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..2c63de2505bd99cd598d8897bd5302f1ce486f82 |
| --- /dev/null |
| +++ b/content/browser/renderer_host/input/buffered_input_router.h |
| @@ -0,0 +1,149 @@ |
| +// Copyright (c) 2013 The Chromium Authors. All rights reserved. |
| +// Use of this source code is governed by a BSD-style license that can be |
| +// found in the LICENSE file. |
| + |
| +#ifndef CONTENT_BROWSER_INPUT_RENDERER_HOST_BUFFERED_INPUT_ROUTER_H_ |
| +#define CONTENT_BROWSER_INPUT_RENDERER_HOST_BUFFERED_INPUT_ROUTER_H_ |
| + |
| +#include <map> |
| + |
| +#include "base/basictypes.h" |
| +#include "base/memory/scoped_ptr.h" |
| +#include "base/time/time.h" |
| +#include "base/timer/timer.h" |
| +#include "content/browser/renderer_host/input/event_ack_handler.h" |
| +#include "content/browser/renderer_host/input/input_queue.h" |
| +#include "content/browser/renderer_host/input/input_queue_client.h" |
| +#include "content/browser/renderer_host/input/input_router.h" |
| + |
| +namespace content { |
| + |
| +class RenderProcessHost; |
| +class RenderWidgetHostImpl; |
| + |
| +// Batches input events into EventPackets using a general input queue. Packets |
| +// are sent the renderer on |Flush()|, called in response to flush requests. |
| +class CONTENT_EXPORT BufferedInputRouter |
| + : public NON_EXPORTED_BASE(InputQueueClient), |
| + public NON_EXPORTED_BASE(InputRouter), |
| + public NON_EXPORTED_BASE(EventAckHandler) { |
| + public: |
| + BufferedInputRouter(RenderProcessHost* process, |
| + InputRouterClient* client, |
| + int routing_id); |
| + virtual ~BufferedInputRouter(); |
| + |
| + // InputRouter |
| + virtual void Flush() OVERRIDE; |
| + virtual bool SendInput(IPC::Message* message) OVERRIDE; |
| + virtual void SendMouseEvent( |
| + const MouseEventWithLatencyInfo& mouse_event) OVERRIDE; |
| + virtual void SendWheelEvent( |
| + const MouseWheelEventWithLatencyInfo& wheel_event) OVERRIDE; |
| + virtual void SendKeyboardEvent( |
| + const NativeWebKeyboardEvent& key_event, |
| + const ui::LatencyInfo& latency_info) OVERRIDE; |
| + virtual void SendGestureEvent( |
| + const GestureEventWithLatencyInfo& gesture_event) OVERRIDE; |
| + virtual void SendTouchEvent( |
| + const TouchEventWithLatencyInfo& touch_event) OVERRIDE; |
| + virtual void SendMouseEventImmediately( |
| + const MouseEventWithLatencyInfo& mouse_event) OVERRIDE; |
| + virtual void SendTouchEventImmediately( |
| + const TouchEventWithLatencyInfo& touch_event) OVERRIDE; |
| + virtual void SendGestureEventImmediately( |
| + const GestureEventWithLatencyInfo& gesture_event) OVERRIDE; |
| + virtual const NativeWebKeyboardEvent* GetLastKeyboardEvent() const OVERRIDE; |
| + virtual bool ShouldForwardTouchEvent() const OVERRIDE; |
| + virtual bool ShouldForwardGestureEvent( |
| + const GestureEventWithLatencyInfo& gesture_event) const OVERRIDE; |
| + virtual bool HasQueuedGestureEvents() const OVERRIDE; |
| + |
| + void set_delayed_packet_timeout_ms(const base::TimeDelta& timeout) { |
| + delayed_packet_timeout_ms_ = timeout.InMilliseconds(); |
| + } |
| + |
| +private: |
| + friend class BufferedInputRouterTest; |
|
aelias_OOO_until_Jul13
2013/08/13 06:11:51
friending can normally be avoided by marking thing
|
| + |
| + // InputQueueClient |
| + virtual void Deliver(const EventPacket& packet) OVERRIDE; |
|
aelias_OOO_until_Jul13
2013/08/13 06:11:51
These are public in the base class so they should
jdduke (slow)
2013/08/13 15:29:48
Done.
|
| + virtual void DidFlush() OVERRIDE; |
| + virtual void SetNeedsFlush() OVERRIDE; |
| + |
| + // EventAckHandler |
| + virtual void OnInputEventAck(const InputEvent& acked_event) OVERRIDE; |
| + virtual void OnInputEventAck(const InputEvent& acked_event, |
| + EventInjector* injector) OVERRIDE; |
| + |
| + // IPC::Receiver |
| + virtual bool OnMessageReceived(const IPC::Message& message) OVERRIDE; |
| + |
| + void OnInputEventAck(int64 event_id, |
| + const WebKit::WebInputEvent& web_event, |
| + const ui::LatencyInfo& latency_info, |
| + InputEventAckState acked_result, |
| + bool ack_from_input_queue); |
| + void OnEventPacketAck(const EventPacket& acked_packet); |
| + void OnHasTouchEventHandlers(bool has_handlers); |
| + |
| + // Returns the non-zero ID associated with the |InputEvent| added to the |
| + // |input_queue_|. If the event was dropped or filtered, returns 0. |
| + int64 QueueWebEvent(const WebKit::WebInputEvent& web_event, |
| + const ui::LatencyInfo& latency_info, |
| + bool is_keyboard_shortcut, |
| + bool has_followup); |
| + // Used by |QueueWebEvent()|; returns true if an event was filtered and should |
| + // not be added to the |input_queue_|. |
| + bool FilterWebEvent(const WebKit::WebInputEvent& web_event, |
| + const ui::LatencyInfo& latency_info); |
| + |
| + void StartDelayedPacketMonitorTimeout(base::TimeDelta delay); |
| + void StopDelayedPacketMonitorTimeout(); |
| + void CheckShouldSignalDelayedPacket(); |
| + |
| + // Generates a monotonically increasing sequences of id's, starting with 1. |
| + int64 NewInputID(); |
|
aelias_OOO_until_Jul13
2013/08/13 06:11:51
Call this NextInputID()
jdduke (slow)
2013/08/13 15:29:48
Done.
|
| + |
| + InputRouterClient* client_; |
| + RenderProcessHost* process_; |
|
aelias_OOO_until_Jul13
2013/08/13 06:11:51
All you ever do with this is send IPCs, so store i
jdduke (slow)
2013/08/13 15:29:48
Done.
|
| + int routing_id_; |
| + |
| + scoped_ptr<InputQueue> input_queue_; |
| + |
| + // TODO(jdduke): Remove when we can properly serialize NativeWebKeyboardEvent. |
| + // Alternatively, attach WebInputEvents to InputEvents but don't serialize. |
| + typedef std::map<int64, NativeWebKeyboardEvent> KeyMap; |
| + KeyMap queued_key_map_; |
| + |
| + // Necessary for |HasQueuedGestureEvents()|. |
| + int queued_gesture_count_; |
| + |
| + // Necessary for |ShouldForwardTouchEvent()|. |
| + bool has_touch_handler_; |
| + int queued_touch_count_; |
| + |
| + // This is non-NULL ONLY in the scope of OnInputEventAck(event, injector). |
| + EventAckHandler::EventInjector* input_queue_override_; |
| + |
| + // Used to assign unique ID's to each InputEvent that is generated. |
| + int64 last_input_id_; |
|
aelias_OOO_until_Jul13
2013/08/13 06:11:51
Common idiom is to call this next_input_id_
jdduke (slow)
2013/08/13 15:29:48
Done.
|
| + |
| + // 0 if there no in-flight EventPacket. |
| + int64 in_flight_packet_id_; |
| + |
| + // How long to wait before an in-flight event packet should be dropped. |
| + int delayed_packet_timeout_ms_; |
|
aelias_OOO_until_Jul13
2013/08/13 06:11:51
Store this as base::TimeDelta as well.
jdduke (slow)
2013/08/13 15:29:48
Done.
|
| + |
| + // Time in the future when we should drop the in-flight event packet. |
| + base::Time time_when_signal_delayed_packet_; |
|
aelias_OOO_until_Jul13
2013/08/13 06:11:51
Use base::TimeTicks instead.
jdduke (slow)
2013/08/13 15:29:48
Done.
|
| + |
| + // Check if time_when_signal_delayed_packet_ has past. |
| + base::OneShotTimer<BufferedInputRouter> delayed_packet_timer_; |
| + |
| + DISALLOW_COPY_AND_ASSIGN(BufferedInputRouter); |
| +}; |
| + |
| +} // namespace content |
| + |
| +#endif // CONTENT_BROWSER_INPUT_RENDERER_HOST_BUFFERED_INPUT_ROUTER_H_ |