Add ICU message format support
[chromium-blink-merge.git] / content / browser / renderer_host / input / input_router_impl.h
blobf42adfade718db1051c7d4acb765e410f9ee00b0
1 // Copyright 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.
5 #ifndef CONTENT_BROWSER_RENDERER_HOST_INPUT_INPUT_ROUTER_IMPL_H_
6 #define CONTENT_BROWSER_RENDERER_HOST_INPUT_INPUT_ROUTER_IMPL_H_
8 #include <queue>
10 #include "base/basictypes.h"
11 #include "base/memory/scoped_ptr.h"
12 #include "base/time/time.h"
13 #include "content/browser/renderer_host/input/gesture_event_queue.h"
14 #include "content/browser/renderer_host/input/input_router.h"
15 #include "content/browser/renderer_host/input/touch_action_filter.h"
16 #include "content/browser/renderer_host/input/touch_event_queue.h"
17 #include "content/browser/renderer_host/input/touchpad_tap_suppression_controller.h"
18 #include "content/common/input/input_event_stream_validator.h"
19 #include "content/public/browser/native_web_keyboard_event.h"
21 namespace IPC {
22 class Sender;
25 namespace ui {
26 class LatencyInfo;
29 namespace content {
31 class InputAckHandler;
32 class InputRouterClient;
33 class OverscrollController;
34 struct DidOverscrollParams;
35 struct InputEventAck;
37 // A default implementation for browser input event routing.
38 class CONTENT_EXPORT InputRouterImpl
39 : public NON_EXPORTED_BASE(InputRouter),
40 public NON_EXPORTED_BASE(GestureEventQueueClient),
41 public NON_EXPORTED_BASE(TouchEventQueueClient),
42 public NON_EXPORTED_BASE(TouchpadTapSuppressionControllerClient) {
43 public:
44 struct CONTENT_EXPORT Config {
45 Config();
46 GestureEventQueue::Config gesture_config;
47 TouchEventQueue::Config touch_config;
50 InputRouterImpl(IPC::Sender* sender,
51 InputRouterClient* client,
52 InputAckHandler* ack_handler,
53 int routing_id,
54 const Config& config);
55 ~InputRouterImpl() override;
57 // InputRouter
58 bool SendInput(scoped_ptr<IPC::Message> message) override;
59 void SendMouseEvent(const MouseEventWithLatencyInfo& mouse_event) override;
60 void SendWheelEvent(
61 const MouseWheelEventWithLatencyInfo& wheel_event) override;
62 void SendKeyboardEvent(const NativeWebKeyboardEventWithLatencyInfo& key_event,
63 bool is_keyboard_shortcut) override;
64 void SendGestureEvent(
65 const GestureEventWithLatencyInfo& gesture_event) override;
66 void SendTouchEvent(const TouchEventWithLatencyInfo& touch_event) override;
67 const NativeWebKeyboardEvent* GetLastKeyboardEvent() const override;
68 void NotifySiteIsMobileOptimized(bool is_mobile_optimized) override;
69 void RequestNotificationWhenFlushed() override;
70 bool HasPendingEvents() const override;
72 // IPC::Listener
73 bool OnMessageReceived(const IPC::Message& message) override;
75 private:
76 friend class InputRouterImplTest;
78 // TouchpadTapSuppressionControllerClient
79 void SendMouseEventImmediately(
80 const MouseEventWithLatencyInfo& mouse_event) override;
82 // TouchEventQueueClient
83 void SendTouchEventImmediately(
84 const TouchEventWithLatencyInfo& touch_event) override;
85 void OnTouchEventAck(const TouchEventWithLatencyInfo& event,
86 InputEventAckState ack_result) override;
88 // GetureEventFilterClient
89 void SendGestureEventImmediately(
90 const GestureEventWithLatencyInfo& gesture_event) override;
91 void OnGestureEventAck(const GestureEventWithLatencyInfo& event,
92 InputEventAckState ack_result) override;
94 bool SendMoveCaret(scoped_ptr<IPC::Message> message);
95 bool SendSelectMessage(scoped_ptr<IPC::Message> message);
96 bool Send(IPC::Message* message);
98 // Filters and forwards |input_event| to the appropriate handler.
99 void FilterAndSendWebInputEvent(const blink::WebInputEvent& input_event,
100 const ui::LatencyInfo& latency_info,
101 bool is_keyboard_shortcut);
103 // Utility routine for filtering and forwarding |input_event| to the
104 // appropriate handler. |input_event| will be offered to the overscroll
105 // controller, client and renderer, in that order.
106 void OfferToHandlers(const blink::WebInputEvent& input_event,
107 const ui::LatencyInfo& latency_info,
108 bool is_keyboard_shortcut);
110 // Returns true if |input_event| was consumed by the overscroll controller.
111 bool OfferToOverscrollController(const blink::WebInputEvent& input_event,
112 const ui::LatencyInfo& latency_info);
114 // Returns true if |input_event| was consumed by the client.
115 bool OfferToClient(const blink::WebInputEvent& input_event,
116 const ui::LatencyInfo& latency_info);
118 // Returns true if |input_event| was successfully sent to the renderer
119 // as an async IPC Message.
120 bool OfferToRenderer(const blink::WebInputEvent& input_event,
121 const ui::LatencyInfo& latency_info,
122 bool is_keyboard_shortcut);
124 // IPC message handlers
125 void OnInputEventAck(const InputEventAck& ack);
126 void OnDidOverscroll(const DidOverscrollParams& params);
127 void OnMsgMoveCaretAck();
128 void OnSelectMessageAck();
129 void OnHasTouchEventHandlers(bool has_handlers);
130 void OnSetTouchAction(TouchAction touch_action);
131 void OnDidStopFlinging();
133 // Indicates the source of an ack provided to |ProcessInputEventAck()|.
134 // The source is tracked by |current_ack_source_|, which aids in ack routing.
135 enum AckSource {
136 RENDERER,
137 CLIENT,
138 IGNORING_DISPOSITION,
139 ACK_SOURCE_NONE
141 // Note: This function may result in |this| being deleted, and as such
142 // should be the last method called in any internal chain of event handling.
143 void ProcessInputEventAck(blink::WebInputEvent::Type event_type,
144 InputEventAckState ack_result,
145 const ui::LatencyInfo& latency_info,
146 uint32 unique_touch_event_id,
147 AckSource ack_source);
149 // Dispatches the ack'ed event to |ack_handler_|.
150 void ProcessKeyboardAck(blink::WebInputEvent::Type type,
151 InputEventAckState ack_result,
152 const ui::LatencyInfo& latency);
154 // Forwards a valid |next_mouse_move_| if |type| is MouseMove.
155 void ProcessMouseAck(blink::WebInputEvent::Type type,
156 InputEventAckState ack_result,
157 const ui::LatencyInfo& latency);
159 // Dispatches the ack'ed event to |ack_handler_|, forwarding queued events
160 // from |coalesced_mouse_wheel_events_|.
161 void ProcessWheelAck(InputEventAckState ack_result,
162 const ui::LatencyInfo& latency);
164 // Forwards the event ack to |gesture_event_queue|, potentially triggering
165 // dispatch of queued gesture events.
166 void ProcessGestureAck(blink::WebInputEvent::Type type,
167 InputEventAckState ack_result,
168 const ui::LatencyInfo& latency);
170 // Forwards the event ack to |touch_event_queue_|, potentially triggering
171 // dispatch of queued touch events, or the creation of gesture events.
172 void ProcessTouchAck(InputEventAckState ack_result,
173 const ui::LatencyInfo& latency,
174 uint32 unique_touch_event_id);
176 // Called when a touch timeout-affecting bit has changed, in turn toggling the
177 // touch ack timeout feature of the |touch_event_queue_| as appropriate. Input
178 // to that determination includes current view properties and the allowed
179 // touch action. Note that this will only affect platforms that have a
180 // non-zero touch timeout configuration.
181 void UpdateTouchAckTimeoutEnabled();
183 // If a flush has been requested, signals a completed flush to the client if
184 // all events have been dispatched (i.e., |HasPendingEvents()| is false).
185 void SignalFlushedIfNecessary();
187 int routing_id() const { return routing_id_; }
190 IPC::Sender* sender_;
191 InputRouterClient* client_;
192 InputAckHandler* ack_handler_;
193 int routing_id_;
195 // (Similar to |mouse_move_pending_|.) True while waiting for SelectRange_ACK
196 // or MoveRangeSelectionExtent_ACK.
197 bool select_message_pending_;
199 // Queue of pending select messages to send after receving the next select
200 // message ack.
201 std::deque<IPC::Message*> pending_select_messages_;
203 // (Similar to |mouse_move_pending_|.) True while waiting for MoveCaret_ACK.
204 bool move_caret_pending_;
206 // (Similar to |next_mouse_move_|.) The next MoveCaret to send, if any.
207 scoped_ptr<IPC::Message> next_move_caret_;
209 // True if a mouse move event was sent to the render view and we are waiting
210 // for a corresponding InputHostMsg_HandleInputEvent_ACK message.
211 bool mouse_move_pending_;
213 // The next mouse move event to send (only non-null while mouse_move_pending_
214 // is true).
215 scoped_ptr<MouseEventWithLatencyInfo> next_mouse_move_;
216 MouseEventWithLatencyInfo current_mouse_move_;
218 // (Similar to |mouse_move_pending_|.) True if a mouse wheel event was sent
219 // and we are waiting for a corresponding ack.
220 bool mouse_wheel_pending_;
221 MouseWheelEventWithLatencyInfo current_wheel_event_;
223 // (Similar to |next_mouse_move_|.) The next mouse wheel events to send.
224 // Unlike mouse moves, mouse wheel events received while one is pending are
225 // coalesced (by accumulating deltas) if they match the previous event in
226 // modifiers. On the Mac, in particular, mouse wheel events are received at a
227 // high rate; not waiting for the ack results in jankiness, and using the same
228 // mechanism as for mouse moves (just dropping old events when multiple ones
229 // would be queued) results in very slow scrolling.
230 typedef std::deque<MouseWheelEventWithLatencyInfo> WheelEventQueue;
231 WheelEventQueue coalesced_mouse_wheel_events_;
233 // A queue of keyboard events. We can't trust data from the renderer so we
234 // stuff key events into a queue and pop them out on ACK, feeding our copy
235 // back to whatever unhandled handler instead of the returned version.
236 typedef std::deque<NativeWebKeyboardEventWithLatencyInfo> KeyQueue;
237 KeyQueue key_queue_;
239 // The time when an input event was sent to the client.
240 base::TimeTicks input_event_start_time_;
242 // The source of the ack within the scope of |ProcessInputEventAck()|.
243 // Defaults to ACK_SOURCE_NONE.
244 AckSource current_ack_source_;
246 // Whether a call to |Flush()| has yet been accompanied by a |DidFlush()| call
247 // to the client_ after all events have been dispatched/acked.
248 bool flush_requested_;
250 // Whether there are any active flings in the renderer. As the fling
251 // end notification is asynchronous, we use a count rather than a boolean
252 // to avoid races in bookkeeping when starting a new fling.
253 int active_renderer_fling_count_;
255 TouchEventQueue touch_event_queue_;
256 GestureEventQueue gesture_event_queue_;
257 TouchActionFilter touch_action_filter_;
258 InputEventStreamValidator input_stream_validator_;
259 InputEventStreamValidator output_stream_validator_;
261 DISALLOW_COPY_AND_ASSIGN(InputRouterImpl);
264 } // namespace content
266 #endif // CONTENT_BROWSER_RENDERER_HOST_INPUT_INPUT_ROUTER_IMPL_H_