Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(681)

Side by Side Diff: content/browser/renderer_host/render_widget_host_view_event_handler.cc

Issue 2882443002: Tiimer based phase info generated for mouse wheel events. (Closed)
Patch Set: debouncing queue disabled to count sent messages properly Created 3 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright 2016 The Chromium Authors. All rights reserved. 1 // Copyright 2016 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_view_event_handler.h" 5 #include "content/browser/renderer_host/render_widget_host_view_event_handler.h"
6 6
7 #include "base/metrics/user_metrics.h" 7 #include "base/metrics/user_metrics.h"
8 #include "base/metrics/user_metrics_action.h" 8 #include "base/metrics/user_metrics_action.h"
9 #include "content/browser/renderer_host/input/touch_selection_controller_client_ aura.h" 9 #include "content/browser/renderer_host/input/touch_selection_controller_client_ aura.h"
10 #include "content/browser/renderer_host/overscroll_controller.h" 10 #include "content/browser/renderer_host/overscroll_controller.h"
(...skipping 318 matching lines...) Expand 10 before | Expand all | Expand 10 after
329 if (host) { 329 if (host) {
330 HWND parent = host->GetAcceleratedWidget(); 330 HWND parent = host->GetAcceleratedWidget();
331 HWND toplevel_hwnd = ::GetAncestor(parent, GA_ROOT); 331 HWND toplevel_hwnd = ::GetAncestor(parent, GA_ROOT);
332 EnumThreadWindows(GetCurrentThreadId(), DismissOwnedPopups, 332 EnumThreadWindows(GetCurrentThreadId(), DismissOwnedPopups,
333 reinterpret_cast<LPARAM>(toplevel_hwnd)); 333 reinterpret_cast<LPARAM>(toplevel_hwnd));
334 } 334 }
335 #endif 335 #endif
336 blink::WebMouseWheelEvent mouse_wheel_event = 336 blink::WebMouseWheelEvent mouse_wheel_event =
337 ui::MakeWebMouseWheelEvent(static_cast<ui::MouseWheelEvent&>(*event), 337 ui::MakeWebMouseWheelEvent(static_cast<ui::MouseWheelEvent&>(*event),
338 base::Bind(&GetScreenLocationFromEvent)); 338 base::Bind(&GetScreenLocationFromEvent));
339 bool should_route_event = ShouldRouteEvent(event);
bokan 2017/05/18 16:47:00 Nit: move this inside the `if` block.
sahel 2017/05/18 18:15:14 Done.
340
339 if (mouse_wheel_event.delta_x != 0 || mouse_wheel_event.delta_y != 0) { 341 if (mouse_wheel_event.delta_x != 0 || mouse_wheel_event.delta_y != 0) {
340 if (ShouldRouteEvent(event)) { 342 if (host_view_->wheel_scroll_latching_enabled())
343 AddSyntheticPhase(mouse_wheel_event, should_route_event);
344 if (should_route_event) {
341 host_->delegate()->GetInputEventRouter()->RouteMouseWheelEvent( 345 host_->delegate()->GetInputEventRouter()->RouteMouseWheelEvent(
342 host_view_, &mouse_wheel_event, *event->latency()); 346 host_view_, &mouse_wheel_event, *event->latency());
343 } else { 347 } else {
344 ProcessMouseWheelEvent(mouse_wheel_event, *event->latency()); 348 ProcessMouseWheelEvent(mouse_wheel_event, *event->latency());
345 } 349 }
346 } 350 }
347 } else { 351 } else {
348 bool is_selection_popup = NeedsInputGrab(popup_child_host_view_); 352 bool is_selection_popup = NeedsInputGrab(popup_child_host_view_);
349 if (CanRendererHandleEvent(event, mouse_locked_, is_selection_popup) && 353 if (CanRendererHandleEvent(event, mouse_locked_, is_selection_popup) &&
350 !(event->flags() & ui::EF_FROM_TOUCH)) { 354 !(event->flags() & ui::EF_FROM_TOUCH)) {
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after
397 return; 401 return;
398 #endif 402 #endif
399 blink::WebGestureEvent gesture_event = ui::MakeWebGestureEventFlingCancel(); 403 blink::WebGestureEvent gesture_event = ui::MakeWebGestureEventFlingCancel();
400 // Coordinates need to be transferred to the fling cancel gesture only 404 // Coordinates need to be transferred to the fling cancel gesture only
401 // for Surface-targeting to ensure that it is targeted to the correct 405 // for Surface-targeting to ensure that it is targeted to the correct
402 // RenderWidgetHost. 406 // RenderWidgetHost.
403 gesture_event.x = event->x(); 407 gesture_event.x = event->x();
404 gesture_event.y = event->y(); 408 gesture_event.y = event->y();
405 blink::WebMouseWheelEvent mouse_wheel_event = ui::MakeWebMouseWheelEvent( 409 blink::WebMouseWheelEvent mouse_wheel_event = ui::MakeWebMouseWheelEvent(
406 *event, base::Bind(&GetScreenLocationFromEvent)); 410 *event, base::Bind(&GetScreenLocationFromEvent));
407 if (ShouldRouteEvent(event)) { 411
412 bool should_route_event = ShouldRouteEvent(event);
413 if (host_view_->wheel_scroll_latching_enabled())
414 AddSyntheticPhase(mouse_wheel_event, should_route_event);
415 if (should_route_event) {
408 host_->delegate()->GetInputEventRouter()->RouteGestureEvent( 416 host_->delegate()->GetInputEventRouter()->RouteGestureEvent(
409 host_view_, &gesture_event, 417 host_view_, &gesture_event,
410 ui::LatencyInfo(ui::SourceEventType::WHEEL)); 418 ui::LatencyInfo(ui::SourceEventType::WHEEL));
411 host_->delegate()->GetInputEventRouter()->RouteMouseWheelEvent( 419 host_->delegate()->GetInputEventRouter()->RouteMouseWheelEvent(
412 host_view_, &mouse_wheel_event, *event->latency()); 420 host_view_, &mouse_wheel_event, *event->latency());
413 } else { 421 } else {
414 host_->ForwardGestureEvent(gesture_event); 422 host_->ForwardGestureEvent(gesture_event);
415 host_->ForwardWheelEventWithLatencyInfo(mouse_wheel_event, 423 host_->ForwardWheelEventWithLatencyInfo(mouse_wheel_event,
416 *event->latency()); 424 *event->latency());
417 } 425 }
418 } else if (event->type() == ui::ET_SCROLL_FLING_START || 426 } else if (event->type() == ui::ET_SCROLL_FLING_START ||
419 event->type() == ui::ET_SCROLL_FLING_CANCEL) { 427 event->type() == ui::ET_SCROLL_FLING_CANCEL) {
420 blink::WebGestureEvent gesture_event = ui::MakeWebGestureEvent( 428 blink::WebGestureEvent gesture_event = ui::MakeWebGestureEvent(
421 *event, base::Bind(&GetScreenLocationFromEvent)); 429 *event, base::Bind(&GetScreenLocationFromEvent));
422 if (ShouldRouteEvent(event)) { 430 bool should_route_event = ShouldRouteEvent(event);
bokan 2017/05/18 16:47:00 Define this variable outside only once and use in
sahel 2017/05/18 18:15:14 Done.
431 if (should_route_event) {
423 host_->delegate()->GetInputEventRouter()->RouteGestureEvent( 432 host_->delegate()->GetInputEventRouter()->RouteGestureEvent(
424 host_view_, &gesture_event, 433 host_view_, &gesture_event,
425 ui::LatencyInfo(ui::SourceEventType::WHEEL)); 434 ui::LatencyInfo(ui::SourceEventType::WHEEL));
426 } else { 435 } else {
427 host_->ForwardGestureEvent(gesture_event); 436 host_->ForwardGestureEvent(gesture_event);
428 } 437 }
429 if (event->type() == ui::ET_SCROLL_FLING_START) 438 if (event->type() == ui::ET_SCROLL_FLING_START) {
430 RecordAction(base::UserMetricsAction("TrackpadScrollFling")); 439 RecordAction(base::UserMetricsAction("TrackpadScrollFling"));
440
441 if (mouse_wheel_phase_timer_.IsRunning()) {
442 // Stop the timer to avoid sending a synthetic wheel event with
443 // kPhaseEnded.
444 mouse_wheel_phase_timer_.Stop();
bokan 2017/05/18 16:47:00 Is there any harm in calling Stop on a timer that
sahel 2017/05/18 18:15:15 Done.
445 }
446 }
431 } 447 }
432 448
433 event->SetHandled(); 449 event->SetHandled();
434 } 450 }
435 451
436 void RenderWidgetHostViewEventHandler::OnTouchEvent(ui::TouchEvent* event) { 452 void RenderWidgetHostViewEventHandler::OnTouchEvent(ui::TouchEvent* event) {
437 TRACE_EVENT0("input", "RenderWidgetHostViewBase::OnTouchEvent"); 453 TRACE_EVENT0("input", "RenderWidgetHostViewBase::OnTouchEvent");
438 454
439 bool had_no_pointer = !pointer_state_.GetPointerCount(); 455 bool had_no_pointer = !pointer_state_.GetPointerCount();
440 456
(...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after
512 if (ShouldRouteEvent(event)) { 528 if (ShouldRouteEvent(event)) {
513 host_->delegate()->GetInputEventRouter()->RouteGestureEvent( 529 host_->delegate()->GetInputEventRouter()->RouteGestureEvent(
514 host_view_, &fling_cancel, 530 host_view_, &fling_cancel,
515 ui::LatencyInfo(ui::SourceEventType::TOUCH)); 531 ui::LatencyInfo(ui::SourceEventType::TOUCH));
516 } else { 532 } else {
517 host_->ForwardGestureEvent(fling_cancel); 533 host_->ForwardGestureEvent(fling_cancel);
518 } 534 }
519 } 535 }
520 536
521 if (gesture.GetType() != blink::WebInputEvent::kUndefined) { 537 if (gesture.GetType() != blink::WebInputEvent::kUndefined) {
538 if (event->type() == ui::ET_GESTURE_SCROLL_BEGIN) {
539 RecordAction(base::UserMetricsAction("TouchscreenScroll"));
540
541 if (mouse_wheel_phase_timer_.IsRunning()) {
542 // If there is a current scroll going on and a new scroll that isn't
543 // wheel based send a synthetic wheel event with kPhaseEnded to cancel
544 // the current scroll.
545 base::Closure task = mouse_wheel_phase_timer_.user_task();
546 mouse_wheel_phase_timer_.Stop();
547 task.Run();
548 }
549 } else if (event->type() == ui::ET_GESTURE_SCROLL_END) {
550 // Make sure that the next wheel event will have phase = |kPhaseBegan|.
551 // This is for maintaining the correct phase info when some of the wheel
552 // events get ignored while a touchscreen scroll is going on.
553 if (mouse_wheel_phase_timer_.IsRunning()) {
bokan 2017/05/18 16:47:00 If the wheel events are ignored while a touchscree
sahel 2017/05/18 18:15:15 They will be still generated (with phase info) and
bokan 2017/05/19 15:52:59 Acknowledged.
554 mouse_wheel_phase_timer_.Stop();
555 }
556 } else if (event->type() == ui::ET_SCROLL_FLING_START) {
557 RecordAction(base::UserMetricsAction("TouchscreenScrollFling"));
558 }
559
522 if (ShouldRouteEvent(event)) { 560 if (ShouldRouteEvent(event)) {
523 host_->delegate()->GetInputEventRouter()->RouteGestureEvent( 561 host_->delegate()->GetInputEventRouter()->RouteGestureEvent(
524 host_view_, &gesture, *event->latency()); 562 host_view_, &gesture, *event->latency());
525 } else { 563 } else {
526 host_->ForwardGestureEventWithLatencyInfo(gesture, *event->latency()); 564 host_->ForwardGestureEventWithLatencyInfo(gesture, *event->latency());
527 } 565 }
528
529 if (event->type() == ui::ET_GESTURE_SCROLL_BEGIN) {
530 RecordAction(base::UserMetricsAction("TouchscreenScroll"));
531 } else if (event->type() == ui::ET_SCROLL_FLING_START) {
532 RecordAction(base::UserMetricsAction("TouchscreenScrollFling"));
533 }
534 } 566 }
535 567
536 // If a gesture is not processed by the webpage, then WebKit processes it 568 // If a gesture is not processed by the webpage, then WebKit processes it
537 // (e.g. generates synthetic mouse events). 569 // (e.g. generates synthetic mouse events).
538 event->SetHandled(); 570 event->SetHandled();
539 } 571 }
540 572
541 bool RenderWidgetHostViewEventHandler::CanRendererHandleEvent( 573 bool RenderWidgetHostViewEventHandler::CanRendererHandleEvent(
542 const ui::MouseEvent* event, 574 const ui::MouseEvent* event,
543 bool mouse_locked, 575 bool mouse_locked,
(...skipping 336 matching lines...) Expand 10 before | Expand all | Expand 10 after
880 const ui::LatencyInfo& latency) { 912 const ui::LatencyInfo& latency) {
881 host_->ForwardWheelEventWithLatencyInfo(event, latency); 913 host_->ForwardWheelEventWithLatencyInfo(event, latency);
882 } 914 }
883 915
884 void RenderWidgetHostViewEventHandler::ProcessTouchEvent( 916 void RenderWidgetHostViewEventHandler::ProcessTouchEvent(
885 const blink::WebTouchEvent& event, 917 const blink::WebTouchEvent& event,
886 const ui::LatencyInfo& latency) { 918 const ui::LatencyInfo& latency) {
887 host_->ForwardTouchEventWithLatencyInfo(event, latency); 919 host_->ForwardTouchEventWithLatencyInfo(event, latency);
888 } 920 }
889 921
922 void RenderWidgetHostViewEventHandler::SendSyntheticWheelEventWithPhaseEnded(
bokan 2017/05/18 16:47:00 Please add a DCHECK that touchpad latching is enab
sahel 2017/05/18 18:15:15 Done.
923 blink::WebMouseWheelEvent last_mouse_wheel_event,
924 bool should_route_event) {
925 blink::WebMouseWheelEvent mouse_wheel_event = last_mouse_wheel_event;
926 mouse_wheel_event.delta_x = 0;
927 mouse_wheel_event.delta_y = 0;
928 mouse_wheel_event.phase = blink::WebMouseWheelEvent::kPhaseEnded;
929 mouse_wheel_event.dispatch_type =
930 blink::WebInputEvent::DispatchType::kEventNonBlocking;
931 if (should_route_event) {
932 host_->delegate()->GetInputEventRouter()->RouteMouseWheelEvent(
933 host_view_, &mouse_wheel_event,
934 ui::LatencyInfo(ui::SourceEventType::WHEEL));
935 } else {
936 ProcessMouseWheelEvent(mouse_wheel_event,
937 ui::LatencyInfo(ui::SourceEventType::WHEEL));
938 }
939 }
940
941 void RenderWidgetHostViewEventHandler::AddSyntheticPhase(
tdresser 2017/05/18 13:49:05 The name of this function doesn't make it clear th
bokan 2017/05/18 16:47:00 IMO, it doesn't matter that the phase is "syntheti
sahel 2017/05/18 18:15:15 Done.
sahel 2017/05/18 18:15:15 I changed the name, it might be too long but is de
bokan 2017/05/19 15:52:59 We have (much) longer :)
942 blink::WebMouseWheelEvent& mouse_wheel_event,
943 bool should_route_event) {
944 DCHECK(mouse_wheel_event.phase == blink::WebMouseWheelEvent::kPhaseNone &&
bokan 2017/05/18 16:47:00 Where do the Mac events that do have this go?
sahel 2017/05/18 18:15:15 This event handler is aura only, mac events are ha
bokan 2017/05/19 15:52:59 Acknowledged.
945 mouse_wheel_event.momentum_phase ==
946 blink::WebMouseWheelEvent::kPhaseNone);
947
948 if (!mouse_wheel_phase_timer_.IsRunning()) {
949 mouse_wheel_event.phase = blink::WebMouseWheelEvent::kPhaseBegan;
950 mouse_wheel_phase_timer_.Start(
951 FROM_HERE,
952 base::TimeDelta::FromMilliseconds(
953 kDefaultMouseWheelLatchingTransactionMs),
954 base::Bind(&RenderWidgetHostViewEventHandler::
955 SendSyntheticWheelEventWithPhaseEnded,
956 base::Unretained(this), mouse_wheel_event,
957 should_route_event));
958 } else {
959 bool non_zero_delta =
960 mouse_wheel_event.delta_x || mouse_wheel_event.delta_y;
961 mouse_wheel_event.phase = non_zero_delta
962 ? blink::WebMouseWheelEvent::kPhaseChanged
963 : blink::WebMouseWheelEvent::kPhaseStationary;
964 mouse_wheel_phase_timer_.Reset();
965 }
966 }
967
890 } // namespace content 968 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698