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

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

Issue 1419123002: android: move overscroll effects to ui/ (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: fix exports for component build Created 5 years, 1 month 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
(Empty)
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
3 // found in the LICENSE file.
4
5 #ifndef CONTENT_BROWSER_ANDROID_OVERSCROLL_GLOW_H_
6 #define CONTENT_BROWSER_ANDROID_OVERSCROLL_GLOW_H_
7
8 #include "base/memory/ref_counted.h"
9 #include "base/memory/scoped_ptr.h"
10 #include "base/time/time.h"
11 #include "content/browser/android/edge_effect_base.h"
12 #include "ui/gfx/geometry/size_f.h"
13 #include "ui/gfx/geometry/vector2d_f.h"
14
15 namespace cc {
16 class Layer;
17 }
18
19 namespace content {
20
21 // Provides lazy, customized EdgeEffect creation.
22 class OverscrollGlowClient {
23 public:
24 virtual ~OverscrollGlowClient() {}
25
26 // Called lazily, after the initial overscrolling event.
27 virtual scoped_ptr<EdgeEffectBase> CreateEdgeEffect() = 0;
28 };
29
30 /* |OverscrollGlow| mirrors its Android counterpart, OverscrollGlow.java.
31 * Conscious tradeoffs were made to align this as closely as possible with the
32 * original Android Java version.
33 */
34 class OverscrollGlow {
35 public:
36 // |client| must be valid for the duration of the effect's lifetime.
37 // The effect is enabled by default, but will remain dormant until the first
38 // overscroll event.
39 explicit OverscrollGlow(OverscrollGlowClient* client);
40 ~OverscrollGlow();
41
42 // Called when the root content layer overscrolls.
43 // |accumulated_overscroll| and |overscroll_delta| are in device pixels, while
44 // |velocity| is in device pixels / second.
45 // |overscroll_location| is the coordinate of the causal overscrolling event.
46 // Returns true if the effect still needs animation ticks.
47 bool OnOverscrolled(base::TimeTicks current_time,
48 const gfx::Vector2dF& accumulated_overscroll,
49 gfx::Vector2dF overscroll_delta,
50 gfx::Vector2dF velocity,
51 const gfx::Vector2dF& overscroll_location);
52
53 // Returns true if the effect still needs animation ticks, with effect layers
54 // attached to |parent_layer| if necessary.
55 // Note: The effect will detach itself when no further animation is required.
56 bool Animate(base::TimeTicks current_time, cc::Layer* parent_layer);
57
58 // Update the effect according to the most recent display parameters,
59 // Note: All dimensions are in device pixels.
60 void OnFrameUpdated(const gfx::SizeF& viewport_size,
61 const gfx::SizeF& content_size,
62 const gfx::Vector2dF& content_scroll_offset);
63
64 // Reset the effect to its inactive state, clearing any active effects.
65 void Reset();
66
67 // Whether the effect is active, either being pulled or receding.
68 bool IsActive() const;
69
70 // The maximum alpha value (in the range [0,1]) of any animated edge layers.
71 // If the effect is inactive, this will be 0.
72 float GetVisibleAlpha() const;
73
74 private:
75 enum Axis { AXIS_X, AXIS_Y };
76 enum { EDGE_COUNT = EdgeEffectBase::EDGE_COUNT };
77
78 // Returns whether the effect has been properly initialized.
79 bool InitializeIfNecessary();
80 bool CheckNeedsAnimate();
81 void UpdateLayerAttachment(cc::Layer* parent);
82 void Detach();
83 void Pull(base::TimeTicks current_time,
84 const gfx::Vector2dF& overscroll_delta,
85 const gfx::Vector2dF& overscroll_location);
86 void Absorb(base::TimeTicks current_time,
87 const gfx::Vector2dF& velocity,
88 bool x_overscroll_started,
89 bool y_overscroll_started);
90 void Release(base::TimeTicks current_time);
91
92 EdgeEffectBase* GetOppositeEdge(int edge_index);
93
94 OverscrollGlowClient* const client_;
95 scoped_ptr<EdgeEffectBase> edge_effects_[EDGE_COUNT];
96
97 gfx::SizeF viewport_size_;
98 float edge_offsets_[EDGE_COUNT];
99 bool initialized_;
100 bool allow_horizontal_overscroll_;
101 bool allow_vertical_overscroll_;
102
103 scoped_refptr<cc::Layer> root_layer_;
104
105 DISALLOW_COPY_AND_ASSIGN(OverscrollGlow);
106 };
107
108 } // namespace content
109
110 #endif // CONTENT_BROWSER_ANDROID_OVERSCROLL_GLOW_H_
OLDNEW
« no previous file with comments | « content/browser/android/overscroll_controller_android.cc ('k') | content/browser/android/overscroll_glow.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698