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

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: Forgot to add the changes to cc_messages.h 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..a7d610d72ee4daa312be360a5d03c9dc07aeb06b
--- /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 startScrollOffset,
+ float topControlsHeight,
+ TimeTicks startTime,
+ TimeDelta maxDuration) {
+ return make_scoped_ptr(new TopControlsAnimation(
+ startScrollOffset, topControlsHeight, startTime, maxDuration));
+}
+
+TopControlsAnimation::TopControlsAnimation(float startScrollOffset,
+ float topControlsHeight,
+ TimeTicks startTime,
+ TimeDelta maxDuration)
+ : start_scroll_offset_(startScrollOffset),
+ top_controls_height_(topControlsHeight),
+ direction_(1),
+ start_time_(startTime),
+ max_duration_(maxDuration) {
+ 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 offsetDelta = timing_function_->getValue(
+ elapsed_time.InSecondsF() / max_duration_.InSecondsF())
+ * direction_ * top_controls_height_;
+ return start_scroll_offset_ + offsetDelta;
+}
+
+bool TopControlsAnimation::isAnimationCompleteAtTime(TimeTicks time) const {
+ float scrollOffset = scrollOffsetAtTime(time);
+ if (direction_ == 1)
+ return scrollOffset >= 0;
+ else
+ return scrollOffset <= -top_controls_height_;
aelias_OOO_until_Jul13 2012/12/19 08:31:18 It would be simpler to just compare max_duration_
Ted C 2012/12/19 21:34:17 I'd prefer to keep it comparing against expected h
+}
+
+} // namespace cc

Powered by Google App Engine
This is Rietveld 408576698