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

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

Issue 679493002: [Android] Add a native pull-to-refresh overscroll effect (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Tests! Created 6 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 2014 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_REFRESH_H_
6 #define CONTENT_BROWSER_ANDROID_OVERSCROLL_REFRESH_H_
7
8 #include "base/memory/scoped_ptr.h"
9 #include "base/time/time.h"
10 #include "content/common/content_export.h"
11 #include "ui/gfx/size_f.h"
12 #include "ui/gfx/vector2d_f.h"
13
14 namespace cc {
15 class Layer;
16 }
17
18 namespace ui {
19 class SystemUIResourceManager;
20 }
21
22 namespace content {
23
24 // Allows both page reload activation and page reloading state queries.
25 class CONTENT_EXPORT OverscrollRefreshClient {
26 public:
27 virtual ~OverscrollRefreshClient() {}
28 virtual void TriggerRefresh() = 0;
29 virtual bool IsTriggeredRefreshActive() const = 0;
30 };
31
32 // Simple pull-to-refresh styled effect. Listens to scroll events, conditionally
33 // activating when:
34 // 1) The scroll begins when the page has no vertical scroll offset.
35 // 2) The page doesn't consume the initial scroll events.
36 // 3) The initial scroll direction is upward.
37 // The actual page reload action is triggered only when the effect is active
38 // and beyond a particular threshold when released.
39 class CONTENT_EXPORT OverscrollRefresh {
40 public:
41 OverscrollRefresh(ui::SystemUIResourceManager* resource_manager,
42 OverscrollRefreshClient* client);
43 ~OverscrollRefresh();
44
45 // Scroll event stream listening methods.
46 void OnScrollBegin();
47 void OnScrollUpdateAck(bool consumed);
48 void OnScrollEnd(const gfx::Vector2dF& velocity);
49
50 // Returns true if the supplied |scroll_delta| is consumed, in which case it
51 // should cease propagation.
52 bool WillHandleScrollUpdate(const gfx::Vector2dF& scroll_delta);
53
54 // Returns true if the effect still needs animation ticks, with effect layers
55 // attached to |parent| if necessary.
56 // Note: The effect will detach itself when no further animation is required.
57 bool Animate(base::TimeTicks current_time, cc::Layer* parent_layer);
58
59 // Update the effect according to the most recent display parameters,
60 // Note: All dimensions are in device pixels.
61 void UpdateDisplay(const gfx::SizeF& viewport_size,
62 const gfx::Vector2dF& content_scroll_offset);
63
64 // Reset the effect to its inactive state, detaching any active effects.
65 void Reset();
66
67 // Returns true if the refresh effect is either being manipulated or animated.
68 bool IsActive() const;
69
70 // Returns true if the effect is waiting for an unconsumed scroll to start.
71 bool IsPendingScrollUpdateAck() const;
72
73 private:
74 void Release(bool allow_activation);
75
76 OverscrollRefreshClient* const client_;
77
78 gfx::SizeF viewport_size_;
79 gfx::Vector2dF scroll_offset_;
80
81 enum ScrollConsumptionState {
82 DISABLED,
83 PENDING_SCROLL_UPDATE_ACK,
84 ENABLED,
85 } scroll_consumption_state_;
86
87 class Effect;
88 scoped_ptr<Effect> effect_;
89
90 DISALLOW_COPY_AND_ASSIGN(OverscrollRefresh);
91 };
92
93 } // namespace content
94
95 #endif // CONTENT_BROWSER_ANDROID_OVERSCROLL_REFRESH_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698