OLD | NEW |
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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 "ui/events/blink/input_handler_proxy.h" | 5 #include "ui/events/blink/input_handler_proxy.h" |
6 | 6 |
7 #include <stddef.h> | 7 #include <stddef.h> |
8 | 8 |
9 #include <algorithm> | 9 #include <algorithm> |
10 | 10 |
11 #include "base/auto_reset.h" | 11 #include "base/auto_reset.h" |
12 #include "base/command_line.h" | 12 #include "base/command_line.h" |
13 #include "base/location.h" | 13 #include "base/location.h" |
14 #include "base/logging.h" | 14 #include "base/logging.h" |
15 #include "base/metrics/histogram.h" | 15 #include "base/metrics/histogram.h" |
16 #include "base/single_thread_task_runner.h" | 16 #include "base/single_thread_task_runner.h" |
17 #include "base/thread_task_runner_handle.h" | 17 #include "base/thread_task_runner_handle.h" |
18 #include "base/trace_event/trace_event.h" | 18 #include "base/trace_event/trace_event.h" |
| 19 #include "cc/input/main_thread_scrolling_reason.h" |
19 #include "third_party/WebKit/public/web/WebInputEvent.h" | 20 #include "third_party/WebKit/public/web/WebInputEvent.h" |
20 #include "ui/events/blink/input_handler_proxy_client.h" | 21 #include "ui/events/blink/input_handler_proxy_client.h" |
21 #include "ui/events/blink/input_scroll_elasticity_controller.h" | 22 #include "ui/events/blink/input_scroll_elasticity_controller.h" |
22 #include "ui/events/latency_info.h" | 23 #include "ui/events/latency_info.h" |
23 #include "ui/gfx/geometry/point_conversions.h" | 24 #include "ui/gfx/geometry/point_conversions.h" |
24 | 25 |
25 using blink::WebFloatPoint; | 26 using blink::WebFloatPoint; |
26 using blink::WebFloatSize; | 27 using blink::WebFloatSize; |
27 using blink::WebGestureEvent; | 28 using blink::WebGestureEvent; |
28 using blink::WebInputEvent; | 29 using blink::WebInputEvent; |
(...skipping 323 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
352 // otherwise disrupt an in-progress touch scroll. | 353 // otherwise disrupt an in-progress touch scroll. |
353 if (fling_curve_) | 354 if (fling_curve_) |
354 CancelCurrentFling(); | 355 CancelCurrentFling(); |
355 } | 356 } |
356 break; | 357 break; |
357 } | 358 } |
358 | 359 |
359 return DID_NOT_HANDLE; | 360 return DID_NOT_HANDLE; |
360 } | 361 } |
361 | 362 |
362 void RecordMainThreadScrollingReasons( | 363 void RecordMainThreadScrollingReasons(WebInputEvent::Type type, |
363 WebInputEvent::Type type, | 364 uint32_t reasons) { |
364 cc::InputHandler::MainThreadScrollingReason reasons) { | |
365 static const char* kGestureHistogramName = | 365 static const char* kGestureHistogramName = |
366 "Renderer4.MainThreadGestureScrollReason"; | 366 "Renderer4.MainThreadGestureScrollReason"; |
367 static const char* kWheelHistogramName = | 367 static const char* kWheelHistogramName = |
368 "Renderer4.MainThreadWheelScrollReason"; | 368 "Renderer4.MainThreadWheelScrollReason"; |
369 | 369 |
370 DCHECK(type == WebInputEvent::GestureScrollBegin || | 370 DCHECK(type == WebInputEvent::GestureScrollBegin || |
371 type == WebInputEvent::MouseWheel); | 371 type == WebInputEvent::MouseWheel); |
372 | 372 |
373 if (type != WebInputEvent::GestureScrollBegin && | 373 if (type != WebInputEvent::GestureScrollBegin && |
374 type != WebInputEvent::MouseWheel) { | 374 type != WebInputEvent::MouseWheel) { |
375 return; | 375 return; |
376 } | 376 } |
377 | 377 |
378 if (reasons == cc::InputHandler::NOT_SCROLLING_ON_MAIN) { | 378 if (reasons == cc::MainThreadScrollingReason::kNotScrollingOnMain) { |
379 if (type == WebInputEvent::GestureScrollBegin) { | 379 if (type == WebInputEvent::GestureScrollBegin) { |
380 UMA_HISTOGRAM_ENUMERATION( | 380 UMA_HISTOGRAM_ENUMERATION( |
381 kGestureHistogramName, cc::InputHandler::NOT_SCROLLING_ON_MAIN, | 381 kGestureHistogramName, |
382 cc::InputHandler::MainThreadScrollingReasonCount); | 382 cc::MainThreadScrollingReason::kNotScrollingOnMain, |
| 383 cc::MainThreadScrollingReason::kMainThreadScrollingReasonCount); |
383 } else { | 384 } else { |
384 UMA_HISTOGRAM_ENUMERATION( | 385 UMA_HISTOGRAM_ENUMERATION( |
385 kWheelHistogramName, cc::InputHandler::NOT_SCROLLING_ON_MAIN, | 386 kWheelHistogramName, |
386 cc::InputHandler::MainThreadScrollingReasonCount); | 387 cc::MainThreadScrollingReason::kNotScrollingOnMain, |
| 388 cc::MainThreadScrollingReason::kMainThreadScrollingReasonCount); |
387 } | 389 } |
388 } | 390 } |
389 | 391 |
390 for (int i = 0; i < cc::InputHandler::MainThreadScrollingReasonCount - 1; | 392 for (uint32_t i = 0; |
| 393 i < cc::MainThreadScrollingReason::kMainThreadScrollingReasonCount - 1; |
391 ++i) { | 394 ++i) { |
392 unsigned val = 1 << i; | 395 unsigned val = 1 << i; |
393 if (reasons & val) { | 396 if (reasons & val) { |
394 if (type == WebInputEvent::GestureScrollBegin) { | 397 if (type == WebInputEvent::GestureScrollBegin) { |
395 UMA_HISTOGRAM_ENUMERATION( | 398 UMA_HISTOGRAM_ENUMERATION( |
396 kGestureHistogramName, i + 1, | 399 kGestureHistogramName, i + 1, |
397 cc::InputHandler::MainThreadScrollingReasonCount); | 400 cc::MainThreadScrollingReason::kMainThreadScrollingReasonCount); |
398 } else { | 401 } else { |
399 UMA_HISTOGRAM_ENUMERATION( | 402 UMA_HISTOGRAM_ENUMERATION( |
400 kWheelHistogramName, i + 1, | 403 kWheelHistogramName, i + 1, |
401 cc::InputHandler::MainThreadScrollingReasonCount); | 404 cc::MainThreadScrollingReason::kMainThreadScrollingReasonCount); |
402 } | 405 } |
403 } | 406 } |
404 } | 407 } |
405 } | 408 } |
406 | 409 |
407 bool InputHandlerProxy::ShouldAnimate( | 410 bool InputHandlerProxy::ShouldAnimate( |
408 const blink::WebMouseWheelEvent& event) const { | 411 const blink::WebMouseWheelEvent& event) const { |
409 #if defined(OS_MACOSX) | 412 #if defined(OS_MACOSX) |
410 // Mac does not smooth scroll wheel events (crbug.com/574283). | 413 // Mac does not smooth scroll wheel events (crbug.com/574283). |
411 return false; | 414 return false; |
(...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
490 // TODO(jamesr): This should be DROP_EVENT, but in cases where we fail | 493 // TODO(jamesr): This should be DROP_EVENT, but in cases where we fail |
491 // to properly sync scrollability it's safer to send the event to the | 494 // to properly sync scrollability it's safer to send the event to the |
492 // main thread. Change back to DROP_EVENT once we have synchronization | 495 // main thread. Change back to DROP_EVENT once we have synchronization |
493 // bugs sorted out. | 496 // bugs sorted out. |
494 result = DID_NOT_HANDLE; | 497 result = DID_NOT_HANDLE; |
495 break; | 498 break; |
496 case cc::InputHandler::SCROLL_UNKNOWN: | 499 case cc::InputHandler::SCROLL_UNKNOWN: |
497 case cc::InputHandler::SCROLL_ON_MAIN_THREAD: | 500 case cc::InputHandler::SCROLL_ON_MAIN_THREAD: |
498 result = DID_NOT_HANDLE; | 501 result = DID_NOT_HANDLE; |
499 break; | 502 break; |
500 case cc::InputHandler::ScrollStatusCount: | |
501 NOTREACHED(); | |
502 break; | |
503 } | 503 } |
504 } | 504 } |
505 | 505 |
506 // Send the event and its disposition to the elasticity controller to update | 506 // Send the event and its disposition to the elasticity controller to update |
507 // the over-scroll animation. If the event is to be handled on the main | 507 // the over-scroll animation. If the event is to be handled on the main |
508 // thread, the event and its disposition will be sent to the elasticity | 508 // thread, the event and its disposition will be sent to the elasticity |
509 // controller after being handled on the main thread. | 509 // controller after being handled on the main thread. |
510 if (scroll_elasticity_controller_ && result != DID_NOT_HANDLE) { | 510 if (scroll_elasticity_controller_ && result != DID_NOT_HANDLE) { |
511 // Note that the call to the elasticity controller is made asynchronously, | 511 // Note that the call to the elasticity controller is made asynchronously, |
512 // to minimize divergence between main thread and impl thread event | 512 // to minimize divergence between main thread and impl thread event |
(...skipping 20 matching lines...) Expand all Loading... |
533 cc::InputHandler::ScrollStatus scroll_status; | 533 cc::InputHandler::ScrollStatus scroll_status; |
534 if (gesture_event.data.scrollBegin.targetViewport) { | 534 if (gesture_event.data.scrollBegin.targetViewport) { |
535 scroll_status = input_handler_->RootScrollBegin(&scroll_state, | 535 scroll_status = input_handler_->RootScrollBegin(&scroll_state, |
536 cc::InputHandler::GESTURE); | 536 cc::InputHandler::GESTURE); |
537 } else { | 537 } else { |
538 scroll_status = | 538 scroll_status = |
539 input_handler_->ScrollBegin(&scroll_state, cc::InputHandler::GESTURE); | 539 input_handler_->ScrollBegin(&scroll_state, cc::InputHandler::GESTURE); |
540 } | 540 } |
541 UMA_HISTOGRAM_ENUMERATION("Renderer4.CompositorScrollHitTestResult", | 541 UMA_HISTOGRAM_ENUMERATION("Renderer4.CompositorScrollHitTestResult", |
542 scroll_status.thread, | 542 scroll_status.thread, |
543 cc::InputHandler::ScrollStatusCount); | 543 cc::InputHandler::LAST_SCROLL_STATUS + 1); |
544 | 544 |
545 RecordMainThreadScrollingReasons(gesture_event.type, | 545 RecordMainThreadScrollingReasons(gesture_event.type, |
546 scroll_status.main_thread_scrolling_reasons); | 546 scroll_status.main_thread_scrolling_reasons); |
547 | 547 |
548 switch (scroll_status.thread) { | 548 switch (scroll_status.thread) { |
549 case cc::InputHandler::SCROLL_ON_IMPL_THREAD: | 549 case cc::InputHandler::SCROLL_ON_IMPL_THREAD: |
550 TRACE_EVENT_INSTANT0("input", | 550 TRACE_EVENT_INSTANT0("input", |
551 "InputHandlerProxy::handle_input gesture scroll", | 551 "InputHandlerProxy::handle_input gesture scroll", |
552 TRACE_EVENT_SCOPE_THREAD); | 552 TRACE_EVENT_SCOPE_THREAD); |
553 gesture_scroll_on_impl_thread_ = true; | 553 gesture_scroll_on_impl_thread_ = true; |
554 return DID_HANDLE; | 554 return DID_HANDLE; |
555 case cc::InputHandler::SCROLL_UNKNOWN: | 555 case cc::InputHandler::SCROLL_UNKNOWN: |
556 case cc::InputHandler::SCROLL_ON_MAIN_THREAD: | 556 case cc::InputHandler::SCROLL_ON_MAIN_THREAD: |
557 return DID_NOT_HANDLE; | 557 return DID_NOT_HANDLE; |
558 case cc::InputHandler::SCROLL_IGNORED: | 558 case cc::InputHandler::SCROLL_IGNORED: |
559 return DROP_EVENT; | 559 return DROP_EVENT; |
560 case cc::InputHandler::ScrollStatusCount: | |
561 NOTREACHED(); | |
562 break; | |
563 } | 560 } |
564 return DID_NOT_HANDLE; | 561 return DID_NOT_HANDLE; |
565 } | 562 } |
566 | 563 |
567 InputHandlerProxy::EventDisposition | 564 InputHandlerProxy::EventDisposition |
568 InputHandlerProxy::HandleGestureScrollUpdate( | 565 InputHandlerProxy::HandleGestureScrollUpdate( |
569 const WebGestureEvent& gesture_event) { | 566 const WebGestureEvent& gesture_event) { |
570 #ifndef NDEBUG | 567 #ifndef NDEBUG |
571 DCHECK(expect_scroll_update_end_); | 568 DCHECK(expect_scroll_update_end_); |
572 #endif | 569 #endif |
(...skipping 20 matching lines...) Expand all Loading... |
593 return DID_NOT_HANDLE; | 590 return DID_NOT_HANDLE; |
594 gesture_scroll_on_impl_thread_ = false; | 591 gesture_scroll_on_impl_thread_ = false; |
595 return DID_HANDLE; | 592 return DID_HANDLE; |
596 } | 593 } |
597 | 594 |
598 InputHandlerProxy::EventDisposition InputHandlerProxy::HandleGestureFlingStart( | 595 InputHandlerProxy::EventDisposition InputHandlerProxy::HandleGestureFlingStart( |
599 const WebGestureEvent& gesture_event) { | 596 const WebGestureEvent& gesture_event) { |
600 cc::ScrollState scroll_state = CreateScrollStateForGesture(gesture_event); | 597 cc::ScrollState scroll_state = CreateScrollStateForGesture(gesture_event); |
601 cc::InputHandler::ScrollStatus scroll_status; | 598 cc::InputHandler::ScrollStatus scroll_status; |
602 scroll_status.main_thread_scrolling_reasons = | 599 scroll_status.main_thread_scrolling_reasons = |
603 cc::InputHandler::NOT_SCROLLING_ON_MAIN; | 600 cc::MainThreadScrollingReason::kNotScrollingOnMain; |
604 switch (gesture_event.sourceDevice) { | 601 switch (gesture_event.sourceDevice) { |
605 case blink::WebGestureDeviceTouchpad: | 602 case blink::WebGestureDeviceTouchpad: |
606 if (gesture_event.data.flingStart.targetViewport) { | 603 if (gesture_event.data.flingStart.targetViewport) { |
607 scroll_status = input_handler_->RootScrollBegin( | 604 scroll_status = input_handler_->RootScrollBegin( |
608 &scroll_state, cc::InputHandler::NON_BUBBLING_GESTURE); | 605 &scroll_state, cc::InputHandler::NON_BUBBLING_GESTURE); |
609 } else { | 606 } else { |
610 scroll_status = input_handler_->ScrollBegin( | 607 scroll_status = input_handler_->ScrollBegin( |
611 &scroll_state, cc::InputHandler::NON_BUBBLING_GESTURE); | 608 &scroll_state, cc::InputHandler::NON_BUBBLING_GESTURE); |
612 } | 609 } |
613 break; | 610 break; |
614 case blink::WebGestureDeviceTouchscreen: | 611 case blink::WebGestureDeviceTouchscreen: |
615 if (!gesture_scroll_on_impl_thread_) { | 612 if (!gesture_scroll_on_impl_thread_) { |
616 scroll_status.thread = cc::InputHandler::SCROLL_ON_MAIN_THREAD; | 613 scroll_status.thread = cc::InputHandler::SCROLL_ON_MAIN_THREAD; |
617 scroll_status.main_thread_scrolling_reasons = | 614 scroll_status.main_thread_scrolling_reasons = |
618 cc::InputHandler::CONTINUING_MAIN_THREAD_SCROLL; | 615 cc::MainThreadScrollingReason::kContinuingMainThreadScroll; |
619 } else { | 616 } else { |
620 scroll_status = input_handler_->FlingScrollBegin(); | 617 scroll_status = input_handler_->FlingScrollBegin(); |
621 } | 618 } |
622 break; | 619 break; |
623 case blink::WebGestureDeviceUninitialized: | 620 case blink::WebGestureDeviceUninitialized: |
624 NOTREACHED(); | 621 NOTREACHED(); |
625 return DID_NOT_HANDLE; | 622 return DID_NOT_HANDLE; |
626 } | 623 } |
627 | 624 |
628 #ifndef NDEBUG | 625 #ifndef NDEBUG |
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
679 TRACE_EVENT_SCOPE_THREAD); | 676 TRACE_EVENT_SCOPE_THREAD); |
680 gesture_scroll_on_impl_thread_ = false; | 677 gesture_scroll_on_impl_thread_ = false; |
681 if (gesture_event.sourceDevice == blink::WebGestureDeviceTouchpad) { | 678 if (gesture_event.sourceDevice == blink::WebGestureDeviceTouchpad) { |
682 // We still pass the curve to the main thread if there's nothing | 679 // We still pass the curve to the main thread if there's nothing |
683 // scrollable, in case something | 680 // scrollable, in case something |
684 // registers a handler before the curve is over. | 681 // registers a handler before the curve is over. |
685 return DID_NOT_HANDLE; | 682 return DID_NOT_HANDLE; |
686 } | 683 } |
687 return DROP_EVENT; | 684 return DROP_EVENT; |
688 } | 685 } |
689 case cc::InputHandler::ScrollStatusCount: | |
690 NOTREACHED(); | |
691 break; | |
692 } | 686 } |
693 return DID_NOT_HANDLE; | 687 return DID_NOT_HANDLE; |
694 } | 688 } |
695 | 689 |
696 InputHandlerProxy::EventDisposition InputHandlerProxy::HandleTouchStart( | 690 InputHandlerProxy::EventDisposition InputHandlerProxy::HandleTouchStart( |
697 const blink::WebTouchEvent& touch_event) { | 691 const blink::WebTouchEvent& touch_event) { |
698 for (size_t i = 0; i < touch_event.touchesLength; ++i) { | 692 for (size_t i = 0; i < touch_event.touchesLength; ++i) { |
699 if (touch_event.touches[i].state != WebTouchPoint::StatePressed) | 693 if (touch_event.touches[i].state != WebTouchPoint::StatePressed) |
700 continue; | 694 continue; |
701 if (input_handler_->DoTouchEventsBlockScrollAt( | 695 if (input_handler_->DoTouchEventsBlockScrollAt( |
(...skipping 443 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1145 // trigger a scroll, e.g., with a trivial time delta between fling updates. | 1139 // trigger a scroll, e.g., with a trivial time delta between fling updates. |
1146 // Return true in this case to prevent early fling termination. | 1140 // Return true in this case to prevent early fling termination. |
1147 if (std::abs(clipped_increment.width) < kScrollEpsilon && | 1141 if (std::abs(clipped_increment.width) < kScrollEpsilon && |
1148 std::abs(clipped_increment.height) < kScrollEpsilon) | 1142 std::abs(clipped_increment.height) < kScrollEpsilon) |
1149 return true; | 1143 return true; |
1150 | 1144 |
1151 return did_scroll; | 1145 return did_scroll; |
1152 } | 1146 } |
1153 | 1147 |
1154 } // namespace ui | 1148 } // namespace ui |
OLD | NEW |