| OLD | NEW |
| 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/memory/scoped_ptr.h" |
| 9 #include "base/time/time.h" | 9 #include "base/time/time.h" |
| 10 #include "content/common/content_export.h" | 10 #include "content/common/content_export.h" |
| (...skipping 19 matching lines...) Expand all Loading... |
| 30 // should cause a refresh of some kind, e.g., page reload. | 30 // should cause a refresh of some kind, e.g., page reload. |
| 31 virtual void TriggerRefresh() = 0; | 31 virtual void TriggerRefresh() = 0; |
| 32 | 32 |
| 33 // Whether the triggered refresh has yet to complete. The effect will continue | 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). | 34 // animating until the refresh completes (or it reaches a reasonable timeout). |
| 35 virtual bool IsStillRefreshing() const = 0; | 35 virtual bool IsStillRefreshing() const = 0; |
| 36 }; | 36 }; |
| 37 | 37 |
| 38 // Simple pull-to-refresh styled effect. Listens to scroll events, conditionally | 38 // Simple pull-to-refresh styled effect. Listens to scroll events, conditionally |
| 39 // activating when: | 39 // activating when: |
| 40 // 1) The scroll begins when the page has no vertical scroll offset. | 40 // 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. |
| 41 // 2) The page doesn't consume the initial scroll events. | 42 // 2) The page doesn't consume the initial scroll events. |
| 42 // 3) The initial scroll direction is upward. | 43 // 3) The initial scroll direction is upward. |
| 43 // The actual page reload action is triggered only when the effect is active | 44 // The actual page reload action is triggered only when the effect is active |
| 44 // and beyond a particular threshold when released. | 45 // and beyond a particular threshold when released. |
| 45 class CONTENT_EXPORT OverscrollRefresh { | 46 class CONTENT_EXPORT OverscrollRefresh { |
| 46 public: | 47 public: |
| 47 // Both |resource_manager| and |client| must not be null. | 48 // Both |resource_manager| and |client| must not be null. |
| 48 // |target_drag_offset_pixels| is the threshold beyond which the effect | 49 // |target_drag_offset_pixels| is the threshold beyond which the effect |
| 49 // will trigger a refresh action when released. When |mirror| is true, | 50 // will trigger a refresh action when released. When |mirror| is true, |
| 50 // the effect and its rotation will be mirrored about the y axis. | 51 // the effect and its rotation will be mirrored about the y axis. |
| (...skipping 18 matching lines...) Expand all Loading... |
| 69 void ReleaseWithoutActivation(); | 70 void ReleaseWithoutActivation(); |
| 70 | 71 |
| 71 // Returns true if the effect still needs animation ticks, with effect layers | 72 // Returns true if the effect still needs animation ticks, with effect layers |
| 72 // attached to |parent| if necessary. | 73 // attached to |parent| if necessary. |
| 73 // Note: The effect will detach itself when no further animation is required. | 74 // Note: The effect will detach itself when no further animation is required. |
| 74 bool Animate(base::TimeTicks current_time, cc::Layer* parent_layer); | 75 bool Animate(base::TimeTicks current_time, cc::Layer* parent_layer); |
| 75 | 76 |
| 76 // Update the effect according to the most recent display parameters, | 77 // Update the effect according to the most recent display parameters, |
| 77 // Note: All dimensions are in device pixels. | 78 // Note: All dimensions are in device pixels. |
| 78 void UpdateDisplay(const gfx::SizeF& viewport_size, | 79 void UpdateDisplay(const gfx::SizeF& viewport_size, |
| 79 const gfx::Vector2dF& content_scroll_offset); | 80 const gfx::Vector2dF& content_scroll_offset, |
| 81 bool root_overflow_y_hidden); |
| 80 | 82 |
| 81 // Reset the effect to its inactive state, immediately detaching and | 83 // Reset the effect to its inactive state, immediately detaching and |
| 82 // disabling any active effects. | 84 // disabling any active effects. |
| 83 void Reset(); | 85 void Reset(); |
| 84 | 86 |
| 85 // Returns true if the refresh effect is either being manipulated or animated. | 87 // Returns true if the refresh effect is either being manipulated or animated. |
| 86 bool IsActive() const; | 88 bool IsActive() const; |
| 87 | 89 |
| 88 // Returns true if the effect is waiting for an unconsumed scroll to start. | 90 // Returns true if the effect is waiting for an unconsumed scroll to start. |
| 89 bool IsAwaitingScrollUpdateAck() const; | 91 bool IsAwaitingScrollUpdateAck() const; |
| 90 | 92 |
| 91 private: | 93 private: |
| 92 void Release(bool allow_activation); | 94 void Release(bool allow_activation); |
| 93 | 95 |
| 94 OverscrollRefreshClient* const client_; | 96 OverscrollRefreshClient* const client_; |
| 95 | 97 |
| 96 gfx::SizeF viewport_size_; | 98 gfx::SizeF viewport_size_; |
| 97 bool scrolled_to_top_; | 99 bool scrolled_to_top_; |
| 100 bool overflow_y_hidden_; |
| 98 | 101 |
| 99 enum ScrollConsumptionState { | 102 enum ScrollConsumptionState { |
| 100 DISABLED, | 103 DISABLED, |
| 101 AWAITING_SCROLL_UPDATE_ACK, | 104 AWAITING_SCROLL_UPDATE_ACK, |
| 102 ENABLED, | 105 ENABLED, |
| 103 } scroll_consumption_state_; | 106 } scroll_consumption_state_; |
| 104 | 107 |
| 105 class Effect; | 108 class Effect; |
| 106 scoped_ptr<Effect> effect_; | 109 scoped_ptr<Effect> effect_; |
| 107 | 110 |
| 108 DISALLOW_COPY_AND_ASSIGN(OverscrollRefresh); | 111 DISALLOW_COPY_AND_ASSIGN(OverscrollRefresh); |
| 109 }; | 112 }; |
| 110 | 113 |
| 111 } // namespace content | 114 } // namespace content |
| 112 | 115 |
| 113 #endif // CONTENT_BROWSER_ANDROID_OVERSCROLL_REFRESH_H_ | 116 #endif // CONTENT_BROWSER_ANDROID_OVERSCROLL_REFRESH_H_ |
| OLD | NEW |