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 #include "ui/android/overscroll_refresh.h" | 5 #include "ui/android/overscroll_refresh.h" |
6 | 6 |
7 #include "base/logging.h" | 7 #include "base/logging.h" |
8 #include "ui/android/overscroll_refresh_handler.h" | 8 #include "ui/android/overscroll_refresh_handler.h" |
9 | 9 |
10 namespace ui { | 10 namespace ui { |
11 namespace { | 11 namespace { |
12 | 12 |
13 // Experimentally determined constant used to allow activation even if touch | 13 // Experimentally determined constant used to allow activation even if touch |
14 // release results in a small upward fling (quite common during a slow scroll). | 14 // release results in a small upward fling (quite common during a slow scroll). |
15 const float kMinFlingVelocityForActivation = -500.f; | 15 const float kMinFlingVelocityForActivation = -500.f; |
16 | 16 |
17 } // namespace | 17 } // namespace |
18 | 18 |
19 OverscrollRefresh::OverscrollRefresh(OverscrollRefreshHandler* handler) | 19 OverscrollRefresh::OverscrollRefresh(OverscrollRefreshHandler* handler) |
20 : scrolled_to_top_(true), | 20 : scrolled_to_top_(true), |
21 overflow_y_hidden_(false), | 21 overflow_y_hidden_(false), |
22 scroll_consumption_state_(DISABLED), | 22 scroll_consumption_state_(DISABLED), |
23 handler_(handler) { | 23 handler_(handler) { |
24 DCHECK(handler); | 24 DCHECK(handler); |
25 } | 25 } |
26 | 26 |
| 27 OverscrollRefresh::OverscrollRefresh() |
| 28 : scrolled_to_top_(true), |
| 29 overflow_y_hidden_(false), |
| 30 scroll_consumption_state_(DISABLED), |
| 31 handler_(nullptr) {} |
| 32 |
27 OverscrollRefresh::~OverscrollRefresh() { | 33 OverscrollRefresh::~OverscrollRefresh() { |
28 } | 34 } |
29 | 35 |
30 void OverscrollRefresh::Reset() { | 36 void OverscrollRefresh::Reset() { |
31 scroll_consumption_state_ = DISABLED; | 37 scroll_consumption_state_ = DISABLED; |
32 handler_->PullReset(); | 38 handler_->PullReset(); |
33 } | 39 } |
34 | 40 |
35 void OverscrollRefresh::OnScrollBegin() { | 41 void OverscrollRefresh::OnScrollBegin() { |
36 ReleaseWithoutActivation(); | 42 ReleaseWithoutActivation(); |
37 if (scrolled_to_top_ && !overflow_y_hidden_) | 43 if (scrolled_to_top_ && !overflow_y_hidden_) |
38 scroll_consumption_state_ = AWAITING_SCROLL_UPDATE_ACK; | 44 scroll_consumption_state_ = AWAITING_SCROLL_UPDATE_ACK; |
39 } | 45 } |
40 | 46 |
41 void OverscrollRefresh::OnScrollEnd(const gfx::Vector2dF& scroll_velocity) { | 47 void OverscrollRefresh::OnScrollEnd(const gfx::Vector2dF& scroll_velocity) { |
42 bool allow_activation = scroll_velocity.y() > kMinFlingVelocityForActivation; | 48 bool allow_activation = scroll_velocity.y() > kMinFlingVelocityForActivation; |
43 Release(allow_activation); | 49 Release(allow_activation); |
44 } | 50 } |
45 | 51 |
46 void OverscrollRefresh::OnScrollUpdateAck(bool was_consumed) { | 52 void OverscrollRefresh::OnOverscrolled(bool can_navigate) { |
47 if (scroll_consumption_state_ != AWAITING_SCROLL_UPDATE_ACK) | 53 if (scroll_consumption_state_ != AWAITING_SCROLL_UPDATE_ACK) |
48 return; | 54 return; |
49 | 55 |
50 if (was_consumed) { | 56 if (!can_navigate) { |
51 scroll_consumption_state_ = DISABLED; | 57 scroll_consumption_state_ = DISABLED; |
52 return; | 58 return; |
53 } | 59 } |
54 | 60 |
55 scroll_consumption_state_ = handler_->PullStart() ? ENABLED : DISABLED; | 61 scroll_consumption_state_ = handler_->PullStart() ? ENABLED : DISABLED; |
56 } | 62 } |
57 | 63 |
58 bool OverscrollRefresh::WillHandleScrollUpdate( | 64 bool OverscrollRefresh::WillHandleScrollUpdate( |
59 const gfx::Vector2dF& scroll_delta) { | 65 const gfx::Vector2dF& scroll_delta) { |
60 switch (scroll_consumption_state_) { | 66 switch (scroll_consumption_state_) { |
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
96 overflow_y_hidden_ = root_overflow_y_hidden; | 102 overflow_y_hidden_ = root_overflow_y_hidden; |
97 } | 103 } |
98 | 104 |
99 void OverscrollRefresh::Release(bool allow_refresh) { | 105 void OverscrollRefresh::Release(bool allow_refresh) { |
100 if (scroll_consumption_state_ == ENABLED) | 106 if (scroll_consumption_state_ == ENABLED) |
101 handler_->PullRelease(allow_refresh); | 107 handler_->PullRelease(allow_refresh); |
102 scroll_consumption_state_ = DISABLED; | 108 scroll_consumption_state_ = DISABLED; |
103 } | 109 } |
104 | 110 |
105 } // namespace ui | 111 } // namespace ui |
OLD | NEW |