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 |
| 29 // Called when the effect is released beyond the activation threshold. This |
| 30 // should cause a refresh of some kind, e.g., page reload. |
| 31 virtual void TriggerRefresh() = 0; |
| 32 |
| 33 // Whether the triggered refresh has yet to complete. The effect will continue |
| 34 // animating until the refresh completes (or it reaches a reasonable timeout). |
| 35 virtual bool IsStillRefreshing() const = 0; |
| 36 }; |
| 37 |
| 38 // Simple pull-to-refresh styled effect. Listens to scroll events, conditionally |
| 39 // activating when: |
| 40 // 1) The scroll begins when the page has no vertical scroll offset. |
| 41 // 2) The page doesn't consume the initial scroll events. |
| 42 // 3) The initial scroll direction is upward. |
| 43 // The actual page reload action is triggered only when the effect is active |
| 44 // and beyond a particular threshold when released. |
| 45 class CONTENT_EXPORT OverscrollRefresh { |
| 46 public: |
| 47 OverscrollRefresh(ui::SystemUIResourceManager* resource_manager, |
| 48 OverscrollRefreshClient* client); |
| 49 ~OverscrollRefresh(); |
| 50 |
| 51 // Scroll event stream listening methods. |
| 52 void OnScrollBegin(); |
| 53 void OnScrollEnd(const gfx::Vector2dF& velocity); |
| 54 |
| 55 // Scroll ack listener. The effect will only be activated if the initial |
| 56 // updates go unconsumed. |
| 57 void OnScrollUpdateAck(bool was_consumed); |
| 58 |
| 59 // Returns true if the effect has consumed the |scroll_delta|. |
| 60 bool WillHandleScrollUpdate(const gfx::Vector2dF& scroll_delta); |
| 61 |
| 62 // Returns true if the effect still needs animation ticks, with effect layers |
| 63 // attached to |parent| if necessary. |
| 64 // Note: The effect will detach itself when no further animation is required. |
| 65 bool Animate(base::TimeTicks current_time, cc::Layer* parent_layer); |
| 66 |
| 67 // Update the effect according to the most recent display parameters, |
| 68 // Note: All dimensions are in device pixels. |
| 69 void UpdateDisplay(const gfx::SizeF& viewport_size, |
| 70 const gfx::Vector2dF& content_scroll_offset); |
| 71 |
| 72 // Reset the effect to its inactive state, detaching any active effects. |
| 73 void Reset(); |
| 74 |
| 75 // Returns true if the refresh effect is either being manipulated or animated. |
| 76 bool IsActive() const; |
| 77 |
| 78 // Returns true if the effect is waiting for an unconsumed scroll to start. |
| 79 bool IsAwaitingScrollUpdateAck() const; |
| 80 |
| 81 private: |
| 82 void Release(bool allow_activation); |
| 83 |
| 84 OverscrollRefreshClient* const client_; |
| 85 |
| 86 gfx::SizeF viewport_size_; |
| 87 bool scrolled_to_top_; |
| 88 |
| 89 enum ScrollConsumptionState { |
| 90 DISABLED, |
| 91 AWAITING_SCROLL_UPDATE_ACK, |
| 92 ENABLED, |
| 93 } scroll_consumption_state_; |
| 94 |
| 95 class Effect; |
| 96 scoped_ptr<Effect> effect_; |
| 97 |
| 98 DISALLOW_COPY_AND_ASSIGN(OverscrollRefresh); |
| 99 }; |
| 100 |
| 101 } // namespace content |
| 102 |
| 103 #endif // CONTENT_BROWSER_ANDROID_OVERSCROLL_REFRESH_H_ |
OLD | NEW |