OLD | NEW |
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "content/browser/renderer_host/input/input_router_impl.h" | 5 #include "content/browser/renderer_host/input/input_router_impl.h" |
6 | 6 |
7 #include <math.h> | 7 #include <math.h> |
8 | 8 |
9 #include "base/auto_reset.h" | 9 #include "base/auto_reset.h" |
10 #include "base/command_line.h" | 10 #include "base/command_line.h" |
(...skipping 134 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
145 } | 145 } |
146 return; | 146 return; |
147 } | 147 } |
148 | 148 |
149 mouse_wheel_pending_ = true; | 149 mouse_wheel_pending_ = true; |
150 current_wheel_event_ = wheel_event; | 150 current_wheel_event_ = wheel_event; |
151 | 151 |
152 LOCAL_HISTOGRAM_COUNTS_100("Renderer.WheelQueueSize", | 152 LOCAL_HISTOGRAM_COUNTS_100("Renderer.WheelQueueSize", |
153 coalesced_mouse_wheel_events_.size()); | 153 coalesced_mouse_wheel_events_.size()); |
154 | 154 |
155 FilterAndSendWebInputEvent(wheel_event.event, wheel_event.latency, false); | 155 FilterAndSendWebInputEvent(wheel_event.event, wheel_event.latency); |
156 } | 156 } |
157 | 157 |
158 void InputRouterImpl::SendKeyboardEvent( | 158 void InputRouterImpl::SendKeyboardEvent( |
159 const NativeWebKeyboardEventWithLatencyInfo& key_event, | 159 const NativeWebKeyboardEventWithLatencyInfo& key_event) { |
160 bool is_keyboard_shortcut) { | |
161 // Put all WebKeyboardEvent objects in a queue since we can't trust the | 160 // Put all WebKeyboardEvent objects in a queue since we can't trust the |
162 // renderer and we need to give something to the HandleKeyboardEvent | 161 // renderer and we need to give something to the HandleKeyboardEvent |
163 // handler. | 162 // handler. |
164 key_queue_.push_back(key_event); | 163 key_queue_.push_back(key_event); |
165 LOCAL_HISTOGRAM_COUNTS_100("Renderer.KeyboardQueueSize", key_queue_.size()); | 164 LOCAL_HISTOGRAM_COUNTS_100("Renderer.KeyboardQueueSize", key_queue_.size()); |
166 | 165 |
167 gesture_event_queue_.FlingHasBeenHalted(); | 166 gesture_event_queue_.FlingHasBeenHalted(); |
168 | 167 |
169 // Only forward the non-native portions of our event. | 168 // Only forward the non-native portions of our event. |
170 FilterAndSendWebInputEvent(key_event.event, | 169 FilterAndSendWebInputEvent(key_event.event, key_event.latency); |
171 key_event.latency, | |
172 is_keyboard_shortcut); | |
173 } | 170 } |
174 | 171 |
175 void InputRouterImpl::SendGestureEvent( | 172 void InputRouterImpl::SendGestureEvent( |
176 const GestureEventWithLatencyInfo& original_gesture_event) { | 173 const GestureEventWithLatencyInfo& original_gesture_event) { |
177 input_stream_validator_.Validate(original_gesture_event.event); | 174 input_stream_validator_.Validate(original_gesture_event.event); |
178 | 175 |
179 GestureEventWithLatencyInfo gesture_event(original_gesture_event); | 176 GestureEventWithLatencyInfo gesture_event(original_gesture_event); |
180 | 177 |
181 if (touch_action_filter_.FilterGestureEvent(&gesture_event.event)) | 178 if (touch_action_filter_.FilterGestureEvent(&gesture_event.event)) |
182 return; | 179 return; |
(...skipping 23 matching lines...) Expand all Loading... |
206 if (!next_mouse_move_) | 203 if (!next_mouse_move_) |
207 next_mouse_move_.reset(new MouseEventWithLatencyInfo(mouse_event)); | 204 next_mouse_move_.reset(new MouseEventWithLatencyInfo(mouse_event)); |
208 else | 205 else |
209 next_mouse_move_->CoalesceWith(mouse_event); | 206 next_mouse_move_->CoalesceWith(mouse_event); |
210 return; | 207 return; |
211 } | 208 } |
212 mouse_move_pending_ = true; | 209 mouse_move_pending_ = true; |
213 current_mouse_move_ = mouse_event; | 210 current_mouse_move_ = mouse_event; |
214 } | 211 } |
215 | 212 |
216 FilterAndSendWebInputEvent(mouse_event.event, mouse_event.latency, false); | 213 FilterAndSendWebInputEvent(mouse_event.event, mouse_event.latency); |
217 } | 214 } |
218 | 215 |
219 void InputRouterImpl::SendTouchEventImmediately( | 216 void InputRouterImpl::SendTouchEventImmediately( |
220 const TouchEventWithLatencyInfo& touch_event) { | 217 const TouchEventWithLatencyInfo& touch_event) { |
221 if (WebTouchEventTraits::IsTouchSequenceStart(touch_event.event)) { | 218 if (WebTouchEventTraits::IsTouchSequenceStart(touch_event.event)) { |
222 touch_action_filter_.ResetTouchAction(); | 219 touch_action_filter_.ResetTouchAction(); |
223 // Note that if the previous touch-action was TOUCH_ACTION_NONE, enabling | 220 // Note that if the previous touch-action was TOUCH_ACTION_NONE, enabling |
224 // the timeout here will not take effect until the *following* touch | 221 // the timeout here will not take effect until the *following* touch |
225 // sequence. This is a desirable side-effect, giving the renderer a chance | 222 // sequence. This is a desirable side-effect, giving the renderer a chance |
226 // to send a touch-action response without racing against the ack timeout. | 223 // to send a touch-action response without racing against the ack timeout. |
227 UpdateTouchAckTimeoutEnabled(); | 224 UpdateTouchAckTimeoutEnabled(); |
228 } | 225 } |
229 | 226 |
230 FilterAndSendWebInputEvent(touch_event.event, touch_event.latency, false); | 227 FilterAndSendWebInputEvent(touch_event.event, touch_event.latency); |
231 } | 228 } |
232 | 229 |
233 void InputRouterImpl::SendGestureEventImmediately( | 230 void InputRouterImpl::SendGestureEventImmediately( |
234 const GestureEventWithLatencyInfo& gesture_event) { | 231 const GestureEventWithLatencyInfo& gesture_event) { |
235 FilterAndSendWebInputEvent(gesture_event.event, gesture_event.latency, false); | 232 FilterAndSendWebInputEvent(gesture_event.event, gesture_event.latency); |
236 } | 233 } |
237 | 234 |
238 const NativeWebKeyboardEvent* InputRouterImpl::GetLastKeyboardEvent() const { | 235 const NativeWebKeyboardEvent* InputRouterImpl::GetLastKeyboardEvent() const { |
239 if (key_queue_.empty()) | 236 if (key_queue_.empty()) |
240 return NULL; | 237 return NULL; |
241 return &key_queue_.front().event; | 238 return &key_queue_.front().event; |
242 } | 239 } |
243 | 240 |
244 void InputRouterImpl::NotifySiteIsMobileOptimized(bool is_mobile_optimized) { | 241 void InputRouterImpl::NotifySiteIsMobileOptimized(bool is_mobile_optimized) { |
245 touch_event_queue_.SetIsMobileOptimizedSite(is_mobile_optimized); | 242 touch_event_queue_.SetIsMobileOptimizedSite(is_mobile_optimized); |
(...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
332 move_caret_pending_ = true; | 329 move_caret_pending_ = true; |
333 return Send(message.release()); | 330 return Send(message.release()); |
334 } | 331 } |
335 | 332 |
336 bool InputRouterImpl::Send(IPC::Message* message) { | 333 bool InputRouterImpl::Send(IPC::Message* message) { |
337 return sender_->Send(message); | 334 return sender_->Send(message); |
338 } | 335 } |
339 | 336 |
340 void InputRouterImpl::FilterAndSendWebInputEvent( | 337 void InputRouterImpl::FilterAndSendWebInputEvent( |
341 const WebInputEvent& input_event, | 338 const WebInputEvent& input_event, |
342 const ui::LatencyInfo& latency_info, | 339 const ui::LatencyInfo& latency_info) { |
343 bool is_keyboard_shortcut) { | |
344 TRACE_EVENT1("input", | 340 TRACE_EVENT1("input", |
345 "InputRouterImpl::FilterAndSendWebInputEvent", | 341 "InputRouterImpl::FilterAndSendWebInputEvent", |
346 "type", | 342 "type", |
347 WebInputEventTraits::GetName(input_event.type)); | 343 WebInputEventTraits::GetName(input_event.type)); |
348 TRACE_EVENT_WITH_FLOW1("input,benchmark", | 344 TRACE_EVENT_WITH_FLOW1("input,benchmark", |
349 "LatencyInfo.Flow", | 345 "LatencyInfo.Flow", |
350 TRACE_ID_DONT_MANGLE(latency_info.trace_id()), | 346 TRACE_ID_DONT_MANGLE(latency_info.trace_id()), |
351 TRACE_EVENT_FLAG_FLOW_IN | TRACE_EVENT_FLAG_FLOW_OUT, | 347 TRACE_EVENT_FLAG_FLOW_IN | TRACE_EVENT_FLAG_FLOW_OUT, |
352 "step", "SendInputEventUI"); | 348 "step", "SendInputEventUI"); |
353 | 349 |
354 // Any input event cancels a pending mouse move event. | 350 // Any input event cancels a pending mouse move event. |
355 next_mouse_move_.reset(); | 351 next_mouse_move_.reset(); |
356 | 352 |
357 OfferToHandlers(input_event, latency_info, is_keyboard_shortcut); | 353 OfferToHandlers(input_event, latency_info); |
358 } | 354 } |
359 | 355 |
360 void InputRouterImpl::OfferToHandlers(const WebInputEvent& input_event, | 356 void InputRouterImpl::OfferToHandlers(const WebInputEvent& input_event, |
361 const ui::LatencyInfo& latency_info, | 357 const ui::LatencyInfo& latency_info) { |
362 bool is_keyboard_shortcut) { | |
363 output_stream_validator_.Validate(input_event); | 358 output_stream_validator_.Validate(input_event); |
364 | 359 |
365 if (OfferToClient(input_event, latency_info)) | 360 if (OfferToClient(input_event, latency_info)) |
366 return; | 361 return; |
367 | 362 |
368 OfferToRenderer(input_event, latency_info, is_keyboard_shortcut); | 363 OfferToRenderer(input_event, latency_info); |
369 | 364 |
370 // Touch events should always indicate in the event whether they are | 365 // Touch events should always indicate in the event whether they are |
371 // cancelable (respect ACK disposition) or not except touchmove. | 366 // cancelable (respect ACK disposition) or not except touchmove. |
372 bool needs_synthetic_ack = | 367 bool needs_synthetic_ack = |
373 !WebInputEventTraits::WillReceiveAckFromRenderer(input_event); | 368 !WebInputEventTraits::WillReceiveAckFromRenderer(input_event); |
374 | 369 |
375 if (WebInputEvent::isTouchEventType(input_event.type) && | 370 if (WebInputEvent::isTouchEventType(input_event.type) && |
376 input_event.type != WebInputEvent::TouchMove) { | 371 input_event.type != WebInputEvent::TouchMove) { |
377 const WebTouchEvent& touch = static_cast<const WebTouchEvent&>(input_event); | 372 const WebTouchEvent& touch = static_cast<const WebTouchEvent&>(input_event); |
378 DCHECK_EQ(needs_synthetic_ack, !touch.cancelable); | 373 DCHECK_EQ(needs_synthetic_ack, !touch.cancelable); |
(...skipping 30 matching lines...) Expand all Loading... |
409 consumed = true; | 404 consumed = true; |
410 break; | 405 break; |
411 default: | 406 default: |
412 break; | 407 break; |
413 } | 408 } |
414 | 409 |
415 return consumed; | 410 return consumed; |
416 } | 411 } |
417 | 412 |
418 bool InputRouterImpl::OfferToRenderer(const WebInputEvent& input_event, | 413 bool InputRouterImpl::OfferToRenderer(const WebInputEvent& input_event, |
419 const ui::LatencyInfo& latency_info, | 414 const ui::LatencyInfo& latency_info) { |
420 bool is_keyboard_shortcut) { | 415 if (Send(new InputMsg_HandleInputEvent(routing_id(), &input_event, |
421 if (Send(new InputMsg_HandleInputEvent( | 416 latency_info))) { |
422 routing_id(), &input_event, latency_info, is_keyboard_shortcut))) { | |
423 // Ack messages for ignored ack event types should never be sent by the | 417 // Ack messages for ignored ack event types should never be sent by the |
424 // renderer. Consequently, such event types should not affect event time | 418 // renderer. Consequently, such event types should not affect event time |
425 // or in-flight event count metrics. | 419 // or in-flight event count metrics. |
426 if (WebInputEventTraits::WillReceiveAckFromRenderer(input_event)) { | 420 if (WebInputEventTraits::WillReceiveAckFromRenderer(input_event)) { |
427 input_event_start_time_ = TimeTicks::Now(); | 421 input_event_start_time_ = TimeTicks::Now(); |
428 client_->IncrementInFlightEventCount(); | 422 client_->IncrementInFlightEventCount(); |
429 } | 423 } |
430 return true; | 424 return true; |
431 } | 425 } |
432 return false; | 426 return false; |
(...skipping 214 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
647 return; | 641 return; |
648 | 642 |
649 if (HasPendingEvents()) | 643 if (HasPendingEvents()) |
650 return; | 644 return; |
651 | 645 |
652 flush_requested_ = false; | 646 flush_requested_ = false; |
653 client_->DidFlush(); | 647 client_->DidFlush(); |
654 } | 648 } |
655 | 649 |
656 } // namespace content | 650 } // namespace content |
OLD | NEW |