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/auto_reset.h" |
8 #include "base/bind.h" | 8 #include "base/bind.h" |
9 #include "base/command_line.h" | 9 #include "base/command_line.h" |
10 #include "base/logging.h" | 10 #include "base/logging.h" |
(...skipping 223 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
234 const ui::LatencyInfo& latency_info) { | 234 const ui::LatencyInfo& latency_info) { |
235 LogInputEventLatencyUmaImpl(event.type, event.timeStampSeconds, now); | 235 LogInputEventLatencyUmaImpl(event.type, event.timeStampSeconds, now); |
236 for (size_t i = 0; i < latency_info.coalesced_events_size(); i++) { | 236 for (size_t i = 0; i < latency_info.coalesced_events_size(); i++) { |
237 LogInputEventLatencyUmaImpl( | 237 LogInputEventLatencyUmaImpl( |
238 event.type, | 238 event.type, |
239 latency_info.timestamps_of_coalesced_events()[i], | 239 latency_info.timestamps_of_coalesced_events()[i], |
240 now); | 240 now); |
241 } | 241 } |
242 } | 242 } |
243 | 243 |
244 void LogPassiveLatency(int64 latency) { | |
245 UMA_HISTOGRAM_CUSTOM_COUNTS("Event.PassiveListeners.Latency", latency, 1, | |
246 10000000, 100); | |
247 } | |
248 | |
249 void LogPassiveEventListenersUma(WebInputEventResult result, | |
250 bool passive, | |
251 bool cancelable, | |
252 double event_timestamp, | |
253 base::TimeTicks now, | |
254 const ui::LatencyInfo& latency_info) { | |
255 enum { | |
256 PASSIVE_LISTENER_UMA_ENUM_PASSIVE, | |
257 PASSIVE_LISTENER_UMA_ENUM_UNCANCELABLE, | |
258 PASSIVE_LISTENER_UMA_ENUM_CANCELABLE, | |
259 PASSIVE_LISTENER_UMA_ENUM_CANCELABLE_AND_CANCELED, | |
260 PASSIVE_LISTENER_UMA_ENUM_COUNT | |
261 }; | |
262 | |
263 int enum_value; | |
264 if (passive) | |
265 enum_value = PASSIVE_LISTENER_UMA_ENUM_PASSIVE; | |
266 else if (!cancelable) | |
267 enum_value = PASSIVE_LISTENER_UMA_ENUM_UNCANCELABLE; | |
268 else if (result == WebInputEventResult::HandledScript) | |
269 enum_value = PASSIVE_LISTENER_UMA_ENUM_CANCELABLE_AND_CANCELED; | |
270 else | |
271 enum_value = PASSIVE_LISTENER_UMA_ENUM_CANCELABLE; | |
272 | |
273 UMA_HISTOGRAM_ENUMERATION("Event.PassiveListeners", enum_value, | |
274 PASSIVE_LISTENER_UMA_ENUM_COUNT); | |
275 | |
276 if (enum_value == PASSIVE_LISTENER_UMA_ENUM_CANCELABLE && !now.is_null()) { | |
277 LogPassiveLatency(GetEventLatencyMicros(event_timestamp, now)); | |
278 for (size_t i = 0; i < latency_info.coalesced_events_size(); i++) | |
279 LogPassiveLatency(GetEventLatencyMicros( | |
280 latency_info.timestamps_of_coalesced_events()[i], now)); | |
281 } | |
282 } | |
283 | |
244 } // namespace | 284 } // namespace |
245 | 285 |
246 namespace content { | 286 namespace content { |
247 | 287 |
248 // RenderWidget::ScreenMetricsEmulator ---------------------------------------- | 288 // RenderWidget::ScreenMetricsEmulator ---------------------------------------- |
249 | 289 |
250 class RenderWidget::ScreenMetricsEmulator { | 290 class RenderWidget::ScreenMetricsEmulator { |
251 public: | 291 public: |
252 ScreenMetricsEmulator( | 292 ScreenMetricsEmulator( |
253 RenderWidget* widget, | 293 RenderWidget* widget, |
(...skipping 832 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1086 TRACE_EVENT0("renderer", "RenderWidget::OnSwapBuffersComplete"); | 1126 TRACE_EVENT0("renderer", "RenderWidget::OnSwapBuffersComplete"); |
1087 | 1127 |
1088 // Notify subclasses that composited rendering was flushed to the screen. | 1128 // Notify subclasses that composited rendering was flushed to the screen. |
1089 DidFlushPaint(); | 1129 DidFlushPaint(); |
1090 } | 1130 } |
1091 | 1131 |
1092 void RenderWidget::OnHandleInputEvent(const blink::WebInputEvent* input_event, | 1132 void RenderWidget::OnHandleInputEvent(const blink::WebInputEvent* input_event, |
1093 const ui::LatencyInfo& latency_info) { | 1133 const ui::LatencyInfo& latency_info) { |
1094 if (!input_event) | 1134 if (!input_event) |
1095 return; | 1135 return; |
1136 bool passive = false; | |
tdresser
2015/11/23 21:14:34
Add a comment linking to the bug indicating that t
dtapuska
2015/11/27 20:05:25
Done.
| |
1096 base::AutoReset<bool> handling_input_event_resetter(&handling_input_event_, | 1137 base::AutoReset<bool> handling_input_event_resetter(&handling_input_event_, |
1097 true); | 1138 true); |
1098 base::AutoReset<WebInputEvent::Type> handling_event_type_resetter( | 1139 base::AutoReset<WebInputEvent::Type> handling_event_type_resetter( |
1099 &handling_event_type_, input_event->type); | 1140 &handling_event_type_, input_event->type); |
1100 | 1141 |
1101 // Calls into |didOverscroll()| while handling this event will populate | 1142 // Calls into |didOverscroll()| while handling this event will populate |
1102 // |event_overscroll|, which in turn will be bundled with the event ack. | 1143 // |event_overscroll|, which in turn will be bundled with the event ack. |
1103 scoped_ptr<DidOverscrollParams> event_overscroll; | 1144 scoped_ptr<DidOverscrollParams> event_overscroll; |
1104 base::AutoReset<scoped_ptr<DidOverscrollParams>*> | 1145 base::AutoReset<scoped_ptr<DidOverscrollParams>*> |
1105 handling_event_overscroll_resetter(&handling_event_overscroll_, | 1146 handling_event_overscroll_resetter(&handling_event_overscroll_, |
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1171 #endif | 1212 #endif |
1172 } | 1213 } |
1173 | 1214 |
1174 if (WebInputEvent::isGestureEventType(input_event->type)) { | 1215 if (WebInputEvent::isGestureEventType(input_event->type)) { |
1175 const WebGestureEvent& gesture_event = | 1216 const WebGestureEvent& gesture_event = |
1176 *static_cast<const WebGestureEvent*>(input_event); | 1217 *static_cast<const WebGestureEvent*>(input_event); |
1177 context_menu_source_type_ = ui::MENU_SOURCE_TOUCH; | 1218 context_menu_source_type_ = ui::MENU_SOURCE_TOUCH; |
1178 prevent_default = prevent_default || WillHandleGestureEvent(gesture_event); | 1219 prevent_default = prevent_default || WillHandleGestureEvent(gesture_event); |
1179 } | 1220 } |
1180 | 1221 |
1181 bool processed = prevent_default; | 1222 WebInputEventResult processed = |
1223 prevent_default ? WebInputEventResult::HandledDefaultHandler | |
1224 : WebInputEventResult::NotHandled; | |
1182 if (input_event->type != WebInputEvent::Char || !suppress_next_char_events_) { | 1225 if (input_event->type != WebInputEvent::Char || !suppress_next_char_events_) { |
1183 suppress_next_char_events_ = false; | 1226 suppress_next_char_events_ = false; |
1184 if (!processed && webwidget_) | 1227 if (processed == WebInputEventResult::NotHandled && webwidget_) |
1185 processed = webwidget_->handleInputEvent(*input_event) != | 1228 processed = webwidget_->handleInputEvent(*input_event); |
1186 WebInputEventResult::NotHandled; | 1229 } |
1230 | |
1231 if (input_event->type == WebInputEvent::TouchStart || | |
1232 input_event->type == WebInputEvent::TouchMove || | |
1233 input_event->type == WebInputEvent::TouchEnd) { | |
tdresser
2015/11/23 21:14:34
Does isTouchEventType work for you?
https://code.g
dtapuska
2015/11/23 21:33:57
I didn't necessarily want to capture TouchCancel s
| |
1234 LogPassiveEventListenersUma( | |
1235 processed, passive, | |
1236 static_cast<const WebTouchEvent*>(input_event)->cancelable, | |
1237 input_event->timeStampSeconds, start_time, latency_info); | |
1238 } else if (input_event->type == WebInputEvent::MouseWheel) { | |
1239 LogPassiveEventListenersUma(processed, passive, !passive, | |
tdresser
2015/11/23 21:14:34
Does this make it more difficult to draw conclusio
dtapuska
2015/11/23 21:33:57
UMA would only record a non-cancelable event for t
| |
1240 input_event->timeStampSeconds, start_time, | |
1241 latency_info); | |
1187 } | 1242 } |
1188 | 1243 |
1189 // If this RawKeyDown event corresponds to a browser keyboard shortcut and | 1244 // If this RawKeyDown event corresponds to a browser keyboard shortcut and |
1190 // it's not processed by webkit, then we need to suppress the upcoming Char | 1245 // it's not processed by webkit, then we need to suppress the upcoming Char |
1191 // events. | 1246 // events. |
1192 bool is_keyboard_shortcut = | 1247 bool is_keyboard_shortcut = |
1193 input_event->type == WebInputEvent::RawKeyDown && | 1248 input_event->type == WebInputEvent::RawKeyDown && |
1194 static_cast<const WebKeyboardEvent*>(input_event)->isBrowserShortcut; | 1249 static_cast<const WebKeyboardEvent*>(input_event)->isBrowserShortcut; |
1195 if (!processed && is_keyboard_shortcut) | 1250 if (processed == WebInputEventResult::NotHandled && is_keyboard_shortcut) |
1196 suppress_next_char_events_ = true; | 1251 suppress_next_char_events_ = true; |
1197 | 1252 |
1198 InputEventAckState ack_result = processed ? | 1253 InputEventAckState ack_result = processed == WebInputEventResult::NotHandled |
1199 INPUT_EVENT_ACK_STATE_CONSUMED : INPUT_EVENT_ACK_STATE_NOT_CONSUMED; | 1254 ? INPUT_EVENT_ACK_STATE_NOT_CONSUMED |
1200 if (!processed && input_event->type == WebInputEvent::TouchStart) { | 1255 : INPUT_EVENT_ACK_STATE_CONSUMED; |
1256 if (processed == WebInputEventResult::NotHandled && | |
1257 input_event->type == WebInputEvent::TouchStart) { | |
1201 const WebTouchEvent& touch_event = | 1258 const WebTouchEvent& touch_event = |
1202 *static_cast<const WebTouchEvent*>(input_event); | 1259 *static_cast<const WebTouchEvent*>(input_event); |
1203 // Hit-test for all the pressed touch points. If there is a touch-handler | 1260 // Hit-test for all the pressed touch points. If there is a touch-handler |
1204 // for any of the touch points, then the renderer should continue to receive | 1261 // for any of the touch points, then the renderer should continue to receive |
1205 // touch events. | 1262 // touch events. |
1206 ack_result = INPUT_EVENT_ACK_STATE_NO_CONSUMER_EXISTS; | 1263 ack_result = INPUT_EVENT_ACK_STATE_NO_CONSUMER_EXISTS; |
1207 for (size_t i = 0; i < touch_event.touchesLength; ++i) { | 1264 for (size_t i = 0; i < touch_event.touchesLength; ++i) { |
1208 if (touch_event.touches[i].state == WebTouchPoint::StatePressed && | 1265 if (touch_event.touches[i].state == WebTouchPoint::StatePressed && |
1209 HasTouchEventHandlersAt( | 1266 HasTouchEventHandlersAt( |
1210 gfx::ToFlooredPoint(touch_event.touches[i].position))) { | 1267 gfx::ToFlooredPoint(touch_event.touches[i].position))) { |
1211 ack_result = INPUT_EVENT_ACK_STATE_NOT_CONSUMED; | 1268 ack_result = INPUT_EVENT_ACK_STATE_NOT_CONSUMED; |
1212 break; | 1269 break; |
1213 } | 1270 } |
1214 } | 1271 } |
1215 } | 1272 } |
1216 | 1273 |
1217 // Send mouse wheel events and their disposition to the compositor thread, so | 1274 // Send mouse wheel events and their disposition to the compositor thread, so |
1218 // that they can be used to produce the elastic overscroll effect on Mac. | 1275 // that they can be used to produce the elastic overscroll effect on Mac. |
1219 if (input_event->type == WebInputEvent::MouseWheel) { | 1276 if (input_event->type == WebInputEvent::MouseWheel) { |
1220 ObserveWheelEventAndResult( | 1277 ObserveWheelEventAndResult( |
1221 static_cast<const WebMouseWheelEvent&>(*input_event), | 1278 static_cast<const WebMouseWheelEvent&>(*input_event), |
1222 event_overscroll ? event_overscroll->latest_overscroll_delta | 1279 event_overscroll ? event_overscroll->latest_overscroll_delta |
1223 : gfx::Vector2dF(), | 1280 : gfx::Vector2dF(), |
1224 processed); | 1281 processed != WebInputEventResult::NotHandled); |
1225 } | 1282 } |
1226 | 1283 |
1227 bool frame_pending = compositor_ && compositor_->BeginMainFrameRequested(); | 1284 bool frame_pending = compositor_ && compositor_->BeginMainFrameRequested(); |
1228 | 1285 |
1229 // If we don't have a fast and accurate Now(), we assume the input handlers | 1286 // If we don't have a fast and accurate Now(), we assume the input handlers |
1230 // are heavy and rate limit them. | 1287 // are heavy and rate limit them. |
1231 bool rate_limiting_wanted = | 1288 bool rate_limiting_wanted = |
1232 input_event->type == WebInputEvent::MouseMove || | 1289 input_event->type == WebInputEvent::MouseMove || |
1233 input_event->type == WebInputEvent::MouseWheel; | 1290 input_event->type == WebInputEvent::MouseWheel; |
1234 if (rate_limiting_wanted && !start_time.is_null()) { | 1291 if (rate_limiting_wanted && !start_time.is_null()) { |
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1281 RenderThreadImpl::current() | 1338 RenderThreadImpl::current() |
1282 ->GetRendererScheduler() | 1339 ->GetRendererScheduler() |
1283 ->DidHandleInputEventOnMainThread(*input_event); | 1340 ->DidHandleInputEventOnMainThread(*input_event); |
1284 } | 1341 } |
1285 if (input_event->type == WebInputEvent::MouseMove) | 1342 if (input_event->type == WebInputEvent::MouseMove) |
1286 ignore_ack_for_mouse_move_from_debugger_ = false; | 1343 ignore_ack_for_mouse_move_from_debugger_ = false; |
1287 | 1344 |
1288 #if defined(OS_ANDROID) | 1345 #if defined(OS_ANDROID) |
1289 // Allow the IME to be shown when the focus changes as a consequence | 1346 // Allow the IME to be shown when the focus changes as a consequence |
1290 // of a processed touch end event. | 1347 // of a processed touch end event. |
1291 if (input_event->type == WebInputEvent::TouchEnd && processed) | 1348 if (input_event->type == WebInputEvent::TouchEnd && |
1349 processed != WebInputEventResult::NotHandled) | |
tdresser
2015/11/23 21:14:34
I'm a fan of braces when the condition is multi-li
dtapuska
2015/11/23 21:33:57
woops; that is me not checking git cl format.
dtapuska
2015/11/27 20:05:25
Done.
| |
1292 UpdateTextInputState(SHOW_IME_IF_NEEDED, FROM_NON_IME); | 1350 UpdateTextInputState(SHOW_IME_IF_NEEDED, FROM_NON_IME); |
1293 #elif defined(USE_AURA) | 1351 #elif defined(USE_AURA) |
1294 // Show the virtual keyboard if enabled and a user gesture triggers a focus | 1352 // Show the virtual keyboard if enabled and a user gesture triggers a focus |
1295 // change. | 1353 // change. |
1296 if (processed && (input_event->type == WebInputEvent::TouchEnd || | 1354 if (processed != WebInputEventResult::NotHandled && |
1297 input_event->type == WebInputEvent::MouseUp)) { | 1355 (input_event->type == WebInputEvent::TouchEnd || |
1356 input_event->type == WebInputEvent::MouseUp)) { | |
1298 UpdateTextInputState(SHOW_IME_IF_NEEDED, FROM_IME); | 1357 UpdateTextInputState(SHOW_IME_IF_NEEDED, FROM_IME); |
1299 } | 1358 } |
1300 #endif | 1359 #endif |
1301 | 1360 |
1302 if (!prevent_default) { | 1361 if (!prevent_default) { |
1303 if (WebInputEvent::isKeyboardEventType(input_event->type)) | 1362 if (WebInputEvent::isKeyboardEventType(input_event->type)) |
1304 DidHandleKeyEvent(); | 1363 DidHandleKeyEvent(); |
1305 } | 1364 } |
1306 | 1365 |
1307 // TODO(rouslan): Fix ChromeOS and Windows 8 behavior of autofill popup with | 1366 // TODO(rouslan): Fix ChromeOS and Windows 8 behavior of autofill popup with |
1308 // virtual keyboard. | 1367 // virtual keyboard. |
1309 #if !defined(OS_ANDROID) | 1368 #if !defined(OS_ANDROID) |
1310 // Virtual keyboard is not supported, so react to focus change immediately. | 1369 // Virtual keyboard is not supported, so react to focus change immediately. |
1311 if (processed && (input_event->type == WebInputEvent::TouchEnd || | 1370 if (processed != WebInputEventResult::NotHandled && |
1312 input_event->type == WebInputEvent::MouseUp)) { | 1371 (input_event->type == WebInputEvent::TouchEnd || |
1372 input_event->type == WebInputEvent::MouseUp)) { | |
1313 FocusChangeComplete(); | 1373 FocusChangeComplete(); |
1314 } | 1374 } |
1315 #endif | 1375 #endif |
1316 } | 1376 } |
1317 | 1377 |
1318 void RenderWidget::OnCursorVisibilityChange(bool is_visible) { | 1378 void RenderWidget::OnCursorVisibilityChange(bool is_visible) { |
1319 if (webwidget_) | 1379 if (webwidget_) |
1320 webwidget_->setCursorVisibilityState(is_visible); | 1380 webwidget_->setCursorVisibilityState(is_visible); |
1321 } | 1381 } |
1322 | 1382 |
(...skipping 1130 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
2453 void RenderWidget::RegisterVideoHoleFrame(RenderFrameImpl* frame) { | 2513 void RenderWidget::RegisterVideoHoleFrame(RenderFrameImpl* frame) { |
2454 video_hole_frames_.AddObserver(frame); | 2514 video_hole_frames_.AddObserver(frame); |
2455 } | 2515 } |
2456 | 2516 |
2457 void RenderWidget::UnregisterVideoHoleFrame(RenderFrameImpl* frame) { | 2517 void RenderWidget::UnregisterVideoHoleFrame(RenderFrameImpl* frame) { |
2458 video_hole_frames_.RemoveObserver(frame); | 2518 video_hole_frames_.RemoveObserver(frame); |
2459 } | 2519 } |
2460 #endif // defined(VIDEO_HOLE) | 2520 #endif // defined(VIDEO_HOLE) |
2461 | 2521 |
2462 } // namespace content | 2522 } // namespace content |
OLD | NEW |