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