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

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: Refactoring Created 7 years, 3 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/memory/scoped_vector.h"
13 #include "content/browser/renderer_host/input/browser_input_event.h"
14 #include "content/browser/renderer_host/input/input_queue.h"
15 #include "content/browser/renderer_host/input/input_queue_client.h"
16 #include "content/browser/renderer_host/input/input_router.h"
17
18 namespace IPC {
19 class Sender;
20 }
21
22 namespace content {
23
24 class InputAckHandler;
25 class RenderProcessHost;
26 class RenderWidgetHostImpl;
27
28 // Batches input events into EventPackets using a general input queue. Packets
29 // are sent the renderer on |Flush()|, called in response to flush requests.
30 class CONTENT_EXPORT BufferedInputRouter
31 : public NON_EXPORTED_BASE(BrowserInputEventClient),
32 public NON_EXPORTED_BASE(InputQueueClient),
33 public NON_EXPORTED_BASE(InputRouter) {
34 public:
35 // |sender|, |client| and |ack_handler| must outlive the BufferedInputRouter.
36 BufferedInputRouter(IPC::Sender* sender,
37 InputRouterClient* client,
38 InputAckHandler* ack_handler,
39 int routing_id);
40 virtual ~BufferedInputRouter();
41
42 // InputRouter
43 virtual void Flush() OVERRIDE;
44 virtual bool SendInput(scoped_ptr<IPC::Message> message) OVERRIDE;
45
46 // WebInputEvent's sent to the router synchronously after an ack dispatch to
aelias_OOO_until_Jul13 2013/09/09 22:31:14 Please update this comment to be clearer about exa
jdduke (slow) 2013/09/10 19:41:16 Done.
47 // |ack_handler_| will be inserted into InputQueue's flush stream.
48 virtual void SendMouseEvent(
49 const MouseEventWithLatencyInfo& mouse_event) OVERRIDE;
50 virtual void SendWheelEvent(
51 const MouseWheelEventWithLatencyInfo& wheel_event) OVERRIDE;
52 virtual void SendKeyboardEvent(
53 const NativeWebKeyboardEvent& key_event,
54 const ui::LatencyInfo& latency_info) OVERRIDE;
55 virtual void SendGestureEvent(
56 const GestureEventWithLatencyInfo& gesture_event) OVERRIDE;
57 virtual void SendTouchEvent(
58 const TouchEventWithLatencyInfo& touch_event) OVERRIDE;
59 virtual void SendMouseEventImmediately(
60 const MouseEventWithLatencyInfo& mouse_event) OVERRIDE;
61 virtual void SendTouchEventImmediately(
62 const TouchEventWithLatencyInfo& touch_event) OVERRIDE;
63 virtual void SendGestureEventImmediately(
64 const GestureEventWithLatencyInfo& gesture_event) OVERRIDE;
65 virtual const NativeWebKeyboardEvent* GetLastKeyboardEvent() const OVERRIDE;
66 virtual bool ShouldForwardTouchEvent() const OVERRIDE;
67 virtual bool ShouldForwardGestureEvent(
68 const GestureEventWithLatencyInfo& gesture_event) const OVERRIDE;
69 virtual bool HasQueuedGestureEvents() const OVERRIDE;
70
71 // InputQueueClient
72 virtual void Deliver(const EventPacket& packet) OVERRIDE;
73 virtual void DidFinishFlush() OVERRIDE;
74 virtual void SetNeedsFlush() OVERRIDE;
75
76 // BrowserInputEventClient
77 virtual void OnDispatched(const BrowserInputEvent& event,
78 InputEventDisposition disposition) OVERRIDE;
79 // Events delivered to the router within the scope of
80 // |OnDispatched()| will be added to |followup|.
81 virtual void OnDispatched(const BrowserInputEvent& event,
82 InputEventDisposition disposition,
83 ScopedVector<BrowserInputEvent>* followup) OVERRIDE;
84
85 // IPC::Receiver
86 virtual bool OnMessageReceived(const IPC::Message& message) OVERRIDE;
87
88 protected:
89 void OnWebInputEventAck(int64 event_id,
90 const WebKit::WebInputEvent& web_event,
91 const ui::LatencyInfo& latency_info,
92 InputEventAckState acked_result,
93 bool ack_from_input_queue);
94 void OnEventPacketAck(int64 packet_id,
95 const InputEventDispositions& dispositions);
96 void OnHasTouchEventHandlers(bool has_handlers);
97
98 // Returns the non-zero ID associated with the |InputEvent| added to the
99 // |input_queue_|. If the event was dropped or filtered, returns 0.
100 int64 QueueWebEvent(const WebKit::WebInputEvent& web_event,
101 const ui::LatencyInfo& latency_info,
102 bool is_key_shortcut,
103 bool creates_followup_events);
104 // Used by |QueueWebEvent()|; returns true if an event was filtered and should
105 // not be added to the |input_queue_|.
106 bool FilterWebEvent(const WebKit::WebInputEvent& web_event,
107 const ui::LatencyInfo& latency_info);
108
109 // Generates a monotonically increasing sequences of id's, starting with 1.
110 int64 NextInputID();
111
112 const InputQueue* input_queue() const { return input_queue_.get(); }
113
114 private:
115 InputRouterClient* client_;
116 InputAckHandler* ack_handler_;
117 IPC::Sender* sender_;
118 int routing_id_;
119
120 scoped_ptr<InputQueue> input_queue_;
121
122 // TODO(jdduke): Remove when we can properly serialize NativeWebKeyboardEvent.
123 // Alternatively, attach WebInputEvents to InputEvents but don't serialize.
124 typedef std::map<int64, NativeWebKeyboardEvent> KeyMap;
125 KeyMap queued_key_map_;
126
127 // Necessary for |HasQueuedGestureEvents()|.
128 int queued_gesture_count_;
129
130 // Necessary for |ShouldForwardTouchEvent()|.
131 bool has_touch_handler_;
132 int queued_touch_count_;
133
134 // This is non-NULL ONLY in the scope of OnInputEventAck(event, injector).
135 ScopedVector<BrowserInputEvent>* input_queue_override_;
136
137 // Used to assign unique ID's to each InputEvent that is generated.
138 int64 next_input_id_;
139
140 // 0 if there no in-flight EventPacket.
141 int64 in_flight_packet_id_;
142
143 DISALLOW_COPY_AND_ASSIGN(BufferedInputRouter);
144 };
145
146 } // namespace content
147
148 #endif // CONTENT_BROWSER_INPUT_RENDERER_HOST_BUFFERED_INPUT_ROUTER_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698