| 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/browser/renderer_host/render_widget_host_impl.h" | 5 #include "content/browser/renderer_host/render_widget_host_impl.h" |
| 6 | 6 |
| 7 #include <math.h> | 7 #include <math.h> |
| 8 #include <utility> | 8 #include <utility> |
| 9 | 9 |
| 10 #include "base/auto_reset.h" | 10 #include "base/auto_reset.h" |
| (...skipping 149 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 160 ignore_input_events_(false), | 160 ignore_input_events_(false), |
| 161 text_direction_updated_(false), | 161 text_direction_updated_(false), |
| 162 text_direction_(WebKit::WebTextDirectionLeftToRight), | 162 text_direction_(WebKit::WebTextDirectionLeftToRight), |
| 163 text_direction_canceled_(false), | 163 text_direction_canceled_(false), |
| 164 suppress_next_char_events_(false), | 164 suppress_next_char_events_(false), |
| 165 pending_mouse_lock_request_(false), | 165 pending_mouse_lock_request_(false), |
| 166 allow_privileged_mouse_lock_(false), | 166 allow_privileged_mouse_lock_(false), |
| 167 has_touch_handler_(false), | 167 has_touch_handler_(false), |
| 168 weak_factory_(this), | 168 weak_factory_(this), |
| 169 touch_event_queue_(new TouchEventQueue(this)), | 169 touch_event_queue_(new TouchEventQueue(this)), |
| 170 gesture_event_filter_(new GestureEventFilter(this)) { | 170 gesture_event_filter_(new GestureEventFilter(this)), |
| 171 last_input_number_(0) { |
| 171 CHECK(delegate_); | 172 CHECK(delegate_); |
| 172 if (routing_id_ == MSG_ROUTING_NONE) { | 173 if (routing_id_ == MSG_ROUTING_NONE) { |
| 173 routing_id_ = process_->GetNextRoutingID(); | 174 routing_id_ = process_->GetNextRoutingID(); |
| 174 surface_id_ = GpuSurfaceTracker::Get()->AddSurfaceForRenderer( | 175 surface_id_ = GpuSurfaceTracker::Get()->AddSurfaceForRenderer( |
| 175 process_->GetID(), | 176 process_->GetID(), |
| 176 routing_id_); | 177 routing_id_); |
| 177 } else { | 178 } else { |
| 178 // TODO(piman): This is a O(N) lookup, where we could forward the | 179 // TODO(piman): This is a O(N) lookup, where we could forward the |
| 179 // information from the RenderWidgetHelper. The problem is that doing so | 180 // information from the RenderWidgetHelper. The problem is that doing so |
| 180 // currently leaks outside of content all the way to chrome classes, and | 181 // currently leaks outside of content all the way to chrome classes, and |
| (...skipping 731 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 912 WebInputEvent::GesturePinchEnd, mouse_event.timeStampSeconds, | 913 WebInputEvent::GesturePinchEnd, mouse_event.timeStampSeconds, |
| 913 x, y, 0)); | 914 x, y, 0)); |
| 914 } | 915 } |
| 915 break; | 916 break; |
| 916 case WebMouseEvent::ButtonNone: | 917 case WebMouseEvent::ButtonNone: |
| 917 break; | 918 break; |
| 918 } | 919 } |
| 919 } | 920 } |
| 920 | 921 |
| 921 void RenderWidgetHostImpl::ForwardMouseEvent(const WebMouseEvent& mouse_event) { | 922 void RenderWidgetHostImpl::ForwardMouseEvent(const WebMouseEvent& mouse_event) { |
| 922 TRACE_EVENT2("renderer_host", "RenderWidgetHostImpl::ForwardMouseEvent", | 923 ForwardMouseEventWithLatencyInfo( |
| 923 "x", mouse_event.x, "y", mouse_event.y); | 924 MouseEventWithLatencyInfo(mouse_event, NewInputLatencyInfo())); |
| 925 } |
| 926 |
| 927 void RenderWidgetHostImpl::ForwardMouseEventWithLatencyInfo( |
| 928 const MouseEventWithLatencyInfo& mouse_event) { |
| 929 TRACE_EVENT2("renderer_host", |
| 930 "RenderWidgetHostImpl::ForwardMouseEventWithLatencyInfo", |
| 931 "x", mouse_event.event.x, "y", mouse_event.event.y); |
| 924 if (ignore_input_events_ || process_->IgnoreInputEvents()) | 932 if (ignore_input_events_ || process_->IgnoreInputEvents()) |
| 925 return; | 933 return; |
| 926 | 934 |
| 927 if (CommandLine::ForCurrentProcess()->HasSwitch( | 935 if (CommandLine::ForCurrentProcess()->HasSwitch( |
| 928 switches::kSimulateTouchScreenWithMouse)) { | 936 switches::kSimulateTouchScreenWithMouse)) { |
| 929 SimulateTouchGestureWithMouse(mouse_event); | 937 SimulateTouchGestureWithMouse(mouse_event.event); |
| 930 return; | 938 return; |
| 931 } | 939 } |
| 932 | 940 |
| 933 if (mouse_event.type == WebInputEvent::MouseDown && | 941 if (mouse_event.event.type == WebInputEvent::MouseDown && |
| 934 gesture_event_filter_->GetTouchpadTapSuppressionController()-> | 942 gesture_event_filter_->GetTouchpadTapSuppressionController()-> |
| 935 ShouldDeferMouseDown(mouse_event)) | 943 ShouldDeferMouseDown(mouse_event)) |
| 936 return; | 944 return; |
| 937 if (mouse_event.type == WebInputEvent::MouseUp && | 945 if (mouse_event.event.type == WebInputEvent::MouseUp && |
| 938 gesture_event_filter_->GetTouchpadTapSuppressionController()-> | 946 gesture_event_filter_->GetTouchpadTapSuppressionController()-> |
| 939 ShouldSuppressMouseUp()) | 947 ShouldSuppressMouseUp()) |
| 940 return; | 948 return; |
| 941 | 949 |
| 942 ForwardMouseEventImmediately(mouse_event); | 950 ForwardMouseEventImmediately(mouse_event); |
| 943 } | 951 } |
| 944 | 952 |
| 945 void RenderWidgetHostImpl::OnPointerEventActivate() { | 953 void RenderWidgetHostImpl::OnPointerEventActivate() { |
| 946 } | 954 } |
| 947 | 955 |
| 948 void RenderWidgetHostImpl::ForwardWheelEvent( | 956 void RenderWidgetHostImpl::ForwardWheelEvent( |
| 949 const WebMouseWheelEvent& wheel_event) { | 957 const WebMouseWheelEvent& wheel_event) { |
| 950 TRACE_EVENT0("renderer_host", "RenderWidgetHostImpl::ForwardWheelEvent"); | 958 ForwardWheelEventWithLatencyInfo(wheel_event, NewInputLatencyInfo()); |
| 959 } |
| 960 |
| 961 void RenderWidgetHostImpl::ForwardWheelEventWithLatencyInfo( |
| 962 const WebMouseWheelEvent& wheel_event, |
| 963 const cc::LatencyInfo& latency_info) { |
| 964 TRACE_EVENT0("renderer_host", |
| 965 "RenderWidgetHostImpl::ForwardWheelEventWithLatencyInfo"); |
| 951 if (ignore_input_events_ || process_->IgnoreInputEvents()) | 966 if (ignore_input_events_ || process_->IgnoreInputEvents()) |
| 952 return; | 967 return; |
| 953 | 968 |
| 954 if (delegate_->PreHandleWheelEvent(wheel_event)) | 969 if (delegate_->PreHandleWheelEvent(wheel_event)) |
| 955 return; | 970 return; |
| 956 | 971 |
| 957 // If there's already a mouse wheel event waiting to be sent to the renderer, | 972 // If there's already a mouse wheel event waiting to be sent to the renderer, |
| 958 // add the new deltas to that event. Not doing so (e.g., by dropping the old | 973 // add the new deltas to that event. Not doing so (e.g., by dropping the old |
| 959 // event, as for mouse moves) results in very slow scrolling on the Mac (on | 974 // event, as for mouse moves) results in very slow scrolling on the Mac (on |
| 960 // which many, very small wheel events are sent). | 975 // which many, very small wheel events are sent). |
| 961 if (mouse_wheel_pending_) { | 976 if (mouse_wheel_pending_) { |
| 962 if (coalesced_mouse_wheel_events_.empty() || | 977 if (coalesced_mouse_wheel_events_.empty() || |
| 963 !ShouldCoalesceMouseWheelEvents(coalesced_mouse_wheel_events_.back(), | 978 !ShouldCoalesceMouseWheelEvents( |
| 964 wheel_event)) { | 979 coalesced_mouse_wheel_events_.back().event, wheel_event)) { |
| 965 coalesced_mouse_wheel_events_.push_back(wheel_event); | 980 coalesced_mouse_wheel_events_.push_back( |
| 981 MouseWheelEventWithLatencyInfo(wheel_event, latency_info)); |
| 966 } else { | 982 } else { |
| 967 WebMouseWheelEvent* last_wheel_event = | 983 MouseWheelEventWithLatencyInfo* last_wheel_event = |
| 968 &coalesced_mouse_wheel_events_.back(); | 984 &coalesced_mouse_wheel_events_.back(); |
| 969 float unaccelerated_x = | 985 float unaccelerated_x = |
| 970 GetUnacceleratedDelta(last_wheel_event->deltaX, | 986 GetUnacceleratedDelta(last_wheel_event->event.deltaX, |
| 971 last_wheel_event->accelerationRatioX) + | 987 last_wheel_event->event.accelerationRatioX) + |
| 972 GetUnacceleratedDelta(wheel_event.deltaX, | 988 GetUnacceleratedDelta(wheel_event.deltaX, |
| 973 wheel_event.accelerationRatioX); | 989 wheel_event.accelerationRatioX); |
| 974 float unaccelerated_y = | 990 float unaccelerated_y = |
| 975 GetUnacceleratedDelta(last_wheel_event->deltaY, | 991 GetUnacceleratedDelta(last_wheel_event->event.deltaY, |
| 976 last_wheel_event->accelerationRatioY) + | 992 last_wheel_event->event.accelerationRatioY) + |
| 977 GetUnacceleratedDelta(wheel_event.deltaY, | 993 GetUnacceleratedDelta(wheel_event.deltaY, |
| 978 wheel_event.accelerationRatioY); | 994 wheel_event.accelerationRatioY); |
| 979 last_wheel_event->deltaX += wheel_event.deltaX; | 995 last_wheel_event->event.deltaX += wheel_event.deltaX; |
| 980 last_wheel_event->deltaY += wheel_event.deltaY; | 996 last_wheel_event->event.deltaY += wheel_event.deltaY; |
| 981 last_wheel_event->wheelTicksX += wheel_event.wheelTicksX; | 997 last_wheel_event->event.wheelTicksX += wheel_event.wheelTicksX; |
| 982 last_wheel_event->wheelTicksY += wheel_event.wheelTicksY; | 998 last_wheel_event->event.wheelTicksY += wheel_event.wheelTicksY; |
| 983 last_wheel_event->accelerationRatioX = | 999 last_wheel_event->event.accelerationRatioX = |
| 984 GetAccelerationRatio(last_wheel_event->deltaX, unaccelerated_x); | 1000 GetAccelerationRatio(last_wheel_event->event.deltaX, unaccelerated_x); |
| 985 last_wheel_event->accelerationRatioY = | 1001 last_wheel_event->event.accelerationRatioY = |
| 986 GetAccelerationRatio(last_wheel_event->deltaY, unaccelerated_y); | 1002 GetAccelerationRatio(last_wheel_event->event.deltaY, unaccelerated_y); |
| 987 DCHECK_GE(wheel_event.timeStampSeconds, | 1003 DCHECK_GE(wheel_event.timeStampSeconds, |
| 988 last_wheel_event->timeStampSeconds); | 1004 last_wheel_event->event.timeStampSeconds); |
| 989 last_wheel_event->timeStampSeconds = wheel_event.timeStampSeconds; | 1005 last_wheel_event->event.timeStampSeconds = wheel_event.timeStampSeconds; |
| 1006 last_wheel_event->latency.MergeWith(latency_info); |
| 990 } | 1007 } |
| 991 return; | 1008 return; |
| 992 } | 1009 } |
| 993 mouse_wheel_pending_ = true; | 1010 mouse_wheel_pending_ = true; |
| 994 current_wheel_event_ = wheel_event; | 1011 current_wheel_event_ = wheel_event; |
| 995 | 1012 |
| 996 HISTOGRAM_COUNTS_100("MPArch.RWH_WheelQueueSize", | 1013 HISTOGRAM_COUNTS_100("MPArch.RWH_WheelQueueSize", |
| 997 coalesced_mouse_wheel_events_.size()); | 1014 coalesced_mouse_wheel_events_.size()); |
| 998 | 1015 |
| 999 ForwardInputEvent(wheel_event, sizeof(WebMouseWheelEvent), false); | 1016 ForwardInputEvent(wheel_event, sizeof(WebMouseWheelEvent), latency_info, |
| 1017 false); |
| 1000 } | 1018 } |
| 1001 | 1019 |
| 1002 void RenderWidgetHostImpl::ForwardGestureEvent( | 1020 void RenderWidgetHostImpl::ForwardGestureEvent( |
| 1003 const WebKit::WebGestureEvent& gesture_event) { | 1021 const WebKit::WebGestureEvent& gesture_event) { |
| 1004 TRACE_EVENT0("renderer_host", "RenderWidgetHostImpl::ForwardGestureEvent"); | 1022 TRACE_EVENT0("renderer_host", "RenderWidgetHostImpl::ForwardGestureEvent"); |
| 1005 if (ignore_input_events_ || process_->IgnoreInputEvents()) | 1023 if (ignore_input_events_ || process_->IgnoreInputEvents()) |
| 1006 return; | 1024 return; |
| 1007 | 1025 |
| 1026 cc::LatencyInfo latency_info = NewInputLatencyInfo(); |
| 1027 |
| 1008 if (!IsInOverscrollGesture() && | 1028 if (!IsInOverscrollGesture() && |
| 1009 !gesture_event_filter_->ShouldForward(gesture_event)) | 1029 !gesture_event_filter_->ShouldForward( |
| 1030 GestureEventWithLatencyInfo(gesture_event, latency_info))) |
| 1010 return; | 1031 return; |
| 1011 | 1032 |
| 1012 ForwardInputEvent(gesture_event, sizeof(WebGestureEvent), false); | 1033 ForwardInputEvent(gesture_event, sizeof(WebGestureEvent), |
| 1034 latency_info, false); |
| 1013 } | 1035 } |
| 1014 | 1036 |
| 1015 // Forwards MouseEvent without passing it through | 1037 // Forwards MouseEvent without passing it through |
| 1016 // TouchpadTapSuppressionController. | 1038 // TouchpadTapSuppressionController. |
| 1017 void RenderWidgetHostImpl::ForwardMouseEventImmediately( | 1039 void RenderWidgetHostImpl::ForwardMouseEventImmediately( |
| 1018 const WebMouseEvent& mouse_event) { | 1040 const MouseEventWithLatencyInfo& mouse_event) { |
| 1019 TRACE_EVENT2("renderer_host", | 1041 TRACE_EVENT2("renderer_host", |
| 1020 "RenderWidgetHostImpl::ForwardMouseEventImmediately", | 1042 "RenderWidgetHostImpl::ForwardMouseEventImmediately", |
| 1021 "x", mouse_event.x, "y", mouse_event.y); | 1043 "x", mouse_event.event.x, "y", mouse_event.event.y); |
| 1022 if (ignore_input_events_ || process_->IgnoreInputEvents()) | 1044 if (ignore_input_events_ || process_->IgnoreInputEvents()) |
| 1023 return; | 1045 return; |
| 1024 | 1046 |
| 1025 if (CommandLine::ForCurrentProcess()->HasSwitch( | 1047 if (CommandLine::ForCurrentProcess()->HasSwitch( |
| 1026 switches::kSimulateTouchScreenWithMouse)) { | 1048 switches::kSimulateTouchScreenWithMouse)) { |
| 1027 SimulateTouchGestureWithMouse(mouse_event); | 1049 SimulateTouchGestureWithMouse(mouse_event.event); |
| 1028 return; | 1050 return; |
| 1029 } | 1051 } |
| 1030 | 1052 |
| 1031 // Avoid spamming the renderer with mouse move events. It is important | 1053 // Avoid spamming the renderer with mouse move events. It is important |
| 1032 // to note that WM_MOUSEMOVE events are anyways synthetic, but since our | 1054 // to note that WM_MOUSEMOVE events are anyways synthetic, but since our |
| 1033 // thread is able to rapidly consume WM_MOUSEMOVE events, we may get way | 1055 // thread is able to rapidly consume WM_MOUSEMOVE events, we may get way |
| 1034 // more WM_MOUSEMOVE events than we wish to send to the renderer. | 1056 // more WM_MOUSEMOVE events than we wish to send to the renderer. |
| 1035 if (mouse_event.type == WebInputEvent::MouseMove) { | 1057 if (mouse_event.event.type == WebInputEvent::MouseMove) { |
| 1036 if (mouse_move_pending_) { | 1058 if (mouse_move_pending_) { |
| 1037 if (!next_mouse_move_) { | 1059 if (!next_mouse_move_) { |
| 1038 next_mouse_move_.reset(new WebMouseEvent(mouse_event)); | 1060 next_mouse_move_.reset(new MouseEventWithLatencyInfo(mouse_event)); |
| 1039 } else { | 1061 } else { |
| 1040 // Accumulate movement deltas. | 1062 // Accumulate movement deltas. |
| 1041 int x = next_mouse_move_->movementX; | 1063 int x = next_mouse_move_->event.movementX; |
| 1042 int y = next_mouse_move_->movementY; | 1064 int y = next_mouse_move_->event.movementY; |
| 1043 *next_mouse_move_ = mouse_event; | 1065 next_mouse_move_->event = mouse_event.event; |
| 1044 next_mouse_move_->movementX += x; | 1066 next_mouse_move_->event.movementX += x; |
| 1045 next_mouse_move_->movementY += y; | 1067 next_mouse_move_->event.movementY += y; |
| 1068 next_mouse_move_->latency.MergeWith(mouse_event.latency); |
| 1046 } | 1069 } |
| 1047 return; | 1070 return; |
| 1048 } | 1071 } |
| 1049 mouse_move_pending_ = true; | 1072 mouse_move_pending_ = true; |
| 1050 } else if (mouse_event.type == WebInputEvent::MouseDown) { | 1073 } else if (mouse_event.event.type == WebInputEvent::MouseDown) { |
| 1051 OnUserGesture(); | 1074 OnUserGesture(); |
| 1052 } | 1075 } |
| 1053 | 1076 |
| 1054 ForwardInputEvent(mouse_event, sizeof(WebMouseEvent), false); | 1077 ForwardInputEvent(mouse_event.event, sizeof(WebMouseEvent), |
| 1078 mouse_event.latency, false); |
| 1055 } | 1079 } |
| 1056 | 1080 |
| 1057 void RenderWidgetHostImpl::ForwardTouchEventImmediately( | 1081 void RenderWidgetHostImpl::ForwardTouchEventImmediately( |
| 1058 const WebKit::WebTouchEvent& touch_event) { | 1082 const WebKit::WebTouchEvent& touch_event) { |
| 1059 TRACE_EVENT0("renderer_host", "RenderWidgetHostImpl::ForwardTouchEvent"); | 1083 TRACE_EVENT0("renderer_host", "RenderWidgetHostImpl::ForwardTouchEvent"); |
| 1060 if (ignore_input_events_ || process_->IgnoreInputEvents()) | 1084 if (ignore_input_events_ || process_->IgnoreInputEvents()) |
| 1061 return; | 1085 return; |
| 1062 | 1086 |
| 1063 ForwardInputEvent(touch_event, sizeof(WebKit::WebTouchEvent), false); | 1087 ForwardInputEvent(touch_event, sizeof(WebKit::WebTouchEvent), |
| 1088 NewInputLatencyInfo(), false); |
| 1064 } | 1089 } |
| 1065 | 1090 |
| 1066 void RenderWidgetHostImpl::ForwardGestureEventImmediately( | 1091 void RenderWidgetHostImpl::ForwardGestureEventImmediately( |
| 1067 const WebKit::WebGestureEvent& gesture_event) { | 1092 const GestureEventWithLatencyInfo& gesture_event) { |
| 1068 if (ignore_input_events_ || process_->IgnoreInputEvents()) | 1093 if (ignore_input_events_ || process_->IgnoreInputEvents()) |
| 1069 return; | 1094 return; |
| 1070 ForwardInputEvent(gesture_event, sizeof(WebGestureEvent), false); | 1095 ForwardInputEvent(gesture_event.event, sizeof(WebGestureEvent), |
| 1096 gesture_event.latency, false); |
| 1071 } | 1097 } |
| 1072 | 1098 |
| 1073 void RenderWidgetHostImpl::ForwardKeyboardEvent( | 1099 void RenderWidgetHostImpl::ForwardKeyboardEvent( |
| 1074 const NativeWebKeyboardEvent& key_event) { | 1100 const NativeWebKeyboardEvent& key_event) { |
| 1075 TRACE_EVENT0("renderer_host", "RenderWidgetHostImpl::ForwardKeyboardEvent"); | 1101 TRACE_EVENT0("renderer_host", "RenderWidgetHostImpl::ForwardKeyboardEvent"); |
| 1076 if (ignore_input_events_ || process_->IgnoreInputEvents()) | 1102 if (ignore_input_events_ || process_->IgnoreInputEvents()) |
| 1077 return; | 1103 return; |
| 1078 | 1104 |
| 1079 // First, let keypress listeners take a shot at handling the event. If a | 1105 // First, let keypress listeners take a shot at handling the event. If a |
| 1080 // listener handles the event, it should not be propagated to the renderer. | 1106 // listener handles the event, it should not be propagated to the renderer. |
| (...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1132 // Put all WebKeyboardEvent objects in a queue since we can't trust the | 1158 // Put all WebKeyboardEvent objects in a queue since we can't trust the |
| 1133 // renderer and we need to give something to the HandleKeyboardEvent | 1159 // renderer and we need to give something to the HandleKeyboardEvent |
| 1134 // handler. | 1160 // handler. |
| 1135 key_queue_.push_back(key_event); | 1161 key_queue_.push_back(key_event); |
| 1136 HISTOGRAM_COUNTS_100("Renderer.KeyboardQueueSize", key_queue_.size()); | 1162 HISTOGRAM_COUNTS_100("Renderer.KeyboardQueueSize", key_queue_.size()); |
| 1137 | 1163 |
| 1138 gesture_event_filter_->FlingHasBeenHalted(); | 1164 gesture_event_filter_->FlingHasBeenHalted(); |
| 1139 | 1165 |
| 1140 // Only forward the non-native portions of our event. | 1166 // Only forward the non-native portions of our event. |
| 1141 ForwardInputEvent(key_event, sizeof(WebKeyboardEvent), | 1167 ForwardInputEvent(key_event, sizeof(WebKeyboardEvent), |
| 1168 NewInputLatencyInfo(), |
| 1142 is_keyboard_shortcut); | 1169 is_keyboard_shortcut); |
| 1143 } | 1170 } |
| 1144 } | 1171 } |
| 1145 | 1172 |
| 1146 void RenderWidgetHostImpl::SendCursorVisibilityState(bool is_visible) { | 1173 void RenderWidgetHostImpl::SendCursorVisibilityState(bool is_visible) { |
| 1147 Send(new InputMsg_CursorVisibilityChange(GetRoutingID(), is_visible)); | 1174 Send(new InputMsg_CursorVisibilityChange(GetRoutingID(), is_visible)); |
| 1148 } | 1175 } |
| 1149 | 1176 |
| 1177 int64 RenderWidgetHostImpl::GetLatencyComponentId() { |
| 1178 return GetRoutingID() | (static_cast<int64>(GetProcess()->GetID()) << 32); |
| 1179 } |
| 1180 |
| 1181 cc::LatencyInfo RenderWidgetHostImpl::NewInputLatencyInfo() { |
| 1182 cc::LatencyInfo info; |
| 1183 info.AddLatencyNumber( |
| 1184 cc::kInputEvent, GetLatencyComponentId(), ++last_input_number_); |
| 1185 return info; |
| 1186 } |
| 1187 |
| 1150 void RenderWidgetHostImpl::SendInputEvent(const WebInputEvent& input_event, | 1188 void RenderWidgetHostImpl::SendInputEvent(const WebInputEvent& input_event, |
| 1151 int event_size, | 1189 int event_size, |
| 1190 const cc::LatencyInfo& latency_info, |
| 1152 bool is_keyboard_shortcut) { | 1191 bool is_keyboard_shortcut) { |
| 1153 input_event_start_time_ = TimeTicks::Now(); | 1192 input_event_start_time_ = TimeTicks::Now(); |
| 1154 Send(new InputMsg_HandleInputEvent( | 1193 Send(new InputMsg_HandleInputEvent( |
| 1155 routing_id_, &input_event, is_keyboard_shortcut)); | 1194 routing_id_, &input_event, latency_info, is_keyboard_shortcut)); |
| 1156 increment_in_flight_event_count(); | 1195 increment_in_flight_event_count(); |
| 1157 } | 1196 } |
| 1158 | 1197 |
| 1159 void RenderWidgetHostImpl::ForwardInputEvent(const WebInputEvent& input_event, | 1198 void RenderWidgetHostImpl::ForwardInputEvent( |
| 1160 int event_size, | 1199 const WebInputEvent& input_event, int event_size, |
| 1161 bool is_keyboard_shortcut) { | 1200 const cc::LatencyInfo& latency_info, bool is_keyboard_shortcut) { |
| 1162 TRACE_EVENT0("renderer_host", "RenderWidgetHostImpl::ForwardInputEvent"); | 1201 TRACE_EVENT0("renderer_host", "RenderWidgetHostImpl::ForwardInputEvent"); |
| 1163 | 1202 |
| 1164 if (!process_->HasConnection()) | 1203 if (!process_->HasConnection()) |
| 1165 return; | 1204 return; |
| 1166 | 1205 |
| 1167 DCHECK(!process_->IgnoreInputEvents()); | 1206 DCHECK(!process_->IgnoreInputEvents()); |
| 1168 | 1207 |
| 1169 if (overscroll_controller_.get() && | 1208 if (overscroll_controller_.get() && |
| 1170 !overscroll_controller_->WillDispatchEvent(input_event)) { | 1209 !overscroll_controller_->WillDispatchEvent(input_event, latency_info)) { |
| 1171 // Reset the wheel-event state when appropriate. | 1210 // Reset the wheel-event state when appropriate. |
| 1172 if (input_event.type == WebKit::WebInputEvent::MouseWheel) { | 1211 if (input_event.type == WebKit::WebInputEvent::MouseWheel) { |
| 1173 mouse_wheel_pending_ = false; | 1212 mouse_wheel_pending_ = false; |
| 1174 } else if (WebInputEvent::isGestureEventType(input_event.type) && | 1213 } else if (WebInputEvent::isGestureEventType(input_event.type) && |
| 1175 gesture_event_filter_->HasQueuedGestureEvents()) { | 1214 gesture_event_filter_->HasQueuedGestureEvents()) { |
| 1176 // If the gesture-event filter has queued gesture events, that implies it | 1215 // If the gesture-event filter has queued gesture events, that implies it |
| 1177 // is awaiting an ack for the event. Since the event is being consumed by | 1216 // is awaiting an ack for the event. Since the event is being consumed by |
| 1178 // the over scroll here, it is never sent to the renderer, and so it won't | 1217 // the over scroll here, it is never sent to the renderer, and so it won't |
| 1179 // receive any ACKs. So send the ACK to the gesture event filter | 1218 // receive any ACKs. So send the ACK to the gesture event filter |
| 1180 // immediately, and mark it as having been processed. | 1219 // immediately, and mark it as having been processed. |
| (...skipping 10 matching lines...) Expand all Loading... |
| 1191 return; | 1230 return; |
| 1192 } | 1231 } |
| 1193 | 1232 |
| 1194 in_process_event_types_.push(input_event.type); | 1233 in_process_event_types_.push(input_event.type); |
| 1195 | 1234 |
| 1196 // Transmit any pending wheel events on a non-wheel event. This ensures that | 1235 // Transmit any pending wheel events on a non-wheel event. This ensures that |
| 1197 // the renderer receives the final PhaseEnded wheel event, which is necessary | 1236 // the renderer receives the final PhaseEnded wheel event, which is necessary |
| 1198 // to terminate rubber-banding, for example. | 1237 // to terminate rubber-banding, for example. |
| 1199 if (input_event.type != WebInputEvent::MouseWheel) { | 1238 if (input_event.type != WebInputEvent::MouseWheel) { |
| 1200 for (size_t i = 0; i < coalesced_mouse_wheel_events_.size(); ++i) { | 1239 for (size_t i = 0; i < coalesced_mouse_wheel_events_.size(); ++i) { |
| 1201 SendInputEvent(coalesced_mouse_wheel_events_[i], | 1240 SendInputEvent(coalesced_mouse_wheel_events_[i].event, |
| 1202 sizeof(WebMouseWheelEvent), false); | 1241 sizeof(WebMouseWheelEvent), |
| 1242 coalesced_mouse_wheel_events_[i].latency, |
| 1243 false); |
| 1203 } | 1244 } |
| 1204 coalesced_mouse_wheel_events_.clear(); | 1245 coalesced_mouse_wheel_events_.clear(); |
| 1205 } | 1246 } |
| 1206 | 1247 |
| 1207 if (view_) { | 1248 if (view_) { |
| 1208 // Perform optional, synchronous event handling, sending ACK messages for | 1249 // Perform optional, synchronous event handling, sending ACK messages for |
| 1209 // processed events, or proceeding as usual. | 1250 // processed events, or proceeding as usual. |
| 1210 InputEventAckState filter_ack = view_->FilterInputEvent(input_event); | 1251 InputEventAckState filter_ack = view_->FilterInputEvent(input_event); |
| 1211 switch (filter_ack) { | 1252 switch (filter_ack) { |
| 1212 // Send the ACK and early exit. | 1253 // Send the ACK and early exit. |
| 1213 case INPUT_EVENT_ACK_STATE_CONSUMED: | 1254 case INPUT_EVENT_ACK_STATE_CONSUMED: |
| 1214 case INPUT_EVENT_ACK_STATE_NO_CONSUMER_EXISTS: | 1255 case INPUT_EVENT_ACK_STATE_NO_CONSUMER_EXISTS: |
| 1215 next_mouse_move_.reset(); | 1256 next_mouse_move_.reset(); |
| 1216 OnInputEventAck(input_event.type, filter_ack); | 1257 OnInputEventAck(input_event.type, filter_ack); |
| 1217 // WARNING: |this| may be deleted at this point. | 1258 // WARNING: |this| may be deleted at this point. |
| 1218 return; | 1259 return; |
| 1219 | 1260 |
| 1220 // Proceed as normal. | 1261 // Proceed as normal. |
| 1221 case INPUT_EVENT_ACK_STATE_UNKNOWN: | 1262 case INPUT_EVENT_ACK_STATE_UNKNOWN: |
| 1222 case INPUT_EVENT_ACK_STATE_NOT_CONSUMED: | 1263 case INPUT_EVENT_ACK_STATE_NOT_CONSUMED: |
| 1223 default: | 1264 default: |
| 1224 break; | 1265 break; |
| 1225 }; | 1266 }; |
| 1226 } | 1267 } |
| 1227 | 1268 |
| 1228 SendInputEvent(input_event, event_size, is_keyboard_shortcut); | 1269 SendInputEvent(input_event, event_size, latency_info, is_keyboard_shortcut); |
| 1229 | 1270 |
| 1230 // Any input event cancels a pending mouse move event. Note that | 1271 // Any input event cancels a pending mouse move event. Note that |
| 1231 // |next_mouse_move_| possibly owns |input_event|, so don't use |input_event| | 1272 // |next_mouse_move_| possibly owns |input_event|, so don't use |input_event| |
| 1232 // after this line. | 1273 // after this line. |
| 1233 next_mouse_move_.reset(); | 1274 next_mouse_move_.reset(); |
| 1234 | 1275 |
| 1235 StartHangMonitorTimeout( | 1276 StartHangMonitorTimeout( |
| 1236 TimeDelta::FromMilliseconds(hung_renderer_delay_ms_)); | 1277 TimeDelta::FromMilliseconds(hung_renderer_delay_ms_)); |
| 1237 } | 1278 } |
| 1238 | 1279 |
| (...skipping 583 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1822 | 1863 |
| 1823 int type = static_cast<int>(event_type); | 1864 int type = static_cast<int>(event_type); |
| 1824 if (type < WebInputEvent::Undefined) { | 1865 if (type < WebInputEvent::Undefined) { |
| 1825 RecordAction(UserMetricsAction("BadMessageTerminate_RWH2")); | 1866 RecordAction(UserMetricsAction("BadMessageTerminate_RWH2")); |
| 1826 process_->ReceivedBadMessage(); | 1867 process_->ReceivedBadMessage(); |
| 1827 } else if (type == WebInputEvent::MouseMove) { | 1868 } else if (type == WebInputEvent::MouseMove) { |
| 1828 mouse_move_pending_ = false; | 1869 mouse_move_pending_ = false; |
| 1829 | 1870 |
| 1830 // now, we can send the next mouse move event | 1871 // now, we can send the next mouse move event |
| 1831 if (next_mouse_move_) { | 1872 if (next_mouse_move_) { |
| 1832 DCHECK(next_mouse_move_->type == WebInputEvent::MouseMove); | 1873 DCHECK(next_mouse_move_->event.type == WebInputEvent::MouseMove); |
| 1833 ForwardMouseEvent(*next_mouse_move_); | 1874 ForwardMouseEventWithLatencyInfo(*next_mouse_move_); |
| 1834 } | 1875 } |
| 1835 } else if (WebInputEvent::isKeyboardEventType(type)) { | 1876 } else if (WebInputEvent::isKeyboardEventType(type)) { |
| 1836 ProcessKeyboardEventAck(type, processed); | 1877 ProcessKeyboardEventAck(type, processed); |
| 1837 } else if (type == WebInputEvent::MouseWheel) { | 1878 } else if (type == WebInputEvent::MouseWheel) { |
| 1838 ProcessWheelAck(processed); | 1879 ProcessWheelAck(processed); |
| 1839 } else if (WebInputEvent::isTouchEventType(type)) { | 1880 } else if (WebInputEvent::isTouchEventType(type)) { |
| 1840 ProcessTouchAck(ack_result); | 1881 ProcessTouchAck(ack_result); |
| 1841 } else if (WebInputEvent::isGestureEventType(type)) { | 1882 } else if (WebInputEvent::isGestureEventType(type)) { |
| 1842 ProcessGestureAck(processed, type); | 1883 ProcessGestureAck(processed, type); |
| 1843 } | 1884 } |
| (...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1881 } | 1922 } |
| 1882 | 1923 |
| 1883 void RenderWidgetHostImpl::ProcessWheelAck(bool processed) { | 1924 void RenderWidgetHostImpl::ProcessWheelAck(bool processed) { |
| 1884 mouse_wheel_pending_ = false; | 1925 mouse_wheel_pending_ = false; |
| 1885 | 1926 |
| 1886 if (overscroll_controller_) | 1927 if (overscroll_controller_) |
| 1887 overscroll_controller_->ReceivedEventACK(current_wheel_event_, processed); | 1928 overscroll_controller_->ReceivedEventACK(current_wheel_event_, processed); |
| 1888 | 1929 |
| 1889 // Now send the next (coalesced) mouse wheel event. | 1930 // Now send the next (coalesced) mouse wheel event. |
| 1890 if (!coalesced_mouse_wheel_events_.empty()) { | 1931 if (!coalesced_mouse_wheel_events_.empty()) { |
| 1891 WebMouseWheelEvent next_wheel_event = | 1932 MouseWheelEventWithLatencyInfo next_wheel_event = |
| 1892 coalesced_mouse_wheel_events_.front(); | 1933 coalesced_mouse_wheel_events_.front(); |
| 1893 coalesced_mouse_wheel_events_.pop_front(); | 1934 coalesced_mouse_wheel_events_.pop_front(); |
| 1894 ForwardWheelEvent(next_wheel_event); | 1935 ForwardWheelEventWithLatencyInfo(next_wheel_event.event, |
| 1936 next_wheel_event.latency); |
| 1895 } | 1937 } |
| 1896 | 1938 |
| 1897 if (!processed && !is_hidden_ && view_) | 1939 if (!processed && !is_hidden_ && view_) |
| 1898 view_->UnhandledWheelEvent(current_wheel_event_); | 1940 view_->UnhandledWheelEvent(current_wheel_event_); |
| 1899 } | 1941 } |
| 1900 | 1942 |
| 1901 void RenderWidgetHostImpl::ProcessGestureAck(bool processed, int type) { | 1943 void RenderWidgetHostImpl::ProcessGestureAck(bool processed, int type) { |
| 1902 if (overscroll_controller_) { | 1944 if (overscroll_controller_) { |
| 1903 overscroll_controller_->ReceivedEventACK( | 1945 overscroll_controller_->ReceivedEventACK( |
| 1904 gesture_event_filter_->GetGestureEventAwaitingAck(), processed); | 1946 gesture_event_filter_->GetGestureEventAwaitingAck(), processed); |
| (...skipping 493 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2398 if (!should_auto_resize_) | 2440 if (!should_auto_resize_) |
| 2399 return; | 2441 return; |
| 2400 | 2442 |
| 2401 OnRenderAutoResized(new_size); | 2443 OnRenderAutoResized(new_size); |
| 2402 } | 2444 } |
| 2403 | 2445 |
| 2404 void RenderWidgetHostImpl::DetachDelegate() { | 2446 void RenderWidgetHostImpl::DetachDelegate() { |
| 2405 delegate_ = NULL; | 2447 delegate_ = NULL; |
| 2406 } | 2448 } |
| 2407 | 2449 |
| 2450 void RenderWidgetHostImpl::FrameSwapped(const cc::LatencyInfo& latency_info) { |
| 2451 } |
| 2452 |
| 2408 } // namespace content | 2453 } // namespace content |
| OLD | NEW |