Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(122)

Side by Side Diff: content/browser/renderer_host/input/buffered_input_router.h

Issue 20356003: Provided batched input delivery with a BufferedInputRouter (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: BufferedInputRouter unit tests Created 7 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
(Empty)
1 // Copyright (c) 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 CONTENT_BROWSER_INPUT_RENDERER_HOST_BUFFERED_INPUT_ROUTER_H_
6 #define CONTENT_BROWSER_INPUT_RENDERER_HOST_BUFFERED_INPUT_ROUTER_H_
7
8 #include <map>
9
10 #include "base/basictypes.h"
11 #include "base/memory/scoped_ptr.h"
12 #include "base/time/time.h"
13 #include "base/timer/timer.h"
14 #include "content/browser/renderer_host/input/event_ack_handler.h"
15 #include "content/browser/renderer_host/input/input_queue.h"
16 #include "content/browser/renderer_host/input/input_queue_client.h"
17 #include "content/browser/renderer_host/input/input_router.h"
18
19 namespace content {
20
21 class RenderProcessHost;
22 class RenderWidgetHostImpl;
23
24 // Batches input events into EventPackets using a general input queue. Packets
25 // are sent the renderer on |Flush()|, called in response to flush requests.
26 class CONTENT_EXPORT BufferedInputRouter
27 : public NON_EXPORTED_BASE(InputQueueClient),
28 public NON_EXPORTED_BASE(InputRouter),
29 public NON_EXPORTED_BASE(EventAckHandler) {
30 public:
31 BufferedInputRouter(RenderProcessHost* process,
32 InputRouterClient* client,
33 int routing_id);
34 virtual ~BufferedInputRouter();
35
36 // InputRouter
37 virtual void Flush() OVERRIDE;
38 virtual bool SendInput(IPC::Message* message) OVERRIDE;
39 virtual void SendMouseEvent(
40 const MouseEventWithLatencyInfo& mouse_event) OVERRIDE;
41 virtual void SendWheelEvent(
42 const MouseWheelEventWithLatencyInfo& wheel_event) OVERRIDE;
43 virtual void SendKeyboardEvent(
44 const NativeWebKeyboardEvent& key_event,
45 const ui::LatencyInfo& latency_info) OVERRIDE;
46 virtual void SendGestureEvent(
47 const GestureEventWithLatencyInfo& gesture_event) OVERRIDE;
48 virtual void SendTouchEvent(
49 const TouchEventWithLatencyInfo& touch_event) OVERRIDE;
50 virtual void SendMouseEventImmediately(
51 const MouseEventWithLatencyInfo& mouse_event) OVERRIDE;
52 virtual void SendTouchEventImmediately(
53 const TouchEventWithLatencyInfo& touch_event) OVERRIDE;
54 virtual void SendGestureEventImmediately(
55 const GestureEventWithLatencyInfo& gesture_event) OVERRIDE;
56 virtual const NativeWebKeyboardEvent* GetLastKeyboardEvent() const OVERRIDE;
57 virtual bool ShouldForwardTouchEvent() const OVERRIDE;
58 virtual bool ShouldForwardGestureEvent(
59 const GestureEventWithLatencyInfo& gesture_event) const OVERRIDE;
60 virtual bool HasQueuedGestureEvents() const OVERRIDE;
61
62 void set_delayed_packet_timeout_ms(const base::TimeDelta& timeout) {
63 delayed_packet_timeout_ms_ = timeout.InMilliseconds();
64 }
65
66 private:
67 friend class BufferedInputRouterTest;
aelias_OOO_until_Jul13 2013/08/13 06:11:51 friending can normally be avoided by marking thing
68
69 // InputQueueClient
70 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.
71 virtual void DidFlush() OVERRIDE;
72 virtual void SetNeedsFlush() OVERRIDE;
73
74 // EventAckHandler
75 virtual void OnInputEventAck(const InputEvent& acked_event) OVERRIDE;
76 virtual void OnInputEventAck(const InputEvent& acked_event,
77 EventInjector* injector) OVERRIDE;
78
79 // IPC::Receiver
80 virtual bool OnMessageReceived(const IPC::Message& message) OVERRIDE;
81
82 void OnInputEventAck(int64 event_id,
83 const WebKit::WebInputEvent& web_event,
84 const ui::LatencyInfo& latency_info,
85 InputEventAckState acked_result,
86 bool ack_from_input_queue);
87 void OnEventPacketAck(const EventPacket& acked_packet);
88 void OnHasTouchEventHandlers(bool has_handlers);
89
90 // Returns the non-zero ID associated with the |InputEvent| added to the
91 // |input_queue_|. If the event was dropped or filtered, returns 0.
92 int64 QueueWebEvent(const WebKit::WebInputEvent& web_event,
93 const ui::LatencyInfo& latency_info,
94 bool is_keyboard_shortcut,
95 bool has_followup);
96 // Used by |QueueWebEvent()|; returns true if an event was filtered and should
97 // not be added to the |input_queue_|.
98 bool FilterWebEvent(const WebKit::WebInputEvent& web_event,
99 const ui::LatencyInfo& latency_info);
100
101 void StartDelayedPacketMonitorTimeout(base::TimeDelta delay);
102 void StopDelayedPacketMonitorTimeout();
103 void CheckShouldSignalDelayedPacket();
104
105 // Generates a monotonically increasing sequences of id's, starting with 1.
106 int64 NewInputID();
aelias_OOO_until_Jul13 2013/08/13 06:11:51 Call this NextInputID()
jdduke (slow) 2013/08/13 15:29:48 Done.
107
108 InputRouterClient* client_;
109 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.
110 int routing_id_;
111
112 scoped_ptr<InputQueue> input_queue_;
113
114 // TODO(jdduke): Remove when we can properly serialize NativeWebKeyboardEvent.
115 // Alternatively, attach WebInputEvents to InputEvents but don't serialize.
116 typedef std::map<int64, NativeWebKeyboardEvent> KeyMap;
117 KeyMap queued_key_map_;
118
119 // Necessary for |HasQueuedGestureEvents()|.
120 int queued_gesture_count_;
121
122 // Necessary for |ShouldForwardTouchEvent()|.
123 bool has_touch_handler_;
124 int queued_touch_count_;
125
126 // This is non-NULL ONLY in the scope of OnInputEventAck(event, injector).
127 EventAckHandler::EventInjector* input_queue_override_;
128
129 // Used to assign unique ID's to each InputEvent that is generated.
130 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.
131
132 // 0 if there no in-flight EventPacket.
133 int64 in_flight_packet_id_;
134
135 // How long to wait before an in-flight event packet should be dropped.
136 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.
137
138 // Time in the future when we should drop the in-flight event packet.
139 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.
140
141 // Check if time_when_signal_delayed_packet_ has past.
142 base::OneShotTimer<BufferedInputRouter> delayed_packet_timer_;
143
144 DISALLOW_COPY_AND_ASSIGN(BufferedInputRouter);
145 };
146
147 } // namespace content
148
149 #endif // CONTENT_BROWSER_INPUT_RENDERER_HOST_BUFFERED_INPUT_ROUTER_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698