Chromium Code Reviews| OLD | NEW |
|---|---|
| (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 OnScrollEnd(const gfx::Vector2dF& velocity); | |
| 48 | |
| 49 // Scroll ack listener. The effect will only be activated if the initial | |
| 50 // update ack specifies ALLOW_ACTIVATION. | |
| 51 enum ActivationAllowance { ALLOW_ACTIVATION, PREVENT_ACTIVATION }; | |
|
aelias_OOO_until_Jul13
2014/11/06 22:28:49
This enum seems like an unnecessary abstraction.
jdduke (slow)
2014/11/07 18:33:45
Hmm, yeah, I had a bool, then I needed a second bo
| |
| 52 void OnScrollUpdateAck(ActivationAllowance allowance); | |
| 53 | |
| 54 // Returns true if the supplied |scroll_delta| is consumed, in which case it | |
|
aelias_OOO_until_Jul13
2014/11/06 22:28:48
Please avoid the slightly ambiguous passive tense
| |
| 55 // should cease propagation. | |
| 56 bool WillHandleScrollUpdate(const gfx::Vector2dF& scroll_delta); | |
| 57 | |
| 58 // Returns true if the effect still needs animation ticks, with effect layers | |
| 59 // attached to |parent| if necessary. | |
| 60 // Note: The effect will detach itself when no further animation is required. | |
| 61 bool Animate(base::TimeTicks current_time, cc::Layer* parent_layer); | |
| 62 | |
| 63 // Update the effect according to the most recent display parameters, | |
| 64 // Note: All dimensions are in device pixels. | |
| 65 void UpdateDisplay(const gfx::SizeF& viewport_size, | |
| 66 const gfx::Vector2dF& content_scroll_offset); | |
| 67 | |
| 68 // Reset the effect to its inactive state, detaching any active effects. | |
| 69 void Reset(); | |
| 70 | |
| 71 // Returns true if the refresh effect is either being manipulated or animated. | |
| 72 bool IsActive() const; | |
|
aelias_OOO_until_Jul13
2014/11/06 22:28:49
Here you use "active" to mean "exists at all" and
jdduke (slow)
2014/11/07 18:33:45
Yeah, the other |Active()| is prefixed to |IsTrigg
| |
| 73 | |
| 74 // Returns true if the effect is waiting for an unconsumed scroll to start. | |
| 75 bool IsPendingScrollUpdateAck() const; | |
|
aelias_OOO_until_Jul13
2014/11/06 22:28:48
Please rename to IsAwaitingScrollUpdateAck, I thin
jdduke (slow)
2014/11/07 18:33:44
Done.
| |
| 76 | |
| 77 private: | |
| 78 void Release(bool allow_activation); | |
| 79 | |
| 80 OverscrollRefreshClient* const client_; | |
| 81 | |
| 82 gfx::SizeF viewport_size_; | |
| 83 gfx::Vector2dF scroll_offset_; | |
|
aelias_OOO_until_Jul13
2014/11/06 22:28:49
I'd prefer this as a "bool scrolled_to_top_" as th
jdduke (slow)
2014/11/07 18:33:44
Done.
| |
| 84 | |
| 85 enum ScrollConsumptionState { | |
| 86 DISABLED, | |
| 87 PENDING_SCROLL_UPDATE_ACK, | |
|
aelias_OOO_until_Jul13
2014/11/06 22:28:48
Please rename to AWAITING_SCROLL_UPDATE_ACK.
jdduke (slow)
2014/11/07 18:33:45
Done.
| |
| 88 ENABLED, | |
| 89 } scroll_consumption_state_; | |
| 90 | |
| 91 class Effect; | |
| 92 scoped_ptr<Effect> effect_; | |
| 93 | |
| 94 DISALLOW_COPY_AND_ASSIGN(OverscrollRefresh); | |
| 95 }; | |
| 96 | |
| 97 } // namespace content | |
| 98 | |
| 99 #endif // CONTENT_BROWSER_ANDROID_OVERSCROLL_REFRESH_H_ | |
| OLD | NEW |