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" |
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 ui { | |
22 class SystemUIResourceManager; | |
23 } | |
24 | |
21 namespace content { | 25 namespace content { |
22 | 26 |
27 // A wrapper class over the cc::Layer. | |
28 class OverscrollGlowLayerWrapper { | |
jdduke (slow)
2014/07/12 01:01:09
Could we have EdgeEffect define this interface (in
powei
2014/07/16 17:10:52
Done.
| |
29 public: | |
30 virtual scoped_refptr<cc::Layer> layer() = 0; | |
jdduke (slow)
2014/07/12 01:01:09
What about just returning a naked pointer?
powei
2014/07/16 17:10:51
Done.
| |
31 virtual ~OverscrollGlowLayerWrapper() {} | |
32 }; | |
33 | |
23 /* |OverscrollGlow| mirrors its Android counterpart, OverscrollGlow.java. | 34 /* |OverscrollGlow| mirrors its Android counterpart, OverscrollGlow.java. |
24 * Conscious tradeoffs were made to align this as closely as possible with the | 35 * Conscious tradeoffs were made to align this as closely as possible with the |
25 * original Android Java version. | 36 * original Android Java version. |
26 */ | 37 */ |
27 class OverscrollGlow { | 38 class OverscrollGlow { |
28 public: | 39 public: |
29 // Create a new effect. If |enabled| is false, the effect will remain | 40 // Create a new effect. WindowAndroid provides the resource for the effect. |
jdduke (slow)
2014/07/12 01:01:09
Hmm, did you mean to reference WindowAndroid inste
powei
2014/07/16 17:10:52
Done.
| |
30 // deactivated until explicitly enabled. | 41 // If |enabled| is false, the effect will remain deactivated until explicitly |
31 // Note: No resources will be allocated until the effect is both | 42 // enabled. |
32 // enabled and an overscroll event has occurred. | 43 static scoped_ptr<OverscrollGlow> Create( |
33 static scoped_ptr<OverscrollGlow> Create(bool enabled); | 44 ui::SystemUIResourceManager* resource_manager); |
34 | 45 |
35 ~OverscrollGlow(); | 46 ~OverscrollGlow(); |
36 | 47 |
37 // Enable the effect. If the effect was previously disabled, it will remain | 48 // Enable the effect. If the effect was previously disabled, it will remain |
38 // dormant until subsequent calls to |OnOverscrolled()|. | 49 // dormant until subsequent calls to |OnOverscrolled()|. |
39 void Enable(); | 50 void Enable(); |
40 | 51 |
41 // Deactivate and detach the effect. Subsequent calls to |OnOverscrolled()| or | 52 // Deactivate and detach the effect. Subsequent calls to |OnOverscrolled()| or |
42 // |Animate()| will have no effect. | 53 // |Animate()| will have no effect. |
43 void Disable(); | 54 void Disable(); |
(...skipping 19 matching lines...) Expand all Loading... | |
63 gfx::SizeF size; | 74 gfx::SizeF size; |
64 float edge_offsets[EdgeEffect::EDGE_COUNT]; | 75 float edge_offsets[EdgeEffect::EDGE_COUNT]; |
65 float device_scale_factor; | 76 float device_scale_factor; |
66 }; | 77 }; |
67 void UpdateDisplayParameters(const DisplayParameters& params); | 78 void UpdateDisplayParameters(const DisplayParameters& params); |
68 | 79 |
69 | 80 |
70 private: | 81 private: |
71 enum Axis { AXIS_X, AXIS_Y }; | 82 enum Axis { AXIS_X, AXIS_Y }; |
72 | 83 |
73 OverscrollGlow(bool enabled); | 84 OverscrollGlow(ui::SystemUIResourceManager* resource_manager); |
74 | 85 |
75 // Returns whether the effect is initialized. | 86 // Returns whether the effect is initialized. |
76 bool InitializeIfNecessary(); | 87 bool InitializeIfNecessary(); |
77 bool NeedsAnimate() const; | 88 bool NeedsAnimate() const; |
78 void UpdateLayerAttachment(cc::Layer* parent); | 89 void UpdateLayerAttachment(cc::Layer* parent); |
79 void Detach(); | 90 void Detach(); |
80 void Pull(base::TimeTicks current_time, gfx::Vector2dF overscroll_delta); | 91 void Pull(base::TimeTicks current_time, gfx::Vector2dF overscroll_delta); |
81 void Absorb(base::TimeTicks current_time, | 92 void Absorb(base::TimeTicks current_time, |
82 gfx::Vector2dF velocity, | 93 gfx::Vector2dF velocity, |
83 bool x_overscroll_started, | 94 bool x_overscroll_started, |
84 bool y_overscroll_started); | 95 bool y_overscroll_started); |
85 void Release(base::TimeTicks current_time); | 96 void Release(base::TimeTicks current_time); |
86 void ReleaseAxis(Axis axis, base::TimeTicks current_time); | 97 void ReleaseAxis(Axis axis, base::TimeTicks current_time); |
87 | 98 |
88 EdgeEffect* GetOppositeEdge(int edge_index); | 99 EdgeEffect* GetOppositeEdge(int edge_index); |
89 | 100 |
90 scoped_ptr<EdgeEffect> edge_effects_[EdgeEffect::EDGE_COUNT]; | 101 scoped_ptr<EdgeEffect> edge_effects_[EdgeEffect::EDGE_COUNT]; |
91 | 102 |
92 DisplayParameters display_params_; | 103 DisplayParameters display_params_; |
93 bool enabled_; | 104 bool enabled_; |
94 bool initialized_; | 105 bool initialized_; |
95 | 106 |
96 scoped_refptr<cc::Layer> root_layer_; | 107 scoped_refptr<cc::Layer> root_layer_; |
108 ui::SystemUIResourceManager* resource_manager_; | |
97 | 109 |
98 DISALLOW_COPY_AND_ASSIGN(OverscrollGlow); | 110 DISALLOW_COPY_AND_ASSIGN(OverscrollGlow); |
99 }; | 111 }; |
100 | 112 |
101 } // namespace content | 113 } // namespace content |
102 | 114 |
103 #endif // CONTENT_BROWSER_ANDROID_SCROLL_GLOW_H_ | 115 #endif // CONTENT_BROWSER_ANDROID_SCROLL_GLOW_H_ |
OLD | NEW |