Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(64)

Unified Diff: remoting/client/fling_animation.h

Issue 2869723007: [CRD iOS] Viewport fling animation (Closed)
Patch Set: Merge branch 'master' into feat-fling-animation Created 3 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: remoting/client/fling_animation.h
diff --git a/remoting/client/fling_animation.h b/remoting/client/fling_animation.h
new file mode 100644
index 0000000000000000000000000000000000000000..511f44fa7860f56e2cf22e9fabe6e9f2f04441cb
--- /dev/null
+++ b/remoting/client/fling_animation.h
@@ -0,0 +1,50 @@
+// Copyright 2017 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#ifndef REMOTING_CLIENT_FLING_ANIMATION_H_
+#define REMOTING_CLIENT_FLING_ANIMATION_H_
+
+#include "base/callback.h"
+#include "remoting/client/fling_tracker.h"
+
+namespace remoting {
+
+// This class helps interpolating the positions of an object with the given
+// initial velocity and feeds the change in position back to the callback.
+class FlingAnimation {
+ public:
+ using FlingCallback = base::Callback<void(float, float)>;
nicholss 2017/05/10 19:34:05 Can you document the callback please
Yuwei 2017/05/10 23:28:24 Done.
+
+ // FlingCallback: arguments are delta_x and delta_y with respect to the
+ // positions at previous tick.
nicholss 2017/05/10 19:34:05 running git cl format leaves these spaces?
Yuwei 2017/05/10 23:28:24 I was trying to follow the four-space indenting ru
+ FlingAnimation(float time_constant, const FlingCallback& fling_callback);
+ ~FlingAnimation();
+
+ // (Re)starts the fling animation with the given initial velocity.
+ void Reset(float velocity_x, float velocity_y);
nicholss 2017/05/10 19:34:05 rename to setVelocity() ?
Yuwei 2017/05/10 23:28:24 Done.
+
+ bool IsAnimationInProgress() const;
+
+ // Moves forward the animation to catch up with current time. Calls the fling
+ // callback with the new positions. No-op if fling animation is not in
+ // progress.
+ void Tick();
+
+ // Aborts the animation.
+ void Abort();
+
+ private:
+ FlingTracker fling_tracker_;
nicholss 2017/05/10 19:34:05 Forward declare rather than include?
Yuwei 2017/05/10 23:28:24 This is not a pointer nor a reference so forward d
+ FlingCallback fling_callback_;
+
+ float previous_position_x_ = 0.f;
+ float previous_position_y_ = 0.f;
+
+ // FlingAnimation is neither copyable nor movable.
+ FlingAnimation(const FlingAnimation&) = delete;
+ FlingAnimation& operator=(const FlingAnimation&) = delete;
+};
+
+} // namespace remoting
+#endif // REMOTING_CLIENT_FLING_ANIMATION_H_

Powered by Google App Engine
This is Rietveld 408576698