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

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: 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 "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 if (base::CommandLine::ForCurrentProcess()->HasSwitch( 89 if (base::CommandLine::ForCurrentProcess()->HasSwitch(
90 switches::kDisablePullToRefreshEffect)) { 90 switches::kDisablePullToRefreshEffect)) {
91 return nullptr; 91 return nullptr;
92 } 92 }
93 93
94 return base::MakeUnique<OverscrollRefresh>(overscroll_refresh_handler); 94 return base::MakeUnique<OverscrollRefresh>(overscroll_refresh_handler);
95 } 95 }
96 96
97 } // namespace 97 } // namespace
98 98
99 // static
100 std::unique_ptr<OverscrollControllerAndroid>
101 OverscrollControllerAndroid::CreateForTests(
102 ui::WindowAndroidCompositor* compositor,
103 float dpi_scale,
104 std::unique_ptr<ui::OverscrollGlow> glow_effect,
105 std::unique_ptr<ui::OverscrollRefresh> refresh_effect) {
106 return std::unique_ptr<OverscrollControllerAndroid>(
107 new OverscrollControllerAndroid(compositor, dpi_scale,
108 std::move(glow_effect),
109 std::move(refresh_effect)));
110 }
111
112 OverscrollControllerAndroid::OverscrollControllerAndroid(
113 ui::WindowAndroidCompositor* compositor,
114 float dpi_scale,
115 std::unique_ptr<ui::OverscrollGlow> glow_effect,
116 std::unique_ptr<ui::OverscrollRefresh> refresh_effect)
117 : compositor_(compositor),
118 dpi_scale_(dpi_scale),
119 enabled_(true),
120 glow_effect_(std::move(glow_effect)),
121 refresh_effect_(std::move(refresh_effect)) {}
122
99 OverscrollControllerAndroid::OverscrollControllerAndroid( 123 OverscrollControllerAndroid::OverscrollControllerAndroid(
100 ui::OverscrollRefreshHandler* overscroll_refresh_handler, 124 ui::OverscrollRefreshHandler* overscroll_refresh_handler,
101 ui::WindowAndroidCompositor* compositor, 125 ui::WindowAndroidCompositor* compositor,
102 float dpi_scale) 126 float dpi_scale)
103 : compositor_(compositor), 127 : compositor_(compositor),
104 dpi_scale_(dpi_scale), 128 dpi_scale_(dpi_scale),
105 enabled_(true), 129 enabled_(true),
106 glow_effect_(CreateGlowEffect(this, dpi_scale_)), 130 glow_effect_(CreateGlowEffect(this, dpi_scale_)),
107 refresh_effect_(CreateRefreshEffect(overscroll_refresh_handler)) { 131 refresh_effect_(CreateRefreshEffect(overscroll_refresh_handler)) {
108 DCHECK(compositor_); 132 DCHECK(compositor_);
(...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after
183 // sent from the renderer compositor. 207 // sent from the renderer compositor.
184 if (event.GetType() == blink::WebInputEvent::kGestureScrollEnd || 208 if (event.GetType() == blink::WebInputEvent::kGestureScrollEnd ||
185 event.GetType() == blink::WebInputEvent::kGestureFlingStart) { 209 event.GetType() == blink::WebInputEvent::kGestureFlingStart) {
186 OnOverscrolled(DidOverscrollParams()); 210 OnOverscrolled(DidOverscrollParams());
187 } 211 }
188 212
189 if (event.GetType() == blink::WebInputEvent::kGestureScrollUpdate && 213 if (event.GetType() == blink::WebInputEvent::kGestureScrollUpdate &&
190 refresh_effect_) { 214 refresh_effect_) {
191 // The effect should only be allowed if both the causal touch events go 215 // The effect should only be allowed if both the causal touch events go
192 // unconsumed and the generated scroll events go unconsumed. 216 // unconsumed and the generated scroll events go unconsumed.
193 bool consumed = 217 if (ack_result == INPUT_EVENT_ACK_STATE_CONSUMED ||
194 ack_result == INPUT_EVENT_ACK_STATE_CONSUMED || 218 event.data.scroll_update.previous_update_in_sequence_prevented) {
195 event.data.scroll_update.previous_update_in_sequence_prevented; 219 refresh_effect_->Reset();
196 refresh_effect_->OnScrollUpdateAck(consumed); 220 }
197 } 221 }
198 } 222 }
199 223
200 void OverscrollControllerAndroid::OnOverscrolled( 224 void OverscrollControllerAndroid::OnOverscrolled(
201 const DidOverscrollParams& params) { 225 const DidOverscrollParams& params) {
202 if (!enabled_) 226 if (!enabled_)
203 return; 227 return;
204 228
205 if (refresh_effect_ && (refresh_effect_->IsActive() || 229 if (refresh_effect_) {
206 refresh_effect_->IsAwaitingScrollUpdateAck())) { 230 if (params.scroll_boundary_behavior.y !=
207 // An active (or potentially active) refresh effect should always pre-empt 231 cc::ScrollBoundaryBehavior::ScrollBoundaryBehaviorType::
208 // the passive glow effect. 232 kScrollBoundaryBehaviorTypeAuto)
209 return; 233 refresh_effect_->Reset();
234 else
235 refresh_effect_->OnOverscrolled();
236
237 if (refresh_effect_->IsActive() ||
238 refresh_effect_->IsAwaitingScrollUpdateAck()) {
239 // An active (or potentially active) refresh effect should always pre-empt
240 // the passive glow effect.
241 return;
242 }
210 } 243 }
211 244
212 // When use-zoom-for-dsf is enabled, each value of params was already scaled 245 // When use-zoom-for-dsf is enabled, each value of params was already scaled
213 // by the device scale factor. 246 // by the device scale factor.
214 float scale_factor = IsUseZoomForDSFEnabled() ? 1.f : dpi_scale_; 247 float scale_factor = IsUseZoomForDSFEnabled() ? 1.f : dpi_scale_;
215 if (glow_effect_ && 248 gfx::Vector2dF accumulated_overscroll =
216 glow_effect_->OnOverscrolled( 249 gfx::ScaleVector2d(params.accumulated_overscroll, scale_factor);
217 base::TimeTicks::Now(), 250 gfx::Vector2dF latest_overscroll_delta =
218 gfx::ScaleVector2d(params.accumulated_overscroll, scale_factor), 251 gfx::ScaleVector2d(params.latest_overscroll_delta, scale_factor);
219 gfx::ScaleVector2d(params.latest_overscroll_delta, scale_factor), 252 gfx::Vector2dF current_fling_velocity =
220 gfx::ScaleVector2d(params.current_fling_velocity, scale_factor), 253 gfx::ScaleVector2d(params.current_fling_velocity, scale_factor);
221 gfx::ScaleVector2d( 254 gfx::Vector2dF overscroll_location = gfx::ScaleVector2d(
222 params.causal_event_viewport_point.OffsetFromOrigin(), 255 params.causal_event_viewport_point.OffsetFromOrigin(), scale_factor);
223 scale_factor))) { 256
257 if (params.scroll_boundary_behavior.x ==
258 cc::ScrollBoundaryBehavior::ScrollBoundaryBehaviorType::
259 kScrollBoundaryBehaviorTypeNone) {
260 accumulated_overscroll.set_x(0);
261 latest_overscroll_delta.set_x(0);
262 current_fling_velocity.set_x(0);
263 }
264
265 if (params.scroll_boundary_behavior.y ==
266 cc::ScrollBoundaryBehavior::ScrollBoundaryBehaviorType::
267 kScrollBoundaryBehaviorTypeNone) {
268 accumulated_overscroll.set_y(0);
269 latest_overscroll_delta.set_y(0);
270 current_fling_velocity.set_y(0);
271 }
272
273 if (glow_effect_ && glow_effect_->OnOverscrolled(
274 base::TimeTicks::Now(), accumulated_overscroll,
275 latest_overscroll_delta, current_fling_velocity,
276 overscroll_location)) {
224 SetNeedsAnimate(); 277 SetNeedsAnimate();
225 } 278 }
226 } 279 }
227 280
228 bool OverscrollControllerAndroid::Animate(base::TimeTicks current_time, 281 bool OverscrollControllerAndroid::Animate(base::TimeTicks current_time,
229 cc::Layer* parent_layer) { 282 cc::Layer* parent_layer) {
230 DCHECK(parent_layer); 283 DCHECK(parent_layer);
231 if (!enabled_ || !glow_effect_) 284 if (!enabled_ || !glow_effect_)
232 return false; 285 return false;
233 286
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after
282 std::unique_ptr<EdgeEffectBase> 335 std::unique_ptr<EdgeEffectBase>
283 OverscrollControllerAndroid::CreateEdgeEffect() { 336 OverscrollControllerAndroid::CreateEdgeEffect() {
284 return CreateGlowEdgeEffect(&compositor_->GetResourceManager(), dpi_scale_); 337 return CreateGlowEdgeEffect(&compositor_->GetResourceManager(), dpi_scale_);
285 } 338 }
286 339
287 void OverscrollControllerAndroid::SetNeedsAnimate() { 340 void OverscrollControllerAndroid::SetNeedsAnimate() {
288 compositor_->SetNeedsAnimate(); 341 compositor_->SetNeedsAnimate();
289 } 342 }
290 343
291 } // namespace content 344 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698