blob: a0ca321ef2a03ab8c0eb3ee36968d161bac9f2b6 [file] [log] [blame]
[email protected]c6de4d8e2013-05-17 17:51:511// 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.
4
5#ifndef CONTENT_BROWSER_ANDROID_OVERSCROLL_GLOW_H_
6#define CONTENT_BROWSER_ANDROID_OVERSCROLL_GLOW_H_
7
8#include "base/memory/ref_counted.h"
9#include "base/memory/scoped_ptr.h"
10#include "base/time.h"
11#include "content/browser/android/edge_effect.h"
12#include "ui/gfx/size_f.h"
13#include "ui/gfx/vector2d_f.h"
14
15class SkBitmap;
16
17namespace cc {
18class Layer;
19}
20
21namespace content {
22
23/* |OverscrollGlow| mirrors its Android counterpart, EdgeEffect.java.
24 * Conscious tradeoffs were made to align this as closely as possible with the
25 * original Android java version.
26 */
27class OverscrollGlow {
28 public:
29 static scoped_ptr<OverscrollGlow> Create();
30
31 ~OverscrollGlow();
32
33 void OnOverscrolled(base::TimeTicks current_time,
34 gfx::Vector2dF overscroll,
35 gfx::Vector2dF velocity);
36 // Returns true if the effect still needs animation ticks.
37 bool Animate(base::TimeTicks current_time);
38 void Finish();
39
40 // Returns true if the effect needs animation ticks.
41 bool IsActive() const;
42
43 // The root layer of the effect (not necessarily of the tree).
44 scoped_refptr<cc::Layer> root_layer() const {
45 return root_layer_;
46 }
47
48 void set_horizontal_overscroll_enabled(bool enabled) {
49 horizontal_overscroll_enabled_ = enabled;
50 }
51 void set_vertical_overscroll_enabled(bool enabled) {
52 vertical_overscroll_enabled_ = enabled;
53 }
54
55 void set_size(gfx::SizeF size) {
56 size_ = size;
57 }
58
59 private:
60 enum Axis { AXIS_X, AXIS_Y };
61
62 OverscrollGlow(const SkBitmap& edge, const SkBitmap& glow);
63
64 void Pull(base::TimeTicks current_time,
65 gfx::Vector2dF added_overscroll);
66 void Absorb(base::TimeTicks current_time,
67 gfx::Vector2dF velocity,
68 gfx::Vector2dF overscroll,
69 gfx::Vector2dF old_overscroll);
70
71 void Release(base::TimeTicks current_time);
72 void Release(Axis axis, base::TimeTicks current_time);
73
74 EdgeEffect* GetOppositeEdge(int edge_index);
75
76 scoped_ptr<EdgeEffect> edge_effects_[EdgeEffect::EDGE_COUNT];
77
78 gfx::SizeF size_;
79 gfx::Vector2dF old_overscroll_;
80 gfx::Vector2dF old_velocity_;
81 bool horizontal_overscroll_enabled_;
82 bool vertical_overscroll_enabled_;
83
84 scoped_refptr<cc::Layer> root_layer_;
85
86 DISALLOW_COPY_AND_ASSIGN(OverscrollGlow);
87};
88
89} // namespace content
90
91#endif // CONTENT_BROWSER_ANDROID_SCROLL_GLOW_H_