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_mouse_move_from_debugger_(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 screen_info_(screen_info), | 387 screen_info_(screen_info), |
(...skipping 514 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
901 } | 902 } |
902 | 903 |
903 void RenderWidget::OnHandleInputEvent(const blink::WebInputEvent* input_event, | 904 void RenderWidget::OnHandleInputEvent(const blink::WebInputEvent* input_event, |
904 const ui::LatencyInfo& latency_info, | 905 const ui::LatencyInfo& latency_info, |
905 bool is_keyboard_shortcut) { | 906 bool is_keyboard_shortcut) { |
906 handling_input_event_ = true; | 907 handling_input_event_ = true; |
907 if (!input_event) { | 908 if (!input_event) { |
908 handling_input_event_ = false; | 909 handling_input_event_ = false; |
909 return; | 910 return; |
910 } | 911 } |
912 handling_event_type_ = input_event->type; | |
jdduke (slow)
2014/05/19 15:10:37
Any reason we can't use base::AutoReset here (also
dgozman
2014/05/20 08:54:13
Done.
| |
911 | 913 |
912 base::TimeTicks start_time; | 914 base::TimeTicks start_time; |
913 if (base::TimeTicks::IsHighResNowFastAndReliable()) | 915 if (base::TimeTicks::IsHighResNowFastAndReliable()) |
914 start_time = base::TimeTicks::HighResNow(); | 916 start_time = base::TimeTicks::HighResNow(); |
915 | 917 |
916 const char* const event_name = | 918 const char* const event_name = |
917 WebInputEventTraits::GetName(input_event->type); | 919 WebInputEventTraits::GetName(input_event->type); |
918 TRACE_EVENT1("renderer", "RenderWidget::OnHandleInputEvent", | 920 TRACE_EVENT1("renderer", "RenderWidget::OnHandleInputEvent", |
919 "event", event_name); | 921 "event", event_name); |
920 TRACE_EVENT_SYNTHETIC_DELAY_BEGIN("blink.HandleInputEvent"); | 922 TRACE_EVENT_SYNTHETIC_DELAY_BEGIN("blink.HandleInputEvent"); |
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
986 #endif | 988 #endif |
987 } | 989 } |
988 | 990 |
989 if (WebInputEvent::isGestureEventType(input_event->type)) { | 991 if (WebInputEvent::isGestureEventType(input_event->type)) { |
990 const WebGestureEvent& gesture_event = | 992 const WebGestureEvent& gesture_event = |
991 *static_cast<const WebGestureEvent*>(input_event); | 993 *static_cast<const WebGestureEvent*>(input_event); |
992 context_menu_source_type_ = ui::MENU_SOURCE_TOUCH; | 994 context_menu_source_type_ = ui::MENU_SOURCE_TOUCH; |
993 prevent_default = prevent_default || WillHandleGestureEvent(gesture_event); | 995 prevent_default = prevent_default || WillHandleGestureEvent(gesture_event); |
994 } | 996 } |
995 | 997 |
996 if (input_event->type == WebInputEvent::TouchStart) | |
997 handling_touchstart_event_ = true; | |
998 | |
999 bool processed = prevent_default; | 998 bool processed = prevent_default; |
1000 if (input_event->type != WebInputEvent::Char || !suppress_next_char_events_) { | 999 if (input_event->type != WebInputEvent::Char || !suppress_next_char_events_) { |
1001 suppress_next_char_events_ = false; | 1000 suppress_next_char_events_ = false; |
1002 if (!processed && webwidget_) | 1001 if (!processed && webwidget_) |
1003 processed = webwidget_->handleInputEvent(*input_event); | 1002 processed = webwidget_->handleInputEvent(*input_event); |
1004 } | 1003 } |
1005 | 1004 |
1006 handling_touchstart_event_ = false; | |
1007 | |
1008 // If this RawKeyDown event corresponds to a browser keyboard shortcut and | 1005 // If this RawKeyDown event corresponds to a browser keyboard shortcut and |
1009 // it's not processed by webkit, then we need to suppress the upcoming Char | 1006 // it's not processed by webkit, then we need to suppress the upcoming Char |
1010 // events. | 1007 // events. |
1011 if (!processed && is_keyboard_shortcut) | 1008 if (!processed && is_keyboard_shortcut) |
1012 suppress_next_char_events_ = true; | 1009 suppress_next_char_events_ = true; |
1013 | 1010 |
1014 InputEventAckState ack_result = processed ? | 1011 InputEventAckState ack_result = processed ? |
1015 INPUT_EVENT_ACK_STATE_CONSUMED : INPUT_EVENT_ACK_STATE_NOT_CONSUMED; | 1012 INPUT_EVENT_ACK_STATE_CONSUMED : INPUT_EVENT_ACK_STATE_NOT_CONSUMED; |
1016 if (!processed && input_event->type == WebInputEvent::TouchStart) { | 1013 if (!processed && input_event->type == WebInputEvent::TouchStart) { |
1017 const WebTouchEvent& touch_event = | 1014 const WebTouchEvent& touch_event = |
(...skipping 28 matching lines...) Expand all Loading... | |
1046 if (base::TimeTicks::IsHighResNowFastAndReliable()) { | 1043 if (base::TimeTicks::IsHighResNowFastAndReliable()) { |
1047 base::TimeTicks end_time = base::TimeTicks::HighResNow(); | 1044 base::TimeTicks end_time = base::TimeTicks::HighResNow(); |
1048 total_input_handling_time_this_frame_ += (end_time - start_time); | 1045 total_input_handling_time_this_frame_ += (end_time - start_time); |
1049 rate_limiting_wanted = | 1046 rate_limiting_wanted = |
1050 total_input_handling_time_this_frame_.InMicroseconds() > | 1047 total_input_handling_time_this_frame_.InMicroseconds() > |
1051 kInputHandlingTimeThrottlingThresholdMicroseconds; | 1048 kInputHandlingTimeThrottlingThresholdMicroseconds; |
1052 } | 1049 } |
1053 | 1050 |
1054 TRACE_EVENT_SYNTHETIC_DELAY_END("blink.HandleInputEvent"); | 1051 TRACE_EVENT_SYNTHETIC_DELAY_END("blink.HandleInputEvent"); |
1055 | 1052 |
1056 if (!WebInputEventTraits::IgnoresAckDisposition(*input_event)) { | 1053 // Note that we can't use handling_event_type_ here since it will be overriden |
1054 // by reentrant calls for events after the paused one. | |
1055 bool no_ack = ignore_ack_for_mouse_move_from_debugger_ && | |
1056 input_event->type == WebInputEvent::MouseMove; | |
1057 if (!WebInputEventTraits::IgnoresAckDisposition(*input_event) && !no_ack) { | |
1057 scoped_ptr<IPC::Message> response( | 1058 scoped_ptr<IPC::Message> response( |
1058 new InputHostMsg_HandleInputEvent_ACK(routing_id_, | 1059 new InputHostMsg_HandleInputEvent_ACK(routing_id_, |
1059 input_event->type, | 1060 input_event->type, |
1060 ack_result, | 1061 ack_result, |
1061 swap_latency_info)); | 1062 swap_latency_info)); |
1062 if (rate_limiting_wanted && event_type_can_be_rate_limited && | 1063 if (rate_limiting_wanted && event_type_can_be_rate_limited && |
1063 frame_pending && !is_hidden_) { | 1064 frame_pending && !is_hidden_) { |
1064 // We want to rate limit the input events in this case, so we'll wait for | 1065 // We want to rate limit the input events in this case, so we'll wait for |
1065 // painting to finish before ACKing this message. | 1066 // painting to finish before ACKing this message. |
1066 TRACE_EVENT_INSTANT0("renderer", | 1067 TRACE_EVENT_INSTANT0("renderer", |
1067 "RenderWidget::OnHandleInputEvent ack throttled", | 1068 "RenderWidget::OnHandleInputEvent ack throttled", |
1068 TRACE_EVENT_SCOPE_THREAD); | 1069 TRACE_EVENT_SCOPE_THREAD); |
1069 if (pending_input_event_ack_) { | 1070 if (pending_input_event_ack_) { |
1070 // As two different kinds of events could cause us to postpone an ack | 1071 // As two different kinds of events could cause us to postpone an ack |
1071 // we send it now, if we have one pending. The Browser should never | 1072 // we send it now, if we have one pending. The Browser should never |
1072 // send us the same kind of event we are delaying the ack for. | 1073 // send us the same kind of event we are delaying the ack for. |
1073 Send(pending_input_event_ack_.release()); | 1074 Send(pending_input_event_ack_.release()); |
1074 } | 1075 } |
1075 pending_input_event_ack_ = response.Pass(); | 1076 pending_input_event_ack_ = response.Pass(); |
1076 if (compositor_) | 1077 if (compositor_) |
1077 compositor_->NotifyInputThrottledUntilCommit(); | 1078 compositor_->NotifyInputThrottledUntilCommit(); |
1078 } else { | 1079 } else { |
1079 Send(response.release()); | 1080 Send(response.release()); |
1080 } | 1081 } |
1081 } | 1082 } |
1083 ignore_ack_for_mouse_move_from_debugger_ = false; | |
1082 | 1084 |
1083 #if defined(OS_ANDROID) | 1085 #if defined(OS_ANDROID) |
1084 // Allow the IME to be shown when the focus changes as a consequence | 1086 // Allow the IME to be shown when the focus changes as a consequence |
1085 // of a processed touch end event. | 1087 // of a processed touch end event. |
1086 if (input_event->type == WebInputEvent::TouchEnd && processed) | 1088 if (input_event->type == WebInputEvent::TouchEnd && processed) |
1087 UpdateTextInputState(SHOW_IME_IF_NEEDED, FROM_NON_IME); | 1089 UpdateTextInputState(SHOW_IME_IF_NEEDED, FROM_NON_IME); |
1088 #elif defined(USE_AURA) | 1090 #elif defined(USE_AURA) |
1089 // Show the virtual keyboard if enabled and a user gesture triggers a focus | 1091 // Show the virtual keyboard if enabled and a user gesture triggers a focus |
1090 // change. | 1092 // change. |
1091 if (processed && (input_event->type == WebInputEvent::TouchEnd || | 1093 if (processed && (input_event->type == WebInputEvent::TouchEnd || |
1092 input_event->type == WebInputEvent::MouseUp)) | 1094 input_event->type == WebInputEvent::MouseUp)) |
1093 UpdateTextInputState(SHOW_IME_IF_NEEDED, FROM_IME); | 1095 UpdateTextInputState(SHOW_IME_IF_NEEDED, FROM_IME); |
1094 #endif | 1096 #endif |
1095 | 1097 |
1098 handling_event_type_ = WebInputEvent::Undefined; | |
1096 handling_input_event_ = false; | 1099 handling_input_event_ = false; |
1097 | 1100 |
1098 if (!prevent_default) { | 1101 if (!prevent_default) { |
1099 if (WebInputEvent::isKeyboardEventType(input_event->type)) | 1102 if (WebInputEvent::isKeyboardEventType(input_event->type)) |
1100 DidHandleKeyEvent(); | 1103 DidHandleKeyEvent(); |
1101 if (WebInputEvent::isMouseEventType(input_event->type)) | 1104 if (WebInputEvent::isMouseEventType(input_event->type)) |
1102 DidHandleMouseEvent(*(static_cast<const WebMouseEvent*>(input_event))); | 1105 DidHandleMouseEvent(*(static_cast<const WebMouseEvent*>(input_event))); |
1103 if (WebInputEvent::isTouchEventType(input_event->type)) | 1106 if (WebInputEvent::isTouchEventType(input_event->type)) |
1104 DidHandleTouchEvent(*(static_cast<const WebTouchEvent*>(input_event))); | 1107 DidHandleTouchEvent(*(static_cast<const WebTouchEvent*>(input_event))); |
1105 } | 1108 } |
(...skipping 403 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1509 #endif | 1512 #endif |
1510 | 1513 |
1511 bool RenderWidget::ShouldHandleImeEvent() { | 1514 bool RenderWidget::ShouldHandleImeEvent() { |
1512 #if defined(OS_ANDROID) | 1515 #if defined(OS_ANDROID) |
1513 return !!webwidget_ && outstanding_ime_acks_ == 0; | 1516 return !!webwidget_ && outstanding_ime_acks_ == 0; |
1514 #else | 1517 #else |
1515 return !!webwidget_; | 1518 return !!webwidget_; |
1516 #endif | 1519 #endif |
1517 } | 1520 } |
1518 | 1521 |
1522 bool RenderWidget::SendAckForMouseMoveFromDebugger() { | |
1523 if (handling_event_type_ == WebInputEvent::MouseMove) { | |
1524 Send(new InputHostMsg_HandleInputEvent_ACK(routing_id_, | |
1525 handling_event_type_, | |
1526 INPUT_EVENT_ACK_STATE_CONSUMED, | |
1527 ui::LatencyInfo())); | |
1528 return true; | |
1529 } | |
1530 return false; | |
1531 } | |
1532 | |
1533 void RenderWidget::IgnoreAckForMouseMoveFromDebugger() { | |
1534 ignore_ack_for_mouse_move_from_debugger_ = true; | |
1535 } | |
1536 | |
1519 void RenderWidget::SetDeviceScaleFactor(float device_scale_factor) { | 1537 void RenderWidget::SetDeviceScaleFactor(float device_scale_factor) { |
1520 if (device_scale_factor_ == device_scale_factor) | 1538 if (device_scale_factor_ == device_scale_factor) |
1521 return; | 1539 return; |
1522 | 1540 |
1523 device_scale_factor_ = device_scale_factor; | 1541 device_scale_factor_ = device_scale_factor; |
1524 scheduleComposite(); | 1542 scheduleComposite(); |
1525 } | 1543 } |
1526 | 1544 |
1527 void RenderWidget::OnOrientationChange() { | 1545 void RenderWidget::OnOrientationChange() { |
1528 } | 1546 } |
(...skipping 426 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1955 | 1973 |
1956 void RenderWidget::hasTouchEventHandlers(bool has_handlers) { | 1974 void RenderWidget::hasTouchEventHandlers(bool has_handlers) { |
1957 Send(new ViewHostMsg_HasTouchEventHandlers(routing_id_, has_handlers)); | 1975 Send(new ViewHostMsg_HasTouchEventHandlers(routing_id_, has_handlers)); |
1958 } | 1976 } |
1959 | 1977 |
1960 void RenderWidget::setTouchAction( | 1978 void RenderWidget::setTouchAction( |
1961 blink::WebTouchAction web_touch_action) { | 1979 blink::WebTouchAction web_touch_action) { |
1962 | 1980 |
1963 // Ignore setTouchAction calls that result from synthetic touch events (eg. | 1981 // Ignore setTouchAction calls that result from synthetic touch events (eg. |
1964 // when blink is emulating touch with mouse). | 1982 // when blink is emulating touch with mouse). |
1965 if (!handling_touchstart_event_) | 1983 if (!handling_event_type_ == WebInputEvent::TouchStart) |
jdduke (slow)
2014/05/19 15:10:37
|handling_event_type_ != WebInputEvent::TouchStart
dgozman
2014/05/20 08:54:13
Nice catch! Done.
| |
1966 return; | 1984 return; |
1967 | 1985 |
1968 // Verify the same values are used by the types so we can cast between them. | 1986 // Verify the same values are used by the types so we can cast between them. |
1969 COMPILE_ASSERT(static_cast<blink::WebTouchAction>(TOUCH_ACTION_AUTO) == | 1987 COMPILE_ASSERT(static_cast<blink::WebTouchAction>(TOUCH_ACTION_AUTO) == |
1970 blink::WebTouchActionAuto, | 1988 blink::WebTouchActionAuto, |
1971 enum_values_must_match_for_touch_action); | 1989 enum_values_must_match_for_touch_action); |
1972 COMPILE_ASSERT(static_cast<blink::WebTouchAction>(TOUCH_ACTION_NONE) == | 1990 COMPILE_ASSERT(static_cast<blink::WebTouchAction>(TOUCH_ACTION_NONE) == |
1973 blink::WebTouchActionNone, | 1991 blink::WebTouchActionNone, |
1974 enum_values_must_match_for_touch_action); | 1992 enum_values_must_match_for_touch_action); |
1975 COMPILE_ASSERT(static_cast<blink::WebTouchAction>(TOUCH_ACTION_PAN_X) == | 1993 COMPILE_ASSERT(static_cast<blink::WebTouchAction>(TOUCH_ACTION_PAN_X) == |
(...skipping 97 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
2073 | 2091 |
2074 void RenderWidget::RegisterSwappedOutChildFrame(RenderFrameImpl* frame) { | 2092 void RenderWidget::RegisterSwappedOutChildFrame(RenderFrameImpl* frame) { |
2075 swapped_out_frames_.AddObserver(frame); | 2093 swapped_out_frames_.AddObserver(frame); |
2076 } | 2094 } |
2077 | 2095 |
2078 void RenderWidget::UnregisterSwappedOutChildFrame(RenderFrameImpl* frame) { | 2096 void RenderWidget::UnregisterSwappedOutChildFrame(RenderFrameImpl* frame) { |
2079 swapped_out_frames_.RemoveObserver(frame); | 2097 swapped_out_frames_.RemoveObserver(frame); |
2080 } | 2098 } |
2081 | 2099 |
2082 } // namespace content | 2100 } // namespace content |
OLD | NEW |