Drive: Add BatchableRequest subclass.
[chromium-blink-merge.git] / ui / views / animation / scroll_animator.h
blobdcca55aac84d2ec58152189e2f0c1ce7c75a5fb8
1 // Copyright (c) 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.
5 #ifndef UI_VIEWS_ANIMATION_SCROLL_ANIMATOR_H_
6 #define UI_VIEWS_ANIMATION_SCROLL_ANIMATOR_H_
8 #include "base/basictypes.h"
9 #include "base/memory/scoped_ptr.h"
10 #include "ui/gfx/animation/animation_delegate.h"
11 #include "ui/views/views_export.h"
13 namespace gfx {
14 class SlideAnimation;
17 namespace views {
19 class VIEWS_EXPORT ScrollDelegate {
20 public:
21 // Returns true if the content was actually scrolled, false otherwise.
22 virtual bool OnScroll(float dx, float dy) = 0;
24 protected:
25 ~ScrollDelegate() {}
28 class VIEWS_EXPORT ScrollAnimator : public gfx::AnimationDelegate {
29 public:
30 // The ScrollAnimator does not own the delegate. Uses default acceleration.
31 explicit ScrollAnimator(ScrollDelegate* delegate);
32 ~ScrollAnimator() override;
34 // Use this if you would prefer different acceleration than the default.
35 void set_acceleration(float acceleration) { acceleration_ = acceleration; }
37 void Start(float velocity_x, float velocity_y);
38 void Stop();
40 bool is_scrolling() const { return !!animation_.get(); }
42 private:
43 // Implementation of gfx::AnimationDelegate.
44 void AnimationEnded(const gfx::Animation* animation) override;
45 void AnimationProgressed(const gfx::Animation* animation) override;
46 void AnimationCanceled(const gfx::Animation* animation) override;
48 ScrollDelegate* delegate_;
50 float velocity_x_;
51 float velocity_y_;
52 float last_t_;
53 float duration_;
54 float acceleration_;
56 scoped_ptr<gfx::SlideAnimation> animation_;
58 DISALLOW_COPY_AND_ASSIGN(ScrollAnimator);
61 } // namespace views
63 #endif // UI_VIEWS_ANIMATION_SCROLL_ANIMATOR_H_