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/time.h" | 10 #include "base/time/time.h" |
(...skipping 12 matching lines...) Expand all Loading... |
23 /* |OverscrollGlow| mirrors its Android counterpart, OverscrollGlow.java. | 23 /* |OverscrollGlow| mirrors its Android counterpart, OverscrollGlow.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 // Create and initialize a new effect with the necessary resources. | 29 // Create and initialize a new effect with the necessary resources. |
30 // If |enabled| is false, the effect will be be deactivated until | 30 // If |enabled| is false, the effect will be be deactivated until |
31 // SetEnabled(true) is called. | 31 // SetEnabled(true) is called. |
32 // The caller should attach |root_layer| to the desired layer tree. | 32 // The caller should attach |root_layer| to the desired layer tree. |
33 static scoped_ptr<OverscrollGlow> Create(bool enabled); | 33 static scoped_ptr<OverscrollGlow> Create(bool enabled, gfx::SizeF size); |
34 | 34 |
35 // Force loading of any necessary resources. This function is thread-safe. | 35 // Force loading of any necessary resources. This function is thread-safe. |
36 static void EnsureResources(); | 36 static void EnsureResources(); |
37 | 37 |
38 ~OverscrollGlow(); | 38 ~OverscrollGlow(); |
39 | 39 |
40 // If false, the glow will be deactivated, and subsequent calls to | 40 // If false, the glow will be deactivated, and subsequent calls to |
41 // OnOverscrolled or Animate will have no effect. | 41 // OnOverscrolled or Animate will have no effect. |
42 void SetEnabled(bool enabled); | 42 void SetEnabled(bool enabled); |
43 | 43 |
(...skipping 28 matching lines...) Expand all Loading... |
72 vertical_overscroll_enabled_ = enabled; | 72 vertical_overscroll_enabled_ = enabled; |
73 } | 73 } |
74 // The size of the layer for which edges will be animated. | 74 // The size of the layer for which edges will be animated. |
75 void set_size(gfx::SizeF size) { | 75 void set_size(gfx::SizeF size) { |
76 size_ = size; | 76 size_ = size; |
77 } | 77 } |
78 | 78 |
79 private: | 79 private: |
80 enum Axis { AXIS_X, AXIS_Y }; | 80 enum Axis { AXIS_X, AXIS_Y }; |
81 | 81 |
82 OverscrollGlow(bool enabled, const SkBitmap& edge, const SkBitmap& glow); | 82 OverscrollGlow(bool enabled, |
| 83 gfx::SizeF size, |
| 84 const SkBitmap& edge, |
| 85 const SkBitmap& glow); |
83 | 86 |
84 void Pull(base::TimeTicks current_time, | 87 void Pull(base::TimeTicks current_time, |
85 gfx::Vector2dF added_overscroll); | 88 gfx::Vector2dF added_overscroll); |
86 void Absorb(base::TimeTicks current_time, | 89 void Absorb(base::TimeTicks current_time, |
87 gfx::Vector2dF velocity, | 90 gfx::Vector2dF velocity, |
88 gfx::Vector2dF overscroll, | 91 gfx::Vector2dF overscroll, |
89 gfx::Vector2dF old_overscroll); | 92 gfx::Vector2dF old_overscroll); |
90 | 93 |
91 void ReleaseAxis(Axis axis, base::TimeTicks current_time); | 94 void ReleaseAxis(Axis axis, base::TimeTicks current_time); |
92 | 95 |
93 EdgeEffect* GetOppositeEdge(int edge_index); | 96 EdgeEffect* GetOppositeEdge(int edge_index); |
94 | 97 |
95 scoped_ptr<EdgeEffect> edge_effects_[EdgeEffect::EDGE_COUNT]; | 98 scoped_ptr<EdgeEffect> edge_effects_[EdgeEffect::EDGE_COUNT]; |
96 | 99 |
97 bool enabled_; | 100 bool enabled_; |
98 gfx::SizeF size_; | 101 gfx::SizeF size_; |
99 gfx::Vector2dF old_overscroll_; | 102 gfx::Vector2dF old_overscroll_; |
100 gfx::Vector2dF old_velocity_; | 103 gfx::Vector2dF old_velocity_; |
101 bool horizontal_overscroll_enabled_; | 104 bool horizontal_overscroll_enabled_; |
102 bool vertical_overscroll_enabled_; | 105 bool vertical_overscroll_enabled_; |
103 | 106 |
104 scoped_refptr<cc::Layer> root_layer_; | 107 scoped_refptr<cc::Layer> root_layer_; |
105 | 108 |
106 DISALLOW_COPY_AND_ASSIGN(OverscrollGlow); | 109 DISALLOW_COPY_AND_ASSIGN(OverscrollGlow); |
107 }; | 110 }; |
108 | 111 |
109 } // namespace content | 112 } // namespace content |
110 | 113 |
111 #endif // CONTENT_BROWSER_ANDROID_SCROLL_GLOW_H_ | 114 #endif // CONTENT_BROWSER_ANDROID_SCROLL_GLOW_H_ |
OLD | NEW |