| OLD | NEW |
| 1 // Copyright 2017 The Chromium Authors. All rights reserved. | 1 // Copyright 2017 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 "remoting/client/ui/fling_animation.h" | 5 #include "remoting/client/ui/fling_animation.h" |
| 6 | 6 |
| 7 #include "base/time/default_tick_clock.h" | 7 #include "base/time/default_tick_clock.h" |
| 8 | 8 |
| 9 namespace remoting { | 9 namespace remoting { |
| 10 | 10 |
| 11 FlingAnimation::FlingAnimation(float time_constant, | 11 FlingAnimation::FlingAnimation(float time_constant, |
| 12 const FlingCallback& fling_callback) | 12 const FlingCallback& fling_callback) |
| 13 : fling_tracker_(time_constant), | 13 : fling_tracker_(time_constant), |
| 14 fling_callback_(fling_callback), | 14 fling_callback_(fling_callback), |
| 15 clock_(new base::DefaultTickClock()) {} | 15 clock_(new base::DefaultTickClock()) {} |
| 16 | 16 |
| 17 FlingAnimation::~FlingAnimation() {} | 17 FlingAnimation::~FlingAnimation() {} |
| 18 | 18 |
| 19 void FlingAnimation::SetVelocity(float velocity_x, float velocity_y) { | 19 void FlingAnimation::SetVelocity(float velocity_x, float velocity_y) { |
| 20 fling_tracker_.StartFling(velocity_x, velocity_y); | 20 fling_tracker_.StartFling(velocity_x, velocity_y); |
| 21 fling_start_time_ = clock_->NowTicks(); | 21 fling_start_time_ = clock_->NowTicks(); |
| 22 } | 22 } |
| 23 | 23 |
| 24 bool FlingAnimation::IsAnimationInProgress() const { | 24 bool FlingAnimation::IsAnimationInProgress() const { |
| 25 return fling_tracker_.IsFlingInProgress(); | 25 return fling_tracker_.IsFlingInProgress(); |
| 26 } | 26 } |
| 27 | 27 |
| 28 void FlingAnimation::Tick() { | 28 void FlingAnimation::Tick() { |
| 29 if (!IsAnimationInProgress()) { |
| 30 return; |
| 31 } |
| 32 |
| 29 float dx, dy; | 33 float dx, dy; |
| 30 bool in_progress = fling_tracker_.TrackMovement( | 34 bool in_progress = fling_tracker_.TrackMovement( |
| 31 clock_->NowTicks() - fling_start_time_, &dx, &dy); | 35 clock_->NowTicks() - fling_start_time_, &dx, &dy); |
| 32 if (in_progress) { | 36 if (in_progress) { |
| 33 fling_callback_.Run(dx, dy); | 37 fling_callback_.Run(dx, dy); |
| 34 } | 38 } |
| 35 } | 39 } |
| 36 | 40 |
| 37 void FlingAnimation::Abort() { | 41 void FlingAnimation::Abort() { |
| 38 fling_tracker_.StopFling(); | 42 fling_tracker_.StopFling(); |
| 39 } | 43 } |
| 40 | 44 |
| 41 void FlingAnimation::SetTickClockForTest( | 45 void FlingAnimation::SetTickClockForTest( |
| 42 std::unique_ptr<base::TickClock> clock) { | 46 std::unique_ptr<base::TickClock> clock) { |
| 43 clock_ = std::move(clock); | 47 clock_ = std::move(clock); |
| 44 } | 48 } |
| 45 | 49 |
| 46 } // namespace remoting | 50 } // namespace remoting |
| OLD | NEW |