| 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
|
|
|