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 "cc/resources/ui_resource_client.h" |
11 #include "content/browser/android/edge_effect.h" | 12 #include "content/browser/android/edge_effect.h" |
| 13 #include "ui/gfx/size.h" |
12 #include "ui/gfx/size_f.h" | 14 #include "ui/gfx/size_f.h" |
13 #include "ui/gfx/vector2d_f.h" | 15 #include "ui/gfx/vector2d_f.h" |
14 | 16 |
15 class SkBitmap; | 17 class SkBitmap; |
16 | 18 |
17 namespace cc { | 19 namespace cc { |
18 class Layer; | 20 class Layer; |
| 21 class UIResourceLayer; |
19 } | 22 } |
20 | 23 |
21 namespace content { | 24 namespace content { |
22 | 25 |
23 /* |OverscrollGlow| mirrors its Android counterpart, OverscrollGlow.java. | 26 /* |OverscrollGlow| mirrors its Android counterpart, OverscrollGlow.java. |
24 * Conscious tradeoffs were made to align this as closely as possible with the | 27 * Conscious tradeoffs were made to align this as closely as possible with the |
25 * original Android Java version. | 28 * original Android Java version. |
26 */ | 29 */ |
27 class OverscrollGlow { | 30 class OverscrollGlow { |
28 public: | 31 public: |
(...skipping 12 matching lines...) Expand all Loading... |
41 // Deactivate and detach the effect. Subsequent calls to |OnOverscrolled()| or | 44 // Deactivate and detach the effect. Subsequent calls to |OnOverscrolled()| or |
42 // |Animate()| will have no effect. | 45 // |Animate()| will have no effect. |
43 void Disable(); | 46 void Disable(); |
44 | 47 |
45 // Effect layers will be attached to |overscrolling_layer| if necessary. | 48 // Effect layers will be attached to |overscrolling_layer| if necessary. |
46 // |accumulated_overscroll| and |overscroll_delta| are in device pixels, while | 49 // |accumulated_overscroll| and |overscroll_delta| are in device pixels, while |
47 // |velocity| is in device pixels / second. | 50 // |velocity| is in device pixels / second. |
48 // Returns true if the effect still needs animation ticks. | 51 // Returns true if the effect still needs animation ticks. |
49 bool OnOverscrolled(cc::Layer* overscrolling_layer, | 52 bool OnOverscrolled(cc::Layer* overscrolling_layer, |
50 base::TimeTicks current_time, | 53 base::TimeTicks current_time, |
| 54 cc::UIResourceId edge_ui_resource, |
| 55 cc::UIResourceId glow_ui_resource, |
51 gfx::Vector2dF accumulated_overscroll, | 56 gfx::Vector2dF accumulated_overscroll, |
52 gfx::Vector2dF overscroll_delta, | 57 gfx::Vector2dF overscroll_delta, |
53 gfx::Vector2dF velocity); | 58 gfx::Vector2dF velocity); |
54 | 59 |
55 // Returns true if the effect still needs animation ticks. | 60 // Returns true if the effect still needs animation ticks. |
56 // Note: The effect will detach itself when no further animation is required. | 61 // Note: The effect will detach itself when no further animation is required. |
57 bool Animate(base::TimeTicks current_time); | 62 bool Animate(base::TimeTicks current_time); |
58 | 63 |
59 // Update the effect according to the most recent display parameters, | 64 // Update the effect according to the most recent display parameters, |
60 // Note: All dimensions are in device pixels. | 65 // Note: All dimensions are in device pixels. |
61 struct DisplayParameters { | 66 struct DisplayParameters { |
62 DisplayParameters(); | 67 DisplayParameters(); |
63 gfx::SizeF size; | 68 gfx::SizeF size; |
64 float edge_offsets[EdgeEffect::EDGE_COUNT]; | 69 float edge_offsets[EdgeEffect::EDGE_COUNT]; |
65 float device_scale_factor; | 70 float device_scale_factor; |
66 }; | 71 }; |
67 void UpdateDisplayParameters(const DisplayParameters& params); | 72 void UpdateDisplayParameters(const DisplayParameters& params); |
68 | 73 |
69 | |
70 private: | 74 private: |
71 enum Axis { AXIS_X, AXIS_Y }; | 75 enum Axis { AXIS_X, AXIS_Y }; |
72 | 76 |
73 OverscrollGlow(bool enabled); | 77 OverscrollGlow(bool enabled); |
74 | 78 |
75 // Returns whether the effect is initialized. | 79 // Returns whether the effect is initialized. |
76 bool InitializeIfNecessary(); | 80 bool InitializeIfNecessary(); |
77 bool NeedsAnimate() const; | 81 bool NeedsAnimate() const; |
78 void UpdateLayerAttachment(cc::Layer* parent); | 82 void UpdateLayerAttachment(cc::Layer* parent, |
| 83 cc::UIResourceId edge_ui_resource, |
| 84 cc::UIResourceId glow_ui_resource); |
79 void Detach(); | 85 void Detach(); |
80 void Pull(base::TimeTicks current_time, gfx::Vector2dF overscroll_delta); | 86 void Pull(base::TimeTicks current_time, gfx::Vector2dF overscroll_delta); |
81 void Absorb(base::TimeTicks current_time, | 87 void Absorb(base::TimeTicks current_time, |
82 gfx::Vector2dF velocity, | 88 gfx::Vector2dF velocity, |
83 bool x_overscroll_started, | 89 bool x_overscroll_started, |
84 bool y_overscroll_started); | 90 bool y_overscroll_started); |
85 void Release(base::TimeTicks current_time); | 91 void Release(base::TimeTicks current_time); |
86 void ReleaseAxis(Axis axis, base::TimeTicks current_time); | 92 void ReleaseAxis(Axis axis, base::TimeTicks current_time); |
87 | 93 |
88 EdgeEffect* GetOppositeEdge(int edge_index); | 94 EdgeEffect* GetOppositeEdge(int edge_index); |
89 | 95 |
90 scoped_ptr<EdgeEffect> edge_effects_[EdgeEffect::EDGE_COUNT]; | 96 scoped_ptr<EdgeEffect> edge_effects_[EdgeEffect::EDGE_COUNT]; |
91 | 97 |
92 DisplayParameters display_params_; | 98 DisplayParameters display_params_; |
93 bool enabled_; | 99 bool enabled_; |
94 bool initialized_; | 100 bool initialized_; |
95 | 101 |
96 scoped_refptr<cc::Layer> root_layer_; | 102 scoped_refptr<cc::Layer> root_layer_; |
97 | 103 |
98 DISALLOW_COPY_AND_ASSIGN(OverscrollGlow); | 104 DISALLOW_COPY_AND_ASSIGN(OverscrollGlow); |
99 }; | 105 }; |
100 | 106 |
101 } // namespace content | 107 } // namespace content |
102 | 108 |
103 #endif // CONTENT_BROWSER_ANDROID_SCROLL_GLOW_H_ | 109 #endif // CONTENT_BROWSER_ANDROID_SCROLL_GLOW_H_ |
OLD | NEW |