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

Unified Diff: cc/top_controls_animation.cc

Issue 11552009: Add support for calculating the position of the top controls in the cc layer. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Remove some unnecessary bits after addressing comments. Created 8 years 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: cc/top_controls_animation.cc
diff --git a/cc/top_controls_animation.cc b/cc/top_controls_animation.cc
new file mode 100644
index 0000000000000000000000000000000000000000..7720533f0efa7636715b785e618e06024a1b20ad
--- /dev/null
+++ b/cc/top_controls_animation.cc
@@ -0,0 +1,59 @@
+// Copyright 2012 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.
+
+#include "cc/top_controls_animation.h"
+
+#include "base/logging.h"
+#include "cc/timing_function.h"
+
+using base::TimeDelta;
+using base::TimeTicks;
+
+namespace cc {
+
+scoped_ptr<TopControlsAnimation> TopControlsAnimation::Create(
+ float start_y_offset,
+ float top_controls_height,
+ TimeTicks start_time,
+ TimeDelta max_duration) {
+ return make_scoped_ptr(new TopControlsAnimation(
+ start_y_offset, top_controls_height, start_time, max_duration));
+}
+
+TopControlsAnimation::TopControlsAnimation(float start_y_offset,
+ float top_controls_height,
+ TimeTicks start_time,
+ TimeDelta max_duration)
+ : start_y_offset_(start_y_offset),
+ top_controls_height_(top_controls_height),
+ direction_(1),
+ start_time_(start_time),
+ max_duration_(max_duration) {
+ timing_function_ = EaseTimingFunction::create();
+}
+
+TopControlsAnimation::~TopControlsAnimation() {
+}
+
+void TopControlsAnimation::SetDirection(bool showing) {
+ direction_ = showing ? 1 : -1;
+}
+
+float TopControlsAnimation::ScrollOffsetAtTime(TimeTicks time) const {
+ TimeDelta elapsed_time = time - start_time_;
+ float offset_delta = timing_function_->getValue(
+ elapsed_time.InSecondsF() / max_duration_.InSecondsF())
+ * direction_ * top_controls_height_;
+ return start_y_offset_ + offset_delta;
+}
+
+bool TopControlsAnimation::IsAnimationCompleteAtTime(TimeTicks time) const {
+ float scroll_offset = ScrollOffsetAtTime(time);
+ if (direction_ == 1)
+ return scroll_offset >= 0;
+ else
+ return scroll_offset <= -top_controls_height_;
+}
+
+} // namespace cc

Powered by Google App Engine
This is Rietveld 408576698