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