OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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/child/fling_animator_impl_android.h" | 5 #include "content/child/fling_animator_impl_android.h" |
6 | 6 |
7 #include "base/logging.h" | 7 #include "base/logging.h" |
8 #include "third_party/WebKit/public/platform/WebFloatSize.h" | 8 #include "third_party/WebKit/public/platform/WebFloatSize.h" |
9 #include "third_party/WebKit/public/platform/WebGestureCurveTarget.h" | 9 #include "third_party/WebKit/public/platform/WebGestureCurveTarget.h" |
10 #include "ui/gfx/frame_time.h" | 10 #include "ui/gfx/frame_time.h" |
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
59 void FlingAnimatorImpl::CancelFling() { | 59 void FlingAnimatorImpl::CancelFling() { |
60 if (!is_active_) | 60 if (!is_active_) |
61 return; | 61 return; |
62 | 62 |
63 is_active_ = false; | 63 is_active_ = false; |
64 scroller_.AbortAnimation(); | 64 scroller_.AbortAnimation(); |
65 } | 65 } |
66 | 66 |
67 bool FlingAnimatorImpl::apply(double time, | 67 bool FlingAnimatorImpl::apply(double time, |
68 blink::WebGestureCurveTarget* target) { | 68 blink::WebGestureCurveTarget* target) { |
| 69 // If the fling has yet to start, simply return and report true to prevent |
| 70 // fling termination. |
| 71 if (time <= 0) |
| 72 return true; |
| 73 |
69 const base::TimeTicks time_ticks = | 74 const base::TimeTicks time_ticks = |
70 base::TimeTicks() + base::TimeDelta::FromMicroseconds( | 75 base::TimeTicks() + base::TimeDelta::FromMicroseconds( |
71 time * base::Time::kMicrosecondsPerSecond); | 76 time * base::Time::kMicrosecondsPerSecond); |
72 if (!scroller_.ComputeScrollOffset(time_ticks)) { | 77 if (!scroller_.ComputeScrollOffset(time_ticks)) { |
73 is_active_ = false; | 78 is_active_ = false; |
74 return false; | 79 return false; |
75 } | 80 } |
76 | 81 |
77 gfx::PointF current_position(scroller_.GetCurrX(), scroller_.GetCurrY()); | 82 gfx::PointF current_position(scroller_.GetCurrX(), scroller_.GetCurrY()); |
78 gfx::Vector2dF scroll_amount(current_position - last_position_); | 83 gfx::Vector2dF scroll_amount(current_position - last_position_); |
79 last_position_ = current_position; | 84 last_position_ = current_position; |
80 | 85 |
81 // scrollBy() could delete this curve if the animation is over, so don't touch | 86 // scrollBy() could delete this curve if the animation is over, so don't touch |
82 // any member variables after making that call. | 87 // any member variables after making that call. |
83 return target->scrollBy(blink::WebFloatSize(scroll_amount), | 88 return target->scrollBy(blink::WebFloatSize(scroll_amount), |
84 blink::WebFloatSize(scroller_.GetCurrVelocityX(), | 89 blink::WebFloatSize(scroller_.GetCurrVelocityX(), |
85 scroller_.GetCurrVelocityY())); | 90 scroller_.GetCurrVelocityY())); |
86 } | 91 } |
87 | 92 |
88 FlingAnimatorImpl* FlingAnimatorImpl::CreateAndroidGestureCurve( | 93 FlingAnimatorImpl* FlingAnimatorImpl::CreateAndroidGestureCurve( |
89 const blink::WebFloatPoint& velocity, | 94 const blink::WebFloatPoint& velocity, |
90 const blink::WebSize&) { | 95 const blink::WebSize&) { |
91 FlingAnimatorImpl* gesture_curve = new FlingAnimatorImpl(); | 96 FlingAnimatorImpl* gesture_curve = new FlingAnimatorImpl(); |
92 gesture_curve->StartFling(velocity); | 97 gesture_curve->StartFling(velocity); |
93 return gesture_curve; | 98 return gesture_curve; |
94 } | 99 } |
95 | 100 |
96 } // namespace content | 101 } // namespace content |
OLD | NEW |