Chromium Code Reviews| 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 |