OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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/renderer/render_widget.h" | 5 #include "content/renderer/render_widget.h" |
6 | 6 |
7 #include "base/bind.h" | 7 #include "base/bind.h" |
8 #include "base/command_line.h" | 8 #include "base/command_line.h" |
9 #include "base/debug/trace_event.h" | 9 #include "base/debug/trace_event.h" |
10 #include "base/debug/trace_event_synthetic_delay.h" | 10 #include "base/debug/trace_event_synthetic_delay.h" |
(...skipping 355 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
366 next_paint_flags_(0), | 366 next_paint_flags_(0), |
367 auto_resize_mode_(false), | 367 auto_resize_mode_(false), |
368 need_update_rect_for_auto_resize_(false), | 368 need_update_rect_for_auto_resize_(false), |
369 did_show_(false), | 369 did_show_(false), |
370 is_hidden_(hidden), | 370 is_hidden_(hidden), |
371 never_visible_(never_visible), | 371 never_visible_(never_visible), |
372 is_fullscreen_(false), | 372 is_fullscreen_(false), |
373 has_focus_(false), | 373 has_focus_(false), |
374 handling_input_event_(false), | 374 handling_input_event_(false), |
375 handling_ime_event_(false), | 375 handling_ime_event_(false), |
376 handling_touchstart_event_(false), | 376 handling_event_type_(WebInputEvent::Undefined), |
| 377 ignore_ack_for_current_mouse_move_(false), |
377 closing_(false), | 378 closing_(false), |
378 is_swapped_out_(swapped_out), | 379 is_swapped_out_(swapped_out), |
379 input_method_is_active_(false), | 380 input_method_is_active_(false), |
380 text_input_type_(ui::TEXT_INPUT_TYPE_NONE), | 381 text_input_type_(ui::TEXT_INPUT_TYPE_NONE), |
381 text_input_mode_(ui::TEXT_INPUT_MODE_DEFAULT), | 382 text_input_mode_(ui::TEXT_INPUT_MODE_DEFAULT), |
382 can_compose_inline_(true), | 383 can_compose_inline_(true), |
383 popup_type_(popup_type), | 384 popup_type_(popup_type), |
384 pending_window_rect_count_(0), | 385 pending_window_rect_count_(0), |
385 suppress_next_char_events_(false), | 386 suppress_next_char_events_(false), |
386 is_accelerated_compositing_active_(false), | 387 is_accelerated_compositing_active_(false), |
(...skipping 522 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
909 } | 910 } |
910 | 911 |
911 void RenderWidget::OnHandleInputEvent(const blink::WebInputEvent* input_event, | 912 void RenderWidget::OnHandleInputEvent(const blink::WebInputEvent* input_event, |
912 const ui::LatencyInfo& latency_info, | 913 const ui::LatencyInfo& latency_info, |
913 bool is_keyboard_shortcut) { | 914 bool is_keyboard_shortcut) { |
914 handling_input_event_ = true; | 915 handling_input_event_ = true; |
915 if (!input_event) { | 916 if (!input_event) { |
916 handling_input_event_ = false; | 917 handling_input_event_ = false; |
917 return; | 918 return; |
918 } | 919 } |
| 920 handling_event_type_ = input_event->type; |
919 | 921 |
920 base::TimeTicks start_time; | 922 base::TimeTicks start_time; |
921 if (base::TimeTicks::IsHighResNowFastAndReliable()) | 923 if (base::TimeTicks::IsHighResNowFastAndReliable()) |
922 start_time = base::TimeTicks::HighResNow(); | 924 start_time = base::TimeTicks::HighResNow(); |
923 | 925 |
924 const char* const event_name = | 926 const char* const event_name = |
925 WebInputEventTraits::GetName(input_event->type); | 927 WebInputEventTraits::GetName(input_event->type); |
926 TRACE_EVENT1("renderer", "RenderWidget::OnHandleInputEvent", | 928 TRACE_EVENT1("renderer", "RenderWidget::OnHandleInputEvent", |
927 "event", event_name); | 929 "event", event_name); |
928 TRACE_EVENT_SYNTHETIC_DELAY_BEGIN("blink.HandleInputEvent"); | 930 TRACE_EVENT_SYNTHETIC_DELAY_BEGIN("blink.HandleInputEvent"); |
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
994 #endif | 996 #endif |
995 } | 997 } |
996 | 998 |
997 if (WebInputEvent::isGestureEventType(input_event->type)) { | 999 if (WebInputEvent::isGestureEventType(input_event->type)) { |
998 const WebGestureEvent& gesture_event = | 1000 const WebGestureEvent& gesture_event = |
999 *static_cast<const WebGestureEvent*>(input_event); | 1001 *static_cast<const WebGestureEvent*>(input_event); |
1000 context_menu_source_type_ = ui::MENU_SOURCE_TOUCH; | 1002 context_menu_source_type_ = ui::MENU_SOURCE_TOUCH; |
1001 prevent_default = prevent_default || WillHandleGestureEvent(gesture_event); | 1003 prevent_default = prevent_default || WillHandleGestureEvent(gesture_event); |
1002 } | 1004 } |
1003 | 1005 |
1004 if (input_event->type == WebInputEvent::TouchStart) | |
1005 handling_touchstart_event_ = true; | |
1006 | |
1007 bool processed = prevent_default; | 1006 bool processed = prevent_default; |
1008 if (input_event->type != WebInputEvent::Char || !suppress_next_char_events_) { | 1007 if (input_event->type != WebInputEvent::Char || !suppress_next_char_events_) { |
1009 suppress_next_char_events_ = false; | 1008 suppress_next_char_events_ = false; |
1010 if (!processed && webwidget_) | 1009 if (!processed && webwidget_) |
1011 processed = webwidget_->handleInputEvent(*input_event); | 1010 processed = webwidget_->handleInputEvent(*input_event); |
1012 } | 1011 } |
1013 | 1012 |
1014 handling_touchstart_event_ = false; | |
1015 | |
1016 // If this RawKeyDown event corresponds to a browser keyboard shortcut and | 1013 // If this RawKeyDown event corresponds to a browser keyboard shortcut and |
1017 // it's not processed by webkit, then we need to suppress the upcoming Char | 1014 // it's not processed by webkit, then we need to suppress the upcoming Char |
1018 // events. | 1015 // events. |
1019 if (!processed && is_keyboard_shortcut) | 1016 if (!processed && is_keyboard_shortcut) |
1020 suppress_next_char_events_ = true; | 1017 suppress_next_char_events_ = true; |
1021 | 1018 |
1022 InputEventAckState ack_result = processed ? | 1019 InputEventAckState ack_result = processed ? |
1023 INPUT_EVENT_ACK_STATE_CONSUMED : INPUT_EVENT_ACK_STATE_NOT_CONSUMED; | 1020 INPUT_EVENT_ACK_STATE_CONSUMED : INPUT_EVENT_ACK_STATE_NOT_CONSUMED; |
1024 if (!processed && input_event->type == WebInputEvent::TouchStart) { | 1021 if (!processed && input_event->type == WebInputEvent::TouchStart) { |
1025 const WebTouchEvent& touch_event = | 1022 const WebTouchEvent& touch_event = |
(...skipping 28 matching lines...) Expand all Loading... |
1054 if (base::TimeTicks::IsHighResNowFastAndReliable()) { | 1051 if (base::TimeTicks::IsHighResNowFastAndReliable()) { |
1055 base::TimeTicks end_time = base::TimeTicks::HighResNow(); | 1052 base::TimeTicks end_time = base::TimeTicks::HighResNow(); |
1056 total_input_handling_time_this_frame_ += (end_time - start_time); | 1053 total_input_handling_time_this_frame_ += (end_time - start_time); |
1057 rate_limiting_wanted = | 1054 rate_limiting_wanted = |
1058 total_input_handling_time_this_frame_.InMicroseconds() > | 1055 total_input_handling_time_this_frame_.InMicroseconds() > |
1059 kInputHandlingTimeThrottlingThresholdMicroseconds; | 1056 kInputHandlingTimeThrottlingThresholdMicroseconds; |
1060 } | 1057 } |
1061 | 1058 |
1062 TRACE_EVENT_SYNTHETIC_DELAY_END("blink.HandleInputEvent"); | 1059 TRACE_EVENT_SYNTHETIC_DELAY_END("blink.HandleInputEvent"); |
1063 | 1060 |
1064 if (!WebInputEventTraits::IgnoresAckDisposition(*input_event)) { | 1061 // Note that we can't use handling_event_type_ here since it will be overriden |
| 1062 // by reentrant calls for events after the paused one. |
| 1063 bool no_ack = ignore_ack_for_current_mouse_move_ && |
| 1064 input_event->type == WebInputEvent::MouseMove; |
| 1065 if (!WebInputEventTraits::IgnoresAckDisposition(*input_event) && !no_ack) { |
1065 scoped_ptr<IPC::Message> response( | 1066 scoped_ptr<IPC::Message> response( |
1066 new InputHostMsg_HandleInputEvent_ACK(routing_id_, | 1067 new InputHostMsg_HandleInputEvent_ACK(routing_id_, |
1067 input_event->type, | 1068 input_event->type, |
1068 ack_result, | 1069 ack_result, |
1069 swap_latency_info)); | 1070 swap_latency_info)); |
1070 if (rate_limiting_wanted && event_type_can_be_rate_limited && | 1071 if (rate_limiting_wanted && event_type_can_be_rate_limited && |
1071 frame_pending && !is_hidden_) { | 1072 frame_pending && !is_hidden_) { |
1072 // We want to rate limit the input events in this case, so we'll wait for | 1073 // We want to rate limit the input events in this case, so we'll wait for |
1073 // painting to finish before ACKing this message. | 1074 // painting to finish before ACKing this message. |
1074 TRACE_EVENT_INSTANT0("renderer", | 1075 TRACE_EVENT_INSTANT0("renderer", |
1075 "RenderWidget::OnHandleInputEvent ack throttled", | 1076 "RenderWidget::OnHandleInputEvent ack throttled", |
1076 TRACE_EVENT_SCOPE_THREAD); | 1077 TRACE_EVENT_SCOPE_THREAD); |
1077 if (pending_input_event_ack_) { | 1078 if (pending_input_event_ack_) { |
1078 // As two different kinds of events could cause us to postpone an ack | 1079 // As two different kinds of events could cause us to postpone an ack |
1079 // we send it now, if we have one pending. The Browser should never | 1080 // we send it now, if we have one pending. The Browser should never |
1080 // send us the same kind of event we are delaying the ack for. | 1081 // send us the same kind of event we are delaying the ack for. |
1081 Send(pending_input_event_ack_.release()); | 1082 Send(pending_input_event_ack_.release()); |
1082 } | 1083 } |
1083 pending_input_event_ack_ = response.Pass(); | 1084 pending_input_event_ack_ = response.Pass(); |
1084 if (compositor_) | 1085 if (compositor_) |
1085 compositor_->NotifyInputThrottledUntilCommit(); | 1086 compositor_->NotifyInputThrottledUntilCommit(); |
1086 } else { | 1087 } else { |
1087 Send(response.release()); | 1088 Send(response.release()); |
1088 } | 1089 } |
1089 } | 1090 } |
| 1091 ignore_ack_for_current_mouse_move_ = false; |
1090 | 1092 |
1091 #if defined(OS_ANDROID) | 1093 #if defined(OS_ANDROID) |
1092 // Allow the IME to be shown when the focus changes as a consequence | 1094 // Allow the IME to be shown when the focus changes as a consequence |
1093 // of a processed touch end event. | 1095 // of a processed touch end event. |
1094 if (input_event->type == WebInputEvent::TouchEnd && processed) | 1096 if (input_event->type == WebInputEvent::TouchEnd && processed) |
1095 UpdateTextInputState(SHOW_IME_IF_NEEDED, FROM_NON_IME); | 1097 UpdateTextInputState(SHOW_IME_IF_NEEDED, FROM_NON_IME); |
1096 #elif defined(USE_AURA) | 1098 #elif defined(USE_AURA) |
1097 // Show the virtual keyboard if enabled and a user gesture triggers a focus | 1099 // Show the virtual keyboard if enabled and a user gesture triggers a focus |
1098 // change. | 1100 // change. |
1099 if (processed && (input_event->type == WebInputEvent::TouchEnd || | 1101 if (processed && (input_event->type == WebInputEvent::TouchEnd || |
1100 input_event->type == WebInputEvent::MouseUp)) | 1102 input_event->type == WebInputEvent::MouseUp)) |
1101 UpdateTextInputState(SHOW_IME_IF_NEEDED, FROM_IME); | 1103 UpdateTextInputState(SHOW_IME_IF_NEEDED, FROM_IME); |
1102 #endif | 1104 #endif |
1103 | 1105 |
| 1106 handling_event_type_ = WebInputEvent::Undefined; |
1104 handling_input_event_ = false; | 1107 handling_input_event_ = false; |
1105 | 1108 |
1106 if (!prevent_default) { | 1109 if (!prevent_default) { |
1107 if (WebInputEvent::isKeyboardEventType(input_event->type)) | 1110 if (WebInputEvent::isKeyboardEventType(input_event->type)) |
1108 DidHandleKeyEvent(); | 1111 DidHandleKeyEvent(); |
1109 if (WebInputEvent::isMouseEventType(input_event->type)) | 1112 if (WebInputEvent::isMouseEventType(input_event->type)) |
1110 DidHandleMouseEvent(*(static_cast<const WebMouseEvent*>(input_event))); | 1113 DidHandleMouseEvent(*(static_cast<const WebMouseEvent*>(input_event))); |
1111 if (WebInputEvent::isTouchEventType(input_event->type)) | 1114 if (WebInputEvent::isTouchEventType(input_event->type)) |
1112 DidHandleTouchEvent(*(static_cast<const WebTouchEvent*>(input_event))); | 1115 DidHandleTouchEvent(*(static_cast<const WebTouchEvent*>(input_event))); |
1113 } | 1116 } |
(...skipping 420 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1534 #endif | 1537 #endif |
1535 | 1538 |
1536 bool RenderWidget::ShouldHandleImeEvent() { | 1539 bool RenderWidget::ShouldHandleImeEvent() { |
1537 #if defined(OS_ANDROID) | 1540 #if defined(OS_ANDROID) |
1538 return !!webwidget_ && outstanding_ime_acks_ == 0; | 1541 return !!webwidget_ && outstanding_ime_acks_ == 0; |
1539 #else | 1542 #else |
1540 return !!webwidget_; | 1543 return !!webwidget_; |
1541 #endif | 1544 #endif |
1542 } | 1545 } |
1543 | 1546 |
| 1547 bool RenderWidget::SendAckForCurrentMouseMove() { |
| 1548 if (handling_event_type_ == WebInputEvent::MouseMove) { |
| 1549 Send(new InputHostMsg_HandleInputEvent_ACK(routing_id_, |
| 1550 handling_event_type_, |
| 1551 INPUT_EVENT_ACK_STATE_CONSUMED, |
| 1552 ui::LatencyInfo())); |
| 1553 return true; |
| 1554 } |
| 1555 return false; |
| 1556 } |
| 1557 |
| 1558 void RenderWidget::IgnoreAckForCurrentMouseMove() { |
| 1559 ignore_ack_for_current_mouse_move_ = true; |
| 1560 } |
| 1561 |
1544 void RenderWidget::SetDeviceScaleFactor(float device_scale_factor) { | 1562 void RenderWidget::SetDeviceScaleFactor(float device_scale_factor) { |
1545 if (device_scale_factor_ == device_scale_factor) | 1563 if (device_scale_factor_ == device_scale_factor) |
1546 return; | 1564 return; |
1547 | 1565 |
1548 device_scale_factor_ = device_scale_factor; | 1566 device_scale_factor_ = device_scale_factor; |
1549 | 1567 |
1550 if (!is_accelerated_compositing_active_) { | 1568 if (!is_accelerated_compositing_active_) { |
1551 didInvalidateRect(gfx::Rect(size_.width(), size_.height())); | 1569 didInvalidateRect(gfx::Rect(size_.width(), size_.height())); |
1552 } else { | 1570 } else { |
1553 scheduleComposite(); | 1571 scheduleComposite(); |
(...skipping 431 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1985 | 2003 |
1986 void RenderWidget::hasTouchEventHandlers(bool has_handlers) { | 2004 void RenderWidget::hasTouchEventHandlers(bool has_handlers) { |
1987 Send(new ViewHostMsg_HasTouchEventHandlers(routing_id_, has_handlers)); | 2005 Send(new ViewHostMsg_HasTouchEventHandlers(routing_id_, has_handlers)); |
1988 } | 2006 } |
1989 | 2007 |
1990 void RenderWidget::setTouchAction( | 2008 void RenderWidget::setTouchAction( |
1991 blink::WebTouchAction web_touch_action) { | 2009 blink::WebTouchAction web_touch_action) { |
1992 | 2010 |
1993 // Ignore setTouchAction calls that result from synthetic touch events (eg. | 2011 // Ignore setTouchAction calls that result from synthetic touch events (eg. |
1994 // when blink is emulating touch with mouse). | 2012 // when blink is emulating touch with mouse). |
1995 if (!handling_touchstart_event_) | 2013 if (!handling_event_type_ == WebInputEvent::TouchStart) |
1996 return; | 2014 return; |
1997 | 2015 |
1998 // Verify the same values are used by the types so we can cast between them. | 2016 // Verify the same values are used by the types so we can cast between them. |
1999 COMPILE_ASSERT(static_cast<blink::WebTouchAction>(TOUCH_ACTION_AUTO) == | 2017 COMPILE_ASSERT(static_cast<blink::WebTouchAction>(TOUCH_ACTION_AUTO) == |
2000 blink::WebTouchActionAuto, | 2018 blink::WebTouchActionAuto, |
2001 enum_values_must_match_for_touch_action); | 2019 enum_values_must_match_for_touch_action); |
2002 COMPILE_ASSERT(static_cast<blink::WebTouchAction>(TOUCH_ACTION_NONE) == | 2020 COMPILE_ASSERT(static_cast<blink::WebTouchAction>(TOUCH_ACTION_NONE) == |
2003 blink::WebTouchActionNone, | 2021 blink::WebTouchActionNone, |
2004 enum_values_must_match_for_touch_action); | 2022 enum_values_must_match_for_touch_action); |
2005 COMPILE_ASSERT(static_cast<blink::WebTouchAction>(TOUCH_ACTION_PAN_X) == | 2023 COMPILE_ASSERT(static_cast<blink::WebTouchAction>(TOUCH_ACTION_PAN_X) == |
(...skipping 97 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2103 | 2121 |
2104 void RenderWidget::RegisterSwappedOutChildFrame(RenderFrameImpl* frame) { | 2122 void RenderWidget::RegisterSwappedOutChildFrame(RenderFrameImpl* frame) { |
2105 swapped_out_frames_.AddObserver(frame); | 2123 swapped_out_frames_.AddObserver(frame); |
2106 } | 2124 } |
2107 | 2125 |
2108 void RenderWidget::UnregisterSwappedOutChildFrame(RenderFrameImpl* frame) { | 2126 void RenderWidget::UnregisterSwappedOutChildFrame(RenderFrameImpl* frame) { |
2109 swapped_out_frames_.RemoveObserver(frame); | 2127 swapped_out_frames_.RemoveObserver(frame); |
2110 } | 2128 } |
2111 | 2129 |
2112 } // namespace content | 2130 } // namespace content |
OLD | NEW |