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

Side by Side 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: Rebase Created 7 years, 11 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 unified diff | Download patch | Annotate | Revision Log
OLDNEW
(Empty)
1 // Copyright 2012 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 "cc/top_controls_animation.h"
6
7 #include "base/logging.h"
8 #include "cc/timing_function.h"
9
10 using base::TimeDelta;
11 using base::TimeTicks;
12
13 namespace cc {
14
15 scoped_ptr<TopControlsAnimation> TopControlsAnimation::Create(
16 float start_y_offset,
17 float top_controls_height,
18 TimeTicks start_time,
19 TimeDelta max_duration) {
20 return make_scoped_ptr(new TopControlsAnimation(
21 start_y_offset, top_controls_height, start_time, max_duration));
22 }
23
24 TopControlsAnimation::TopControlsAnimation(float start_y_offset,
25 float top_controls_height,
26 TimeTicks start_time,
27 TimeDelta max_duration)
28 : start_y_offset_(start_y_offset),
29 top_controls_height_(top_controls_height),
30 direction_(1),
31 start_time_(start_time),
32 max_duration_(max_duration) {
33 timing_function_ = EaseTimingFunction::create();
34 }
35
36 TopControlsAnimation::~TopControlsAnimation() {
37 }
38
39 void TopControlsAnimation::SetDirection(bool showing) {
40 direction_ = showing ? 1 : -1;
41 }
42
43 float TopControlsAnimation::ScrollOffsetAtTime(TimeTicks time) const {
44 TimeDelta elapsed_time = time - start_time_;
45 float offset_delta = timing_function_->getValue(
46 elapsed_time.InSecondsF() / max_duration_.InSecondsF())
47 * direction_ * top_controls_height_;
48 return start_y_offset_ + offset_delta;
49 }
50
51 bool TopControlsAnimation::IsAnimationCompleteAtTime(TimeTicks time) const {
52 float scroll_offset = ScrollOffsetAtTime(time);
53 if (direction_ == 1)
54 return scroll_offset >= 0;
55 else
56 return scroll_offset <= -top_controls_height_;
57 }
58
59 } // namespace cc
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698