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" |
11 #include "content/browser/android/edge_effect.h" | 11 #include "content/browser/android/edge_effect.h" |
12 #include "ui/gfx/size_f.h" | 12 #include "ui/gfx/size_f.h" |
13 #include "ui/gfx/vector2d_f.h" | 13 #include "ui/gfx/vector2d_f.h" |
14 | 14 |
15 class SkBitmap; | 15 class SkBitmap; |
16 | 16 |
17 namespace cc { | 17 namespace cc { |
18 class Layer; | 18 class Layer; |
19 } | 19 } |
20 | 20 |
21 namespace content { | 21 namespace content { |
22 | 22 |
23 /* |OverscrollGlow| mirrors its Android counterpart, EdgeEffect.java. | 23 /* |OverscrollGlow| mirrors its Android counterpart, EdgeEffect.java. |
24 * Conscious tradeoffs were made to align this as closely as possible with the | 24 * Conscious tradeoffs were made to align this as closely as possible with the |
25 * original Android java version. | 25 * original Android java version. |
26 */ | 26 */ |
27 class OverscrollGlow { | 27 class OverscrollGlow { |
28 public: | 28 public: |
29 static scoped_ptr<OverscrollGlow> Create(); | 29 // Create and initialize a new effect with the necessary resources. |
| 30 // If |enabled| is false, the effect will be be deactivated until |
| 31 // SetEnabled(true) is called. |
| 32 // The caller should attach |root_layer| to the desired layer tree. |
| 33 static scoped_ptr<OverscrollGlow> Create(bool enabled); |
30 | 34 |
31 // Force loading of any necessary resources. This function is thread-safe. | 35 // Force loading of any necessary resources. This function is thread-safe. |
32 static void EnsureResources(); | 36 static void EnsureResources(); |
33 | 37 |
34 ~OverscrollGlow(); | 38 ~OverscrollGlow(); |
35 | 39 |
| 40 // If false, the glow will be deactivated, and subsequent calls to |
| 41 // OnOverscrolled or Animate will have no effect. |
| 42 void SetEnabled(bool enabled); |
| 43 |
| 44 // |overscroll| is the accumulated overscroll for the current gesture. |
| 45 // |velocity| is the instantaneous velocity for the overscroll. |
36 void OnOverscrolled(base::TimeTicks current_time, | 46 void OnOverscrolled(base::TimeTicks current_time, |
37 gfx::Vector2dF overscroll, | 47 gfx::Vector2dF overscroll, |
38 gfx::Vector2dF velocity); | 48 gfx::Vector2dF velocity); |
| 49 |
39 // Returns true if the effect still needs animation ticks. | 50 // Returns true if the effect still needs animation ticks. |
40 bool Animate(base::TimeTicks current_time); | 51 bool Animate(base::TimeTicks current_time); |
41 void Finish(); | |
42 | 52 |
43 // Returns true if the effect needs animation ticks. | 53 // Returns true if the effect needs animation ticks. |
44 bool IsActive() const; | 54 bool NeedsAnimate() const; |
45 | 55 |
46 // The root layer of the effect (not necessarily of the tree). | 56 // The root layer of the effect (not necessarily of the tree). |
47 scoped_refptr<cc::Layer> root_layer() const { | 57 scoped_refptr<cc::Layer> root_layer() const { |
48 return root_layer_; | 58 return root_layer_; |
49 } | 59 } |
50 | 60 |
| 61 // Horizontal overscroll will be ignored when false. |
51 void set_horizontal_overscroll_enabled(bool enabled) { | 62 void set_horizontal_overscroll_enabled(bool enabled) { |
52 horizontal_overscroll_enabled_ = enabled; | 63 horizontal_overscroll_enabled_ = enabled; |
53 } | 64 } |
| 65 // Vertical overscroll will be ignored when false. |
54 void set_vertical_overscroll_enabled(bool enabled) { | 66 void set_vertical_overscroll_enabled(bool enabled) { |
55 vertical_overscroll_enabled_ = enabled; | 67 vertical_overscroll_enabled_ = enabled; |
56 } | 68 } |
57 | 69 // The size of the layer for which edges will be animated. |
58 void set_size(gfx::SizeF size) { | 70 void set_size(gfx::SizeF size) { |
59 size_ = size; | 71 size_ = size; |
60 } | 72 } |
61 | 73 |
62 private: | 74 private: |
63 enum Axis { AXIS_X, AXIS_Y }; | 75 enum Axis { AXIS_X, AXIS_Y }; |
64 | 76 |
65 OverscrollGlow(const SkBitmap& edge, const SkBitmap& glow); | 77 OverscrollGlow(bool enabled, const SkBitmap& edge, const SkBitmap& glow); |
66 | 78 |
67 void Pull(base::TimeTicks current_time, | 79 void Pull(base::TimeTicks current_time, |
68 gfx::Vector2dF added_overscroll); | 80 gfx::Vector2dF added_overscroll); |
69 void Absorb(base::TimeTicks current_time, | 81 void Absorb(base::TimeTicks current_time, |
70 gfx::Vector2dF velocity, | 82 gfx::Vector2dF velocity, |
71 gfx::Vector2dF overscroll, | 83 gfx::Vector2dF overscroll, |
72 gfx::Vector2dF old_overscroll); | 84 gfx::Vector2dF old_overscroll); |
73 | 85 |
74 void Release(base::TimeTicks current_time); | 86 void Release(base::TimeTicks current_time); |
75 void Release(Axis axis, base::TimeTicks current_time); | 87 void Release(Axis axis, base::TimeTicks current_time); |
76 | 88 |
77 EdgeEffect* GetOppositeEdge(int edge_index); | 89 EdgeEffect* GetOppositeEdge(int edge_index); |
78 | 90 |
79 scoped_ptr<EdgeEffect> edge_effects_[EdgeEffect::EDGE_COUNT]; | 91 scoped_ptr<EdgeEffect> edge_effects_[EdgeEffect::EDGE_COUNT]; |
80 | 92 |
| 93 bool enabled_; |
81 gfx::SizeF size_; | 94 gfx::SizeF size_; |
82 gfx::Vector2dF old_overscroll_; | 95 gfx::Vector2dF old_overscroll_; |
83 gfx::Vector2dF old_velocity_; | 96 gfx::Vector2dF old_velocity_; |
84 bool horizontal_overscroll_enabled_; | 97 bool horizontal_overscroll_enabled_; |
85 bool vertical_overscroll_enabled_; | 98 bool vertical_overscroll_enabled_; |
86 | 99 |
87 scoped_refptr<cc::Layer> root_layer_; | 100 scoped_refptr<cc::Layer> root_layer_; |
88 | 101 |
89 DISALLOW_COPY_AND_ASSIGN(OverscrollGlow); | 102 DISALLOW_COPY_AND_ASSIGN(OverscrollGlow); |
90 }; | 103 }; |
91 | 104 |
92 } // namespace content | 105 } // namespace content |
93 | 106 |
94 #endif // CONTENT_BROWSER_ANDROID_SCROLL_GLOW_H_ | 107 #endif // CONTENT_BROWSER_ANDROID_SCROLL_GLOW_H_ |
OLD | NEW |