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 2528823002: Separate SwipeRefreshHandler and ContentViewCore (Closed)
Patch Set: Remove unused SwipeRefreshHandler.mNativeSwipeRefreshHandler field Created 4 years 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 "jni/SwipeRefreshHandler_jni.h"
5 #include "ui/android/overscroll_refresh.h" 6 #include "ui/android/overscroll_refresh.h"
6 7
7 #include "base/logging.h" 8 #include "base/logging.h"
8 9
9 namespace ui { 10 namespace ui {
10 namespace { 11 namespace {
11 12
12 // Experimentally determined constant used to allow activation even if touch 13 // Experimentally determined constant used to allow activation even if touch
13 // 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).
14 const float kMinFlingVelocityForActivation = -500.f; 15 const float kMinFlingVelocityForActivation = -500.f;
15 16
16 } // namespace 17 } // namespace
17 18
18 OverscrollRefresh::OverscrollRefresh(OverscrollRefreshHandler* handler) 19 using base::android::AttachCurrentThread;
20
21 OverscrollRefresh::OverscrollRefresh(
22 const base::android::JavaRef<jobject>& handler)
19 : scrolled_to_top_(true), 23 : scrolled_to_top_(true),
20 overflow_y_hidden_(false), 24 overflow_y_hidden_(false),
21 scroll_consumption_state_(DISABLED), 25 scroll_consumption_state_(DISABLED),
22 handler_(handler) { 26 handler_(nullptr, handler.obj()) {
boliu 2016/12/01 00:01:57 huh odd, null is actually ok here, but I don't see
23 DCHECK(handler); 27 DCHECK(!handler_.is_null());
24 } 28 }
25 29
26 OverscrollRefresh::~OverscrollRefresh() { 30 OverscrollRefresh::~OverscrollRefresh() {
27 } 31 }
28 32
29 void OverscrollRefresh::Reset() { 33 void OverscrollRefresh::Reset() {
30 scroll_consumption_state_ = DISABLED; 34 scroll_consumption_state_ = DISABLED;
31 handler_->PullReset(); 35 Java_SwipeRefreshHandler_reset(AttachCurrentThread(), handler_);
32 } 36 }
33 37
34 void OverscrollRefresh::OnScrollBegin() { 38 void OverscrollRefresh::OnScrollBegin() {
35 ReleaseWithoutActivation(); 39 ReleaseWithoutActivation();
36 if (scrolled_to_top_ && !overflow_y_hidden_) 40 if (scrolled_to_top_ && !overflow_y_hidden_)
37 scroll_consumption_state_ = AWAITING_SCROLL_UPDATE_ACK; 41 scroll_consumption_state_ = AWAITING_SCROLL_UPDATE_ACK;
38 } 42 }
39 43
40 void OverscrollRefresh::OnScrollEnd(const gfx::Vector2dF& scroll_velocity) { 44 void OverscrollRefresh::OnScrollEnd(const gfx::Vector2dF& scroll_velocity) {
41 bool allow_activation = scroll_velocity.y() > kMinFlingVelocityForActivation; 45 bool allow_activation = scroll_velocity.y() > kMinFlingVelocityForActivation;
42 Release(allow_activation); 46 Release(allow_activation);
43 } 47 }
44 48
45 void OverscrollRefresh::OnScrollUpdateAck(bool was_consumed) { 49 void OverscrollRefresh::OnScrollUpdateAck(bool was_consumed) {
46 if (scroll_consumption_state_ != AWAITING_SCROLL_UPDATE_ACK) 50 if (scroll_consumption_state_ != AWAITING_SCROLL_UPDATE_ACK)
47 return; 51 return;
48 52
49 if (was_consumed) { 53 if (was_consumed) {
50 scroll_consumption_state_ = DISABLED; 54 scroll_consumption_state_ = DISABLED;
51 return; 55 return;
52 } 56 }
53 57
54 scroll_consumption_state_ = handler_->PullStart() ? ENABLED : DISABLED; 58 bool pull_started =
59 Java_SwipeRefreshHandler_start(AttachCurrentThread(), handler_);
60
61 scroll_consumption_state_ = pull_started ? ENABLED : DISABLED;
55 } 62 }
56 63
57 bool OverscrollRefresh::WillHandleScrollUpdate( 64 bool OverscrollRefresh::WillHandleScrollUpdate(
58 const gfx::Vector2dF& scroll_delta) { 65 const gfx::Vector2dF& scroll_delta) {
59 switch (scroll_consumption_state_) { 66 switch (scroll_consumption_state_) {
60 case DISABLED: 67 case DISABLED:
61 return false; 68 return false;
62 69
63 case AWAITING_SCROLL_UPDATE_ACK: 70 case AWAITING_SCROLL_UPDATE_ACK:
64 // If the initial scroll motion is downward, never allow activation. 71 // If the initial scroll motion is downward, never allow activation.
65 if (scroll_delta.y() <= 0) 72 if (scroll_delta.y() <= 0)
66 scroll_consumption_state_ = DISABLED; 73 scroll_consumption_state_ = DISABLED;
67 return false; 74 return false;
68 75
69 case ENABLED: 76 case ENABLED:
70 handler_->PullUpdate(scroll_delta.y()); 77 Java_SwipeRefreshHandler_pull(AttachCurrentThread(), handler_,
78 scroll_delta.y());
71 return true; 79 return true;
72 } 80 }
73 81
74 NOTREACHED() << "Invalid overscroll state: " << scroll_consumption_state_; 82 NOTREACHED() << "Invalid overscroll state: " << scroll_consumption_state_;
75 return false; 83 return false;
76 } 84 }
77 85
78 void OverscrollRefresh::ReleaseWithoutActivation() { 86 void OverscrollRefresh::ReleaseWithoutActivation() {
79 bool allow_activation = false; 87 bool allow_activation = false;
80 Release(allow_activation); 88 Release(allow_activation);
81 } 89 }
82 90
83 bool OverscrollRefresh::IsActive() const { 91 bool OverscrollRefresh::IsActive() const {
84 return scroll_consumption_state_ == ENABLED; 92 return scroll_consumption_state_ == ENABLED;
85 } 93 }
86 94
87 bool OverscrollRefresh::IsAwaitingScrollUpdateAck() const { 95 bool OverscrollRefresh::IsAwaitingScrollUpdateAck() const {
88 return scroll_consumption_state_ == AWAITING_SCROLL_UPDATE_ACK; 96 return scroll_consumption_state_ == AWAITING_SCROLL_UPDATE_ACK;
89 } 97 }
90 98
91 void OverscrollRefresh::OnFrameUpdated( 99 void OverscrollRefresh::OnFrameUpdated(
92 const gfx::Vector2dF& content_scroll_offset, 100 const gfx::Vector2dF& content_scroll_offset,
93 bool root_overflow_y_hidden) { 101 bool root_overflow_y_hidden) {
94 scrolled_to_top_ = content_scroll_offset.y() == 0; 102 scrolled_to_top_ = content_scroll_offset.y() == 0;
95 overflow_y_hidden_ = root_overflow_y_hidden; 103 overflow_y_hidden_ = root_overflow_y_hidden;
96 } 104 }
97 105
98 void OverscrollRefresh::Release(bool allow_refresh) { 106 void OverscrollRefresh::Release(bool allow_refresh) {
99 if (scroll_consumption_state_ == ENABLED) 107 if (scroll_consumption_state_ == ENABLED)
100 handler_->PullRelease(allow_refresh); 108 Java_SwipeRefreshHandler_release(AttachCurrentThread(), handler_,
109 allow_refresh);
101 scroll_consumption_state_ = DISABLED; 110 scroll_consumption_state_ = DISABLED;
102 } 111 }
103 112
104 } // namespace ui 113 } // namespace ui
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698