Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(136)

Side by Side Diff: content/browser/android/overscroll_glow.h

Issue 82553015: Switch the android overscroll glow to use UIResources. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: minor naming changes Created 7 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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/layers/ui_resource_layer.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:
29 // Create and initialize a new effect with the necessary resources. 32 // Create and initialize a new effect with the necessary resources.
30 // If |enabled| is false, the effect will be be deactivated until 33 // If |enabled| is false, the effect will be be deactivated until
31 // SetEnabled(true) is called. 34 // SetEnabled(true) is called.
32 // The caller should attach |root_layer| to the desired layer tree. 35 // The caller should attach |root_layer| to the desired layer tree.
33 static scoped_ptr<OverscrollGlow> Create(bool enabled, gfx::SizeF size); 36 static scoped_ptr<OverscrollGlow> Create(bool enabled, gfx::SizeF size);
34 37
35 // Force loading of any necessary resources. This function is thread-safe.
36 static void EnsureResources();
37
38 ~OverscrollGlow(); 38 ~OverscrollGlow();
39 39
40 // If false, the glow will be deactivated, and subsequent calls to 40 // If false, the glow will be deactivated, and subsequent calls to
41 // OnOverscrolled or Animate will have no effect. 41 // OnOverscrolled or Animate will have no effect.
42 void SetEnabled(bool enabled); 42 void SetEnabled(bool enabled);
43 43
44 // |overscroll| is the accumulated overscroll for the current gesture. 44 // |overscroll| is the accumulated overscroll for the current gesture.
45 // |velocity| is the instantaneous velocity for the overscroll. 45 // |velocity| is the instantaneous velocity for the overscroll.
46 void OnOverscrolled(base::TimeTicks current_time, 46 void OnOverscrolled(base::TimeTicks current_time,
47 gfx::Vector2dF overscroll, 47 gfx::Vector2dF overscroll,
48 gfx::Vector2dF velocity); 48 gfx::Vector2dF velocity);
49 49
50 // Returns true if the effect still needs animation ticks. 50 // Returns true if the effect still needs animation ticks.
51 bool Animate(base::TimeTicks current_time); 51 bool Animate(base::TimeTicks current_time);
52 52
53 // Returns true if the effect needs animation ticks. 53 // Returns true if the effect needs animation ticks.
54 bool NeedsAnimate() const; 54 bool NeedsAnimate() const;
55 55
56 // The root layer of the effect (not necessarily of the tree). 56 void AttachLayerTo(scoped_refptr<cc::Layer> layer);
57 scoped_refptr<cc::Layer> root_layer() const { 57 void RemoveLayer();
58 return root_layer_; 58 bool IsAttached() const;
59 } 59
60 // Sets the layer resources, which are allocated on the compositor. Return
61 // true if the resources have been updated with new values, false otherwise.
62 bool SetLayerResources(cc::UIResourceId edge_resource_id,
63 cc::UIResourceId glow_resource_id,
64 gfx::Size edge_bitmap_size,
65 gfx::Size glow_bitmap_size);
60 66
61 // Horizontal overscroll will be ignored when false. 67 // Horizontal overscroll will be ignored when false.
62 void set_horizontal_overscroll_enabled(bool enabled) { 68 void set_horizontal_overscroll_enabled(bool enabled) {
63 horizontal_overscroll_enabled_ = enabled; 69 horizontal_overscroll_enabled_ = enabled;
64 } 70 }
65 // Vertical overscroll will be ignored when false. 71 // Vertical overscroll will be ignored when false.
66 void set_vertical_overscroll_enabled(bool enabled) { 72 void set_vertical_overscroll_enabled(bool enabled) {
67 vertical_overscroll_enabled_ = enabled; 73 vertical_overscroll_enabled_ = enabled;
68 } 74 }
69 // The size of the layer for which edges will be animated. 75 // The size of the layer for which edges will be animated.
70 void set_size(gfx::SizeF size) { 76 void set_size(gfx::SizeF size) {
71 size_ = size; 77 size_ = size;
72 } 78 }
73 79
74 private: 80 private:
75 enum Axis { AXIS_X, AXIS_Y }; 81 enum Axis { AXIS_X, AXIS_Y };
76 82
77 OverscrollGlow(bool enabled, 83 OverscrollGlow(bool enabled,
78 gfx::SizeF size, 84 gfx::SizeF size);
79 const SkBitmap& edge,
80 const SkBitmap& glow);
81 85
82 void Pull(base::TimeTicks current_time, 86 void Pull(base::TimeTicks current_time,
83 gfx::Vector2dF added_overscroll); 87 gfx::Vector2dF added_overscroll);
84 void Absorb(base::TimeTicks current_time, 88 void Absorb(base::TimeTicks current_time,
85 gfx::Vector2dF velocity, 89 gfx::Vector2dF velocity,
86 gfx::Vector2dF overscroll, 90 gfx::Vector2dF overscroll,
87 gfx::Vector2dF old_overscroll); 91 gfx::Vector2dF old_overscroll);
88 void Release(base::TimeTicks current_time); 92 void Release(base::TimeTicks current_time);
89 void ReleaseAxis(Axis axis, base::TimeTicks current_time); 93 void ReleaseAxis(Axis axis, base::TimeTicks current_time);
90 94
91 EdgeEffect* GetOppositeEdge(int edge_index); 95 EdgeEffect* GetOppositeEdge(int edge_index);
92 96
93 scoped_ptr<EdgeEffect> edge_effects_[EdgeEffect::EDGE_COUNT]; 97 scoped_ptr<EdgeEffect> edge_effects_[EdgeEffect::EDGE_COUNT];
94 98
95 bool enabled_; 99 bool enabled_;
96 gfx::SizeF size_; 100 gfx::SizeF size_;
97 gfx::Vector2dF old_overscroll_; 101 gfx::Vector2dF old_overscroll_;
98 gfx::Vector2dF old_velocity_; 102 gfx::Vector2dF old_velocity_;
99 bool horizontal_overscroll_enabled_; 103 bool horizontal_overscroll_enabled_;
100 bool vertical_overscroll_enabled_; 104 bool vertical_overscroll_enabled_;
101 105
102 scoped_refptr<cc::Layer> root_layer_; 106 scoped_refptr<cc::Layer> root_layer_;
107 scoped_refptr<cc::UIResourceLayer> edge_layer_;
108 scoped_refptr<cc::UIResourceLayer> glow_layer_;
109 cc::UIResourceId edge_resource_id_;
110 cc::UIResourceId glow_resource_id_;
111 gfx::Size edge_bitmap_size_;
112 gfx::Size glow_bitmap_size_;
103 113
104 DISALLOW_COPY_AND_ASSIGN(OverscrollGlow); 114 DISALLOW_COPY_AND_ASSIGN(OverscrollGlow);
105 }; 115 };
106 116
107 } // namespace content 117 } // namespace content
108 118
109 #endif // CONTENT_BROWSER_ANDROID_SCROLL_GLOW_H_ 119 #endif // CONTENT_BROWSER_ANDROID_SCROLL_GLOW_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698