| 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 |
| (...skipping 214 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 225 } | 225 } |
| 226 } | 226 } |
| 227 | 227 |
| 228 cc::InputHandler::ScrollInputType GestureScrollInputType( | 228 cc::InputHandler::ScrollInputType GestureScrollInputType( |
| 229 blink::WebGestureDevice device) { | 229 blink::WebGestureDevice device) { |
| 230 return device == blink::WebGestureDeviceTouchpad | 230 return device == blink::WebGestureDeviceTouchpad |
| 231 ? cc::InputHandler::WHEEL | 231 ? cc::InputHandler::WHEEL |
| 232 : cc::InputHandler::TOUCHSCREEN; | 232 : cc::InputHandler::TOUCHSCREEN; |
| 233 } | 233 } |
| 234 | 234 |
| 235 enum ScrollingThreadStatus { |
| 236 SCROLLING_ON_COMPOSITOR, |
| 237 SCROLLING_ON_COMPOSITOR_BLOCKED_ON_MAIN, |
| 238 SCROLLING_ON_MAIN, |
| 239 LAST_SCROLLING_THREAD_STATUS_VALUE = SCROLLING_ON_MAIN, |
| 240 }; |
| 241 |
| 235 } // namespace | 242 } // namespace |
| 236 | 243 |
| 237 namespace ui { | 244 namespace ui { |
| 238 | 245 |
| 239 InputHandlerProxy::InputHandlerProxy(cc::InputHandler* input_handler, | 246 InputHandlerProxy::InputHandlerProxy(cc::InputHandler* input_handler, |
| 240 InputHandlerProxyClient* client) | 247 InputHandlerProxyClient* client) |
| 241 : client_(client), | 248 : client_(client), |
| 242 input_handler_(input_handler), | 249 input_handler_(input_handler), |
| 243 deferred_fling_cancel_time_seconds_(0), | 250 deferred_fling_cancel_time_seconds_(0), |
| 244 synchronous_input_handler_(nullptr), | 251 synchronous_input_handler_(nullptr), |
| 245 allow_root_animate_(true), | 252 allow_root_animate_(true), |
| 246 #ifndef NDEBUG | 253 #ifndef NDEBUG |
| 247 expect_scroll_update_end_(false), | 254 expect_scroll_update_end_(false), |
| 248 #endif | 255 #endif |
| 249 gesture_scroll_on_impl_thread_(false), | 256 gesture_scroll_on_impl_thread_(false), |
| 250 gesture_pinch_on_impl_thread_(false), | 257 gesture_pinch_on_impl_thread_(false), |
| 251 fling_may_be_active_on_main_thread_(false), | 258 fling_may_be_active_on_main_thread_(false), |
| 252 disallow_horizontal_fling_scroll_(false), | 259 disallow_horizontal_fling_scroll_(false), |
| 253 disallow_vertical_fling_scroll_(false), | 260 disallow_vertical_fling_scroll_(false), |
| 254 has_fling_animation_started_(false), | 261 has_fling_animation_started_(false), |
| 255 smooth_scroll_enabled_(false), | 262 smooth_scroll_enabled_(false), |
| 256 uma_latency_reporting_enabled_(base::TimeTicks::IsHighResolution()), | 263 uma_latency_reporting_enabled_(base::TimeTicks::IsHighResolution()), |
| 257 touchpad_and_wheel_scroll_latching_enabled_(false), | 264 touchpad_and_wheel_scroll_latching_enabled_(false), |
| 258 touch_start_result_(kEventDispositionUndefined), | 265 touch_start_result_(kEventDispositionUndefined), |
| 266 mouse_wheel_result_(kEventDispositionUndefined), |
| 259 current_overscroll_params_(nullptr), | 267 current_overscroll_params_(nullptr), |
| 260 has_ongoing_compositor_scroll_pinch_(false), | 268 has_ongoing_compositor_scroll_pinch_(false), |
| 261 tick_clock_(base::MakeUnique<base::DefaultTickClock>()) { | 269 tick_clock_(base::MakeUnique<base::DefaultTickClock>()) { |
| 262 DCHECK(client); | 270 DCHECK(client); |
| 263 input_handler_->BindToClient(this); | 271 input_handler_->BindToClient(this); |
| 264 cc::ScrollElasticityHelper* scroll_elasticity_helper = | 272 cc::ScrollElasticityHelper* scroll_elasticity_helper = |
| 265 input_handler_->CreateScrollElasticityHelper(); | 273 input_handler_->CreateScrollElasticityHelper(); |
| 266 if (scroll_elasticity_helper) { | 274 if (scroll_elasticity_helper) { |
| 267 scroll_elasticity_controller_.reset( | 275 scroll_elasticity_controller_.reset( |
| 268 new InputScrollElasticityController(scroll_elasticity_helper)); | 276 new InputScrollElasticityController(scroll_elasticity_helper)); |
| (...skipping 309 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 578 UMA_HISTOGRAM_ENUMERATION(kGestureHistogramName, i + 1, | 586 UMA_HISTOGRAM_ENUMERATION(kGestureHistogramName, i + 1, |
| 579 mainThreadScrollingReasonEnumMax); | 587 mainThreadScrollingReasonEnumMax); |
| 580 } else { | 588 } else { |
| 581 UMA_HISTOGRAM_ENUMERATION(kWheelHistogramName, i + 1, | 589 UMA_HISTOGRAM_ENUMERATION(kWheelHistogramName, i + 1, |
| 582 mainThreadScrollingReasonEnumMax); | 590 mainThreadScrollingReasonEnumMax); |
| 583 } | 591 } |
| 584 } | 592 } |
| 585 } | 593 } |
| 586 } | 594 } |
| 587 | 595 |
| 596 void InputHandlerProxy::RecordScrollingThreadStatus( |
| 597 blink::WebGestureDevice device, |
| 598 uint32_t reasons) { |
| 599 DCHECK(device == blink::WebGestureDeviceTouchpad || |
| 600 device == blink::WebGestureDeviceTouchscreen); |
| 601 |
| 602 if (device != blink::WebGestureDeviceTouchpad && |
| 603 device != blink::WebGestureDeviceTouchscreen) { |
| 604 return; |
| 605 } |
| 606 |
| 607 ScrollingThreadStatus scrolling_thread_status = SCROLLING_ON_MAIN; |
| 608 if (reasons == cc::MainThreadScrollingReason::kNotScrollingOnMain) { |
| 609 int32_t event_disposition_result = |
| 610 (device == blink::WebGestureDeviceTouchpad ? mouse_wheel_result_ |
| 611 : touch_start_result_); |
| 612 switch (event_disposition_result) { |
| 613 case kEventDispositionUndefined: |
| 614 case DID_NOT_HANDLE_NON_BLOCKING_DUE_TO_FLING: |
| 615 case DID_HANDLE_NON_BLOCKING: |
| 616 case DROP_EVENT: |
| 617 scrolling_thread_status = SCROLLING_ON_COMPOSITOR; |
| 618 break; |
| 619 case DID_NOT_HANDLE: |
| 620 scrolling_thread_status = SCROLLING_ON_COMPOSITOR_BLOCKED_ON_MAIN; |
| 621 break; |
| 622 default: |
| 623 NOTREACHED(); |
| 624 scrolling_thread_status = SCROLLING_ON_COMPOSITOR; |
| 625 } |
| 626 } |
| 627 |
| 628 // UMA_HISTOGRAM_ENUMERATION requires that the enum_max must be strictly |
| 629 // greater than the sample value. |
| 630 const uint32_t kScrolingThreadStatusEnumMax = |
| 631 ScrollingThreadStatus::LAST_SCROLLING_THREAD_STATUS_VALUE + 1; |
| 632 |
| 633 if (device == blink::WebGestureDeviceTouchscreen) { |
| 634 UMA_HISTOGRAM_ENUMERATION("Renderer4.GestureScrollingThreadStatus", |
| 635 scrolling_thread_status, |
| 636 kScrolingThreadStatusEnumMax); |
| 637 } else { |
| 638 UMA_HISTOGRAM_ENUMERATION("Renderer4.WheelScrollingThreadStatus", |
| 639 scrolling_thread_status, |
| 640 kScrolingThreadStatusEnumMax); |
| 641 } |
| 642 } |
| 643 |
| 588 bool InputHandlerProxy::ShouldAnimate(bool has_precise_scroll_deltas) const { | 644 bool InputHandlerProxy::ShouldAnimate(bool has_precise_scroll_deltas) const { |
| 589 #if defined(OS_MACOSX) | 645 #if defined(OS_MACOSX) |
| 590 // Mac does not smooth scroll wheel events (crbug.com/574283). | 646 // Mac does not smooth scroll wheel events (crbug.com/574283). |
| 591 return false; | 647 return false; |
| 592 #else | 648 #else |
| 593 return smooth_scroll_enabled_ && !has_precise_scroll_deltas; | 649 return smooth_scroll_enabled_ && !has_precise_scroll_deltas; |
| 594 #endif | 650 #endif |
| 595 } | 651 } |
| 596 | 652 |
| 597 InputHandlerProxy::EventDisposition InputHandlerProxy::HandleMouseWheel( | 653 InputHandlerProxy::EventDisposition InputHandlerProxy::HandleMouseWheel( |
| 598 const WebMouseWheelEvent& wheel_event) { | 654 const WebMouseWheelEvent& wheel_event) { |
| 599 // Only call |CancelCurrentFling()| if a fling was active, as it will | 655 // Only call |CancelCurrentFling()| if a fling was active, as it will |
| 600 // otherwise disrupt an in-progress touch scroll. | 656 // otherwise disrupt an in-progress touch scroll. |
| 601 if (!wheel_event.hasPreciseScrollingDeltas && fling_curve_) | 657 if (!wheel_event.hasPreciseScrollingDeltas && fling_curve_) |
| 602 CancelCurrentFling(); | 658 CancelCurrentFling(); |
| 603 | 659 |
| 660 InputHandlerProxy::EventDisposition result = DROP_EVENT; |
| 604 cc::EventListenerProperties properties = | 661 cc::EventListenerProperties properties = |
| 605 input_handler_->GetEventListenerProperties( | 662 input_handler_->GetEventListenerProperties( |
| 606 cc::EventListenerClass::kMouseWheel); | 663 cc::EventListenerClass::kMouseWheel); |
| 607 switch (properties) { | 664 switch (properties) { |
| 608 case cc::EventListenerProperties::kPassive: | 665 case cc::EventListenerProperties::kPassive: |
| 609 return DID_HANDLE_NON_BLOCKING; | 666 result = DID_HANDLE_NON_BLOCKING; |
| 667 break; |
| 610 case cc::EventListenerProperties::kBlockingAndPassive: | 668 case cc::EventListenerProperties::kBlockingAndPassive: |
| 611 case cc::EventListenerProperties::kBlocking: | 669 case cc::EventListenerProperties::kBlocking: |
| 612 return DID_NOT_HANDLE; | 670 result = DID_NOT_HANDLE; |
| 671 break; |
| 613 case cc::EventListenerProperties::kNone: | 672 case cc::EventListenerProperties::kNone: |
| 614 return DROP_EVENT; | 673 result = DROP_EVENT; |
| 674 break; |
| 615 default: | 675 default: |
| 616 NOTREACHED(); | 676 NOTREACHED(); |
| 617 return DROP_EVENT; | 677 result = DROP_EVENT; |
| 618 } | 678 } |
| 679 |
| 680 mouse_wheel_result_ = result; |
| 681 return result; |
| 619 } | 682 } |
| 620 | 683 |
| 621 InputHandlerProxy::EventDisposition InputHandlerProxy::FlingScrollByMouseWheel( | 684 InputHandlerProxy::EventDisposition InputHandlerProxy::FlingScrollByMouseWheel( |
| 622 const WebMouseWheelEvent& wheel_event, | 685 const WebMouseWheelEvent& wheel_event, |
| 623 cc::EventListenerProperties listener_properties) { | 686 cc::EventListenerProperties listener_properties) { |
| 624 DCHECK(listener_properties == cc::EventListenerProperties::kPassive || | 687 DCHECK(listener_properties == cc::EventListenerProperties::kPassive || |
| 625 listener_properties == cc::EventListenerProperties::kNone); | 688 listener_properties == cc::EventListenerProperties::kNone); |
| 626 | 689 |
| 627 DCHECK(!wheel_event.railsMode); | 690 DCHECK(!wheel_event.railsMode); |
| 628 gfx::Vector2dF scroll_delta(-wheel_event.deltaX, -wheel_event.deltaY); | 691 gfx::Vector2dF scroll_delta(-wheel_event.deltaX, -wheel_event.deltaY); |
| (...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 663 scroll_state_begin_data.position_y = wheel_event.y; | 726 scroll_state_begin_data.position_y = wheel_event.y; |
| 664 scroll_state_begin_data.is_beginning = true; | 727 scroll_state_begin_data.is_beginning = true; |
| 665 cc::ScrollState scroll_state_begin(scroll_state_begin_data); | 728 cc::ScrollState scroll_state_begin(scroll_state_begin_data); |
| 666 cc::InputHandler::ScrollStatus scroll_status = input_handler_->ScrollBegin( | 729 cc::InputHandler::ScrollStatus scroll_status = input_handler_->ScrollBegin( |
| 667 &scroll_state_begin, cc::InputHandler::WHEEL); | 730 &scroll_state_begin, cc::InputHandler::WHEEL); |
| 668 | 731 |
| 669 RecordMainThreadScrollingReasons( | 732 RecordMainThreadScrollingReasons( |
| 670 blink::WebGestureDeviceTouchpad, | 733 blink::WebGestureDeviceTouchpad, |
| 671 scroll_status.main_thread_scrolling_reasons); | 734 scroll_status.main_thread_scrolling_reasons); |
| 672 | 735 |
| 736 mouse_wheel_result_ = |
| 737 (listener_properties == cc::EventListenerProperties::kPassive) |
| 738 ? DID_HANDLE_NON_BLOCKING |
| 739 : DROP_EVENT; |
| 740 RecordScrollingThreadStatus(blink::WebGestureDeviceTouchpad, |
| 741 scroll_status.main_thread_scrolling_reasons); |
| 742 |
| 673 switch (scroll_status.thread) { | 743 switch (scroll_status.thread) { |
| 674 case cc::InputHandler::SCROLL_ON_IMPL_THREAD: { | 744 case cc::InputHandler::SCROLL_ON_IMPL_THREAD: { |
| 675 TRACE_EVENT_INSTANT2("input", | 745 TRACE_EVENT_INSTANT2("input", |
| 676 "InputHandlerProxy::handle_input wheel scroll", | 746 "InputHandlerProxy::handle_input wheel scroll", |
| 677 TRACE_EVENT_SCOPE_THREAD, "deltaX", | 747 TRACE_EVENT_SCOPE_THREAD, "deltaX", |
| 678 scroll_delta.x(), "deltaY", scroll_delta.y()); | 748 scroll_delta.x(), "deltaY", scroll_delta.y()); |
| 679 | 749 |
| 680 cc::ScrollStateData scroll_state_update_data; | 750 cc::ScrollStateData scroll_state_update_data; |
| 681 scroll_state_update_data.delta_x = scroll_delta.x(); | 751 scroll_state_update_data.delta_x = scroll_delta.x(); |
| 682 scroll_state_update_data.delta_y = scroll_delta.y(); | 752 scroll_state_update_data.delta_y = scroll_delta.y(); |
| (...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 744 } else { | 814 } else { |
| 745 scroll_status = input_handler_->ScrollBegin( | 815 scroll_status = input_handler_->ScrollBegin( |
| 746 &scroll_state, GestureScrollInputType(gesture_event.sourceDevice)); | 816 &scroll_state, GestureScrollInputType(gesture_event.sourceDevice)); |
| 747 } | 817 } |
| 748 UMA_HISTOGRAM_ENUMERATION("Renderer4.CompositorScrollHitTestResult", | 818 UMA_HISTOGRAM_ENUMERATION("Renderer4.CompositorScrollHitTestResult", |
| 749 scroll_status.thread, | 819 scroll_status.thread, |
| 750 cc::InputHandler::LAST_SCROLL_STATUS + 1); | 820 cc::InputHandler::LAST_SCROLL_STATUS + 1); |
| 751 | 821 |
| 752 RecordMainThreadScrollingReasons(gesture_event.sourceDevice, | 822 RecordMainThreadScrollingReasons(gesture_event.sourceDevice, |
| 753 scroll_status.main_thread_scrolling_reasons); | 823 scroll_status.main_thread_scrolling_reasons); |
| 824 RecordScrollingThreadStatus(gesture_event.sourceDevice, |
| 825 scroll_status.main_thread_scrolling_reasons); |
| 754 | 826 |
| 755 InputHandlerProxy::EventDisposition result = DID_NOT_HANDLE; | 827 InputHandlerProxy::EventDisposition result = DID_NOT_HANDLE; |
| 756 switch (scroll_status.thread) { | 828 switch (scroll_status.thread) { |
| 757 case cc::InputHandler::SCROLL_ON_IMPL_THREAD: | 829 case cc::InputHandler::SCROLL_ON_IMPL_THREAD: |
| 758 TRACE_EVENT_INSTANT0("input", | 830 TRACE_EVENT_INSTANT0("input", |
| 759 "InputHandlerProxy::handle_input gesture scroll", | 831 "InputHandlerProxy::handle_input gesture scroll", |
| 760 TRACE_EVENT_SCOPE_THREAD); | 832 TRACE_EVENT_SCOPE_THREAD); |
| 761 gesture_scroll_on_impl_thread_ = true; | 833 gesture_scroll_on_impl_thread_ = true; |
| 762 result = DID_HANDLE; | 834 result = DID_HANDLE; |
| 763 break; | 835 break; |
| (...skipping 776 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1540 scroll_elasticity_controller_->GetWeakPtr(), gesture_event, | 1612 scroll_elasticity_controller_->GetWeakPtr(), gesture_event, |
| 1541 scroll_result)); | 1613 scroll_result)); |
| 1542 } | 1614 } |
| 1543 | 1615 |
| 1544 void InputHandlerProxy::SetTickClockForTesting( | 1616 void InputHandlerProxy::SetTickClockForTesting( |
| 1545 std::unique_ptr<base::TickClock> tick_clock) { | 1617 std::unique_ptr<base::TickClock> tick_clock) { |
| 1546 tick_clock_ = std::move(tick_clock); | 1618 tick_clock_ = std::move(tick_clock); |
| 1547 } | 1619 } |
| 1548 | 1620 |
| 1549 } // namespace ui | 1621 } // namespace ui |
| OLD | NEW |