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

Side by Side Diff: content/browser/android/overscroll_controller_android.cc

Issue 2884423003: Use scroll-boundary-behavior to control overscroll-refresh/glow on android. (Closed)
Patch Set: Update the test Created 3 years, 6 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 "content/browser/android/overscroll_controller_android.h" 5 #include "content/browser/android/overscroll_controller_android.h"
6 6
7 #include "base/android/build_info.h" 7 #include "base/android/build_info.h"
8 #include "base/command_line.h" 8 #include "base/command_line.h"
9 #include "base/memory/ptr_util.h" 9 #include "base/memory/ptr_util.h"
10 #include "cc/layers/layer.h" 10 #include "cc/layers/layer.h"
(...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after
89 switches::kDisablePullToRefreshEffect)) { 89 switches::kDisablePullToRefreshEffect)) {
90 return nullptr; 90 return nullptr;
91 } 91 }
92 92
93 return base::MakeUnique<OverscrollRefresh>(overscroll_refresh_handler); 93 return base::MakeUnique<OverscrollRefresh>(overscroll_refresh_handler);
94 } 94 }
95 95
96 } // namespace 96 } // namespace
97 97
98 OverscrollControllerAndroid::OverscrollControllerAndroid( 98 OverscrollControllerAndroid::OverscrollControllerAndroid(
99 ui::OverscrollGlow* glow_effect,
100 ui::OverscrollRefresh* refresh_effect,
101 ui::WindowAndroidCompositor* compositor,
102 float dpi_scale)
103 : compositor_(compositor),
104 dpi_scale_(dpi_scale),
105 enabled_(true),
106 scroll_update_consumed_(false),
107 glow_effect_(glow_effect),
108 refresh_effect_(refresh_effect) {
109 DCHECK(compositor_);
110 }
111
112 OverscrollControllerAndroid::OverscrollControllerAndroid(
99 ui::OverscrollRefreshHandler* overscroll_refresh_handler, 113 ui::OverscrollRefreshHandler* overscroll_refresh_handler,
100 ui::WindowAndroidCompositor* compositor, 114 ui::WindowAndroidCompositor* compositor,
101 float dpi_scale) 115 float dpi_scale)
102 : compositor_(compositor), 116 : compositor_(compositor),
103 dpi_scale_(dpi_scale), 117 dpi_scale_(dpi_scale),
104 enabled_(true), 118 enabled_(true),
119 scroll_update_consumed_(false),
105 glow_effect_(CreateGlowEffect(this, dpi_scale_)), 120 glow_effect_(CreateGlowEffect(this, dpi_scale_)),
106 refresh_effect_(CreateRefreshEffect(overscroll_refresh_handler)) { 121 refresh_effect_(CreateRefreshEffect(overscroll_refresh_handler)) {
majidvp 2017/07/12 21:04:20 This constructor should delegate to the one above
sunyunjia 2017/07/19 20:44:11 Done. I'm not sure if the delegate is worth it. I
107 DCHECK(compositor_); 122 DCHECK(compositor_);
108 } 123 }
109 124
110 OverscrollControllerAndroid::~OverscrollControllerAndroid() { 125 OverscrollControllerAndroid::~OverscrollControllerAndroid() {
111 } 126 }
112 127
113 bool OverscrollControllerAndroid::WillHandleGestureEvent( 128 bool OverscrollControllerAndroid::WillHandleGestureEvent(
114 const blink::WebGestureEvent& event) { 129 const blink::WebGestureEvent& event) {
115 if (!enabled_) 130 if (!enabled_)
116 return false; 131 return false;
117 132
118 if (!refresh_effect_) 133 if (!refresh_effect_)
119 return false; 134 return false;
120 135
121 // Suppress refresh detection if the glow effect is still prominent. 136 // Suppress refresh detection if the glow effect is still prominent.
122 if (glow_effect_ && glow_effect_->IsActive()) { 137 if (glow_effect_ && glow_effect_->IsActive()) {
123 if (glow_effect_->GetVisibleAlpha() > MinGlowAlphaToDisableRefresh()) 138 if (glow_effect_->GetVisibleAlpha() > MinGlowAlphaToDisableRefresh())
124 return false; 139 return false;
125 } 140 }
126 141
127 bool handled = false; 142 bool handled = false;
128 switch (event.GetType()) { 143 switch (event.GetType()) {
129 case blink::WebInputEvent::kGestureScrollBegin: 144 case blink::WebInputEvent::kGestureScrollBegin:
130 refresh_effect_->OnScrollBegin(); 145 refresh_effect_->OnScrollBegin();
146 scroll_update_consumed_ = false;
131 break; 147 break;
132 148
133 case blink::WebInputEvent::kGestureScrollUpdate: { 149 case blink::WebInputEvent::kGestureScrollUpdate: {
134 gfx::Vector2dF scroll_delta(event.data.scroll_update.delta_x, 150 gfx::Vector2dF scroll_delta(event.data.scroll_update.delta_x,
135 event.data.scroll_update.delta_y); 151 event.data.scroll_update.delta_y);
136 scroll_delta.Scale(dpi_scale_); 152 scroll_delta.Scale(dpi_scale_);
137 handled = refresh_effect_->WillHandleScrollUpdate(scroll_delta); 153 handled = refresh_effect_->WillHandleScrollUpdate(scroll_delta);
138 } break; 154 } break;
139 155
140 case blink::WebInputEvent::kGestureScrollEnd: 156 case blink::WebInputEvent::kGestureScrollEnd:
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
182 // sent from the renderer compositor. 198 // sent from the renderer compositor.
183 if (event.GetType() == blink::WebInputEvent::kGestureScrollEnd || 199 if (event.GetType() == blink::WebInputEvent::kGestureScrollEnd ||
184 event.GetType() == blink::WebInputEvent::kGestureFlingStart) { 200 event.GetType() == blink::WebInputEvent::kGestureFlingStart) {
185 OnOverscrolled(DidOverscrollParams()); 201 OnOverscrolled(DidOverscrollParams());
186 } 202 }
187 203
188 if (event.GetType() == blink::WebInputEvent::kGestureScrollUpdate && 204 if (event.GetType() == blink::WebInputEvent::kGestureScrollUpdate &&
189 refresh_effect_) { 205 refresh_effect_) {
190 // The effect should only be allowed if both the causal touch events go 206 // The effect should only be allowed if both the causal touch events go
191 // unconsumed and the generated scroll events go unconsumed. 207 // unconsumed and the generated scroll events go unconsumed.
192 bool consumed = 208 scroll_update_consumed_ =
193 ack_result == INPUT_EVENT_ACK_STATE_CONSUMED || 209 ack_result == INPUT_EVENT_ACK_STATE_CONSUMED ||
194 event.data.scroll_update.previous_update_in_sequence_prevented; 210 event.data.scroll_update.previous_update_in_sequence_prevented;
195 refresh_effect_->OnScrollUpdateAck(consumed);
196 } 211 }
197 } 212 }
198 213
199 void OverscrollControllerAndroid::OnOverscrolled( 214 void OverscrollControllerAndroid::OnOverscrolled(
200 const DidOverscrollParams& params) { 215 const DidOverscrollParams& overscroll_params) {
201 if (!enabled_) 216 if (!enabled_)
202 return; 217 return;
203 218
204 if (refresh_effect_ && (refresh_effect_->IsActive() || 219 DidOverscrollParams params = overscroll_params;
majidvp 2017/07/12 21:04:20 Seems a bit inefficient and unnecessary to create
sunyunjia 2017/07/19 20:44:11 Done.
205 refresh_effect_->IsAwaitingScrollUpdateAck())) { 220
206 // An active (or potentially active) refresh effect should always pre-empt 221 if (refresh_effect_) {
207 // the passive glow effect. 222 bool can_navigate =
208 return; 223 (!scroll_update_consumed_) &&
224 (params.scroll_boundary_behavior.y ==
225 cc::ScrollBoundaryBehavior::ScrollBoundaryBehaviorType::
226 kScrollBoundaryBehaviorTypeAuto);
227 refresh_effect_->OnOverscrolled(can_navigate);
228
229 if (refresh_effect_->IsActive() ||
230 refresh_effect_->IsAwaitingScrollUpdateAck()) {
231 // An active (or potentially active) refresh effect should always pre-empt
232 // the passive glow effect.
233 return;
234 }
235 }
236
237 if (params.scroll_boundary_behavior.x ==
238 cc::ScrollBoundaryBehavior::ScrollBoundaryBehaviorType::
239 kScrollBoundaryBehaviorTypeNone) {
240 params.accumulated_overscroll.set_x(0);
241 params.latest_overscroll_delta.set_x(0);
242 params.current_fling_velocity.set_x(0);
243 }
244
245 if (params.scroll_boundary_behavior.y ==
246 cc::ScrollBoundaryBehavior::ScrollBoundaryBehaviorType::
247 kScrollBoundaryBehaviorTypeNone) {
248 params.accumulated_overscroll.set_y(0);
249 params.latest_overscroll_delta.set_y(0);
250 params.current_fling_velocity.set_y(0);
209 } 251 }
210 252
211 if (glow_effect_ && 253 if (glow_effect_ &&
212 glow_effect_->OnOverscrolled( 254 glow_effect_->OnOverscrolled(
213 base::TimeTicks::Now(), 255 base::TimeTicks::Now(),
214 gfx::ScaleVector2d(params.accumulated_overscroll, dpi_scale_), 256 gfx::ScaleVector2d(params.accumulated_overscroll, dpi_scale_),
215 gfx::ScaleVector2d(params.latest_overscroll_delta, dpi_scale_), 257 gfx::ScaleVector2d(params.latest_overscroll_delta, dpi_scale_),
216 gfx::ScaleVector2d(params.current_fling_velocity, dpi_scale_), 258 gfx::ScaleVector2d(params.current_fling_velocity, dpi_scale_),
217 gfx::ScaleVector2d( 259 gfx::ScaleVector2d(
218 params.causal_event_viewport_point.OffsetFromOrigin(), 260 params.causal_event_viewport_point.OffsetFromOrigin(),
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after
274 std::unique_ptr<EdgeEffectBase> 316 std::unique_ptr<EdgeEffectBase>
275 OverscrollControllerAndroid::CreateEdgeEffect() { 317 OverscrollControllerAndroid::CreateEdgeEffect() {
276 return CreateGlowEdgeEffect(&compositor_->GetResourceManager(), dpi_scale_); 318 return CreateGlowEdgeEffect(&compositor_->GetResourceManager(), dpi_scale_);
277 } 319 }
278 320
279 void OverscrollControllerAndroid::SetNeedsAnimate() { 321 void OverscrollControllerAndroid::SetNeedsAnimate() {
280 compositor_->SetNeedsAnimate(); 322 compositor_->SetNeedsAnimate();
281 } 323 }
282 324
283 } // namespace content 325 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698