| 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 content { | 21 namespace content { |
| 22 | 22 |
| 23 /* |OverscrollGlow| mirrors its Android counterpart, OverscrollGlow.java. | 23 /* |OverscrollGlow| mirrors its Android counterpart, OverscrollGlow.java. |
| 24 * Conscious tradeoffs were made to align this as closely as possible with the | 24 * Conscious tradeoffs were made to align this as closely as possible with the |
| 25 * original Android Java version. | 25 * original Android Java version. |
| 26 */ | 26 */ |
| 27 class OverscrollGlow { | 27 class OverscrollGlow { |
| 28 public: | 28 public: |
| 29 enum Edge { |
| 30 EDGE_TOP = 0, |
| 31 EDGE_LEFT, |
| 32 EDGE_BOTTOM, |
| 33 EDGE_RIGHT, |
| 34 EDGE_COUNT |
| 35 }; |
| 36 |
| 29 // Create a new effect. If |enabled| is false, the effect will remain | 37 // Create a new effect. If |enabled| is false, the effect will remain |
| 30 // deactivated until explicitly enabled. | 38 // deactivated until explicitly enabled. |
| 31 // Note: No resources will be allocated until the effect is both | 39 // Note: No resources will be allocated until the effect is both |
| 32 // enabled and an overscroll event has occurred. | 40 // enabled and an overscroll event has occurred. |
| 33 static scoped_ptr<OverscrollGlow> Create(bool enabled); | 41 static scoped_ptr<OverscrollGlow> Create(bool enabled); |
| 34 | 42 |
| 35 ~OverscrollGlow(); | 43 ~OverscrollGlow(); |
| 36 | 44 |
| 37 // Enable the effect. If the effect was previously disabled, it will remain | 45 // Enable the effect. If the effect was previously disabled, it will remain |
| 38 // dormant until subsequent calls to |OnOverscrolled()|. | 46 // dormant until subsequent calls to |OnOverscrolled()|. |
| 39 void Enable(); | 47 void Enable(); |
| 40 | 48 |
| 41 // Deactivate and detach the effect. Subsequent calls to |OnOverscrolled()| or | 49 // Deactivate and detach the effect. Subsequent calls to |OnOverscrolled()| or |
| 42 // |Animate()| will have no effect. | 50 // |Animate()| will have no effect. |
| 43 void Disable(); | 51 void Disable(); |
| 44 | 52 |
| 45 // Effect layers will be attached to |overscrolling_layer| if necessary. | 53 // Effect layers will be attached to |overscrolling_layer| if necessary. |
| 46 // |accumulated_overscroll| and |overscroll_delta| are in device pixels, while | 54 // |accumulated_overscroll| and |overscroll_delta| are in device pixels, while |
| 47 // |velocity| is in device pixels / second. | 55 // |velocity| is in device pixels / second. |
| 48 // Returns true if the effect still needs animation ticks. | 56 // Returns true if the effect still needs animation ticks. |
| 49 bool OnOverscrolled(cc::Layer* overscrolling_layer, | 57 bool OnOverscrolled(cc::Layer* overscrolling_layer, |
| 50 base::TimeTicks current_time, | 58 base::TimeTicks current_time, |
| 51 gfx::Vector2dF accumulated_overscroll, | 59 gfx::Vector2dF accumulated_overscroll, |
| 52 gfx::Vector2dF overscroll_delta, | 60 gfx::Vector2dF overscroll_delta, |
| 53 gfx::Vector2dF velocity); | 61 gfx::Vector2dF velocity, |
| 62 gfx::Vector2dF overscroll_location); |
| 54 | 63 |
| 55 // Returns true if the effect still needs animation ticks. | 64 // Returns true if the effect still needs animation ticks. |
| 56 // Note: The effect will detach itself when no further animation is required. | 65 // Note: The effect will detach itself when no further animation is required. |
| 57 bool Animate(base::TimeTicks current_time); | 66 bool Animate(base::TimeTicks current_time); |
| 58 | 67 |
| 59 // Update the effect according to the most recent display parameters, | 68 // Update the effect according to the most recent display parameters, |
| 60 // Note: All dimensions are in device pixels. | 69 // Note: All dimensions are in device pixels. |
| 61 struct DisplayParameters { | 70 struct DisplayParameters { |
| 62 DisplayParameters(); | 71 DisplayParameters(); |
| 63 gfx::SizeF size; | 72 gfx::SizeF size; |
| 64 float edge_offsets[EdgeEffect::EDGE_COUNT]; | 73 float edge_offsets[EDGE_COUNT]; |
| 65 float device_scale_factor; | |
| 66 }; | 74 }; |
| 67 void UpdateDisplayParameters(const DisplayParameters& params); | 75 void UpdateDisplayParameters(const DisplayParameters& params); |
| 68 | 76 |
| 69 | 77 |
| 70 private: | 78 private: |
| 71 enum Axis { AXIS_X, AXIS_Y }; | 79 enum Axis { AXIS_X, AXIS_Y }; |
| 72 | 80 |
| 73 OverscrollGlow(bool enabled); | 81 OverscrollGlow(bool enabled); |
| 74 | 82 |
| 75 // Returns whether the effect is initialized. | 83 // Returns whether the effect is initialized. |
| 76 bool InitializeIfNecessary(); | 84 bool InitializeIfNecessary(); |
| 77 bool NeedsAnimate() const; | 85 bool NeedsAnimate() const; |
| 78 void UpdateLayerAttachment(cc::Layer* parent); | 86 void UpdateLayerAttachment(cc::Layer* parent); |
| 79 void Detach(); | 87 void Detach(); |
| 80 void Pull(base::TimeTicks current_time, gfx::Vector2dF overscroll_delta); | 88 void Pull(base::TimeTicks current_time, |
| 89 const gfx::Vector2dF& overscroll_delta, |
| 90 const gfx::Vector2dF& overscroll_location); |
| 81 void Absorb(base::TimeTicks current_time, | 91 void Absorb(base::TimeTicks current_time, |
| 82 gfx::Vector2dF velocity, | 92 const gfx::Vector2dF& velocity, |
| 83 bool x_overscroll_started, | 93 bool x_overscroll_started, |
| 84 bool y_overscroll_started); | 94 bool y_overscroll_started); |
| 85 void Release(base::TimeTicks current_time); | 95 void Release(base::TimeTicks current_time); |
| 86 void ReleaseAxis(Axis axis, base::TimeTicks current_time); | 96 void ReleaseAxis(Axis axis, base::TimeTicks current_time); |
| 87 | 97 |
| 88 EdgeEffect* GetOppositeEdge(int edge_index); | 98 EdgeEffectBase* GetOppositeEdge(int edge_index); |
| 89 | 99 |
| 90 scoped_ptr<EdgeEffect> edge_effects_[EdgeEffect::EDGE_COUNT]; | 100 scoped_ptr<EdgeEffectBase> edge_effects_[EDGE_COUNT]; |
| 91 | 101 |
| 92 DisplayParameters display_params_; | 102 DisplayParameters display_params_; |
| 93 bool enabled_; | 103 bool enabled_; |
| 94 bool initialized_; | 104 bool initialized_; |
| 95 | 105 |
| 96 scoped_refptr<cc::Layer> root_layer_; | 106 scoped_refptr<cc::Layer> root_layer_; |
| 97 | 107 |
| 98 DISALLOW_COPY_AND_ASSIGN(OverscrollGlow); | 108 DISALLOW_COPY_AND_ASSIGN(OverscrollGlow); |
| 99 }; | 109 }; |
| 100 | 110 |
| 101 } // namespace content | 111 } // namespace content |
| 102 | 112 |
| 103 #endif // CONTENT_BROWSER_ANDROID_SCROLL_GLOW_H_ | 113 #endif // CONTENT_BROWSER_ANDROID_SCROLL_GLOW_H_ |
| OLD | NEW |