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

Side by Side Diff: content/browser/renderer_host/overscroll_controller.cc

Issue 478023002: OverscrollController consumes scroll updates only during gesture-nav. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Add TODO to clean up browsertest. Created 6 years, 4 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 | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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/renderer_host/overscroll_controller.h" 5 #include "content/browser/renderer_host/overscroll_controller.h"
6 6
7 #include "base/command_line.h" 7 #include "base/command_line.h"
8 #include "base/logging.h" 8 #include "base/logging.h"
9 #include "content/browser/renderer_host/overscroll_controller_delegate.h" 9 #include "content/browser/renderer_host/overscroll_controller_delegate.h"
10 #include "content/public/browser/overscroll_configuration.h" 10 #include "content/public/browser/overscroll_configuration.h"
(...skipping 194 matching lines...) Expand 10 before | Expand all | Expand 10 after
205 205
206 bool OverscrollController::ProcessEventForOverscroll( 206 bool OverscrollController::ProcessEventForOverscroll(
207 const blink::WebInputEvent& event) { 207 const blink::WebInputEvent& event) {
208 bool event_processed = false; 208 bool event_processed = false;
209 switch (event.type) { 209 switch (event.type) {
210 case blink::WebInputEvent::MouseWheel: { 210 case blink::WebInputEvent::MouseWheel: {
211 const blink::WebMouseWheelEvent& wheel = 211 const blink::WebMouseWheelEvent& wheel =
212 static_cast<const blink::WebMouseWheelEvent&>(event); 212 static_cast<const blink::WebMouseWheelEvent&>(event);
213 if (!wheel.hasPreciseScrollingDeltas) 213 if (!wheel.hasPreciseScrollingDeltas)
214 break; 214 break;
215 215 event_processed =
216 ProcessOverscroll(wheel.deltaX * wheel.accelerationRatioX, 216 ProcessOverscroll(wheel.deltaX * wheel.accelerationRatioX,
217 wheel.deltaY * wheel.accelerationRatioY, 217 wheel.deltaY * wheel.accelerationRatioY,
218 wheel.type); 218 wheel.type);
219 event_processed = true;
220 break; 219 break;
221 } 220 }
222 case blink::WebInputEvent::GestureScrollUpdate: { 221 case blink::WebInputEvent::GestureScrollUpdate: {
223 const blink::WebGestureEvent& gesture = 222 const blink::WebGestureEvent& gesture =
224 static_cast<const blink::WebGestureEvent&>(event); 223 static_cast<const blink::WebGestureEvent&>(event);
225 ProcessOverscroll(gesture.data.scrollUpdate.deltaX, 224 event_processed = ProcessOverscroll(gesture.data.scrollUpdate.deltaX,
226 gesture.data.scrollUpdate.deltaY, 225 gesture.data.scrollUpdate.deltaY,
227 gesture.type); 226 gesture.type);
228 event_processed = true;
229 break; 227 break;
230 } 228 }
231 case blink::WebInputEvent::GestureFlingStart: { 229 case blink::WebInputEvent::GestureFlingStart: {
232 const float kFlingVelocityThreshold = 1100.f; 230 const float kFlingVelocityThreshold = 1100.f;
233 const blink::WebGestureEvent& gesture = 231 const blink::WebGestureEvent& gesture =
234 static_cast<const blink::WebGestureEvent&>(event); 232 static_cast<const blink::WebGestureEvent&>(event);
235 float velocity_x = gesture.data.flingStart.velocityX; 233 float velocity_x = gesture.data.flingStart.velocityX;
236 float velocity_y = gesture.data.flingStart.velocityY; 234 float velocity_y = gesture.data.flingStart.velocityY;
237 if (fabs(velocity_x) > kFlingVelocityThreshold) { 235 if (fabs(velocity_x) > kFlingVelocityThreshold) {
238 if ((overscroll_mode_ == OVERSCROLL_WEST && velocity_x < 0) || 236 if ((overscroll_mode_ == OVERSCROLL_WEST && velocity_x < 0) ||
(...skipping 17 matching lines...) Expand all
256 } 254 }
257 255
258 default: 256 default:
259 DCHECK(blink::WebInputEvent::isGestureEventType(event.type) || 257 DCHECK(blink::WebInputEvent::isGestureEventType(event.type) ||
260 blink::WebInputEvent::isTouchEventType(event.type)) 258 blink::WebInputEvent::isTouchEventType(event.type))
261 << "Received unexpected event: " << event.type; 259 << "Received unexpected event: " << event.type;
262 } 260 }
263 return event_processed; 261 return event_processed;
264 } 262 }
265 263
266 void OverscrollController::ProcessOverscroll(float delta_x, 264 bool OverscrollController::ProcessOverscroll(float delta_x,
267 float delta_y, 265 float delta_y,
268 blink::WebInputEvent::Type type) { 266 blink::WebInputEvent::Type type) {
269 if (scroll_state_ != STATE_CONTENT_SCROLLING) 267 if (scroll_state_ != STATE_CONTENT_SCROLLING)
270 overscroll_delta_x_ += delta_x; 268 overscroll_delta_x_ += delta_x;
271 overscroll_delta_y_ += delta_y; 269 overscroll_delta_y_ += delta_y;
272 270
273 float horiz_threshold = GetOverscrollConfig( 271 float horiz_threshold = GetOverscrollConfig(
274 WebInputEvent::isGestureEventType(type) ? 272 WebInputEvent::isGestureEventType(type) ?
275 OVERSCROLL_CONFIG_HORIZ_THRESHOLD_START_TOUCHSCREEN : 273 OVERSCROLL_CONFIG_HORIZ_THRESHOLD_START_TOUCHSCREEN :
276 OVERSCROLL_CONFIG_HORIZ_THRESHOLD_START_TOUCHPAD); 274 OVERSCROLL_CONFIG_HORIZ_THRESHOLD_START_TOUCHPAD);
277 float vert_threshold = GetOverscrollConfig( 275 float vert_threshold = GetOverscrollConfig(
278 OVERSCROLL_CONFIG_VERT_THRESHOLD_START); 276 OVERSCROLL_CONFIG_VERT_THRESHOLD_START);
279 if (fabs(overscroll_delta_x_) <= horiz_threshold && 277 if (fabs(overscroll_delta_x_) <= horiz_threshold &&
280 fabs(overscroll_delta_y_) <= vert_threshold) { 278 fabs(overscroll_delta_y_) <= vert_threshold) {
281 SetOverscrollMode(OVERSCROLL_NONE); 279 SetOverscrollMode(OVERSCROLL_NONE);
282 return; 280 return true;
283 } 281 }
284 282
285 // Compute the current overscroll direction. If the direction is different 283 // Compute the current overscroll direction. If the direction is different
286 // from the current direction, then always switch to no-overscroll mode first 284 // from the current direction, then always switch to no-overscroll mode first
287 // to make sure that subsequent scroll events go through to the page first. 285 // to make sure that subsequent scroll events go through to the page first.
288 OverscrollMode new_mode = OVERSCROLL_NONE; 286 OverscrollMode new_mode = OVERSCROLL_NONE;
289 const float kMinRatio = 2.5; 287 const float kMinRatio = 2.5;
290 if (fabs(overscroll_delta_x_) > horiz_threshold && 288 if (fabs(overscroll_delta_x_) > horiz_threshold &&
291 fabs(overscroll_delta_x_) > fabs(overscroll_delta_y_) * kMinRatio) 289 fabs(overscroll_delta_x_) > fabs(overscroll_delta_y_) * kMinRatio)
292 new_mode = overscroll_delta_x_ > 0.f ? OVERSCROLL_EAST : OVERSCROLL_WEST; 290 new_mode = overscroll_delta_x_ > 0.f ? OVERSCROLL_EAST : OVERSCROLL_WEST;
293 else if (fabs(overscroll_delta_y_) > vert_threshold && 291 else if (fabs(overscroll_delta_y_) > vert_threshold &&
294 fabs(overscroll_delta_y_) > fabs(overscroll_delta_x_) * kMinRatio) 292 fabs(overscroll_delta_y_) > fabs(overscroll_delta_x_) * kMinRatio)
295 new_mode = overscroll_delta_y_ > 0.f ? OVERSCROLL_SOUTH : OVERSCROLL_NORTH; 293 new_mode = overscroll_delta_y_ > 0.f ? OVERSCROLL_SOUTH : OVERSCROLL_NORTH;
296 294
297 // The vertical oversrcoll currently does not have any UX effects other then 295 // The vertical oversrcoll currently does not have any UX effects other then
298 // for the scroll end effect, so testing if it is enabled. 296 // for the scroll end effect, so testing if it is enabled.
299 if ((new_mode == OVERSCROLL_SOUTH || new_mode == OVERSCROLL_NORTH) && 297 if ((new_mode == OVERSCROLL_SOUTH || new_mode == OVERSCROLL_NORTH) &&
300 !IsScrollEndEffectEnabled()) 298 !IsScrollEndEffectEnabled())
301 new_mode = OVERSCROLL_NONE; 299 new_mode = OVERSCROLL_NONE;
302 300
303 if (overscroll_mode_ == OVERSCROLL_NONE) 301 if (overscroll_mode_ == OVERSCROLL_NONE)
304 SetOverscrollMode(new_mode); 302 SetOverscrollMode(new_mode);
305 else if (new_mode != overscroll_mode_) 303 else if (new_mode != overscroll_mode_)
306 SetOverscrollMode(OVERSCROLL_NONE); 304 SetOverscrollMode(OVERSCROLL_NONE);
307 305
308 if (overscroll_mode_ == OVERSCROLL_NONE) 306 if (overscroll_mode_ == OVERSCROLL_NONE)
309 return; 307 return false;
310 308
311 // Tell the delegate about the overscroll update so that it can update 309 // Tell the delegate about the overscroll update so that it can update
312 // the display accordingly (e.g. show history preview etc.). 310 // the display accordingly (e.g. show history preview etc.).
313 if (delegate_) { 311 if (delegate_) {
314 // Do not include the threshold amount when sending the deltas to the 312 // Do not include the threshold amount when sending the deltas to the
315 // delegate. 313 // delegate.
316 float delegate_delta_x = overscroll_delta_x_; 314 float delegate_delta_x = overscroll_delta_x_;
317 if (fabs(delegate_delta_x) > horiz_threshold) { 315 if (fabs(delegate_delta_x) > horiz_threshold) {
318 if (delegate_delta_x < 0) 316 if (delegate_delta_x < 0)
319 delegate_delta_x += horiz_threshold; 317 delegate_delta_x += horiz_threshold;
320 else 318 else
321 delegate_delta_x -= horiz_threshold; 319 delegate_delta_x -= horiz_threshold;
322 } else { 320 } else {
323 delegate_delta_x = 0.f; 321 delegate_delta_x = 0.f;
324 } 322 }
325 323
326 float delegate_delta_y = overscroll_delta_y_; 324 float delegate_delta_y = overscroll_delta_y_;
327 if (fabs(delegate_delta_y) > vert_threshold) { 325 if (fabs(delegate_delta_y) > vert_threshold) {
328 if (delegate_delta_y < 0) 326 if (delegate_delta_y < 0)
329 delegate_delta_y += vert_threshold; 327 delegate_delta_y += vert_threshold;
330 else 328 else
331 delegate_delta_y -= vert_threshold; 329 delegate_delta_y -= vert_threshold;
332 } else { 330 } else {
333 delegate_delta_y = 0.f; 331 delegate_delta_y = 0.f;
334 } 332 }
335 delegate_->OnOverscrollUpdate(delegate_delta_x, delegate_delta_y); 333 return delegate_->OnOverscrollUpdate(delegate_delta_x, delegate_delta_y);
336 } 334 }
335 return false;
337 } 336 }
338 337
339 void OverscrollController::CompleteAction() { 338 void OverscrollController::CompleteAction() {
340 if (delegate_) 339 if (delegate_)
341 delegate_->OnOverscrollComplete(overscroll_mode_); 340 delegate_->OnOverscrollComplete(overscroll_mode_);
342 overscroll_mode_ = OVERSCROLL_NONE; 341 overscroll_mode_ = OVERSCROLL_NONE;
343 overscroll_delta_x_ = overscroll_delta_y_ = 0.f; 342 overscroll_delta_x_ = overscroll_delta_y_ = 0.f;
344 } 343 }
345 344
346 void OverscrollController::SetOverscrollMode(OverscrollMode mode) { 345 void OverscrollController::SetOverscrollMode(OverscrollMode mode) {
347 if (overscroll_mode_ == mode) 346 if (overscroll_mode_ == mode)
348 return; 347 return;
349 OverscrollMode old_mode = overscroll_mode_; 348 OverscrollMode old_mode = overscroll_mode_;
350 overscroll_mode_ = mode; 349 overscroll_mode_ = mode;
351 if (overscroll_mode_ == OVERSCROLL_NONE) 350 if (overscroll_mode_ == OVERSCROLL_NONE)
352 overscroll_delta_x_ = overscroll_delta_y_ = 0.f; 351 overscroll_delta_x_ = overscroll_delta_y_ = 0.f;
353 else 352 else
354 scroll_state_ = STATE_OVERSCROLLING; 353 scroll_state_ = STATE_OVERSCROLLING;
355 if (delegate_) 354 if (delegate_)
356 delegate_->OnOverscrollModeChange(old_mode, overscroll_mode_); 355 delegate_->OnOverscrollModeChange(old_mode, overscroll_mode_);
357 } 356 }
358 357
359 } // namespace content 358 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698