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

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

Issue 894193005: [Android] Use the platform SwipeRefreshLayout (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Rebase Created 5 years, 8 months 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 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 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_REFRESH_H_ 5 #ifndef CONTENT_BROWSER_ANDROID_OVERSCROLL_REFRESH_H_
6 #define CONTENT_BROWSER_ANDROID_OVERSCROLL_REFRESH_H_ 6 #define CONTENT_BROWSER_ANDROID_OVERSCROLL_REFRESH_H_
7 7
8 #include "base/memory/scoped_ptr.h" 8 #include "base/macros.h"
9 #include "base/time/time.h"
10 #include "content/common/content_export.h" 9 #include "content/common/content_export.h"
11 #include "ui/gfx/geometry/size_f.h" 10 #include "ui/gfx/geometry/size_f.h"
12 #include "ui/gfx/geometry/vector2d_f.h" 11 #include "ui/gfx/geometry/vector2d_f.h"
13 12
14 namespace cc {
15 class Layer;
16 }
17
18 namespace ui {
19 class ResourceManager;
20 }
21
22 namespace content { 13 namespace content {
23 14
24 // Allows both page reload activation and page reloading state queries. 15 class CONTENT_EXPORT OverscrollRefreshHandler {
25 class CONTENT_EXPORT OverscrollRefreshClient {
26 public: 16 public:
27 virtual ~OverscrollRefreshClient() {} 17 // Signals the start of an overscrolling pull. Returns whether the handler
18 // will consume the overscroll gesture, in which case it will receive the
19 // remaining pull updates.
20 virtual bool PullStart() = 0;
28 21
29 // Called when the effect is released beyond the activation threshold. This 22 // Signals a pull update, where |delta| is in device pixels.
30 // should cause a refresh of some kind, e.g., page reload. 23 virtual void PullUpdate(float delta) = 0;
31 virtual void TriggerRefresh() = 0;
32 24
33 // Whether the triggered refresh has yet to complete. The effect will continue 25 // Signals the release of the pull, and whether the release is allowed to
34 // animating until the refresh completes (or it reaches a reasonable timeout). 26 // trigger the refresh action.
35 virtual bool IsStillRefreshing() const = 0; 27 virtual void PullRelease(bool allow_refresh) = 0;
28
29 // Reset the active pull state.
30 virtual void PullReset() = 0;
31
32 protected:
33 virtual ~OverscrollRefreshHandler() {}
36 }; 34 };
37 35
38 // Simple pull-to-refresh styled effect. Listens to scroll events, conditionally 36 // Simple pull-to-refresh styled effect. Listens to scroll events, conditionally
39 // activating when: 37 // activating when:
40 // 1) The scroll begins when the page's root layer 1) has no vertical scroll 38 // 1) The scroll begins when the page's root layer 1) has no vertical scroll
41 // offset and 2) lacks the overflow-y:hidden property. 39 // offset and 2) lacks the overflow-y:hidden property.
42 // 2) The page doesn't consume the initial scroll events. 40 // 2) The page doesn't consume the initial scroll events.
43 // 3) The initial scroll direction is upward. 41 // 3) The initial scroll direction is upward.
44 // The actual page reload action is triggered only when the effect is active 42 // The actuall pull response, animation and action are delegated to the
45 // and beyond a particular threshold when released. 43 // provided refresh handler.
46 class CONTENT_EXPORT OverscrollRefresh { 44 class CONTENT_EXPORT OverscrollRefresh {
47 public: 45 public:
48 // Minmum number of overscrolling pull events required to activate the effect. 46 // Minmum number of overscrolling pull events required to activate the effect.
49 // Useful for avoiding accidental triggering when a scroll janks (is delayed), 47 // Useful for avoiding accidental triggering when a scroll janks (is delayed),
50 // capping the impulse per event. 48 // capping the impulse per event.
51 enum { kMinPullsToActivate = 3 }; 49 enum { kMinPullsToActivate = 3 };
52 50
53 // Both |resource_manager| and |client| must not be null. 51 explicit OverscrollRefresh(OverscrollRefreshHandler* handler);
54 // |target_drag_offset_pixels| is the threshold beyond which the effect
55 // will trigger a refresh action when released. When |mirror| is true,
56 // the effect and its rotation will be mirrored about the y axis.
57 OverscrollRefresh(ui::ResourceManager* resource_manager,
58 OverscrollRefreshClient* client,
59 float target_drag_offset_pixels,
60 bool mirror);
61 ~OverscrollRefresh(); 52 ~OverscrollRefresh();
62 53
63 // Scroll event stream listening methods. 54 // Scroll event stream listening methods.
64 void OnScrollBegin(); 55 void OnScrollBegin();
56 // Returns whether the refresh was activated.
65 void OnScrollEnd(const gfx::Vector2dF& velocity); 57 void OnScrollEnd(const gfx::Vector2dF& velocity);
66 58
67 // Scroll ack listener. The effect will only be activated if the initial 59 // Scroll ack listener. The effect will only be activated if the initial
68 // updates go unconsumed. 60 // updates go unconsumed.
69 void OnScrollUpdateAck(bool was_consumed); 61 void OnScrollUpdateAck(bool was_consumed);
70 62
71 // Returns true if the effect has consumed the |scroll_delta|. 63 // Returns true if the effect has consumed the |scroll_delta|.
72 bool WillHandleScrollUpdate(const gfx::Vector2dF& scroll_delta); 64 bool WillHandleScrollUpdate(const gfx::Vector2dF& scroll_delta);
73 65
74 // Release the effect (if active), preventing any associated refresh action. 66 // Release the effect (if active), preventing any associated refresh action.
75 void ReleaseWithoutActivation(); 67 void ReleaseWithoutActivation();
76 68
77 // Returns true if the effect still needs animation ticks, with effect layers 69 // Notify the effect of the latest scroll offset and overflow properties.
78 // attached to |parent| if necessary. 70 // The effect will be disabled when the offset is non-zero or overflow is
79 // Note: The effect will detach itself when no further animation is required. 71 // hidden. Note: All dimensions are in device pixels.
80 bool Animate(base::TimeTicks current_time, cc::Layer* parent_layer); 72 void OnFrameUpdated(const gfx::Vector2dF& content_scroll_offset,
81 73 bool root_overflow_y_hidden);
82 // Update the effect according to the most recent display parameters,
83 // Note: All dimensions are in device pixels.
84 void UpdateDisplay(const gfx::SizeF& viewport_size,
85 const gfx::Vector2dF& content_scroll_offset,
86 bool root_overflow_y_hidden);
87 74
88 // Reset the effect to its inactive state, immediately detaching and 75 // Reset the effect to its inactive state, immediately detaching and
89 // disabling any active effects. 76 // disabling any active effects.
90 void Reset(); 77 void Reset();
91 78
92 // Returns true if the refresh effect is either being manipulated or animated. 79 // Returns true if the refresh effect is either being manipulated or animated.
93 bool IsActive() const; 80 bool IsActive() const;
94 81
95 // Returns true if the effect is waiting for an unconsumed scroll to start. 82 // Returns true if the effect is waiting for an unconsumed scroll to start.
96 bool IsAwaitingScrollUpdateAck() const; 83 bool IsAwaitingScrollUpdateAck() const;
97 84
98 private: 85 private:
99 void Release(bool allow_activation); 86 void Release(bool allow_refresh);
100 87
101 OverscrollRefreshClient* const client_;
102
103 gfx::SizeF viewport_size_;
104 bool scrolled_to_top_; 88 bool scrolled_to_top_;
105 bool overflow_y_hidden_; 89 bool overflow_y_hidden_;
106 90
107 enum ScrollConsumptionState { 91 enum ScrollConsumptionState {
108 DISABLED, 92 DISABLED,
109 AWAITING_SCROLL_UPDATE_ACK, 93 AWAITING_SCROLL_UPDATE_ACK,
110 ENABLED, 94 ENABLED,
111 } scroll_consumption_state_; 95 } scroll_consumption_state_;
112 96
113 class Effect; 97 OverscrollRefreshHandler* const handler_;
114 scoped_ptr<Effect> effect_;
115 98
116 DISALLOW_COPY_AND_ASSIGN(OverscrollRefresh); 99 DISALLOW_COPY_AND_ASSIGN(OverscrollRefresh);
117 }; 100 };
118 101
119 } // namespace content 102 } // namespace content
120 103
121 #endif // CONTENT_BROWSER_ANDROID_OVERSCROLL_REFRESH_H_ 104 #endif // CONTENT_BROWSER_ANDROID_OVERSCROLL_REFRESH_H_
OLDNEW
« no previous file with comments | « content/browser/android/overscroll_glow.cc ('k') | content/browser/android/overscroll_refresh.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698