Chromium Code Reviews| 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 153 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 164 text_direction_updated_(false), | 164 text_direction_updated_(false), |
| 165 text_direction_(WebKit::WebTextDirectionLeftToRight), | 165 text_direction_(WebKit::WebTextDirectionLeftToRight), |
| 166 text_direction_canceled_(false), | 166 text_direction_canceled_(false), |
| 167 suppress_next_char_events_(false), | 167 suppress_next_char_events_(false), |
| 168 pending_mouse_lock_request_(false), | 168 pending_mouse_lock_request_(false), |
| 169 allow_privileged_mouse_lock_(false), | 169 allow_privileged_mouse_lock_(false), |
| 170 has_touch_handler_(false), | 170 has_touch_handler_(false), |
| 171 ALLOW_THIS_IN_INITIALIZER_LIST(weak_factory_(this)), | 171 ALLOW_THIS_IN_INITIALIZER_LIST(weak_factory_(this)), |
| 172 tick_active_smooth_scroll_gestures_task_posted_(false), | 172 tick_active_smooth_scroll_gestures_task_posted_(false), |
| 173 touch_event_queue_(new TouchEventQueue(this)), | 173 touch_event_queue_(new TouchEventQueue(this)), |
| 174 gesture_event_filter_(new GestureEventFilter(this)) { | 174 gesture_event_filter_(new GestureEventFilter(this)), |
| 175 last_input_number_(0) { | |
| 175 CHECK(delegate_); | 176 CHECK(delegate_); |
| 176 if (routing_id_ == MSG_ROUTING_NONE) { | 177 if (routing_id_ == MSG_ROUTING_NONE) { |
| 177 routing_id_ = process_->GetNextRoutingID(); | 178 routing_id_ = process_->GetNextRoutingID(); |
| 178 surface_id_ = GpuSurfaceTracker::Get()->AddSurfaceForRenderer( | 179 surface_id_ = GpuSurfaceTracker::Get()->AddSurfaceForRenderer( |
| 179 process_->GetID(), | 180 process_->GetID(), |
| 180 routing_id_); | 181 routing_id_); |
| 181 } else { | 182 } else { |
| 182 // TODO(piman): This is a O(N) lookup, where we could forward the | 183 // TODO(piman): This is a O(N) lookup, where we could forward the |
| 183 // information from the RenderWidgetHelper. The problem is that doing so | 184 // information from the RenderWidgetHelper. The problem is that doing so |
| 184 // currently leaks outside of content all the way to chrome classes, and | 185 // currently leaks outside of content all the way to chrome classes, and |
| (...skipping 729 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 914 ForwardGestureEvent(MakeGestureEvent( | 915 ForwardGestureEvent(MakeGestureEvent( |
| 915 WebInputEvent::GesturePinchEnd, mouse_event.timeStampSeconds, | 916 WebInputEvent::GesturePinchEnd, mouse_event.timeStampSeconds, |
| 916 x, y, 0)); | 917 x, y, 0)); |
| 917 } | 918 } |
| 918 break; | 919 break; |
| 919 case WebMouseEvent::ButtonNone: | 920 case WebMouseEvent::ButtonNone: |
| 920 break; | 921 break; |
| 921 } | 922 } |
| 922 } | 923 } |
| 923 | 924 |
| 924 void RenderWidgetHostImpl::ForwardMouseEvent(const WebMouseEvent& mouse_event) { | 925 void RenderWidgetHostImpl::ForwardMouseEvent( |
| 925 TRACE_EVENT2("renderer_host", "RenderWidgetHostImpl::ForwardMouseEvent", | 926 const WebMouseEvent& mouse_event) { |
| 927 ForwardMouseEventWithLatencyInfo(mouse_event, NewInputLatencyInfo()); | |
| 928 } | |
| 929 | |
| 930 void RenderWidgetHostImpl::ForwardMouseEventWithLatencyInfo( | |
| 931 const WebMouseEvent& mouse_event, const cc::LatencyInfo& latency_info) { | |
| 932 TRACE_EVENT2("renderer_host", | |
| 933 "RenderWidgetHostImpl::ForwardMouseEventWithLatencyInfo", | |
| 926 "x", mouse_event.x, "y", mouse_event.y); | 934 "x", mouse_event.x, "y", mouse_event.y); |
| 927 if (ignore_input_events_ || process_->IgnoreInputEvents()) | 935 if (ignore_input_events_ || process_->IgnoreInputEvents()) |
| 928 return; | 936 return; |
| 929 | 937 |
| 930 if (CommandLine::ForCurrentProcess()->HasSwitch( | 938 if (CommandLine::ForCurrentProcess()->HasSwitch( |
| 931 switches::kSimulateTouchScreenWithMouse)) { | 939 switches::kSimulateTouchScreenWithMouse)) { |
| 932 SimulateTouchGestureWithMouse(mouse_event); | 940 SimulateTouchGestureWithMouse(mouse_event); |
| 933 return; | 941 return; |
| 934 } | 942 } |
| 935 | 943 |
| 936 if (mouse_event.type == WebInputEvent::MouseDown && | 944 if (mouse_event.type == WebInputEvent::MouseDown && |
| 937 gesture_event_filter_->GetTouchpadTapSuppressionController()-> | 945 gesture_event_filter_->GetTouchpadTapSuppressionController()-> |
| 938 ShouldDeferMouseDown(mouse_event)) | 946 ShouldDeferMouseDown(mouse_event, latency_info)) |
| 939 return; | 947 return; |
| 940 if (mouse_event.type == WebInputEvent::MouseUp && | 948 if (mouse_event.type == WebInputEvent::MouseUp && |
| 941 gesture_event_filter_->GetTouchpadTapSuppressionController()-> | 949 gesture_event_filter_->GetTouchpadTapSuppressionController()-> |
| 942 ShouldSuppressMouseUp()) | 950 ShouldSuppressMouseUp()) |
| 943 return; | 951 return; |
| 944 | 952 |
| 945 ForwardMouseEventImmediately(mouse_event); | 953 ForwardMouseEventImmediately(mouse_event, latency_info); |
| 946 } | 954 } |
| 947 | 955 |
| 948 void RenderWidgetHostImpl::OnPointerEventActivate() { | 956 void RenderWidgetHostImpl::OnPointerEventActivate() { |
| 949 } | 957 } |
| 950 | 958 |
| 951 void RenderWidgetHostImpl::ForwardWheelEvent( | 959 void RenderWidgetHostImpl::ForwardWheelEvent( |
| 952 const WebMouseWheelEvent& wheel_event) { | 960 const WebMouseWheelEvent& wheel_event) { |
| 953 TRACE_EVENT0("renderer_host", "RenderWidgetHostImpl::ForwardWheelEvent"); | 961 ForwardWheelEventWithLatencyInfo(wheel_event, NewInputLatencyInfo()); |
| 962 } | |
| 963 | |
| 964 void RenderWidgetHostImpl::ForwardWheelEventWithLatencyInfo( | |
| 965 const WebMouseWheelEvent& wheel_event, | |
| 966 const cc::LatencyInfo& latency_info) { | |
| 967 TRACE_EVENT0("renderer_host", | |
| 968 "RenderWidgetHostImpl::ForwardWheelEventWithLatencyInfo"); | |
| 954 if (ignore_input_events_ || process_->IgnoreInputEvents()) | 969 if (ignore_input_events_ || process_->IgnoreInputEvents()) |
| 955 return; | 970 return; |
| 956 | 971 |
| 957 if (delegate_->PreHandleWheelEvent(wheel_event)) | 972 if (delegate_->PreHandleWheelEvent(wheel_event)) |
| 958 return; | 973 return; |
| 959 | 974 |
| 960 // If there's already a mouse wheel event waiting to be sent to the renderer, | 975 // If there's already a mouse wheel event waiting to be sent to the renderer, |
| 961 // add the new deltas to that event. Not doing so (e.g., by dropping the old | 976 // add the new deltas to that event. Not doing so (e.g., by dropping the old |
| 962 // event, as for mouse moves) results in very slow scrolling on the Mac (on | 977 // event, as for mouse moves) results in very slow scrolling on the Mac (on |
| 963 // which many, very small wheel events are sent). | 978 // which many, very small wheel events are sent). |
| 964 if (mouse_wheel_pending_) { | 979 if (mouse_wheel_pending_) { |
| 965 if (coalesced_mouse_wheel_events_.empty() || | 980 if (coalesced_mouse_wheel_events_.empty() || |
| 966 !ShouldCoalesceMouseWheelEvents(coalesced_mouse_wheel_events_.back(), | 981 !ShouldCoalesceMouseWheelEvents( |
| 967 wheel_event)) { | 982 coalesced_mouse_wheel_events_.back().first, wheel_event)) { |
| 968 coalesced_mouse_wheel_events_.push_back(wheel_event); | 983 coalesced_mouse_wheel_events_.push_back( |
| 984 std::make_pair(wheel_event, latency_info)); | |
| 969 } else { | 985 } else { |
| 970 WebMouseWheelEvent* last_wheel_event = | 986 WebMouseWheelEvent* last_wheel_event = |
| 971 &coalesced_mouse_wheel_events_.back(); | 987 &coalesced_mouse_wheel_events_.back().first; |
| 972 float unaccelerated_x = | 988 float unaccelerated_x = |
| 973 GetUnacceleratedDelta(last_wheel_event->deltaX, | 989 GetUnacceleratedDelta(last_wheel_event->deltaX, |
| 974 last_wheel_event->accelerationRatioX) + | 990 last_wheel_event->accelerationRatioX) + |
| 975 GetUnacceleratedDelta(wheel_event.deltaX, | 991 GetUnacceleratedDelta(wheel_event.deltaX, |
| 976 wheel_event.accelerationRatioX); | 992 wheel_event.accelerationRatioX); |
| 977 float unaccelerated_y = | 993 float unaccelerated_y = |
| 978 GetUnacceleratedDelta(last_wheel_event->deltaY, | 994 GetUnacceleratedDelta(last_wheel_event->deltaY, |
| 979 last_wheel_event->accelerationRatioY) + | 995 last_wheel_event->accelerationRatioY) + |
| 980 GetUnacceleratedDelta(wheel_event.deltaY, | 996 GetUnacceleratedDelta(wheel_event.deltaY, |
| 981 wheel_event.accelerationRatioY); | 997 wheel_event.accelerationRatioY); |
| 982 last_wheel_event->deltaX += wheel_event.deltaX; | 998 last_wheel_event->deltaX += wheel_event.deltaX; |
| 983 last_wheel_event->deltaY += wheel_event.deltaY; | 999 last_wheel_event->deltaY += wheel_event.deltaY; |
| 984 last_wheel_event->wheelTicksX += wheel_event.wheelTicksX; | 1000 last_wheel_event->wheelTicksX += wheel_event.wheelTicksX; |
| 985 last_wheel_event->wheelTicksY += wheel_event.wheelTicksY; | 1001 last_wheel_event->wheelTicksY += wheel_event.wheelTicksY; |
| 986 last_wheel_event->accelerationRatioX = | 1002 last_wheel_event->accelerationRatioX = |
| 987 GetAccelerationRatio(last_wheel_event->deltaX, unaccelerated_x); | 1003 GetAccelerationRatio(last_wheel_event->deltaX, unaccelerated_x); |
| 988 last_wheel_event->accelerationRatioY = | 1004 last_wheel_event->accelerationRatioY = |
| 989 GetAccelerationRatio(last_wheel_event->deltaY, unaccelerated_y); | 1005 GetAccelerationRatio(last_wheel_event->deltaY, unaccelerated_y); |
| 990 DCHECK_GE(wheel_event.timeStampSeconds, | 1006 DCHECK_GE(wheel_event.timeStampSeconds, |
| 991 last_wheel_event->timeStampSeconds); | 1007 last_wheel_event->timeStampSeconds); |
| 992 last_wheel_event->timeStampSeconds = wheel_event.timeStampSeconds; | 1008 last_wheel_event->timeStampSeconds = wheel_event.timeStampSeconds; |
| 1009 coalesced_mouse_wheel_events_.back().second.MergeWith(latency_info); | |
| 993 } | 1010 } |
| 994 return; | 1011 return; |
| 995 } | 1012 } |
| 996 mouse_wheel_pending_ = true; | 1013 mouse_wheel_pending_ = true; |
| 997 current_wheel_event_ = wheel_event; | 1014 current_wheel_event_ = wheel_event; |
| 998 | 1015 |
| 999 HISTOGRAM_COUNTS_100("MPArch.RWH_WheelQueueSize", | 1016 HISTOGRAM_COUNTS_100("MPArch.RWH_WheelQueueSize", |
| 1000 coalesced_mouse_wheel_events_.size()); | 1017 coalesced_mouse_wheel_events_.size()); |
| 1001 | 1018 |
| 1002 ForwardInputEvent(wheel_event, sizeof(WebMouseWheelEvent), false); | 1019 ForwardInputEvent(wheel_event, sizeof(WebMouseWheelEvent), latency_info, |
| 1020 false); | |
| 1003 } | 1021 } |
| 1004 | 1022 |
| 1005 void RenderWidgetHostImpl::ForwardGestureEvent( | 1023 void RenderWidgetHostImpl::ForwardGestureEvent( |
| 1006 const WebKit::WebGestureEvent& gesture_event) { | 1024 const WebKit::WebGestureEvent& gesture_event) { |
| 1007 TRACE_EVENT0("renderer_host", "RenderWidgetHostImpl::ForwardGestureEvent"); | 1025 TRACE_EVENT0("renderer_host", "RenderWidgetHostImpl::ForwardGestureEvent"); |
| 1008 if (ignore_input_events_ || process_->IgnoreInputEvents()) | 1026 if (ignore_input_events_ || process_->IgnoreInputEvents()) |
| 1009 return; | 1027 return; |
| 1010 | 1028 |
| 1029 cc::LatencyInfo latency_info = NewInputLatencyInfo(); | |
| 1030 | |
| 1011 if (!IsInOverscrollGesture() && | 1031 if (!IsInOverscrollGesture() && |
| 1012 !gesture_event_filter_->ShouldForward(gesture_event)) | 1032 !gesture_event_filter_->ShouldForward( |
| 1033 GestureEventLatency(gesture_event, latency_info))) | |
| 1013 return; | 1034 return; |
| 1014 | 1035 |
| 1015 ForwardInputEvent(gesture_event, sizeof(WebGestureEvent), false); | 1036 ForwardInputEvent(gesture_event, sizeof(WebGestureEvent), |
| 1037 latency_info, false); | |
| 1016 } | 1038 } |
| 1017 | 1039 |
| 1018 // Forwards MouseEvent without passing it through | 1040 // Forwards MouseEvent without passing it through |
| 1019 // TouchpadTapSuppressionController. | 1041 // TouchpadTapSuppressionController. |
| 1020 void RenderWidgetHostImpl::ForwardMouseEventImmediately( | 1042 void RenderWidgetHostImpl::ForwardMouseEventImmediately( |
| 1021 const WebMouseEvent& mouse_event) { | 1043 const WebMouseEvent& mouse_event, |
| 1044 const cc::LatencyInfo& latency_info) { | |
| 1022 TRACE_EVENT2("renderer_host", | 1045 TRACE_EVENT2("renderer_host", |
| 1023 "RenderWidgetHostImpl::ForwardMouseEventImmediately", | 1046 "RenderWidgetHostImpl::ForwardMouseEventImmediately", |
| 1024 "x", mouse_event.x, "y", mouse_event.y); | 1047 "x", mouse_event.x, "y", mouse_event.y); |
| 1025 if (ignore_input_events_ || process_->IgnoreInputEvents()) | 1048 if (ignore_input_events_ || process_->IgnoreInputEvents()) |
| 1026 return; | 1049 return; |
| 1027 | 1050 |
| 1028 if (CommandLine::ForCurrentProcess()->HasSwitch( | 1051 if (CommandLine::ForCurrentProcess()->HasSwitch( |
| 1029 switches::kSimulateTouchScreenWithMouse)) { | 1052 switches::kSimulateTouchScreenWithMouse)) { |
| 1030 SimulateTouchGestureWithMouse(mouse_event); | 1053 SimulateTouchGestureWithMouse(mouse_event); |
| 1031 return; | 1054 return; |
| 1032 } | 1055 } |
| 1033 | 1056 |
| 1034 // Avoid spamming the renderer with mouse move events. It is important | 1057 // Avoid spamming the renderer with mouse move events. It is important |
| 1035 // to note that WM_MOUSEMOVE events are anyways synthetic, but since our | 1058 // to note that WM_MOUSEMOVE events are anyways synthetic, but since our |
| 1036 // thread is able to rapidly consume WM_MOUSEMOVE events, we may get way | 1059 // thread is able to rapidly consume WM_MOUSEMOVE events, we may get way |
| 1037 // more WM_MOUSEMOVE events than we wish to send to the renderer. | 1060 // more WM_MOUSEMOVE events than we wish to send to the renderer. |
| 1038 if (mouse_event.type == WebInputEvent::MouseMove) { | 1061 if (mouse_event.type == WebInputEvent::MouseMove) { |
| 1039 if (mouse_move_pending_) { | 1062 if (mouse_move_pending_) { |
| 1040 if (!next_mouse_move_) { | 1063 if (!next_mouse_move_) { |
| 1041 next_mouse_move_.reset(new WebMouseEvent(mouse_event)); | 1064 next_mouse_move_.reset(new WebMouseEvent(mouse_event)); |
| 1065 next_mouse_move_latency_info_ = latency_info; | |
| 1042 } else { | 1066 } else { |
| 1043 // Accumulate movement deltas. | 1067 // Accumulate movement deltas. |
| 1044 int x = next_mouse_move_->movementX; | 1068 int x = next_mouse_move_->movementX; |
| 1045 int y = next_mouse_move_->movementY; | 1069 int y = next_mouse_move_->movementY; |
| 1046 *next_mouse_move_ = mouse_event; | 1070 *next_mouse_move_ = mouse_event; |
| 1047 next_mouse_move_->movementX += x; | 1071 next_mouse_move_->movementX += x; |
| 1048 next_mouse_move_->movementY += y; | 1072 next_mouse_move_->movementY += y; |
| 1073 next_mouse_move_latency_info_.MergeWith(latency_info); | |
| 1049 } | 1074 } |
| 1050 return; | 1075 return; |
| 1051 } | 1076 } |
| 1052 mouse_move_pending_ = true; | 1077 mouse_move_pending_ = true; |
| 1053 } else if (mouse_event.type == WebInputEvent::MouseDown) { | 1078 } else if (mouse_event.type == WebInputEvent::MouseDown) { |
| 1054 OnUserGesture(); | 1079 OnUserGesture(); |
| 1055 } | 1080 } |
| 1056 | 1081 |
| 1057 ForwardInputEvent(mouse_event, sizeof(WebMouseEvent), false); | 1082 ForwardInputEvent(mouse_event, sizeof(WebMouseEvent), latency_info, false); |
| 1058 } | 1083 } |
| 1059 | 1084 |
| 1060 void RenderWidgetHostImpl::ForwardTouchEventImmediately( | 1085 void RenderWidgetHostImpl::ForwardTouchEventImmediately( |
| 1061 const WebKit::WebTouchEvent& touch_event) { | 1086 const WebKit::WebTouchEvent& touch_event) { |
| 1062 TRACE_EVENT0("renderer_host", "RenderWidgetHostImpl::ForwardTouchEvent"); | 1087 TRACE_EVENT0("renderer_host", "RenderWidgetHostImpl::ForwardTouchEvent"); |
| 1063 if (ignore_input_events_ || process_->IgnoreInputEvents()) | 1088 if (ignore_input_events_ || process_->IgnoreInputEvents()) |
| 1064 return; | 1089 return; |
| 1065 | 1090 |
| 1066 ForwardInputEvent(touch_event, sizeof(WebKit::WebTouchEvent), false); | 1091 ForwardInputEvent(touch_event, sizeof(WebKit::WebTouchEvent), |
| 1092 NewInputLatencyInfo(), false); | |
| 1067 } | 1093 } |
| 1068 | 1094 |
| 1069 void RenderWidgetHostImpl::ForwardGestureEventImmediately( | 1095 void RenderWidgetHostImpl::ForwardGestureEventImmediately( |
| 1070 const WebKit::WebGestureEvent& gesture_event) { | 1096 const WebKit::WebGestureEvent& gesture_event) { |
| 1071 if (ignore_input_events_ || process_->IgnoreInputEvents()) | 1097 if (ignore_input_events_ || process_->IgnoreInputEvents()) |
| 1072 return; | 1098 return; |
| 1073 ForwardInputEvent(gesture_event, sizeof(WebGestureEvent), false); | 1099 ForwardInputEvent(gesture_event, sizeof(WebGestureEvent), |
| 1100 NewInputLatencyInfo(), false); | |
| 1074 } | 1101 } |
| 1075 | 1102 |
| 1076 void RenderWidgetHostImpl::ForwardKeyboardEvent( | 1103 void RenderWidgetHostImpl::ForwardKeyboardEvent( |
| 1077 const NativeWebKeyboardEvent& key_event) { | 1104 const NativeWebKeyboardEvent& key_event) { |
| 1078 TRACE_EVENT0("renderer_host", "RenderWidgetHostImpl::ForwardKeyboardEvent"); | 1105 TRACE_EVENT0("renderer_host", "RenderWidgetHostImpl::ForwardKeyboardEvent"); |
| 1079 if (ignore_input_events_ || process_->IgnoreInputEvents()) | 1106 if (ignore_input_events_ || process_->IgnoreInputEvents()) |
| 1080 return; | 1107 return; |
| 1081 | 1108 |
| 1082 // First, let keypress listeners take a shot at handling the event. If a | 1109 // First, let keypress listeners take a shot at handling the event. If a |
| 1083 // listener handles the event, it should not be propagated to the renderer. | 1110 // 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... | |
| 1135 // Put all WebKeyboardEvent objects in a queue since we can't trust the | 1162 // Put all WebKeyboardEvent objects in a queue since we can't trust the |
| 1136 // renderer and we need to give something to the HandleKeyboardEvent | 1163 // renderer and we need to give something to the HandleKeyboardEvent |
| 1137 // handler. | 1164 // handler. |
| 1138 key_queue_.push_back(key_event); | 1165 key_queue_.push_back(key_event); |
| 1139 HISTOGRAM_COUNTS_100("Renderer.KeyboardQueueSize", key_queue_.size()); | 1166 HISTOGRAM_COUNTS_100("Renderer.KeyboardQueueSize", key_queue_.size()); |
| 1140 | 1167 |
| 1141 gesture_event_filter_->FlingHasBeenHalted(); | 1168 gesture_event_filter_->FlingHasBeenHalted(); |
| 1142 | 1169 |
| 1143 // Only forward the non-native portions of our event. | 1170 // Only forward the non-native portions of our event. |
| 1144 ForwardInputEvent(key_event, sizeof(WebKeyboardEvent), | 1171 ForwardInputEvent(key_event, sizeof(WebKeyboardEvent), |
| 1172 NewInputLatencyInfo(), | |
| 1145 is_keyboard_shortcut); | 1173 is_keyboard_shortcut); |
| 1146 } | 1174 } |
| 1147 } | 1175 } |
| 1148 | 1176 |
| 1177 int64 RenderWidgetHostImpl::GetLatencyComponentId() { | |
| 1178 return GetRoutingID() | ((int64)GetProcess()->GetID() << 32); | |
|
piman
2013/04/22 20:46:38
nit: no c-style casts.
qq: does anything bad happ
| |
| 1179 } | |
| 1180 | |
| 1181 cc::LatencyInfo RenderWidgetHostImpl::NewInputLatencyInfo() { | |
|
piman
2013/04/22 20:46:38
It's ok to do it by steps, but I want to make sure
| |
| 1182 cc::LatencyInfo info; | |
| 1183 info.AddLatencyNumber(cc::kInputEvent, GetLatencyComponentId(), | |
| 1184 ++last_input_number_); | |
| 1185 return info; | |
| 1186 } | |
| 1187 | |
| 1149 void RenderWidgetHostImpl::SendInputEvent(const WebInputEvent& input_event, | 1188 void RenderWidgetHostImpl::SendInputEvent(const WebInputEvent& input_event, |
| 1150 int event_size, | 1189 int event_size, |
| 1190 const cc::LatencyInfo& latency_info, | |
| 1151 bool is_keyboard_shortcut) { | 1191 bool is_keyboard_shortcut) { |
| 1152 input_event_start_time_ = TimeTicks::Now(); | 1192 input_event_start_time_ = TimeTicks::Now(); |
| 1153 Send(new ViewMsg_HandleInputEvent( | 1193 Send(new ViewMsg_HandleInputEvent( |
| 1154 routing_id_, &input_event, is_keyboard_shortcut)); | 1194 routing_id_, &input_event, latency_info, is_keyboard_shortcut)); |
| 1155 increment_in_flight_event_count(); | 1195 increment_in_flight_event_count(); |
| 1156 } | 1196 } |
| 1157 | 1197 |
| 1158 void RenderWidgetHostImpl::ForwardInputEvent(const WebInputEvent& input_event, | 1198 void RenderWidgetHostImpl::ForwardInputEvent( |
| 1159 int event_size, | 1199 const WebInputEvent& input_event, int event_size, |
| 1160 bool is_keyboard_shortcut) { | 1200 const cc::LatencyInfo& latency_info, bool is_keyboard_shortcut) { |
| 1161 TRACE_EVENT0("renderer_host", "RenderWidgetHostImpl::ForwardInputEvent"); | 1201 TRACE_EVENT0("renderer_host", "RenderWidgetHostImpl::ForwardInputEvent"); |
| 1162 | 1202 |
| 1163 if (!process_->HasConnection()) | 1203 if (!process_->HasConnection()) |
| 1164 return; | 1204 return; |
| 1165 | 1205 |
| 1166 DCHECK(!process_->IgnoreInputEvents()); | 1206 DCHECK(!process_->IgnoreInputEvents()); |
| 1167 | 1207 |
| 1168 if (overscroll_controller_.get() && | 1208 if (overscroll_controller_.get() && |
| 1169 !overscroll_controller_->WillDispatchEvent(input_event)) { | 1209 !overscroll_controller_->WillDispatchEvent(input_event, latency_info)) { |
| 1170 // Reset the wheel-event state when appropriate. | 1210 // Reset the wheel-event state when appropriate. |
| 1171 if (input_event.type == WebKit::WebInputEvent::MouseWheel) { | 1211 if (input_event.type == WebKit::WebInputEvent::MouseWheel) { |
| 1172 mouse_wheel_pending_ = false; | 1212 mouse_wheel_pending_ = false; |
| 1173 } else if (WebInputEvent::isGestureEventType(input_event.type) && | 1213 } else if (WebInputEvent::isGestureEventType(input_event.type) && |
| 1174 gesture_event_filter_->HasQueuedGestureEvents()) { | 1214 gesture_event_filter_->HasQueuedGestureEvents()) { |
| 1175 // 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 |
| 1176 // 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 |
| 1177 // 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 |
| 1178 // 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 |
| 1179 // immediately, and mark it as having been processed. | 1219 // immediately, and mark it as having been processed. |
| (...skipping 10 matching lines...) Expand all Loading... | |
| 1190 return; | 1230 return; |
| 1191 } | 1231 } |
| 1192 | 1232 |
| 1193 in_process_event_types_.push(input_event.type); | 1233 in_process_event_types_.push(input_event.type); |
| 1194 | 1234 |
| 1195 // 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 |
| 1196 // the renderer receives the final PhaseEnded wheel event, which is necessary | 1236 // the renderer receives the final PhaseEnded wheel event, which is necessary |
| 1197 // to terminate rubber-banding, for example. | 1237 // to terminate rubber-banding, for example. |
| 1198 if (input_event.type != WebInputEvent::MouseWheel) { | 1238 if (input_event.type != WebInputEvent::MouseWheel) { |
| 1199 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) { |
| 1200 SendInputEvent(coalesced_mouse_wheel_events_[i], | 1240 SendInputEvent(coalesced_mouse_wheel_events_[i].first, |
| 1201 sizeof(WebMouseWheelEvent), false); | 1241 sizeof(WebMouseWheelEvent), |
| 1242 coalesced_mouse_wheel_events_[i].second, false); | |
| 1202 } | 1243 } |
| 1203 coalesced_mouse_wheel_events_.clear(); | 1244 coalesced_mouse_wheel_events_.clear(); |
| 1204 } | 1245 } |
| 1205 | 1246 |
| 1206 if (view_) { | 1247 if (view_) { |
| 1207 // Perform optional, synchronous event handling, sending ACK messages for | 1248 // Perform optional, synchronous event handling, sending ACK messages for |
| 1208 // processed events, or proceeding as usual. | 1249 // processed events, or proceeding as usual. |
| 1209 InputEventAckState filter_ack = view_->FilterInputEvent(input_event); | 1250 InputEventAckState filter_ack = view_->FilterInputEvent(input_event); |
| 1210 switch (filter_ack) { | 1251 switch (filter_ack) { |
| 1211 // Send the ACK and early exit. | 1252 // Send the ACK and early exit. |
| 1212 case INPUT_EVENT_ACK_STATE_CONSUMED: | 1253 case INPUT_EVENT_ACK_STATE_CONSUMED: |
| 1213 case INPUT_EVENT_ACK_STATE_NO_CONSUMER_EXISTS: | 1254 case INPUT_EVENT_ACK_STATE_NO_CONSUMER_EXISTS: |
| 1214 next_mouse_move_.reset(); | 1255 next_mouse_move_.reset(); |
| 1215 OnInputEventAck(input_event.type, filter_ack); | 1256 OnInputEventAck(input_event.type, filter_ack); |
| 1216 // WARNING: |this| may be deleted at this point. | 1257 // WARNING: |this| may be deleted at this point. |
| 1217 return; | 1258 return; |
| 1218 | 1259 |
| 1219 // Proceed as normal. | 1260 // Proceed as normal. |
| 1220 case INPUT_EVENT_ACK_STATE_UNKNOWN: | 1261 case INPUT_EVENT_ACK_STATE_UNKNOWN: |
| 1221 case INPUT_EVENT_ACK_STATE_NOT_CONSUMED: | 1262 case INPUT_EVENT_ACK_STATE_NOT_CONSUMED: |
| 1222 default: | 1263 default: |
| 1223 break; | 1264 break; |
| 1224 }; | 1265 }; |
| 1225 } | 1266 } |
| 1226 | 1267 |
| 1227 SendInputEvent(input_event, event_size, is_keyboard_shortcut); | 1268 SendInputEvent(input_event, event_size, latency_info, is_keyboard_shortcut); |
| 1228 | 1269 |
| 1229 // Any input event cancels a pending mouse move event. Note that | 1270 // Any input event cancels a pending mouse move event. Note that |
| 1230 // |next_mouse_move_| possibly owns |input_event|, so don't use |input_event| | 1271 // |next_mouse_move_| possibly owns |input_event|, so don't use |input_event| |
| 1231 // after this line. | 1272 // after this line. |
| 1232 next_mouse_move_.reset(); | 1273 next_mouse_move_.reset(); |
| 1233 | 1274 |
| 1234 StartHangMonitorTimeout( | 1275 StartHangMonitorTimeout( |
| 1235 TimeDelta::FromMilliseconds(hung_renderer_delay_ms_)); | 1276 TimeDelta::FromMilliseconds(hung_renderer_delay_ms_)); |
| 1236 } | 1277 } |
| 1237 | 1278 |
| (...skipping 583 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1821 int type = static_cast<int>(event_type); | 1862 int type = static_cast<int>(event_type); |
| 1822 if (type < WebInputEvent::Undefined) { | 1863 if (type < WebInputEvent::Undefined) { |
| 1823 RecordAction(UserMetricsAction("BadMessageTerminate_RWH2")); | 1864 RecordAction(UserMetricsAction("BadMessageTerminate_RWH2")); |
| 1824 process_->ReceivedBadMessage(); | 1865 process_->ReceivedBadMessage(); |
| 1825 } else if (type == WebInputEvent::MouseMove) { | 1866 } else if (type == WebInputEvent::MouseMove) { |
| 1826 mouse_move_pending_ = false; | 1867 mouse_move_pending_ = false; |
| 1827 | 1868 |
| 1828 // now, we can send the next mouse move event | 1869 // now, we can send the next mouse move event |
| 1829 if (next_mouse_move_) { | 1870 if (next_mouse_move_) { |
| 1830 DCHECK(next_mouse_move_->type == WebInputEvent::MouseMove); | 1871 DCHECK(next_mouse_move_->type == WebInputEvent::MouseMove); |
| 1831 ForwardMouseEvent(*next_mouse_move_); | 1872 ForwardMouseEventWithLatencyInfo(*next_mouse_move_, |
| 1873 next_mouse_move_latency_info_); | |
| 1832 } | 1874 } |
| 1833 } else if (WebInputEvent::isKeyboardEventType(type)) { | 1875 } else if (WebInputEvent::isKeyboardEventType(type)) { |
| 1834 ProcessKeyboardEventAck(type, processed); | 1876 ProcessKeyboardEventAck(type, processed); |
| 1835 } else if (type == WebInputEvent::MouseWheel) { | 1877 } else if (type == WebInputEvent::MouseWheel) { |
| 1836 ProcessWheelAck(processed); | 1878 ProcessWheelAck(processed); |
| 1837 } else if (WebInputEvent::isTouchEventType(type)) { | 1879 } else if (WebInputEvent::isTouchEventType(type)) { |
| 1838 ProcessTouchAck(ack_result); | 1880 ProcessTouchAck(ack_result); |
| 1839 } else if (WebInputEvent::isGestureEventType(type)) { | 1881 } else if (WebInputEvent::isGestureEventType(type)) { |
| 1840 ProcessGestureAck(processed, type); | 1882 ProcessGestureAck(processed, type); |
| 1841 } | 1883 } |
| (...skipping 117 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1959 } | 2001 } |
| 1960 | 2002 |
| 1961 void RenderWidgetHostImpl::ProcessWheelAck(bool processed) { | 2003 void RenderWidgetHostImpl::ProcessWheelAck(bool processed) { |
| 1962 mouse_wheel_pending_ = false; | 2004 mouse_wheel_pending_ = false; |
| 1963 | 2005 |
| 1964 if (overscroll_controller_) | 2006 if (overscroll_controller_) |
| 1965 overscroll_controller_->ReceivedEventACK(current_wheel_event_, processed); | 2007 overscroll_controller_->ReceivedEventACK(current_wheel_event_, processed); |
| 1966 | 2008 |
| 1967 // Now send the next (coalesced) mouse wheel event. | 2009 // Now send the next (coalesced) mouse wheel event. |
| 1968 if (!coalesced_mouse_wheel_events_.empty()) { | 2010 if (!coalesced_mouse_wheel_events_.empty()) { |
| 1969 WebMouseWheelEvent next_wheel_event = | 2011 std::pair<WebMouseWheelEvent, cc::LatencyInfo> next_wheel_event = |
| 1970 coalesced_mouse_wheel_events_.front(); | 2012 coalesced_mouse_wheel_events_.front(); |
| 1971 coalesced_mouse_wheel_events_.pop_front(); | 2013 coalesced_mouse_wheel_events_.pop_front(); |
| 1972 ForwardWheelEvent(next_wheel_event); | 2014 ForwardWheelEventWithLatencyInfo(next_wheel_event.first, |
| 2015 next_wheel_event.second); | |
| 1973 } | 2016 } |
| 1974 | 2017 |
| 1975 if (!processed && !is_hidden_ && view_) | 2018 if (!processed && !is_hidden_ && view_) |
| 1976 view_->UnhandledWheelEvent(current_wheel_event_); | 2019 view_->UnhandledWheelEvent(current_wheel_event_); |
| 1977 } | 2020 } |
| 1978 | 2021 |
| 1979 void RenderWidgetHostImpl::ProcessGestureAck(bool processed, int type) { | 2022 void RenderWidgetHostImpl::ProcessGestureAck(bool processed, int type) { |
| 1980 if (overscroll_controller_) { | 2023 if (overscroll_controller_) { |
| 1981 overscroll_controller_->ReceivedEventACK( | 2024 overscroll_controller_->ReceivedEventACK( |
| 1982 gesture_event_filter_->GetGestureEventAwaitingAck(), processed); | 2025 gesture_event_filter_->GetGestureEventAwaitingAck(), processed); |
| (...skipping 483 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 2466 if (!should_auto_resize_) | 2509 if (!should_auto_resize_) |
| 2467 return; | 2510 return; |
| 2468 | 2511 |
| 2469 OnRenderAutoResized(new_size); | 2512 OnRenderAutoResized(new_size); |
| 2470 } | 2513 } |
| 2471 | 2514 |
| 2472 void RenderWidgetHostImpl::DetachDelegate() { | 2515 void RenderWidgetHostImpl::DetachDelegate() { |
| 2473 delegate_ = NULL; | 2516 delegate_ = NULL; |
| 2474 } | 2517 } |
| 2475 | 2518 |
| 2519 void RenderWidgetHostImpl::FrameSwapped(const cc::LatencyInfo& latency_info) { | |
| 2520 FOR_EACH_OBSERVER(FrameSwappedObserver, frame_swapped_observer_list_, | |
| 2521 OnFrameSwapped(this, latency_info)); | |
| 2522 } | |
| 2523 | |
| 2524 void RenderWidgetHostImpl::AddFrameSwappedObserver( | |
| 2525 FrameSwappedObserver* observer) { | |
| 2526 frame_swapped_observer_list_.AddObserver(observer); | |
| 2527 } | |
| 2528 | |
| 2529 void RenderWidgetHostImpl::RemoveFrameSwappedObserver( | |
| 2530 FrameSwappedObserver* observer) { | |
| 2531 frame_swapped_observer_list_.RemoveObserver(observer); | |
| 2532 } | |
| 2533 | |
| 2476 } // namespace content | 2534 } // namespace content |
| OLD | NEW |