| 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 "content/renderer/input/input_handler_proxy.h" | 5 #include "content/renderer/input/input_handler_proxy.h" |
| 6 | 6 |
| 7 #include "base/auto_reset.h" | 7 #include "base/auto_reset.h" |
| 8 #include "base/debug/trace_event.h" | 8 #include "base/debug/trace_event.h" |
| 9 #include "base/logging.h" | 9 #include "base/logging.h" |
| 10 #include "base/metrics/histogram.h" | 10 #include "base/metrics/histogram.h" |
| (...skipping 385 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 396 // Note that the timestamp will only be used to kickstart the animation if | 396 // Note that the timestamp will only be used to kickstart the animation if |
| 397 // its sufficiently close to the timestamp of the first call |Animate()|. | 397 // its sufficiently close to the timestamp of the first call |Animate()|. |
| 398 has_fling_animation_started_ = false; | 398 has_fling_animation_started_ = false; |
| 399 fling_parameters_.startTime = gesture_event.timeStampSeconds; | 399 fling_parameters_.startTime = gesture_event.timeStampSeconds; |
| 400 fling_parameters_.delta = WebFloatPoint(vx, vy); | 400 fling_parameters_.delta = WebFloatPoint(vx, vy); |
| 401 fling_parameters_.point = WebPoint(gesture_event.x, gesture_event.y); | 401 fling_parameters_.point = WebPoint(gesture_event.x, gesture_event.y); |
| 402 fling_parameters_.globalPoint = | 402 fling_parameters_.globalPoint = |
| 403 WebPoint(gesture_event.globalX, gesture_event.globalY); | 403 WebPoint(gesture_event.globalX, gesture_event.globalY); |
| 404 fling_parameters_.modifiers = gesture_event.modifiers; | 404 fling_parameters_.modifiers = gesture_event.modifiers; |
| 405 fling_parameters_.sourceDevice = gesture_event.sourceDevice; | 405 fling_parameters_.sourceDevice = gesture_event.sourceDevice; |
| 406 input_handler_->SetNeedsAnimate(); | 406 input_handler_->SetNeedsAnimateFling(); |
| 407 return DID_HANDLE; | 407 return DID_HANDLE; |
| 408 } | 408 } |
| 409 case cc::InputHandler::ScrollUnknown: | 409 case cc::InputHandler::ScrollUnknown: |
| 410 case cc::InputHandler::ScrollOnMainThread: { | 410 case cc::InputHandler::ScrollOnMainThread: { |
| 411 TRACE_EVENT_INSTANT0("input", | 411 TRACE_EVENT_INSTANT0("input", |
| 412 "InputHandlerProxy::HandleGestureFling::" | 412 "InputHandlerProxy::HandleGestureFling::" |
| 413 "scroll_on_main_thread", | 413 "scroll_on_main_thread", |
| 414 TRACE_EVENT_SCOPE_THREAD); | 414 TRACE_EVENT_SCOPE_THREAD); |
| 415 fling_may_be_active_on_main_thread_ = true; | 415 fling_may_be_active_on_main_thread_ = true; |
| 416 return DID_NOT_HANDLE; | 416 return DID_NOT_HANDLE; |
| (...skipping 161 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 578 | 578 |
| 579 CancelCurrentFling(true); | 579 CancelCurrentFling(true); |
| 580 | 580 |
| 581 if (last_fling_boost_event.type == WebInputEvent::GestureScrollBegin || | 581 if (last_fling_boost_event.type == WebInputEvent::GestureScrollBegin || |
| 582 last_fling_boost_event.type == WebInputEvent::GestureScrollUpdate) { | 582 last_fling_boost_event.type == WebInputEvent::GestureScrollUpdate) { |
| 583 // Synthesize a GestureScrollBegin, as the original was suppressed. | 583 // Synthesize a GestureScrollBegin, as the original was suppressed. |
| 584 HandleInputEvent(ObtainGestureScrollBegin(last_fling_boost_event)); | 584 HandleInputEvent(ObtainGestureScrollBegin(last_fling_boost_event)); |
| 585 } | 585 } |
| 586 } | 586 } |
| 587 | 587 |
| 588 void InputHandlerProxy::Animate(base::TimeTicks time) { | 588 void InputHandlerProxy::AnimateFling(base::TimeTicks time) { |
| 589 if (!fling_curve_) | 589 if (!fling_curve_) |
| 590 return; | 590 return; |
| 591 | 591 |
| 592 double monotonic_time_sec = InSecondsF(time); | 592 double monotonic_time_sec = InSecondsF(time); |
| 593 | 593 |
| 594 if (deferred_fling_cancel_time_seconds_ && | 594 if (deferred_fling_cancel_time_seconds_ && |
| 595 monotonic_time_sec > deferred_fling_cancel_time_seconds_) { | 595 monotonic_time_sec > deferred_fling_cancel_time_seconds_) { |
| 596 FlingBoostCancelAndResumeScrollingIfNecessary(); | 596 FlingBoostCancelAndResumeScrollingIfNecessary(); |
| 597 return; | 597 return; |
| 598 } | 598 } |
| 599 | 599 |
| 600 if (!has_fling_animation_started_) { | 600 if (!has_fling_animation_started_) { |
| 601 has_fling_animation_started_ = true; | 601 has_fling_animation_started_ = true; |
| 602 // Guard against invalid, future or sufficiently stale start times, as there | 602 // Guard against invalid, future or sufficiently stale start times, as there |
| 603 // are no guarantees fling event and animation timestamps are compatible. | 603 // are no guarantees fling event and animation timestamps are compatible. |
| 604 if (!fling_parameters_.startTime || | 604 if (!fling_parameters_.startTime || |
| 605 monotonic_time_sec <= fling_parameters_.startTime || | 605 monotonic_time_sec <= fling_parameters_.startTime || |
| 606 monotonic_time_sec >= fling_parameters_.startTime + | 606 monotonic_time_sec >= fling_parameters_.startTime + |
| 607 kMaxSecondsFromFlingTimestampToFirstAnimate) { | 607 kMaxSecondsFromFlingTimestampToFirstAnimate) { |
| 608 fling_parameters_.startTime = monotonic_time_sec; | 608 fling_parameters_.startTime = monotonic_time_sec; |
| 609 input_handler_->SetNeedsAnimate(); | 609 input_handler_->SetNeedsAnimateFling(); |
| 610 return; | 610 return; |
| 611 } | 611 } |
| 612 } | 612 } |
| 613 | 613 |
| 614 bool fling_is_active = | 614 bool fling_is_active = |
| 615 fling_curve_->apply(monotonic_time_sec - fling_parameters_.startTime, | 615 fling_curve_->apply(monotonic_time_sec - fling_parameters_.startTime, |
| 616 this); | 616 this); |
| 617 | 617 |
| 618 if (disallow_vertical_fling_scroll_ && disallow_horizontal_fling_scroll_) | 618 if (disallow_vertical_fling_scroll_ && disallow_horizontal_fling_scroll_) |
| 619 fling_is_active = false; | 619 fling_is_active = false; |
| 620 | 620 |
| 621 if (fling_is_active) { | 621 if (fling_is_active) { |
| 622 input_handler_->SetNeedsAnimate(); | 622 input_handler_->SetNeedsAnimateFling(); |
| 623 } else { | 623 } else { |
| 624 TRACE_EVENT_INSTANT0("input", | 624 TRACE_EVENT_INSTANT0("input", |
| 625 "InputHandlerProxy::animate::flingOver", | 625 "InputHandlerProxy::animate::flingOver", |
| 626 TRACE_EVENT_SCOPE_THREAD); | 626 TRACE_EVENT_SCOPE_THREAD); |
| 627 CancelCurrentFling(true); | 627 CancelCurrentFling(true); |
| 628 } | 628 } |
| 629 } | 629 } |
| 630 | 630 |
| 631 void InputHandlerProxy::MainThreadHasStoppedFlinging() { | 631 void InputHandlerProxy::MainThreadHasStoppedFlinging() { |
| 632 fling_may_be_active_on_main_thread_ = false; | 632 fling_may_be_active_on_main_thread_ = false; |
| (...skipping 148 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 781 // trigger a scroll, e.g., with a trivial time delta between fling updates. | 781 // trigger a scroll, e.g., with a trivial time delta between fling updates. |
| 782 // Return true in this case to prevent early fling termination. | 782 // Return true in this case to prevent early fling termination. |
| 783 if (std::abs(clipped_increment.width) < kScrollEpsilon && | 783 if (std::abs(clipped_increment.width) < kScrollEpsilon && |
| 784 std::abs(clipped_increment.height) < kScrollEpsilon) | 784 std::abs(clipped_increment.height) < kScrollEpsilon) |
| 785 return true; | 785 return true; |
| 786 | 786 |
| 787 return did_scroll; | 787 return did_scroll; |
| 788 } | 788 } |
| 789 | 789 |
| 790 } // namespace content | 790 } // namespace content |
| OLD | NEW |