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" | 8 #include "base/callback.h" |
9 #include "base/memory/ref_counted.h" | 9 #include "base/memory/ref_counted.h" |
10 #include "base/memory/scoped_ptr.h" | 10 #include "base/memory/scoped_ptr.h" |
(...skipping 20 matching lines...) Expand all Loading... |
31 // Allows lazy creation of the edge effects. | 31 // Allows lazy creation of the edge effects. |
32 typedef base::Callback<scoped_ptr<EdgeEffectBase>(void)> EdgeEffectProvider; | 32 typedef base::Callback<scoped_ptr<EdgeEffectBase>(void)> EdgeEffectProvider; |
33 | 33 |
34 // |edge_effect_provider| must be valid for the duration of the effect's | 34 // |edge_effect_provider| must be valid for the duration of the effect's |
35 // lifetime. The effect is enabled by default, but will remain dormant until | 35 // lifetime. The effect is enabled by default, but will remain dormant until |
36 // the first overscroll event. | 36 // the first overscroll event. |
37 explicit OverscrollGlow(const EdgeEffectProvider& edge_effect_provider); | 37 explicit OverscrollGlow(const EdgeEffectProvider& edge_effect_provider); |
38 | 38 |
39 ~OverscrollGlow(); | 39 ~OverscrollGlow(); |
40 | 40 |
41 // Enable the effect. If the effect was previously disabled, it will remain | 41 // Called when the root content layer overscrolls. |
42 // dormant until subsequent calls to |OnOverscrolled()|. | |
43 void Enable(); | |
44 | |
45 // Deactivate and detach the effect. Subsequent calls to |OnOverscrolled()| or | |
46 // |Animate()| will have no effect. | |
47 void Disable(); | |
48 | |
49 // Effect layers will be attached to |overscrolling_layer| if necessary. | |
50 // |accumulated_overscroll| and |overscroll_delta| are in device pixels, while | 42 // |accumulated_overscroll| and |overscroll_delta| are in device pixels, while |
51 // |velocity| is in device pixels / second. | 43 // |velocity| is in device pixels / second. |
52 // Returns true if the effect still needs animation ticks. | 44 // Returns true if the effect still needs animation ticks. |
53 bool OnOverscrolled(cc::Layer* overscrolling_layer, | 45 bool OnOverscrolled(base::TimeTicks current_time, |
54 base::TimeTicks current_time, | |
55 gfx::Vector2dF accumulated_overscroll, | 46 gfx::Vector2dF accumulated_overscroll, |
56 gfx::Vector2dF overscroll_delta, | 47 gfx::Vector2dF overscroll_delta, |
57 gfx::Vector2dF velocity, | 48 gfx::Vector2dF velocity, |
58 gfx::Vector2dF overscroll_location); | 49 gfx::Vector2dF overscroll_location); |
59 | 50 |
60 // Returns true if the effect still needs animation ticks. | 51 // Returns true if the effect still needs animation ticks, with effect layers |
| 52 // attached to |parent_layer| if necessary. |
61 // Note: The effect will detach itself when no further animation is required. | 53 // Note: The effect will detach itself when no further animation is required. |
62 bool Animate(base::TimeTicks current_time); | 54 bool Animate(base::TimeTicks current_time, cc::Layer* parent_layer); |
63 | 55 |
64 // Update the effect according to the most recent display parameters, | 56 // Update the effect according to the most recent display parameters, |
65 // Note: All dimensions are in device pixels. | 57 // Note: All dimensions are in device pixels. |
66 struct DisplayParameters { | 58 void UpdateDisplay(const gfx::SizeF& viewport_size, |
67 DisplayParameters(); | 59 const gfx::SizeF& content_size, |
68 gfx::SizeF size; | 60 const gfx::Vector2dF& content_scroll_offset); |
69 float edge_offsets[EDGE_COUNT]; | 61 |
70 }; | 62 // Reset the effect to its inactive state, clearing any active effects. |
71 void UpdateDisplayParameters(const DisplayParameters& params); | 63 void Reset(); |
72 | 64 |
73 private: | 65 private: |
74 enum Axis { AXIS_X, AXIS_Y }; | 66 enum Axis { AXIS_X, AXIS_Y }; |
75 | 67 |
76 // Returns whether the effect is initialized. | 68 // Returns whether the effect has been properly initialized. |
77 bool InitializeIfNecessary(); | 69 bool InitializeIfNecessary(); |
78 bool NeedsAnimate() const; | 70 bool CheckNeedsAnimate(); |
79 void UpdateLayerAttachment(cc::Layer* parent); | 71 void UpdateLayerAttachment(cc::Layer* parent); |
80 void Detach(); | 72 void Detach(); |
81 void Pull(base::TimeTicks current_time, | 73 void Pull(base::TimeTicks current_time, |
82 const gfx::Vector2dF& overscroll_delta, | 74 const gfx::Vector2dF& overscroll_delta, |
83 const gfx::Vector2dF& overscroll_location); | 75 const gfx::Vector2dF& overscroll_location); |
84 void Absorb(base::TimeTicks current_time, | 76 void Absorb(base::TimeTicks current_time, |
85 const gfx::Vector2dF& velocity, | 77 const gfx::Vector2dF& velocity, |
86 bool x_overscroll_started, | 78 bool x_overscroll_started, |
87 bool y_overscroll_started); | 79 bool y_overscroll_started); |
88 void Release(base::TimeTicks current_time); | 80 void Release(base::TimeTicks current_time); |
89 | 81 |
90 EdgeEffectBase* GetOppositeEdge(int edge_index); | 82 EdgeEffectBase* GetOppositeEdge(int edge_index); |
91 | 83 |
92 EdgeEffectProvider edge_effect_provider_; | 84 EdgeEffectProvider edge_effect_provider_; |
93 scoped_ptr<EdgeEffectBase> edge_effects_[EDGE_COUNT]; | 85 scoped_ptr<EdgeEffectBase> edge_effects_[EDGE_COUNT]; |
94 | 86 |
95 DisplayParameters display_params_; | 87 gfx::SizeF viewport_size_; |
96 bool enabled_; | 88 float edge_offsets_[EDGE_COUNT]; |
97 bool initialized_; | 89 bool initialized_; |
98 | 90 |
99 scoped_refptr<cc::Layer> root_layer_; | 91 scoped_refptr<cc::Layer> root_layer_; |
100 | 92 |
101 DISALLOW_COPY_AND_ASSIGN(OverscrollGlow); | 93 DISALLOW_COPY_AND_ASSIGN(OverscrollGlow); |
102 }; | 94 }; |
103 | 95 |
104 } // namespace content | 96 } // namespace content |
105 | 97 |
106 #endif // CONTENT_BROWSER_ANDROID_SCROLL_GLOW_H_ | 98 #endif // CONTENT_BROWSER_ANDROID_SCROLL_GLOW_H_ |
OLD | NEW |