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

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: rebase Created 3 years, 5 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;
30 DCHECK(handler_);
32 handler_->PullReset(); 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(bool can_navigate) {
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 if (!can_navigate) {
51 scroll_consumption_state_ = DISABLED; 50 scroll_consumption_state_ = DISABLED;
52 return; 51 return;
53 } 52 }
54 53
54 DCHECK(handler_);
55 scroll_consumption_state_ = handler_->PullStart() ? ENABLED : DISABLED; 55 scroll_consumption_state_ = handler_->PullStart() ? ENABLED : DISABLED;
56 } 56 }
57 57
58 bool OverscrollRefresh::WillHandleScrollUpdate( 58 bool OverscrollRefresh::WillHandleScrollUpdate(
59 const gfx::Vector2dF& scroll_delta) { 59 const gfx::Vector2dF& scroll_delta) {
60 switch (scroll_consumption_state_) { 60 switch (scroll_consumption_state_) {
61 case DISABLED: 61 case DISABLED:
62 return false; 62 return false;
63 63
64 case AWAITING_SCROLL_UPDATE_ACK: 64 case AWAITING_SCROLL_UPDATE_ACK:
65 // If the initial scroll motion is downward, never allow activation. 65 // If the initial scroll motion is downward, never allow activation.
66 if (scroll_delta.y() <= 0) 66 if (scroll_delta.y() <= 0)
67 scroll_consumption_state_ = DISABLED; 67 scroll_consumption_state_ = DISABLED;
68 return false; 68 return false;
69 69
70 case ENABLED: 70 case ENABLED:
71 DCHECK(handler_);
71 handler_->PullUpdate(scroll_delta.y()); 72 handler_->PullUpdate(scroll_delta.y());
72 return true; 73 return true;
73 } 74 }
74 75
75 NOTREACHED() << "Invalid overscroll state: " << scroll_consumption_state_; 76 NOTREACHED() << "Invalid overscroll state: " << scroll_consumption_state_;
76 return false; 77 return false;
77 } 78 }
78 79
79 void OverscrollRefresh::ReleaseWithoutActivation() { 80 void OverscrollRefresh::ReleaseWithoutActivation() {
80 bool allow_activation = false; 81 bool allow_activation = false;
81 Release(allow_activation); 82 Release(allow_activation);
82 } 83 }
83 84
84 bool OverscrollRefresh::IsActive() const { 85 bool OverscrollRefresh::IsActive() const {
85 return scroll_consumption_state_ == ENABLED; 86 return scroll_consumption_state_ == ENABLED;
86 } 87 }
87 88
88 bool OverscrollRefresh::IsAwaitingScrollUpdateAck() const { 89 bool OverscrollRefresh::IsAwaitingScrollUpdateAck() const {
89 return scroll_consumption_state_ == AWAITING_SCROLL_UPDATE_ACK; 90 return scroll_consumption_state_ == AWAITING_SCROLL_UPDATE_ACK;
90 } 91 }
91 92
92 void OverscrollRefresh::OnFrameUpdated( 93 void OverscrollRefresh::OnFrameUpdated(
93 const gfx::Vector2dF& content_scroll_offset, 94 const gfx::Vector2dF& content_scroll_offset,
94 bool root_overflow_y_hidden) { 95 bool root_overflow_y_hidden) {
95 scrolled_to_top_ = content_scroll_offset.y() == 0; 96 scrolled_to_top_ = content_scroll_offset.y() == 0;
96 overflow_y_hidden_ = root_overflow_y_hidden; 97 overflow_y_hidden_ = root_overflow_y_hidden;
97 } 98 }
98 99
99 void OverscrollRefresh::Release(bool allow_refresh) { 100 void OverscrollRefresh::Release(bool allow_refresh) {
100 if (scroll_consumption_state_ == ENABLED) 101 if (scroll_consumption_state_ == ENABLED) {
102 DCHECK(handler_);
101 handler_->PullRelease(allow_refresh); 103 handler_->PullRelease(allow_refresh);
104 }
102 scroll_consumption_state_ = DISABLED; 105 scroll_consumption_state_ = DISABLED;
103 } 106 }
104 107
105 } // namespace ui 108 } // namespace ui
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698