OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #ifndef CONTENT_BROWSER_ANDROID_OVERSCROLL_GLOW_H_ | 5 #ifndef CONTENT_BROWSER_ANDROID_OVERSCROLL_GLOW_H_ |
6 #define CONTENT_BROWSER_ANDROID_OVERSCROLL_GLOW_H_ | 6 #define CONTENT_BROWSER_ANDROID_OVERSCROLL_GLOW_H_ |
7 | 7 |
8 #include "base/memory/ref_counted.h" | 8 #include "base/memory/ref_counted.h" |
9 #include "base/memory/scoped_ptr.h" | 9 #include "base/memory/scoped_ptr.h" |
10 #include "base/time.h" | 10 #include "base/time.h" |
(...skipping 15 matching lines...) Expand all Loading... |
26 */ | 26 */ |
27 class OverscrollGlow { | 27 class OverscrollGlow { |
28 public: | 28 public: |
29 static scoped_ptr<OverscrollGlow> Create(); | 29 static scoped_ptr<OverscrollGlow> Create(); |
30 | 30 |
31 // Force loading of any necessary resources. This function is thread-safe. | 31 // Force loading of any necessary resources. This function is thread-safe. |
32 static void EnsureResources(); | 32 static void EnsureResources(); |
33 | 33 |
34 ~OverscrollGlow(); | 34 ~OverscrollGlow(); |
35 | 35 |
| 36 // If false, the glow will be deactivated, and subsequent calls to |
| 37 // OnOverscrolled or Animate will have no effect. Defaults to enabled. |
| 38 void SetEnabled(bool enabled); |
| 39 |
| 40 // |overscroll| is the accumulated overscroll for the current gesture. |
| 41 // |velocity| is the instantaneous velocity for the overscroll. |
36 void OnOverscrolled(base::TimeTicks current_time, | 42 void OnOverscrolled(base::TimeTicks current_time, |
37 gfx::Vector2dF overscroll, | 43 gfx::Vector2dF overscroll, |
38 gfx::Vector2dF velocity); | 44 gfx::Vector2dF velocity); |
| 45 |
39 // Returns true if the effect still needs animation ticks. | 46 // Returns true if the effect still needs animation ticks. |
40 bool Animate(base::TimeTicks current_time); | 47 bool Animate(base::TimeTicks current_time); |
41 void Finish(); | |
42 | 48 |
43 // Returns true if the effect needs animation ticks. | 49 // Returns true if the effect needs animation ticks. |
44 bool IsActive() const; | 50 bool NeedsAnimate() const; |
45 | 51 |
46 // The root layer of the effect (not necessarily of the tree). | 52 // The root layer of the effect (not necessarily of the tree). |
47 scoped_refptr<cc::Layer> root_layer() const { | 53 scoped_refptr<cc::Layer> root_layer() const { |
48 return root_layer_; | 54 return root_layer_; |
49 } | 55 } |
50 | 56 |
| 57 // Horizontal overscroll will be ignored when false. |
51 void set_horizontal_overscroll_enabled(bool enabled) { | 58 void set_horizontal_overscroll_enabled(bool enabled) { |
52 horizontal_overscroll_enabled_ = enabled; | 59 horizontal_overscroll_enabled_ = enabled; |
53 } | 60 } |
| 61 // Vertical overscroll will be ignored when false. |
54 void set_vertical_overscroll_enabled(bool enabled) { | 62 void set_vertical_overscroll_enabled(bool enabled) { |
55 vertical_overscroll_enabled_ = enabled; | 63 vertical_overscroll_enabled_ = enabled; |
56 } | 64 } |
57 | 65 // The size of the layer for which edges will be animated. |
58 void set_size(gfx::SizeF size) { | 66 void set_size(gfx::SizeF size) { |
59 size_ = size; | 67 size_ = size; |
60 } | 68 } |
61 | 69 |
62 private: | 70 private: |
63 enum Axis { AXIS_X, AXIS_Y }; | 71 enum Axis { AXIS_X, AXIS_Y }; |
64 | 72 |
65 OverscrollGlow(const SkBitmap& edge, const SkBitmap& glow); | 73 OverscrollGlow(const SkBitmap& edge, const SkBitmap& glow); |
66 | 74 |
67 void Pull(base::TimeTicks current_time, | 75 void Pull(base::TimeTicks current_time, |
68 gfx::Vector2dF added_overscroll); | 76 gfx::Vector2dF added_overscroll); |
69 void Absorb(base::TimeTicks current_time, | 77 void Absorb(base::TimeTicks current_time, |
70 gfx::Vector2dF velocity, | 78 gfx::Vector2dF velocity, |
71 gfx::Vector2dF overscroll, | 79 gfx::Vector2dF overscroll, |
72 gfx::Vector2dF old_overscroll); | 80 gfx::Vector2dF old_overscroll); |
73 | 81 |
74 void Release(base::TimeTicks current_time); | 82 void Release(base::TimeTicks current_time); |
75 void Release(Axis axis, base::TimeTicks current_time); | 83 void Release(Axis axis, base::TimeTicks current_time); |
76 | 84 |
77 EdgeEffect* GetOppositeEdge(int edge_index); | 85 EdgeEffect* GetOppositeEdge(int edge_index); |
78 | 86 |
79 scoped_ptr<EdgeEffect> edge_effects_[EdgeEffect::EDGE_COUNT]; | 87 scoped_ptr<EdgeEffect> edge_effects_[EdgeEffect::EDGE_COUNT]; |
80 | 88 |
| 89 bool enabled_; |
81 gfx::SizeF size_; | 90 gfx::SizeF size_; |
82 gfx::Vector2dF old_overscroll_; | 91 gfx::Vector2dF old_overscroll_; |
83 gfx::Vector2dF old_velocity_; | 92 gfx::Vector2dF old_velocity_; |
84 bool horizontal_overscroll_enabled_; | 93 bool horizontal_overscroll_enabled_; |
85 bool vertical_overscroll_enabled_; | 94 bool vertical_overscroll_enabled_; |
86 | 95 |
87 scoped_refptr<cc::Layer> root_layer_; | 96 scoped_refptr<cc::Layer> root_layer_; |
88 | 97 |
89 DISALLOW_COPY_AND_ASSIGN(OverscrollGlow); | 98 DISALLOW_COPY_AND_ASSIGN(OverscrollGlow); |
90 }; | 99 }; |
91 | 100 |
92 } // namespace content | 101 } // namespace content |
93 | 102 |
94 #endif // CONTENT_BROWSER_ANDROID_SCROLL_GLOW_H_ | 103 #endif // CONTENT_BROWSER_ANDROID_SCROLL_GLOW_H_ |
OLD | NEW |