| 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 | 8 |
| 9 #include <set> | 9 #include <set> |
| 10 #include <tuple> | 10 #include <tuple> |
| (...skipping 1026 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1037 return; | 1037 return; |
| 1038 } | 1038 } |
| 1039 | 1039 |
| 1040 ForwardMouseEventWithLatencyInfo(mouse_event, | 1040 ForwardMouseEventWithLatencyInfo(mouse_event, |
| 1041 ui::LatencyInfo(ui::SourceEventType::OTHER)); | 1041 ui::LatencyInfo(ui::SourceEventType::OTHER)); |
| 1042 if (owner_delegate_) | 1042 if (owner_delegate_) |
| 1043 owner_delegate_->RenderWidgetDidForwardMouseEvent(mouse_event); | 1043 owner_delegate_->RenderWidgetDidForwardMouseEvent(mouse_event); |
| 1044 } | 1044 } |
| 1045 | 1045 |
| 1046 void RenderWidgetHostImpl::ForwardMouseEventWithLatencyInfo( | 1046 void RenderWidgetHostImpl::ForwardMouseEventWithLatencyInfo( |
| 1047 const blink::WebMouseEvent& mouse_event, | 1047 const blink::WebMouseEvent& mouse_event, |
| 1048 const ui::LatencyInfo& ui_latency) { | 1048 const ui::LatencyInfo& latency) { |
| 1049 TRACE_EVENT2("input", "RenderWidgetHostImpl::ForwardMouseEvent", "x", | 1049 TRACE_EVENT2("input", "RenderWidgetHostImpl::ForwardMouseEvent", "x", |
| 1050 mouse_event.PositionInWidget().x, "y", | 1050 mouse_event.PositionInWidget().x, "y", |
| 1051 mouse_event.PositionInWidget().y); | 1051 mouse_event.PositionInWidget().y); |
| 1052 | 1052 |
| 1053 for (size_t i = 0; i < mouse_event_callbacks_.size(); ++i) { | 1053 for (size_t i = 0; i < mouse_event_callbacks_.size(); ++i) { |
| 1054 if (mouse_event_callbacks_[i].Run(mouse_event)) | 1054 if (mouse_event_callbacks_[i].Run(mouse_event)) |
| 1055 return; | 1055 return; |
| 1056 } | 1056 } |
| 1057 | 1057 |
| 1058 if (ShouldDropInputEvents()) | 1058 if (ShouldDropInputEvents()) |
| 1059 return; | 1059 return; |
| 1060 | 1060 |
| 1061 if (touch_emulator_ && touch_emulator_->HandleMouseEvent(mouse_event)) | 1061 if (touch_emulator_ && touch_emulator_->HandleMouseEvent(mouse_event)) |
| 1062 return; | 1062 return; |
| 1063 | 1063 |
| 1064 MouseEventWithLatencyInfo mouse_with_latency(mouse_event, ui_latency); | 1064 MouseEventWithLatencyInfo mouse_with_latency(mouse_event, latency); |
| 1065 DispatchInputEventWithLatencyInfo(mouse_event, &mouse_with_latency.latency); | 1065 DispatchInputEventWithLatencyInfo(mouse_event, &mouse_with_latency.latency); |
| 1066 input_router_->SendMouseEvent(mouse_with_latency); | 1066 input_router_->SendMouseEvent(mouse_with_latency); |
| 1067 } | 1067 } |
| 1068 | 1068 |
| 1069 void RenderWidgetHostImpl::ForwardWheelEvent( | 1069 void RenderWidgetHostImpl::ForwardWheelEvent( |
| 1070 const WebMouseWheelEvent& wheel_event) { | 1070 const WebMouseWheelEvent& wheel_event) { |
| 1071 ForwardWheelEventWithLatencyInfo(wheel_event, | 1071 ForwardWheelEventWithLatencyInfo(wheel_event, |
| 1072 ui::LatencyInfo(ui::SourceEventType::WHEEL)); | 1072 ui::LatencyInfo(ui::SourceEventType::WHEEL)); |
| 1073 } | 1073 } |
| 1074 | 1074 |
| 1075 void RenderWidgetHostImpl::ForwardWheelEventWithLatencyInfo( | 1075 void RenderWidgetHostImpl::ForwardWheelEventWithLatencyInfo( |
| 1076 const blink::WebMouseWheelEvent& wheel_event, | 1076 const blink::WebMouseWheelEvent& wheel_event, |
| 1077 const ui::LatencyInfo& ui_latency) { | 1077 const ui::LatencyInfo& latency) { |
| 1078 TRACE_EVENT2("input", "RenderWidgetHostImpl::ForwardWheelEvent", "dx", | 1078 TRACE_EVENT2("input", "RenderWidgetHostImpl::ForwardWheelEvent", "dx", |
| 1079 wheel_event.delta_x, "dy", wheel_event.delta_y); | 1079 wheel_event.delta_x, "dy", wheel_event.delta_y); |
| 1080 | 1080 |
| 1081 if (ShouldDropInputEvents()) | 1081 if (ShouldDropInputEvents()) |
| 1082 return; | 1082 return; |
| 1083 | 1083 |
| 1084 if (touch_emulator_ && touch_emulator_->HandleMouseWheelEvent(wheel_event)) | 1084 if (touch_emulator_ && touch_emulator_->HandleMouseWheelEvent(wheel_event)) |
| 1085 return; | 1085 return; |
| 1086 | 1086 |
| 1087 MouseWheelEventWithLatencyInfo wheel_with_latency(wheel_event, ui_latency); | 1087 MouseWheelEventWithLatencyInfo wheel_with_latency(wheel_event, latency); |
| 1088 DispatchInputEventWithLatencyInfo(wheel_event, &wheel_with_latency.latency); | 1088 DispatchInputEventWithLatencyInfo(wheel_event, &wheel_with_latency.latency); |
| 1089 input_router_->SendWheelEvent(wheel_with_latency); | 1089 input_router_->SendWheelEvent(wheel_with_latency); |
| 1090 } | 1090 } |
| 1091 | 1091 |
| 1092 void RenderWidgetHostImpl::ForwardEmulatedGestureEvent( | 1092 void RenderWidgetHostImpl::ForwardEmulatedGestureEvent( |
| 1093 const blink::WebGestureEvent& gesture_event) { | 1093 const blink::WebGestureEvent& gesture_event) { |
| 1094 ForwardGestureEvent(gesture_event); | 1094 ForwardGestureEvent(gesture_event); |
| 1095 } | 1095 } |
| 1096 | 1096 |
| 1097 void RenderWidgetHostImpl::ForwardGestureEvent( | 1097 void RenderWidgetHostImpl::ForwardGestureEvent( |
| 1098 const blink::WebGestureEvent& gesture_event) { | 1098 const blink::WebGestureEvent& gesture_event) { |
| 1099 ForwardGestureEventWithLatencyInfo( | 1099 ForwardGestureEventWithLatencyInfo( |
| 1100 gesture_event, | 1100 gesture_event, |
| 1101 ui::WebInputEventTraits::CreateLatencyInfoForWebGestureEvent( | 1101 ui::WebInputEventTraits::CreateLatencyInfoForWebGestureEvent( |
| 1102 gesture_event)); | 1102 gesture_event)); |
| 1103 } | 1103 } |
| 1104 | 1104 |
| 1105 void RenderWidgetHostImpl::ForwardGestureEventWithLatencyInfo( | 1105 void RenderWidgetHostImpl::ForwardGestureEventWithLatencyInfo( |
| 1106 const blink::WebGestureEvent& gesture_event, | 1106 const blink::WebGestureEvent& gesture_event, |
| 1107 const ui::LatencyInfo& ui_latency) { | 1107 const ui::LatencyInfo& latency) { |
| 1108 TRACE_EVENT0("input", "RenderWidgetHostImpl::ForwardGestureEvent"); | 1108 TRACE_EVENT0("input", "RenderWidgetHostImpl::ForwardGestureEvent"); |
| 1109 // Early out if necessary, prior to performing latency logic. | 1109 // Early out if necessary, prior to performing latency logic. |
| 1110 if (ShouldDropInputEvents()) | 1110 if (ShouldDropInputEvents()) |
| 1111 return; | 1111 return; |
| 1112 | 1112 |
| 1113 // TODO(wjmaclean) Remove the code for supporting resending gesture events | 1113 // TODO(wjmaclean) Remove the code for supporting resending gesture events |
| 1114 // when WebView transitions to OOPIF and BrowserPlugin is removed. | 1114 // when WebView transitions to OOPIF and BrowserPlugin is removed. |
| 1115 // http://crbug.com/533069 | 1115 // http://crbug.com/533069 |
| 1116 bool* is_in_gesture_scroll = | 1116 bool* is_in_gesture_scroll = |
| 1117 gesture_event.source_device == | 1117 gesture_event.source_device == |
| (...skipping 30 matching lines...) Expand all Loading... |
| 1148 ForwardGestureEventWithLatencyInfo( | 1148 ForwardGestureEventWithLatencyInfo( |
| 1149 CreateScrollBeginForWrapping(gesture_event), | 1149 CreateScrollBeginForWrapping(gesture_event), |
| 1150 ui::WebInputEventTraits::CreateLatencyInfoForWebGestureEvent( | 1150 ui::WebInputEventTraits::CreateLatencyInfoForWebGestureEvent( |
| 1151 gesture_event)); | 1151 gesture_event)); |
| 1152 } | 1152 } |
| 1153 | 1153 |
| 1154 // Delegate must be non-null, due to |ShouldDropInputEvents()| test. | 1154 // Delegate must be non-null, due to |ShouldDropInputEvents()| test. |
| 1155 if (delegate_->PreHandleGestureEvent(gesture_event)) | 1155 if (delegate_->PreHandleGestureEvent(gesture_event)) |
| 1156 return; | 1156 return; |
| 1157 | 1157 |
| 1158 GestureEventWithLatencyInfo gesture_with_latency(gesture_event, ui_latency); | 1158 GestureEventWithLatencyInfo gesture_with_latency(gesture_event, latency); |
| 1159 DispatchInputEventWithLatencyInfo(gesture_event, | 1159 DispatchInputEventWithLatencyInfo(gesture_event, |
| 1160 &gesture_with_latency.latency); | 1160 &gesture_with_latency.latency); |
| 1161 input_router_->SendGestureEvent(gesture_with_latency); | 1161 input_router_->SendGestureEvent(gesture_with_latency); |
| 1162 | 1162 |
| 1163 if (scroll_update_needs_wrapping) { | 1163 if (scroll_update_needs_wrapping) { |
| 1164 ForwardGestureEventWithLatencyInfo( | 1164 ForwardGestureEventWithLatencyInfo( |
| 1165 CreateScrollEndForWrapping(gesture_event), | 1165 CreateScrollEndForWrapping(gesture_event), |
| 1166 ui::WebInputEventTraits::CreateLatencyInfoForWebGestureEvent( | 1166 ui::WebInputEventTraits::CreateLatencyInfoForWebGestureEvent( |
| 1167 gesture_event)); | 1167 gesture_event)); |
| 1168 } | 1168 } |
| 1169 } | 1169 } |
| 1170 | 1170 |
| 1171 void RenderWidgetHostImpl::ForwardEmulatedTouchEvent( | 1171 void RenderWidgetHostImpl::ForwardEmulatedTouchEvent( |
| 1172 const blink::WebTouchEvent& touch_event) { | 1172 const blink::WebTouchEvent& touch_event) { |
| 1173 TRACE_EVENT0("input", "RenderWidgetHostImpl::ForwardEmulatedTouchEvent"); | 1173 TRACE_EVENT0("input", "RenderWidgetHostImpl::ForwardEmulatedTouchEvent"); |
| 1174 ui::LatencyInfo latency_info(ui::SourceEventType::TOUCH); | 1174 ui::LatencyInfo latency_info(ui::SourceEventType::TOUCH); |
| 1175 TouchEventWithLatencyInfo touch_with_latency(touch_event, latency_info); | 1175 TouchEventWithLatencyInfo touch_with_latency(touch_event, latency_info); |
| 1176 DispatchInputEventWithLatencyInfo(touch_event, &touch_with_latency.latency); | 1176 DispatchInputEventWithLatencyInfo(touch_event, &touch_with_latency.latency); |
| 1177 input_router_->SendTouchEvent(touch_with_latency); | 1177 input_router_->SendTouchEvent(touch_with_latency); |
| 1178 } | 1178 } |
| 1179 | 1179 |
| 1180 void RenderWidgetHostImpl::ForwardTouchEventWithLatencyInfo( | 1180 void RenderWidgetHostImpl::ForwardTouchEventWithLatencyInfo( |
| 1181 const blink::WebTouchEvent& touch_event, | 1181 const blink::WebTouchEvent& touch_event, |
| 1182 const ui::LatencyInfo& ui_latency) { | 1182 const ui::LatencyInfo& latency) { |
| 1183 TRACE_EVENT0("input", "RenderWidgetHostImpl::ForwardTouchEvent"); | 1183 TRACE_EVENT0("input", "RenderWidgetHostImpl::ForwardTouchEvent"); |
| 1184 | 1184 |
| 1185 // Always forward TouchEvents for touch stream consistency. They will be | 1185 // Always forward TouchEvents for touch stream consistency. They will be |
| 1186 // ignored if appropriate in FilterInputEvent(). | 1186 // ignored if appropriate in FilterInputEvent(). |
| 1187 | 1187 |
| 1188 TouchEventWithLatencyInfo touch_with_latency(touch_event, ui_latency); | 1188 TouchEventWithLatencyInfo touch_with_latency(touch_event, latency); |
| 1189 if (touch_emulator_ && | 1189 if (touch_emulator_ && |
| 1190 touch_emulator_->HandleTouchEvent(touch_with_latency.event)) { | 1190 touch_emulator_->HandleTouchEvent(touch_with_latency.event)) { |
| 1191 if (view_) { | 1191 if (view_) { |
| 1192 view_->ProcessAckedTouchEvent( | 1192 view_->ProcessAckedTouchEvent( |
| 1193 touch_with_latency, INPUT_EVENT_ACK_STATE_CONSUMED); | 1193 touch_with_latency, INPUT_EVENT_ACK_STATE_CONSUMED); |
| 1194 } | 1194 } |
| 1195 return; | 1195 return; |
| 1196 } | 1196 } |
| 1197 | 1197 |
| 1198 DispatchInputEventWithLatencyInfo(touch_event, &touch_with_latency.latency); | 1198 DispatchInputEventWithLatencyInfo(touch_event, &touch_with_latency.latency); |
| 1199 input_router_->SendTouchEvent(touch_with_latency); | 1199 input_router_->SendTouchEvent(touch_with_latency); |
| 1200 } | 1200 } |
| 1201 | 1201 |
| 1202 void RenderWidgetHostImpl::ForwardKeyboardEvent( | 1202 void RenderWidgetHostImpl::ForwardKeyboardEvent( |
| 1203 const NativeWebKeyboardEvent& key_event) { | 1203 const NativeWebKeyboardEvent& key_event) { |
| 1204 ForwardKeyboardEventWithCommands(key_event, nullptr, nullptr); | 1204 ui::LatencyInfo latency_info; |
| 1205 |
| 1206 if (key_event.GetType() == WebInputEvent::kRawKeyDown || |
| 1207 key_event.GetType() == WebInputEvent::kChar) { |
| 1208 latency_info.set_source_event_type(ui::SourceEventType::KEY_PRESS); |
| 1209 } |
| 1210 ForwardKeyboardEventWithLatencyInfo(key_event, latency_info); |
| 1211 } |
| 1212 |
| 1213 void RenderWidgetHostImpl::ForwardKeyboardEventWithLatencyInfo( |
| 1214 const NativeWebKeyboardEvent& key_event, |
| 1215 const ui::LatencyInfo& latency) { |
| 1216 ForwardKeyboardEventWithCommands(key_event, latency, nullptr, nullptr); |
| 1205 } | 1217 } |
| 1206 | 1218 |
| 1207 void RenderWidgetHostImpl::ForwardKeyboardEventWithCommands( | 1219 void RenderWidgetHostImpl::ForwardKeyboardEventWithCommands( |
| 1208 const NativeWebKeyboardEvent& key_event, | 1220 const NativeWebKeyboardEvent& key_event, |
| 1221 const ui::LatencyInfo& latency, |
| 1209 const std::vector<EditCommand>* commands, | 1222 const std::vector<EditCommand>* commands, |
| 1210 bool* update_event) { | 1223 bool* update_event) { |
| 1211 TRACE_EVENT0("input", "RenderWidgetHostImpl::ForwardKeyboardEvent"); | 1224 TRACE_EVENT0("input", "RenderWidgetHostImpl::ForwardKeyboardEvent"); |
| 1212 if (owner_delegate_ && | 1225 if (owner_delegate_ && |
| 1213 !owner_delegate_->MayRenderWidgetForwardKeyboardEvent(key_event)) { | 1226 !owner_delegate_->MayRenderWidgetForwardKeyboardEvent(key_event)) { |
| 1214 return; | 1227 return; |
| 1215 } | 1228 } |
| 1216 | 1229 |
| 1217 if (ShouldDropInputEvents()) | 1230 if (ShouldDropInputEvents()) |
| 1218 return; | 1231 return; |
| (...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1275 is_shortcut = true; | 1288 is_shortcut = true; |
| 1276 break; | 1289 break; |
| 1277 } | 1290 } |
| 1278 | 1291 |
| 1279 if (key_event.GetType() == WebKeyboardEvent::kRawKeyDown) | 1292 if (key_event.GetType() == WebKeyboardEvent::kRawKeyDown) |
| 1280 suppress_events_until_keydown_ = false; | 1293 suppress_events_until_keydown_ = false; |
| 1281 } | 1294 } |
| 1282 | 1295 |
| 1283 if (touch_emulator_ && touch_emulator_->HandleKeyboardEvent(key_event)) | 1296 if (touch_emulator_ && touch_emulator_->HandleKeyboardEvent(key_event)) |
| 1284 return; | 1297 return; |
| 1285 ui::LatencyInfo latency_info(ui::SourceEventType::OTHER); | |
| 1286 NativeWebKeyboardEventWithLatencyInfo key_event_with_latency(key_event, | 1298 NativeWebKeyboardEventWithLatencyInfo key_event_with_latency(key_event, |
| 1287 latency_info); | 1299 latency); |
| 1288 key_event_with_latency.event.is_browser_shortcut = is_shortcut; | 1300 key_event_with_latency.event.is_browser_shortcut = is_shortcut; |
| 1289 DispatchInputEventWithLatencyInfo(key_event, &key_event_with_latency.latency); | 1301 DispatchInputEventWithLatencyInfo(key_event, &key_event_with_latency.latency); |
| 1290 // TODO(foolip): |InputRouter::SendKeyboardEvent()| may filter events, in | 1302 // TODO(foolip): |InputRouter::SendKeyboardEvent()| may filter events, in |
| 1291 // which the commands will be treated as belonging to the next key event. | 1303 // which the commands will be treated as belonging to the next key event. |
| 1292 // InputMsg_SetEditCommandsForNextKeyEvent should only be sent if | 1304 // InputMsg_SetEditCommandsForNextKeyEvent should only be sent if |
| 1293 // InputMsg_HandleInputEvent is, but has to be sent first. | 1305 // InputMsg_HandleInputEvent is, but has to be sent first. |
| 1294 // https://crbug.com/684298 | 1306 // https://crbug.com/684298 |
| 1295 if (commands && !commands->empty()) { | 1307 if (commands && !commands->empty()) { |
| 1296 Send( | 1308 Send( |
| 1297 new InputMsg_SetEditCommandsForNextKeyEvent(GetRoutingID(), *commands)); | 1309 new InputMsg_SetEditCommandsForNextKeyEvent(GetRoutingID(), *commands)); |
| (...skipping 1334 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2632 RenderProcessHost* rph = GetProcess(); | 2644 RenderProcessHost* rph = GetProcess(); |
| 2633 for (std::vector<IPC::Message>::const_iterator i = messages.begin(); | 2645 for (std::vector<IPC::Message>::const_iterator i = messages.begin(); |
| 2634 i != messages.end(); ++i) { | 2646 i != messages.end(); ++i) { |
| 2635 rph->OnMessageReceived(*i); | 2647 rph->OnMessageReceived(*i); |
| 2636 if (i->dispatch_error()) | 2648 if (i->dispatch_error()) |
| 2637 rph->OnBadMessageReceived(*i); | 2649 rph->OnBadMessageReceived(*i); |
| 2638 } | 2650 } |
| 2639 } | 2651 } |
| 2640 | 2652 |
| 2641 } // namespace content | 2653 } // namespace content |
| OLD | NEW |