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

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

Issue 19220002: [WIP] BufferedInputRouter (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Fix client assignment 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 // Certain unhandled input event acks may create follow-up events, e.g.,
47 // TouchEvent -> GestureEvent. If these follow-up events are sent to the
48 // router synchronously from the original event's |OnDispatched()| ack, they
49 // will be inserted into the current input flush stream.
50 virtual void SendMouseEvent(
51 const MouseEventWithLatencyInfo& mouse_event) OVERRIDE;
52 virtual void SendWheelEvent(
53 const MouseWheelEventWithLatencyInfo& wheel_event) OVERRIDE;
54 virtual void SendKeyboardEvent(const NativeWebKeyboardEvent& key_event,
55 const ui::LatencyInfo& latency_info) OVERRIDE;
56 virtual void SendGestureEvent(
57 const GestureEventWithLatencyInfo& gesture_event) OVERRIDE;
58 virtual void SendTouchEvent(
59 const TouchEventWithLatencyInfo& touch_event) OVERRIDE;
60 virtual void SendMouseEventImmediately(
61 const MouseEventWithLatencyInfo& mouse_event) OVERRIDE;
62 virtual void SendTouchEventImmediately(
63 const TouchEventWithLatencyInfo& touch_event) OVERRIDE;
64 virtual void SendGestureEventImmediately(
65 const GestureEventWithLatencyInfo& gesture_event) OVERRIDE;
66 virtual const NativeWebKeyboardEvent* GetLastKeyboardEvent() const OVERRIDE;
67 virtual bool ShouldForwardTouchEvent() const OVERRIDE;
68 virtual bool ShouldForwardGestureEvent(
69 const GestureEventWithLatencyInfo& gesture_event) const OVERRIDE;
70 virtual bool HasQueuedGestureEvents() const OVERRIDE;
71
72 // InputQueueClient
73 virtual void Deliver(const EventPacket& packet) OVERRIDE;
74 virtual void DidFinishFlush() OVERRIDE;
75 virtual void SetNeedsFlush() OVERRIDE;
76
77 // BrowserInputEventClient
78 virtual void OnDispatched(const BrowserInputEvent& event,
79 InputEventDisposition disposition) OVERRIDE;
80 // Events delivered to the router within the scope of
81 // |OnDispatched()| will be added to |followup|.
82 virtual void OnDispatched(const BrowserInputEvent& event,
83 InputEventDisposition disposition,
84 ScopedVector<BrowserInputEvent>* followup) OVERRIDE;
85
86 // IPC::Receiver
87 virtual bool OnMessageReceived(const IPC::Message& message) OVERRIDE;
88
89 protected:
90 void OnWebInputEventAck(int64 event_id,
91 const WebKit::WebInputEvent& web_event,
92 const ui::LatencyInfo& latency_info,
93 InputEventAckState acked_result,
94 bool ack_from_input_queue);
95 void OnEventPacketAck(int64 packet_id,
96 const InputEventDispositions& dispositions);
97 void OnHasTouchEventHandlers(bool has_handlers);
98
99 // Returns the non-zero ID associated with the |InputEvent| added to the
100 // |input_queue_|. If the event was dropped or filtered, returns 0.
101 int64 QueueWebEvent(const WebKit::WebInputEvent& web_event,
102 const ui::LatencyInfo& latency_info,
103 bool is_key_shortcut);
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