| 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 // Minmum number of overscrolling pull events required to activate the effect. | 48 // Minmum number of overscrolling pull events required to activate the effect. |
| 48 // Useful for avoiding accidental triggering when a scroll janks (is delayed), | 49 // Useful for avoiding accidental triggering when a scroll janks (is delayed), |
| 49 // capping the impulse per event. | 50 // capping the impulse per event. |
| 50 enum { kMinPullsToActivate = 3 }; | 51 enum { kMinPullsToActivate = 3 }; |
| (...skipping 23 matching lines...) Expand all Loading... |
| 74 void ReleaseWithoutActivation(); | 75 void ReleaseWithoutActivation(); |
| 75 | 76 |
| 76 // Returns true if the effect still needs animation ticks, with effect layers | 77 // Returns true if the effect still needs animation ticks, with effect layers |
| 77 // attached to |parent| if necessary. | 78 // attached to |parent| if necessary. |
| 78 // Note: The effect will detach itself when no further animation is required. | 79 // Note: The effect will detach itself when no further animation is required. |
| 79 bool Animate(base::TimeTicks current_time, cc::Layer* parent_layer); | 80 bool Animate(base::TimeTicks current_time, cc::Layer* parent_layer); |
| 80 | 81 |
| 81 // Update the effect according to the most recent display parameters, | 82 // Update the effect according to the most recent display parameters, |
| 82 // Note: All dimensions are in device pixels. | 83 // Note: All dimensions are in device pixels. |
| 83 void UpdateDisplay(const gfx::SizeF& viewport_size, | 84 void UpdateDisplay(const gfx::SizeF& viewport_size, |
| 84 const gfx::Vector2dF& content_scroll_offset); | 85 const gfx::Vector2dF& content_scroll_offset, |
| 86 bool root_overflow_y_hidden); |
| 85 | 87 |
| 86 // Reset the effect to its inactive state, immediately detaching and | 88 // Reset the effect to its inactive state, immediately detaching and |
| 87 // disabling any active effects. | 89 // disabling any active effects. |
| 88 void Reset(); | 90 void Reset(); |
| 89 | 91 |
| 90 // Returns true if the refresh effect is either being manipulated or animated. | 92 // Returns true if the refresh effect is either being manipulated or animated. |
| 91 bool IsActive() const; | 93 bool IsActive() const; |
| 92 | 94 |
| 93 // Returns true if the effect is waiting for an unconsumed scroll to start. | 95 // Returns true if the effect is waiting for an unconsumed scroll to start. |
| 94 bool IsAwaitingScrollUpdateAck() const; | 96 bool IsAwaitingScrollUpdateAck() const; |
| 95 | 97 |
| 96 private: | 98 private: |
| 97 void Release(bool allow_activation); | 99 void Release(bool allow_activation); |
| 98 | 100 |
| 99 OverscrollRefreshClient* const client_; | 101 OverscrollRefreshClient* const client_; |
| 100 | 102 |
| 101 gfx::SizeF viewport_size_; | 103 gfx::SizeF viewport_size_; |
| 102 bool scrolled_to_top_; | 104 bool scrolled_to_top_; |
| 105 bool overflow_y_hidden_; |
| 103 | 106 |
| 104 enum ScrollConsumptionState { | 107 enum ScrollConsumptionState { |
| 105 DISABLED, | 108 DISABLED, |
| 106 AWAITING_SCROLL_UPDATE_ACK, | 109 AWAITING_SCROLL_UPDATE_ACK, |
| 107 ENABLED, | 110 ENABLED, |
| 108 } scroll_consumption_state_; | 111 } scroll_consumption_state_; |
| 109 | 112 |
| 110 class Effect; | 113 class Effect; |
| 111 scoped_ptr<Effect> effect_; | 114 scoped_ptr<Effect> effect_; |
| 112 | 115 |
| 113 DISALLOW_COPY_AND_ASSIGN(OverscrollRefresh); | 116 DISALLOW_COPY_AND_ASSIGN(OverscrollRefresh); |
| 114 }; | 117 }; |
| 115 | 118 |
| 116 } // namespace content | 119 } // namespace content |
| 117 | 120 |
| 118 #endif // CONTENT_BROWSER_ANDROID_OVERSCROLL_REFRESH_H_ | 121 #endif // CONTENT_BROWSER_ANDROID_OVERSCROLL_REFRESH_H_ |
| OLD | NEW |