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

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, 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
« no previous file with comments | « ui/android/overscroll_refresh.h ('k') | ui/android/overscroll_refresh_unittest.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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); 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() {
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) {
51 scroll_consumption_state_ = DISABLED;
52 return;
53 }
54
55 scroll_consumption_state_ = handler_->PullStart() ? ENABLED : DISABLED; 56 scroll_consumption_state_ = handler_->PullStart() ? ENABLED : DISABLED;
56 } 57 }
57 58
58 bool OverscrollRefresh::WillHandleScrollUpdate( 59 bool OverscrollRefresh::WillHandleScrollUpdate(
59 const gfx::Vector2dF& scroll_delta) { 60 const gfx::Vector2dF& scroll_delta) {
60 switch (scroll_consumption_state_) { 61 switch (scroll_consumption_state_) {
61 case DISABLED: 62 case DISABLED:
62 return false; 63 return false;
63 64
64 case AWAITING_SCROLL_UPDATE_ACK: 65 case AWAITING_SCROLL_UPDATE_ACK:
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
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)
101 handler_->PullRelease(allow_refresh); 102 handler_->PullRelease(allow_refresh);
102 scroll_consumption_state_ = DISABLED; 103 scroll_consumption_state_ = DISABLED;
103 } 104 }
104 105
105 } // namespace ui 106 } // namespace ui
OLDNEW
« no previous file with comments | « ui/android/overscroll_refresh.h ('k') | ui/android/overscroll_refresh_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698