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

Side by Side Diff: content/renderer/input/input_scroll_elasticity_controller.cc

Issue 713413002: Hook ScrollElasticityController to InputHandlerProxy (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Reverse dtor order Created 6 years, 1 month 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 | « content/renderer/input/input_scroll_elasticity_controller.h ('k') | no next file » | 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 "content/renderer/input/input_scroll_elasticity_controller.h" 5 #include "content/renderer/input/input_scroll_elasticity_controller.h"
6 6
7 #include <math.h> 7 #include <math.h>
8 8
9 // ScrollElasticityController and ScrollElasticityControllerClient are based on 9 // InputScrollElasticityController is based on
10 // WebKit/Source/platform/mac/ScrollElasticityController.mm 10 // WebKit/Source/platform/mac/InputScrollElasticityController.mm
11 /* 11 /*
12 * Copyright (C) 2011 Apple Inc. All rights reserved. 12 * Copyright (C) 2011 Apple Inc. All rights reserved.
13 * 13 *
14 * Redistribution and use in source and binary forms, with or without 14 * Redistribution and use in source and binary forms, with or without
15 * modification, are permitted provided that the following conditions 15 * modification, are permitted provided that the following conditions
16 * are met: 16 * are met:
17 * 1. Redistributions of source code must retain the above copyright 17 * 1. Redistributions of source code must retain the above copyright
18 * notice, this list of conditions and the following disclaimer. 18 * notice, this list of conditions and the following disclaimer.
19 * 2. Redistributions in binary form must reproduce the above copyright 19 * 2. Redistributions in binary form must reproduce the above copyright
20 * notice, this list of conditions and the following disclaimer in the 20 * notice, this list of conditions and the following disclaimer in the
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after
81 // multiplier = [[NSUserDefaults standardUserDefaults] 81 // multiplier = [[NSUserDefaults standardUserDefaults]
82 // floatForKey:@"NSScrollWheelMultiplier"]; 82 // floatForKey:@"NSScrollWheelMultiplier"];
83 if (multiplier <= 0) 83 if (multiplier <= 0)
84 multiplier = 1; 84 multiplier = 1;
85 } 85 }
86 return multiplier; 86 return multiplier;
87 } 87 }
88 88
89 } // namespace 89 } // namespace
90 90
91 ScrollElasticityController::ScrollElasticityController( 91 InputScrollElasticityController::InputScrollElasticityController(
92 ScrollElasticityControllerClient* client) 92 cc::ScrollElasticityHelper* helper)
93 : client_(client), 93 : helper_(helper),
94 in_scroll_gesture_(false), 94 in_scroll_gesture_(false),
95 has_scrolled_(false), 95 has_scrolled_(false),
96 momentum_scroll_in_progress_(false), 96 momentum_scroll_in_progress_(false),
97 ignore_momentum_scrolls_(false), 97 ignore_momentum_scrolls_(false),
98 last_momentum_scroll_timestamp_(0), 98 last_momentum_scroll_timestamp_(0),
99 snap_rubberband_timer_is_active_(false) { 99 snap_rubberband_timer_is_active_(false),
100 weak_factory_(this) {
100 } 101 }
101 102
102 bool ScrollElasticityController::HandleWheelEvent( 103 InputScrollElasticityController::~InputScrollElasticityController() {
104 }
105
106 base::WeakPtr<InputScrollElasticityController>
107 InputScrollElasticityController::GetWeakPtr() {
108 if (helper_)
109 return weak_factory_.GetWeakPtr();
110 return base::WeakPtr<InputScrollElasticityController>();
111 }
112
113 void InputScrollElasticityController::Animate(base::TimeTicks time) {
114 if (!snap_rubberband_timer_is_active_)
115 return;
116
117 // TODO(ccameron): This should send the time parameter to the snap function,
118 // so that animation can be based on frame time, not arbitrarily-sampled
119 // clock time.
120 SnapRubberbandTimerFired();
121 }
122
123 void InputScrollElasticityController::ObserveWheelEventAndResult(
124 const blink::WebMouseWheelEvent& wheel_event,
125 const cc::InputHandlerScrollResult& scroll_result) {
126 // TODO(ccameron): Pull non-over-scrolling scroll logic out of
127 // HandleWheelEvent, and read the scroll result instead.
128 HandleWheelEvent(wheel_event);
129 }
130
131 bool InputScrollElasticityController::HandleWheelEvent(
103 const blink::WebMouseWheelEvent& wheel_event) { 132 const blink::WebMouseWheelEvent& wheel_event) {
104 if (wheel_event.phase == blink::WebMouseWheelEvent::PhaseMayBegin) 133 if (wheel_event.phase == blink::WebMouseWheelEvent::PhaseMayBegin)
105 return false; 134 return false;
106 135
107 if (wheel_event.phase == blink::WebMouseWheelEvent::PhaseBegan) { 136 if (wheel_event.phase == blink::WebMouseWheelEvent::PhaseBegan) {
108 in_scroll_gesture_ = true; 137 in_scroll_gesture_ = true;
109 has_scrolled_ = false; 138 has_scrolled_ = false;
110 momentum_scroll_in_progress_ = false; 139 momentum_scroll_in_progress_ = false;
111 ignore_momentum_scrolls_ = false; 140 ignore_momentum_scrolls_ = false;
112 last_momentum_scroll_timestamp_ = 0; 141 last_momentum_scroll_timestamp_ = 0;
113 momentum_velocity_ = gfx::Vector2dF(); 142 momentum_velocity_ = gfx::Vector2dF();
114 143
115 gfx::Vector2dF stretch_amount = client_->StretchAmount(); 144 gfx::Vector2dF stretch_amount = helper_->StretchAmount();
116 stretch_scroll_force_.set_x( 145 stretch_scroll_force_.set_x(
117 ReboundDeltaForElasticDelta(stretch_amount.x())); 146 ReboundDeltaForElasticDelta(stretch_amount.x()));
118 stretch_scroll_force_.set_y( 147 stretch_scroll_force_.set_y(
119 ReboundDeltaForElasticDelta(stretch_amount.y())); 148 ReboundDeltaForElasticDelta(stretch_amount.y()));
120 overflow_scroll_delta_ = gfx::Vector2dF(); 149 overflow_scroll_delta_ = gfx::Vector2dF();
121 150
122 StopSnapRubberbandTimer(); 151 StopSnapRubberbandTimer();
123 152
124 // TODO(erikchen): Use the commented out line once Chromium uses the 153 // TODO(erikchen): Use the commented out line once Chromium uses the
125 // return value correctly. 154 // return value correctly.
126 // crbug.com/375512 155 // crbug.com/375512
127 // return ShouldHandleEvent(wheel_event); 156 // return ShouldHandleEvent(wheel_event);
128 157
129 // This logic is incorrect, since diagonal wheel events are not consumed. 158 // This logic is incorrect, since diagonal wheel events are not consumed.
130 if (client_->PinnedInDirection(gfx::Vector2dF(-wheel_event.deltaX, 0))) { 159 if (helper_->PinnedInDirection(gfx::Vector2dF(-wheel_event.deltaX, 0))) {
131 if (wheel_event.deltaX > 0 && !wheel_event.canRubberbandLeft) 160 if (wheel_event.deltaX > 0 && !wheel_event.canRubberbandLeft)
132 return false; 161 return false;
133 if (wheel_event.deltaX < 0 && !wheel_event.canRubberbandRight) 162 if (wheel_event.deltaX < 0 && !wheel_event.canRubberbandRight)
134 return false; 163 return false;
135 } 164 }
136 165
137 return true; 166 return true;
138 } 167 }
139 168
140 if (wheel_event.phase == blink::WebMouseWheelEvent::PhaseEnded || 169 if (wheel_event.phase == blink::WebMouseWheelEvent::PhaseEnded ||
(...skipping 18 matching lines...) Expand all
159 188
160 float delta_x = overflow_scroll_delta_.x() - wheel_event.deltaX; 189 float delta_x = overflow_scroll_delta_.x() - wheel_event.deltaX;
161 float delta_y = overflow_scroll_delta_.y() - wheel_event.deltaY; 190 float delta_y = overflow_scroll_delta_.y() - wheel_event.deltaY;
162 float event_coalesced_delta_x = -wheel_event.deltaX; 191 float event_coalesced_delta_x = -wheel_event.deltaX;
163 float event_coalesced_delta_y = -wheel_event.deltaY; 192 float event_coalesced_delta_y = -wheel_event.deltaY;
164 193
165 // Reset overflow values because we may decide to remove delta at various 194 // Reset overflow values because we may decide to remove delta at various
166 // points and put it into overflow. 195 // points and put it into overflow.
167 overflow_scroll_delta_ = gfx::Vector2dF(); 196 overflow_scroll_delta_ = gfx::Vector2dF();
168 197
169 gfx::Vector2dF stretch_amount = client_->StretchAmount(); 198 gfx::Vector2dF stretch_amount = helper_->StretchAmount();
170 bool is_vertically_stretched = stretch_amount.y() != 0.f; 199 bool is_vertically_stretched = stretch_amount.y() != 0.f;
171 bool is_horizontally_stretched = stretch_amount.x() != 0.f; 200 bool is_horizontally_stretched = stretch_amount.x() != 0.f;
172 201
173 // Slightly prefer scrolling vertically by applying the = case to delta_y 202 // Slightly prefer scrolling vertically by applying the = case to delta_y
174 if (fabsf(delta_y) >= fabsf(delta_x)) 203 if (fabsf(delta_y) >= fabsf(delta_x))
175 delta_x = 0; 204 delta_x = 0;
176 else 205 else
177 delta_y = 0; 206 delta_y = 0;
178 207
179 bool should_stretch = false; 208 bool should_stretch = false;
(...skipping 19 matching lines...) Expand all
199 momentum_velocity_.set_x(event_coalesced_delta_x / (float)time_delta); 228 momentum_velocity_.set_x(event_coalesced_delta_x / (float)time_delta);
200 momentum_velocity_.set_y(event_coalesced_delta_y / (float)time_delta); 229 momentum_velocity_.set_y(event_coalesced_delta_y / (float)time_delta);
201 last_momentum_scroll_timestamp_ = wheel_event.timeStampSeconds; 230 last_momentum_scroll_timestamp_ = wheel_event.timeStampSeconds;
202 } else { 231 } else {
203 last_momentum_scroll_timestamp_ = wheel_event.timeStampSeconds; 232 last_momentum_scroll_timestamp_ = wheel_event.timeStampSeconds;
204 momentum_velocity_ = gfx::Vector2dF(); 233 momentum_velocity_ = gfx::Vector2dF();
205 } 234 }
206 235
207 if (is_vertically_stretched) { 236 if (is_vertically_stretched) {
208 if (!is_horizontally_stretched && 237 if (!is_horizontally_stretched &&
209 client_->PinnedInDirection(gfx::Vector2dF(delta_x, 0))) { 238 helper_->PinnedInDirection(gfx::Vector2dF(delta_x, 0))) {
210 // Stretching only in the vertical. 239 // Stretching only in the vertical.
211 if (delta_y != 0 && 240 if (delta_y != 0 &&
212 (fabsf(delta_x / delta_y) < kRubberbandDirectionLockStretchRatio)) 241 (fabsf(delta_x / delta_y) < kRubberbandDirectionLockStretchRatio))
213 delta_x = 0; 242 delta_x = 0;
214 else if (fabsf(delta_x) < 243 else if (fabsf(delta_x) <
215 kRubberbandMinimumRequiredDeltaBeforeStretch) { 244 kRubberbandMinimumRequiredDeltaBeforeStretch) {
216 overflow_scroll_delta_.set_x(overflow_scroll_delta_.x() + delta_x); 245 overflow_scroll_delta_.set_x(overflow_scroll_delta_.x() + delta_x);
217 delta_x = 0; 246 delta_x = 0;
218 } else 247 } else
219 overflow_scroll_delta_.set_x(overflow_scroll_delta_.x() + delta_x); 248 overflow_scroll_delta_.set_x(overflow_scroll_delta_.x() + delta_x);
220 } 249 }
221 } else if (is_horizontally_stretched) { 250 } else if (is_horizontally_stretched) {
222 // Stretching only in the horizontal. 251 // Stretching only in the horizontal.
223 if (client_->PinnedInDirection(gfx::Vector2dF(0, delta_y))) { 252 if (helper_->PinnedInDirection(gfx::Vector2dF(0, delta_y))) {
224 if (delta_x != 0 && 253 if (delta_x != 0 &&
225 (fabsf(delta_y / delta_x) < kRubberbandDirectionLockStretchRatio)) 254 (fabsf(delta_y / delta_x) < kRubberbandDirectionLockStretchRatio))
226 delta_y = 0; 255 delta_y = 0;
227 else if (fabsf(delta_y) < 256 else if (fabsf(delta_y) <
228 kRubberbandMinimumRequiredDeltaBeforeStretch) { 257 kRubberbandMinimumRequiredDeltaBeforeStretch) {
229 overflow_scroll_delta_.set_y(overflow_scroll_delta_.y() + delta_y); 258 overflow_scroll_delta_.set_y(overflow_scroll_delta_.y() + delta_y);
230 delta_y = 0; 259 delta_y = 0;
231 } else 260 } else
232 overflow_scroll_delta_.set_y(overflow_scroll_delta_.y() + delta_y); 261 overflow_scroll_delta_.set_y(overflow_scroll_delta_.y() + delta_y);
233 } 262 }
234 } else { 263 } else {
235 // Not stretching at all yet. 264 // Not stretching at all yet.
236 if (client_->PinnedInDirection(gfx::Vector2dF(delta_x, delta_y))) { 265 if (helper_->PinnedInDirection(gfx::Vector2dF(delta_x, delta_y))) {
237 if (fabsf(delta_y) >= fabsf(delta_x)) { 266 if (fabsf(delta_y) >= fabsf(delta_x)) {
238 if (fabsf(delta_x) < kRubberbandMinimumRequiredDeltaBeforeStretch) { 267 if (fabsf(delta_x) < kRubberbandMinimumRequiredDeltaBeforeStretch) {
239 overflow_scroll_delta_.set_x(overflow_scroll_delta_.x() + delta_x); 268 overflow_scroll_delta_.set_x(overflow_scroll_delta_.x() + delta_x);
240 delta_x = 0; 269 delta_x = 0;
241 } else 270 } else
242 overflow_scroll_delta_.set_x(overflow_scroll_delta_.x() + delta_x); 271 overflow_scroll_delta_.set_x(overflow_scroll_delta_.x() + delta_x);
243 } 272 }
244 should_stretch = true; 273 should_stretch = true;
245 } 274 }
246 } 275 }
247 } 276 }
248 277
249 if (delta_x != 0 || delta_y != 0) { 278 if (delta_x != 0 || delta_y != 0) {
250 has_scrolled_ = true; 279 has_scrolled_ = true;
251 if (!(should_stretch || is_vertically_stretched || 280 if (!(should_stretch || is_vertically_stretched ||
252 is_horizontally_stretched)) { 281 is_horizontally_stretched)) {
253 if (delta_y != 0) { 282 if (delta_y != 0) {
254 delta_y *= ScrollWheelMultiplier(); 283 delta_y *= ScrollWheelMultiplier();
255 client_->ImmediateScrollBy(gfx::Vector2dF(0, delta_y)); 284 helper_->ImmediateScrollBy(gfx::Vector2dF(0, delta_y));
256 } 285 }
257 if (delta_x != 0) { 286 if (delta_x != 0) {
258 delta_x *= ScrollWheelMultiplier(); 287 delta_x *= ScrollWheelMultiplier();
259 client_->ImmediateScrollBy(gfx::Vector2dF(delta_x, 0)); 288 helper_->ImmediateScrollBy(gfx::Vector2dF(delta_x, 0));
260 } 289 }
261 } else { 290 } else {
262 if (!client_->AllowsHorizontalStretching()) { 291 if (!helper_->AllowsHorizontalStretching()) {
263 delta_x = 0; 292 delta_x = 0;
264 event_coalesced_delta_x = 0; 293 event_coalesced_delta_x = 0;
265 } else if ((delta_x != 0) && !is_horizontally_stretched && 294 } else if ((delta_x != 0) && !is_horizontally_stretched &&
266 !client_->PinnedInDirection(gfx::Vector2dF(delta_x, 0))) { 295 !helper_->PinnedInDirection(gfx::Vector2dF(delta_x, 0))) {
267 delta_x *= ScrollWheelMultiplier(); 296 delta_x *= ScrollWheelMultiplier();
268 297
269 client_->ImmediateScrollByWithoutContentEdgeConstraints( 298 helper_->ImmediateScrollByWithoutContentEdgeConstraints(
270 gfx::Vector2dF(delta_x, 0)); 299 gfx::Vector2dF(delta_x, 0));
271 delta_x = 0; 300 delta_x = 0;
272 } 301 }
273 302
274 if (!client_->AllowsVerticalStretching()) { 303 if (!helper_->AllowsVerticalStretching()) {
275 delta_y = 0; 304 delta_y = 0;
276 event_coalesced_delta_y = 0; 305 event_coalesced_delta_y = 0;
277 } else if ((delta_y != 0) && !is_vertically_stretched && 306 } else if ((delta_y != 0) && !is_vertically_stretched &&
278 !client_->PinnedInDirection(gfx::Vector2dF(0, delta_y))) { 307 !helper_->PinnedInDirection(gfx::Vector2dF(0, delta_y))) {
279 delta_y *= ScrollWheelMultiplier(); 308 delta_y *= ScrollWheelMultiplier();
280 309
281 client_->ImmediateScrollByWithoutContentEdgeConstraints( 310 helper_->ImmediateScrollByWithoutContentEdgeConstraints(
282 gfx::Vector2dF(0, delta_y)); 311 gfx::Vector2dF(0, delta_y));
283 delta_y = 0; 312 delta_y = 0;
284 } 313 }
285 314
286 gfx::Vector2dF stretch_amount = client_->StretchAmount(); 315 gfx::Vector2dF stretch_amount = helper_->StretchAmount();
287 316
288 if (momentum_scroll_in_progress_) { 317 if (momentum_scroll_in_progress_) {
289 if ((client_->PinnedInDirection(gfx::Vector2dF( 318 if ((helper_->PinnedInDirection(gfx::Vector2dF(
290 event_coalesced_delta_x, event_coalesced_delta_y)) || 319 event_coalesced_delta_x, event_coalesced_delta_y)) ||
291 (fabsf(event_coalesced_delta_x) + fabsf(event_coalesced_delta_y) <= 320 (fabsf(event_coalesced_delta_x) + fabsf(event_coalesced_delta_y) <=
292 0)) && 321 0)) &&
293 last_momentum_scroll_timestamp_) { 322 last_momentum_scroll_timestamp_) {
294 ignore_momentum_scrolls_ = true; 323 ignore_momentum_scrolls_ = true;
295 momentum_scroll_in_progress_ = false; 324 momentum_scroll_in_progress_ = false;
296 SnapRubberband(); 325 SnapRubberband();
297 } 326 }
298 } 327 }
299 328
300 stretch_scroll_force_.set_x(stretch_scroll_force_.x() + delta_x); 329 stretch_scroll_force_.set_x(stretch_scroll_force_.x() + delta_x);
301 stretch_scroll_force_.set_y(stretch_scroll_force_.y() + delta_y); 330 stretch_scroll_force_.set_y(stretch_scroll_force_.y() + delta_y);
302 331
303 gfx::Vector2dF damped_delta( 332 gfx::Vector2dF damped_delta(
304 ceilf(ElasticDeltaForReboundDelta(stretch_scroll_force_.x())), 333 ceilf(ElasticDeltaForReboundDelta(stretch_scroll_force_.x())),
305 ceilf(ElasticDeltaForReboundDelta(stretch_scroll_force_.y()))); 334 ceilf(ElasticDeltaForReboundDelta(stretch_scroll_force_.y())));
306 335
307 client_->ImmediateScrollByWithoutContentEdgeConstraints(damped_delta - 336 helper_->ImmediateScrollByWithoutContentEdgeConstraints(damped_delta -
308 stretch_amount); 337 stretch_amount);
309 } 338 }
310 } 339 }
311 340
312 if (momentum_scroll_in_progress_ && 341 if (momentum_scroll_in_progress_ &&
313 momentum_phase == blink::WebMouseWheelEvent::PhaseEnded) { 342 momentum_phase == blink::WebMouseWheelEvent::PhaseEnded) {
314 momentum_scroll_in_progress_ = false; 343 momentum_scroll_in_progress_ = false;
315 ignore_momentum_scrolls_ = false; 344 ignore_momentum_scrolls_ = false;
316 last_momentum_scroll_timestamp_ = 0; 345 last_momentum_scroll_timestamp_ = 0;
317 } 346 }
(...skipping 10 matching lines...) Expand all
328 float RoundToDevicePixelTowardZero(float num) { 357 float RoundToDevicePixelTowardZero(float num) {
329 float rounded_num = roundf(num); 358 float rounded_num = roundf(num);
330 if (fabs(num - rounded_num) < 0.125) 359 if (fabs(num - rounded_num) < 0.125)
331 num = rounded_num; 360 num = rounded_num;
332 361
333 return RoundTowardZero(num); 362 return RoundTowardZero(num);
334 } 363 }
335 364
336 } // namespace 365 } // namespace
337 366
338 void ScrollElasticityController::SnapRubberbandTimerFired() { 367 void InputScrollElasticityController::SnapRubberbandTimerFired() {
339 if (!momentum_scroll_in_progress_ || ignore_momentum_scrolls_) { 368 if (!momentum_scroll_in_progress_ || ignore_momentum_scrolls_) {
340 float time_delta = (base::Time::Now() - start_time_).InSecondsF(); 369 float time_delta = (base::Time::Now() - start_time_).InSecondsF();
341 370
342 if (start_stretch_ == gfx::Vector2dF()) { 371 if (start_stretch_ == gfx::Vector2dF()) {
343 start_stretch_ = client_->StretchAmount(); 372 start_stretch_ = helper_->StretchAmount();
344 if (start_stretch_ == gfx::Vector2dF()) { 373 if (start_stretch_ == gfx::Vector2dF()) {
345 StopSnapRubberbandTimer(); 374 StopSnapRubberbandTimer();
346 375
347 stretch_scroll_force_ = gfx::Vector2dF(); 376 stretch_scroll_force_ = gfx::Vector2dF();
348 start_time_ = base::Time(); 377 start_time_ = base::Time();
349 orig_origin_ = gfx::Vector2dF(); 378 orig_origin_ = gfx::Vector2dF();
350 orig_velocity_ = gfx::Vector2dF(); 379 orig_velocity_ = gfx::Vector2dF();
351 return; 380 return;
352 } 381 }
353 382
354 orig_origin_ = client_->AbsoluteScrollPosition() - start_stretch_; 383 orig_origin_ = helper_->AbsoluteScrollPosition() - start_stretch_;
355 orig_velocity_ = momentum_velocity_; 384 orig_velocity_ = momentum_velocity_;
356 385
357 // Just like normal scrolling, prefer vertical rubberbanding 386 // Just like normal scrolling, prefer vertical rubberbanding
358 if (fabsf(orig_velocity_.y()) >= fabsf(orig_velocity_.x())) 387 if (fabsf(orig_velocity_.y()) >= fabsf(orig_velocity_.x()))
359 orig_velocity_.set_x(0); 388 orig_velocity_.set_x(0);
360 389
361 // Don't rubber-band horizontally if it's not possible to scroll 390 // Don't rubber-band horizontally if it's not possible to scroll
362 // horizontally 391 // horizontally
363 if (!client_->CanScrollHorizontally()) 392 if (!helper_->CanScrollHorizontally())
364 orig_velocity_.set_x(0); 393 orig_velocity_.set_x(0);
365 394
366 // Don't rubber-band vertically if it's not possible to scroll 395 // Don't rubber-band vertically if it's not possible to scroll
367 // vertically 396 // vertically
368 if (!client_->CanScrollVertically()) 397 if (!helper_->CanScrollVertically())
369 orig_velocity_.set_y(0); 398 orig_velocity_.set_y(0);
370 } 399 }
371 400
372 gfx::Vector2dF delta( 401 gfx::Vector2dF delta(
373 RoundToDevicePixelTowardZero(ElasticDeltaForTimeDelta( 402 RoundToDevicePixelTowardZero(ElasticDeltaForTimeDelta(
374 start_stretch_.x(), -orig_velocity_.x(), time_delta)), 403 start_stretch_.x(), -orig_velocity_.x(), time_delta)),
375 RoundToDevicePixelTowardZero(ElasticDeltaForTimeDelta( 404 RoundToDevicePixelTowardZero(ElasticDeltaForTimeDelta(
376 start_stretch_.y(), -orig_velocity_.y(), time_delta))); 405 start_stretch_.y(), -orig_velocity_.y(), time_delta)));
377 406
378 if (fabs(delta.x()) >= 1 || fabs(delta.y()) >= 1) { 407 if (fabs(delta.x()) >= 1 || fabs(delta.y()) >= 1) {
379 client_->ImmediateScrollByWithoutContentEdgeConstraints( 408 helper_->ImmediateScrollByWithoutContentEdgeConstraints(
380 gfx::Vector2dF(delta.x(), delta.y()) - client_->StretchAmount()); 409 gfx::Vector2dF(delta.x(), delta.y()) - helper_->StretchAmount());
381 410
382 gfx::Vector2dF new_stretch = client_->StretchAmount(); 411 gfx::Vector2dF new_stretch = helper_->StretchAmount();
383 412
384 stretch_scroll_force_.set_x(ReboundDeltaForElasticDelta(new_stretch.x())); 413 stretch_scroll_force_.set_x(ReboundDeltaForElasticDelta(new_stretch.x()));
385 stretch_scroll_force_.set_y(ReboundDeltaForElasticDelta(new_stretch.y())); 414 stretch_scroll_force_.set_y(ReboundDeltaForElasticDelta(new_stretch.y()));
386 } else { 415 } else {
387 client_->AdjustScrollPositionToBoundsIfNecessary(); 416 helper_->AdjustScrollPositionToBoundsIfNecessary();
388 417
389 StopSnapRubberbandTimer(); 418 StopSnapRubberbandTimer();
390 stretch_scroll_force_ = gfx::Vector2dF(); 419 stretch_scroll_force_ = gfx::Vector2dF();
391 start_time_ = base::Time(); 420 start_time_ = base::Time();
392 start_stretch_ = gfx::Vector2dF(); 421 start_stretch_ = gfx::Vector2dF();
393 orig_origin_ = gfx::Vector2dF(); 422 orig_origin_ = gfx::Vector2dF();
394 orig_velocity_ = gfx::Vector2dF(); 423 orig_velocity_ = gfx::Vector2dF();
395 } 424 }
396 } else { 425 } else {
397 start_time_ = base::Time::Now(); 426 start_time_ = base::Time::Now();
398 start_stretch_ = gfx::Vector2dF(); 427 start_stretch_ = gfx::Vector2dF();
399 } 428 }
429
430 helper_->SnapRubberbandTimerFired();
400 } 431 }
401 432
402 bool ScrollElasticityController::IsRubberbandInProgress() const { 433 bool InputScrollElasticityController::IsRubberbandInProgress() const {
403 if (!in_scroll_gesture_ && !momentum_scroll_in_progress_ && 434 if (!in_scroll_gesture_ && !momentum_scroll_in_progress_ &&
404 !snap_rubberband_timer_is_active_) 435 !snap_rubberband_timer_is_active_)
405 return false; 436 return false;
406 437
407 return !client_->StretchAmount().IsZero(); 438 return !helper_->StretchAmount().IsZero();
408 } 439 }
409 440
410 void ScrollElasticityController::StopSnapRubberbandTimer() { 441 void InputScrollElasticityController::StopSnapRubberbandTimer() {
411 client_->StopSnapRubberbandTimer(); 442 helper_->StopSnapRubberbandTimer();
412 snap_rubberband_timer_is_active_ = false; 443 snap_rubberband_timer_is_active_ = false;
413 } 444 }
414 445
415 void ScrollElasticityController::SnapRubberband() { 446 void InputScrollElasticityController::SnapRubberband() {
416 double time_delta = SystemUptime() - last_momentum_scroll_timestamp_; 447 double time_delta = SystemUptime() - last_momentum_scroll_timestamp_;
417 if (last_momentum_scroll_timestamp_ && 448 if (last_momentum_scroll_timestamp_ &&
418 time_delta >= kScrollVelocityZeroingTimeout) 449 time_delta >= kScrollVelocityZeroingTimeout)
419 momentum_velocity_ = gfx::Vector2dF(); 450 momentum_velocity_ = gfx::Vector2dF();
420 451
421 in_scroll_gesture_ = false; 452 in_scroll_gesture_ = false;
422 453
423 if (snap_rubberband_timer_is_active_) 454 if (snap_rubberband_timer_is_active_)
424 return; 455 return;
425 456
426 start_stretch_ = gfx::Vector2dF(); 457 start_stretch_ = gfx::Vector2dF();
427 orig_origin_ = gfx::Vector2dF(); 458 orig_origin_ = gfx::Vector2dF();
428 orig_velocity_ = gfx::Vector2dF(); 459 orig_velocity_ = gfx::Vector2dF();
429 460
430 // If there's no momentum scroll or stretch amount, no need to start the 461 // If there's no momentum scroll or stretch amount, no need to start the
431 // timer. 462 // timer.
432 if (!momentum_scroll_in_progress_ && 463 if (!momentum_scroll_in_progress_ &&
433 client_->StretchAmount() == gfx::Vector2dF()) { 464 helper_->StretchAmount() == gfx::Vector2dF()) {
434 start_time_ = base::Time(); 465 start_time_ = base::Time();
435 stretch_scroll_force_ = gfx::Vector2dF(); 466 stretch_scroll_force_ = gfx::Vector2dF();
436 return; 467 return;
437 } 468 }
438 469
439 start_time_ = base::Time::Now(); 470 start_time_ = base::Time::Now();
440 client_->StartSnapRubberbandTimer(); 471 helper_->StartSnapRubberbandTimer();
441 snap_rubberband_timer_is_active_ = true; 472 snap_rubberband_timer_is_active_ = true;
442 } 473 }
443 474
444 bool ScrollElasticityController::ShouldHandleEvent( 475 bool InputScrollElasticityController::ShouldHandleEvent(
445 const blink::WebMouseWheelEvent& wheel_event) { 476 const blink::WebMouseWheelEvent& wheel_event) {
446 // Once any scrolling has happened, all future events should be handled. 477 // Once any scrolling has happened, all future events should be handled.
447 if (has_scrolled_) 478 if (has_scrolled_)
448 return true; 479 return true;
449 480
450 // The event can't cause scrolling to start if its delta is 0. 481 // The event can't cause scrolling to start if its delta is 0.
451 if (wheel_event.deltaX == 0 && wheel_event.deltaY == 0) 482 if (wheel_event.deltaX == 0 && wheel_event.deltaY == 0)
452 return false; 483 return false;
453 484
454 // If the client isn't pinned, then the event is guaranteed to cause 485 // If the helper isn't pinned, then the event is guaranteed to cause
455 // scrolling. 486 // scrolling.
456 if (!client_->PinnedInDirection(gfx::Vector2dF(-wheel_event.deltaX, 0))) 487 if (!helper_->PinnedInDirection(gfx::Vector2dF(-wheel_event.deltaX, 0)))
457 return true; 488 return true;
458 489
459 // If the event is pinned, then the client can't scroll, but it might rubber 490 // If the event is pinned, then the helper can't scroll, but it might rubber
460 // band. 491 // band.
461 // Check if the event allows rubber banding. 492 // Check if the event allows rubber banding.
462 if (wheel_event.deltaY == 0) { 493 if (wheel_event.deltaY == 0) {
463 if (wheel_event.deltaX > 0 && !wheel_event.canRubberbandLeft) 494 if (wheel_event.deltaX > 0 && !wheel_event.canRubberbandLeft)
464 return false; 495 return false;
465 if (wheel_event.deltaX < 0 && !wheel_event.canRubberbandRight) 496 if (wheel_event.deltaX < 0 && !wheel_event.canRubberbandRight)
466 return false; 497 return false;
467 } 498 }
468 499
469 // The event is going to either cause scrolling or rubber banding. 500 // The event is going to either cause scrolling or rubber banding.
470 return true; 501 return true;
471 } 502 }
472 503
473 } // namespace content 504 } // namespace content
OLDNEW
« no previous file with comments | « content/renderer/input/input_scroll_elasticity_controller.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698