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/callback.h" | |
9 #include "base/memory/ref_counted.h" | 8 #include "base/memory/ref_counted.h" |
10 #include "base/memory/scoped_ptr.h" | 9 #include "base/memory/scoped_ptr.h" |
11 #include "base/time/time.h" | 10 #include "base/time/time.h" |
12 #include "ui/gfx/size_f.h" | 11 #include "ui/gfx/size_f.h" |
13 #include "ui/gfx/vector2d_f.h" | 12 #include "ui/gfx/vector2d_f.h" |
14 | 13 |
15 namespace cc { | 14 namespace cc { |
16 class Layer; | 15 class Layer; |
17 } | 16 } |
18 | 17 |
19 namespace content { | 18 namespace content { |
20 | 19 |
21 class EdgeEffectBase; | 20 class EdgeEffectBase; |
22 | 21 |
| 22 // Provides lazy, customized EdgeEffect creation. |
| 23 class OverscrollGlowClient { |
| 24 public: |
| 25 virtual ~OverscrollGlowClient() {} |
| 26 |
| 27 // Called lazily, after the initial overscrolling event. |
| 28 virtual scoped_ptr<EdgeEffectBase> CreateEdgeEffect() = 0; |
| 29 }; |
| 30 |
23 /* |OverscrollGlow| mirrors its Android counterpart, OverscrollGlow.java. | 31 /* |OverscrollGlow| mirrors its Android counterpart, OverscrollGlow.java. |
24 * Conscious tradeoffs were made to align this as closely as possible with the | 32 * Conscious tradeoffs were made to align this as closely as possible with the |
25 * original Android Java version. | 33 * original Android Java version. |
26 */ | 34 */ |
27 class OverscrollGlow { | 35 class OverscrollGlow { |
28 public: | 36 public: |
29 enum Edge { EDGE_TOP = 0, EDGE_LEFT, EDGE_BOTTOM, EDGE_RIGHT, EDGE_COUNT }; | 37 enum Edge { EDGE_TOP = 0, EDGE_LEFT, EDGE_BOTTOM, EDGE_RIGHT, EDGE_COUNT }; |
30 | 38 |
31 // Allows lazy creation of the edge effects. | 39 // |client| must be valid for the duration of the effect's lifetime. |
32 typedef base::Callback<scoped_ptr<EdgeEffectBase>(void)> EdgeEffectProvider; | 40 // The effect is enabled by default, but will remain dormant until the first |
33 | 41 // overscroll event. |
34 // |edge_effect_provider| must be valid for the duration of the effect's | 42 explicit OverscrollGlow(OverscrollGlowClient* client); |
35 // lifetime. The effect is enabled by default, but will remain dormant until | |
36 // the first overscroll event. | |
37 explicit OverscrollGlow(const EdgeEffectProvider& edge_effect_provider); | |
38 | |
39 ~OverscrollGlow(); | 43 ~OverscrollGlow(); |
40 | 44 |
41 // Called when the root content layer overscrolls. | 45 // Called when the root content layer overscrolls. |
42 // |accumulated_overscroll| and |overscroll_delta| are in device pixels, while | 46 // |accumulated_overscroll| and |overscroll_delta| are in device pixels, while |
43 // |velocity| is in device pixels / second. | 47 // |velocity| is in device pixels / second. |
44 // Returns true if the effect still needs animation ticks. | 48 // Returns true if the effect still needs animation ticks. |
45 bool OnOverscrolled(base::TimeTicks current_time, | 49 bool OnOverscrolled(base::TimeTicks current_time, |
46 gfx::Vector2dF accumulated_overscroll, | 50 gfx::Vector2dF accumulated_overscroll, |
47 gfx::Vector2dF overscroll_delta, | 51 gfx::Vector2dF overscroll_delta, |
48 gfx::Vector2dF velocity, | 52 gfx::Vector2dF velocity, |
(...skipping 25 matching lines...) Expand all Loading... |
74 const gfx::Vector2dF& overscroll_delta, | 78 const gfx::Vector2dF& overscroll_delta, |
75 const gfx::Vector2dF& overscroll_location); | 79 const gfx::Vector2dF& overscroll_location); |
76 void Absorb(base::TimeTicks current_time, | 80 void Absorb(base::TimeTicks current_time, |
77 const gfx::Vector2dF& velocity, | 81 const gfx::Vector2dF& velocity, |
78 bool x_overscroll_started, | 82 bool x_overscroll_started, |
79 bool y_overscroll_started); | 83 bool y_overscroll_started); |
80 void Release(base::TimeTicks current_time); | 84 void Release(base::TimeTicks current_time); |
81 | 85 |
82 EdgeEffectBase* GetOppositeEdge(int edge_index); | 86 EdgeEffectBase* GetOppositeEdge(int edge_index); |
83 | 87 |
84 EdgeEffectProvider edge_effect_provider_; | 88 OverscrollGlowClient* const client_; |
85 scoped_ptr<EdgeEffectBase> edge_effects_[EDGE_COUNT]; | 89 scoped_ptr<EdgeEffectBase> edge_effects_[EDGE_COUNT]; |
86 | 90 |
87 gfx::SizeF viewport_size_; | 91 gfx::SizeF viewport_size_; |
88 float edge_offsets_[EDGE_COUNT]; | 92 float edge_offsets_[EDGE_COUNT]; |
89 bool initialized_; | 93 bool initialized_; |
90 | 94 |
91 scoped_refptr<cc::Layer> root_layer_; | 95 scoped_refptr<cc::Layer> root_layer_; |
92 | 96 |
93 DISALLOW_COPY_AND_ASSIGN(OverscrollGlow); | 97 DISALLOW_COPY_AND_ASSIGN(OverscrollGlow); |
94 }; | 98 }; |
95 | 99 |
96 } // namespace content | 100 } // namespace content |
97 | 101 |
98 #endif // CONTENT_BROWSER_ANDROID_SCROLL_GLOW_H_ | 102 #endif // CONTENT_BROWSER_ANDROID_SCROLL_GLOW_H_ |
OLD | NEW |