| 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 UI_ANDROID_OVERSCROLL_REFRESH_H_ | 5 #ifndef UI_ANDROID_OVERSCROLL_REFRESH_H_ |
| 6 #define UI_ANDROID_OVERSCROLL_REFRESH_H_ | 6 #define UI_ANDROID_OVERSCROLL_REFRESH_H_ |
| 7 | 7 |
| 8 #include "base/macros.h" | 8 #include "base/macros.h" |
| 9 #include "ui/android/ui_android_export.h" | 9 #include "ui/android/ui_android_export.h" |
| 10 #include "ui/gfx/geometry/size_f.h" | 10 #include "ui/gfx/geometry/size_f.h" |
| (...skipping 12 matching lines...) Expand all Loading... |
| 23 // The actuall pull response, animation and action are delegated to the | 23 // The actuall pull response, animation and action are delegated to the |
| 24 // provided refresh handler. | 24 // provided refresh handler. |
| 25 class UI_ANDROID_EXPORT OverscrollRefresh { | 25 class UI_ANDROID_EXPORT OverscrollRefresh { |
| 26 public: | 26 public: |
| 27 // Minmum number of overscrolling pull events required to activate the effect. | 27 // Minmum number of overscrolling pull events required to activate the effect. |
| 28 // Useful for avoiding accidental triggering when a scroll janks (is delayed), | 28 // Useful for avoiding accidental triggering when a scroll janks (is delayed), |
| 29 // capping the impulse per event. | 29 // capping the impulse per event. |
| 30 enum { kMinPullsToActivate = 3 }; | 30 enum { kMinPullsToActivate = 3 }; |
| 31 | 31 |
| 32 explicit OverscrollRefresh(OverscrollRefreshHandler* handler); | 32 explicit OverscrollRefresh(OverscrollRefreshHandler* handler); |
| 33 |
| 33 ~OverscrollRefresh(); | 34 ~OverscrollRefresh(); |
| 34 | 35 |
| 35 // Scroll event stream listening methods. | 36 // Scroll event stream listening methods. |
| 36 void OnScrollBegin(); | 37 void OnScrollBegin(); |
| 37 // Returns whether the refresh was activated. | 38 // Returns whether the refresh was activated. |
| 38 void OnScrollEnd(const gfx::Vector2dF& velocity); | 39 void OnScrollEnd(const gfx::Vector2dF& velocity); |
| 39 | 40 |
| 40 // Scroll ack listener. The effect will only be activated if the initial | 41 // Scroll ack listener. The effect will only be activated if |can_navigate| |
| 41 // updates go unconsumed. | 42 // is true which happens when the scroll update is not consumed and the |
| 42 void OnScrollUpdateAck(bool was_consumed); | 43 // scroll_boundary_behavior on y axis is 'auto'. |
| 44 // This method is made virtual for mocking. |
| 45 virtual void OnOverscrolled(); |
| 43 | 46 |
| 44 // Returns true if the effect has consumed the |scroll_delta|. | 47 // Returns true if the effect has consumed the |scroll_delta|. |
| 45 bool WillHandleScrollUpdate(const gfx::Vector2dF& scroll_delta); | 48 bool WillHandleScrollUpdate(const gfx::Vector2dF& scroll_delta); |
| 46 | 49 |
| 47 // Release the effect (if active), preventing any associated refresh action. | 50 // Release the effect (if active), preventing any associated refresh action. |
| 48 void ReleaseWithoutActivation(); | 51 void ReleaseWithoutActivation(); |
| 49 | 52 |
| 50 // Notify the effect of the latest scroll offset and overflow properties. | 53 // Notify the effect of the latest scroll offset and overflow properties. |
| 51 // The effect will be disabled when the offset is non-zero or overflow is | 54 // The effect will be disabled when the offset is non-zero or overflow is |
| 52 // hidden. Note: All dimensions are in device pixels. | 55 // hidden. Note: All dimensions are in device pixels. |
| 53 void OnFrameUpdated(const gfx::Vector2dF& content_scroll_offset, | 56 void OnFrameUpdated(const gfx::Vector2dF& content_scroll_offset, |
| 54 bool root_overflow_y_hidden); | 57 bool root_overflow_y_hidden); |
| 55 | 58 |
| 56 // Reset the effect to its inactive state, immediately detaching and | 59 // Reset the effect to its inactive state, immediately detaching and |
| 57 // disabling any active effects. | 60 // disabling any active effects. |
| 58 void Reset(); | 61 // This method is made virtual for mocking. |
| 62 virtual void Reset(); |
| 59 | 63 |
| 60 // Returns true if the refresh effect is either being manipulated or animated. | 64 // Returns true if the refresh effect is either being manipulated or animated. |
| 61 bool IsActive() const; | 65 // This method is made virtual for mocking. |
| 66 virtual bool IsActive() const; |
| 62 | 67 |
| 63 // Returns true if the effect is waiting for an unconsumed scroll to start. | 68 // Returns true if the effect is waiting for an unconsumed scroll to start. |
| 64 bool IsAwaitingScrollUpdateAck() const; | 69 // This method is made virtual for mocking. |
| 70 virtual bool IsAwaitingScrollUpdateAck() const; |
| 71 |
| 72 protected: |
| 73 // This constructor is for mocking only. |
| 74 OverscrollRefresh(); |
| 65 | 75 |
| 66 private: | 76 private: |
| 67 void Release(bool allow_refresh); | 77 void Release(bool allow_refresh); |
| 68 | 78 |
| 69 bool scrolled_to_top_; | 79 bool scrolled_to_top_; |
| 70 bool overflow_y_hidden_; | 80 bool overflow_y_hidden_; |
| 71 | 81 |
| 72 enum ScrollConsumptionState { | 82 enum ScrollConsumptionState { |
| 73 DISABLED, | 83 DISABLED, |
| 74 AWAITING_SCROLL_UPDATE_ACK, | 84 AWAITING_SCROLL_UPDATE_ACK, |
| 75 ENABLED, | 85 ENABLED, |
| 76 } scroll_consumption_state_; | 86 } scroll_consumption_state_; |
| 77 | 87 |
| 78 OverscrollRefreshHandler* const handler_; | 88 OverscrollRefreshHandler* const handler_; |
| 79 | 89 |
| 80 DISALLOW_COPY_AND_ASSIGN(OverscrollRefresh); | 90 DISALLOW_COPY_AND_ASSIGN(OverscrollRefresh); |
| 81 }; | 91 }; |
| 82 | 92 |
| 83 } // namespace ui | 93 } // namespace ui |
| 84 | 94 |
| 85 #endif // UI_ANDROID_OVERSCROLL_REFRESH_H_ | 95 #endif // UI_ANDROID_OVERSCROLL_REFRESH_H_ |
| OLD | NEW |