Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(217)

Side by Side Diff: ui/android/overscroll_refresh.cc

Issue 2884423003: Use scroll-boundary-behavior to control overscroll-refresh/glow on android. (Closed)
Patch Set: Fix nits and rebase Created 3 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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);
25 }
26 24
27 OverscrollRefresh::~OverscrollRefresh() { 25 OverscrollRefresh::~OverscrollRefresh() {
28 } 26 }
29 27
30 void OverscrollRefresh::Reset() { 28 void OverscrollRefresh::Reset() {
31 scroll_consumption_state_ = DISABLED; 29 scroll_consumption_state_ = DISABLED;
32 handler_->PullReset(); 30 if (handler_)
boliu 2017/08/23 19:17:02 hmm, handler is constant, so if this one needs a n
sunyunjia 2017/08/23 23:47:06 Feels like it's a bit complicated to mock an Overs
31 handler_->PullReset();
33 } 32 }
34 33
35 void OverscrollRefresh::OnScrollBegin() { 34 void OverscrollRefresh::OnScrollBegin() {
36 ReleaseWithoutActivation(); 35 ReleaseWithoutActivation();
37 if (scrolled_to_top_ && !overflow_y_hidden_) 36 if (scrolled_to_top_ && !overflow_y_hidden_)
38 scroll_consumption_state_ = AWAITING_SCROLL_UPDATE_ACK; 37 scroll_consumption_state_ = AWAITING_SCROLL_UPDATE_ACK;
39 } 38 }
40 39
41 void OverscrollRefresh::OnScrollEnd(const gfx::Vector2dF& scroll_velocity) { 40 void OverscrollRefresh::OnScrollEnd(const gfx::Vector2dF& scroll_velocity) {
42 bool allow_activation = scroll_velocity.y() > kMinFlingVelocityForActivation; 41 bool allow_activation = scroll_velocity.y() > kMinFlingVelocityForActivation;
43 Release(allow_activation); 42 Release(allow_activation);
44 } 43 }
45 44
46 void OverscrollRefresh::OnScrollUpdateAck(bool was_consumed) { 45 void OverscrollRefresh::OnOverscrolled() {
47 if (scroll_consumption_state_ != AWAITING_SCROLL_UPDATE_ACK) 46 if (scroll_consumption_state_ != AWAITING_SCROLL_UPDATE_ACK)
48 return; 47 return;
49 48
50 if (was_consumed) { 49 DCHECK(handler_);
51 scroll_consumption_state_ = DISABLED;
52 return;
53 }
54
55 scroll_consumption_state_ = handler_->PullStart() ? ENABLED : DISABLED; 50 scroll_consumption_state_ = handler_->PullStart() ? ENABLED : DISABLED;
56 } 51 }
57 52
58 bool OverscrollRefresh::WillHandleScrollUpdate( 53 bool OverscrollRefresh::WillHandleScrollUpdate(
59 const gfx::Vector2dF& scroll_delta) { 54 const gfx::Vector2dF& scroll_delta) {
60 switch (scroll_consumption_state_) { 55 switch (scroll_consumption_state_) {
61 case DISABLED: 56 case DISABLED:
62 return false; 57 return false;
63 58
64 case AWAITING_SCROLL_UPDATE_ACK: 59 case AWAITING_SCROLL_UPDATE_ACK:
65 // If the initial scroll motion is downward, never allow activation. 60 // If the initial scroll motion is downward, never allow activation.
66 if (scroll_delta.y() <= 0) 61 if (scroll_delta.y() <= 0)
67 scroll_consumption_state_ = DISABLED; 62 scroll_consumption_state_ = DISABLED;
68 return false; 63 return false;
69 64
70 case ENABLED: 65 case ENABLED:
66 DCHECK(handler_);
71 handler_->PullUpdate(scroll_delta.y()); 67 handler_->PullUpdate(scroll_delta.y());
72 return true; 68 return true;
73 } 69 }
74 70
75 NOTREACHED() << "Invalid overscroll state: " << scroll_consumption_state_; 71 NOTREACHED() << "Invalid overscroll state: " << scroll_consumption_state_;
76 return false; 72 return false;
77 } 73 }
78 74
79 void OverscrollRefresh::ReleaseWithoutActivation() { 75 void OverscrollRefresh::ReleaseWithoutActivation() {
80 bool allow_activation = false; 76 bool allow_activation = false;
81 Release(allow_activation); 77 Release(allow_activation);
82 } 78 }
83 79
84 bool OverscrollRefresh::IsActive() const { 80 bool OverscrollRefresh::IsActive() const {
85 return scroll_consumption_state_ == ENABLED; 81 return scroll_consumption_state_ == ENABLED;
86 } 82 }
87 83
88 bool OverscrollRefresh::IsAwaitingScrollUpdateAck() const { 84 bool OverscrollRefresh::IsAwaitingScrollUpdateAck() const {
89 return scroll_consumption_state_ == AWAITING_SCROLL_UPDATE_ACK; 85 return scroll_consumption_state_ == AWAITING_SCROLL_UPDATE_ACK;
90 } 86 }
91 87
92 void OverscrollRefresh::OnFrameUpdated( 88 void OverscrollRefresh::OnFrameUpdated(
93 const gfx::Vector2dF& content_scroll_offset, 89 const gfx::Vector2dF& content_scroll_offset,
94 bool root_overflow_y_hidden) { 90 bool root_overflow_y_hidden) {
95 scrolled_to_top_ = content_scroll_offset.y() == 0; 91 scrolled_to_top_ = content_scroll_offset.y() == 0;
96 overflow_y_hidden_ = root_overflow_y_hidden; 92 overflow_y_hidden_ = root_overflow_y_hidden;
97 } 93 }
98 94
99 void OverscrollRefresh::Release(bool allow_refresh) { 95 void OverscrollRefresh::Release(bool allow_refresh) {
100 if (scroll_consumption_state_ == ENABLED) 96 if (scroll_consumption_state_ == ENABLED) {
97 DCHECK(handler_);
101 handler_->PullRelease(allow_refresh); 98 handler_->PullRelease(allow_refresh);
99 }
102 scroll_consumption_state_ = DISABLED; 100 scroll_consumption_state_ = DISABLED;
103 } 101 }
104 102
105 } // namespace ui 103 } // namespace ui
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698