| 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 25 matching lines...) Expand all Loading... |
| 36 | 36 |
| 37 // Enable the effect. If the effect was previously disabled, it will remain | 37 // Enable the effect. If the effect was previously disabled, it will remain |
| 38 // dormant until subsequent calls to |OnOverscrolled()|. | 38 // dormant until subsequent calls to |OnOverscrolled()|. |
| 39 void Enable(); | 39 void Enable(); |
| 40 | 40 |
| 41 // Deactivate and detach the effect. Subsequent calls to |OnOverscrolled()| or | 41 // Deactivate and detach the effect. Subsequent calls to |OnOverscrolled()| or |
| 42 // |Animate()| will have no effect. | 42 // |Animate()| will have no effect. |
| 43 void Disable(); | 43 void Disable(); |
| 44 | 44 |
| 45 // Effect layers will be attached to |overscrolling_layer| if necessary. | 45 // Effect layers will be attached to |overscrolling_layer| if necessary. |
| 46 // |overscroll| is the accumulated overscroll for the current gesture, in | 46 // |accumulated_overscroll| and |overscroll_delta| are in device pixels, while |
| 47 // device pixels. |velocity| is the instantaneous velocity of the overscroll, | 47 // |velocity| is in device pixels / second. |
| 48 // in device pixels / second. | |
| 49 // Returns true if the effect still needs animation ticks. | 48 // Returns true if the effect still needs animation ticks. |
| 50 bool OnOverscrolled(cc::Layer* overscrolling_layer, | 49 bool OnOverscrolled(cc::Layer* overscrolling_layer, |
| 51 base::TimeTicks current_time, | 50 base::TimeTicks current_time, |
| 52 gfx::Vector2dF overscroll, | 51 gfx::Vector2dF accumulated_overscroll, |
| 52 gfx::Vector2dF overscroll_delta, |
| 53 gfx::Vector2dF velocity); | 53 gfx::Vector2dF velocity); |
| 54 | 54 |
| 55 // Returns true if the effect still needs animation ticks. | 55 // Returns true if the effect still needs animation ticks. |
| 56 // Note: The effect will detach itself when no further animation is required. | 56 // Note: The effect will detach itself when no further animation is required. |
| 57 bool Animate(base::TimeTicks current_time); | 57 bool Animate(base::TimeTicks current_time); |
| 58 | 58 |
| 59 // Update the effect according to the most recent display parameters, | 59 // Update the effect according to the most recent display parameters, |
| 60 // Note: All dimensions are in device pixels. | 60 // Note: All dimensions are in device pixels. |
| 61 struct DisplayParameters { | 61 struct DisplayParameters { |
| 62 DisplayParameters(); | 62 DisplayParameters(); |
| 63 gfx::SizeF size; | 63 gfx::SizeF size; |
| 64 float edge_offsets[EdgeEffect::EDGE_COUNT]; | 64 float edge_offsets[EdgeEffect::EDGE_COUNT]; |
| 65 float device_scale_factor; | 65 float device_scale_factor; |
| 66 }; | 66 }; |
| 67 void UpdateDisplayParameters(const DisplayParameters& params); | 67 void UpdateDisplayParameters(const DisplayParameters& params); |
| 68 | 68 |
| 69 | 69 |
| 70 private: | 70 private: |
| 71 enum Axis { AXIS_X, AXIS_Y }; | 71 enum Axis { AXIS_X, AXIS_Y }; |
| 72 | 72 |
| 73 OverscrollGlow(bool enabled); | 73 OverscrollGlow(bool enabled); |
| 74 | 74 |
| 75 // Returns whether the effect is initialized. | 75 // Returns whether the effect is initialized. |
| 76 bool InitializeIfNecessary(); | 76 bool InitializeIfNecessary(); |
| 77 bool NeedsAnimate() const; | 77 bool NeedsAnimate() const; |
| 78 void UpdateLayerAttachment(cc::Layer* parent); | 78 void UpdateLayerAttachment(cc::Layer* parent); |
| 79 void Detach(); | 79 void Detach(); |
| 80 void Pull(base::TimeTicks current_time, | 80 void Pull(base::TimeTicks current_time, gfx::Vector2dF overscroll_delta); |
| 81 gfx::Vector2dF added_overscroll); | |
| 82 void Absorb(base::TimeTicks current_time, | 81 void Absorb(base::TimeTicks current_time, |
| 83 gfx::Vector2dF velocity, | 82 gfx::Vector2dF velocity, |
| 84 gfx::Vector2dF overscroll, | 83 bool x_overscroll_started, |
| 85 gfx::Vector2dF old_overscroll); | 84 bool y_overscroll_started); |
| 86 void Release(base::TimeTicks current_time); | 85 void Release(base::TimeTicks current_time); |
| 87 void ReleaseAxis(Axis axis, base::TimeTicks current_time); | 86 void ReleaseAxis(Axis axis, base::TimeTicks current_time); |
| 88 | 87 |
| 89 EdgeEffect* GetOppositeEdge(int edge_index); | 88 EdgeEffect* GetOppositeEdge(int edge_index); |
| 90 | 89 |
| 91 scoped_ptr<EdgeEffect> edge_effects_[EdgeEffect::EDGE_COUNT]; | 90 scoped_ptr<EdgeEffect> edge_effects_[EdgeEffect::EDGE_COUNT]; |
| 92 | 91 |
| 93 DisplayParameters display_params_; | 92 DisplayParameters display_params_; |
| 94 gfx::Vector2dF old_overscroll_; | |
| 95 gfx::Vector2dF old_velocity_; | |
| 96 bool enabled_; | 93 bool enabled_; |
| 97 bool initialized_; | 94 bool initialized_; |
| 98 | 95 |
| 99 scoped_refptr<cc::Layer> root_layer_; | 96 scoped_refptr<cc::Layer> root_layer_; |
| 100 | 97 |
| 101 DISALLOW_COPY_AND_ASSIGN(OverscrollGlow); | 98 DISALLOW_COPY_AND_ASSIGN(OverscrollGlow); |
| 102 }; | 99 }; |
| 103 | 100 |
| 104 } // namespace content | 101 } // namespace content |
| 105 | 102 |
| 106 #endif // CONTENT_BROWSER_ANDROID_SCROLL_GLOW_H_ | 103 #endif // CONTENT_BROWSER_ANDROID_SCROLL_GLOW_H_ |
| OLD | NEW |