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

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

Issue 136173004: Early terminate flings when scrolling impossible (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Rebase Created 6 years, 8 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 2013 The Chromium Authors. All rights reserved. 1 // Copyright 2013 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_handler_proxy.h" 5 #include "content/renderer/input/input_handler_proxy.h"
6 6
7 #include "base/auto_reset.h"
7 #include "base/debug/trace_event.h" 8 #include "base/debug/trace_event.h"
8 #include "base/logging.h" 9 #include "base/logging.h"
9 #include "base/metrics/histogram.h" 10 #include "base/metrics/histogram.h"
11 #include "content/common/input/did_overscroll_params.h"
10 #include "content/common/input/web_input_event_traits.h" 12 #include "content/common/input/web_input_event_traits.h"
11 #include "content/renderer/input/input_handler_proxy_client.h" 13 #include "content/renderer/input/input_handler_proxy_client.h"
12 #include "third_party/WebKit/public/platform/Platform.h" 14 #include "third_party/WebKit/public/platform/Platform.h"
13 #include "third_party/WebKit/public/web/WebInputEvent.h" 15 #include "third_party/WebKit/public/web/WebInputEvent.h"
14 #include "ui/events/latency_info.h" 16 #include "ui/events/latency_info.h"
15 #include "ui/gfx/frame_time.h" 17 #include "ui/gfx/frame_time.h"
16 #include "ui/gfx/geometry/point_conversions.h" 18 #include "ui/gfx/geometry/point_conversions.h"
17 19
18 using blink::WebFloatPoint; 20 using blink::WebFloatPoint;
19 using blink::WebFloatSize; 21 using blink::WebFloatSize;
(...skipping 348 matching lines...) Expand 10 before | Expand all | Expand 10 after
368 TRACE_EVENT_SCOPE_THREAD); 370 TRACE_EVENT_SCOPE_THREAD);
369 CancelCurrentFling(true); 371 CancelCurrentFling(true);
370 } 372 }
371 } 373 }
372 374
373 void InputHandlerProxy::MainThreadHasStoppedFlinging() { 375 void InputHandlerProxy::MainThreadHasStoppedFlinging() {
374 fling_may_be_active_on_main_thread_ = false; 376 fling_may_be_active_on_main_thread_ = false;
375 client_->DidStopFlinging(); 377 client_->DidStopFlinging();
376 } 378 }
377 379
378 void InputHandlerProxy::DidOverscroll(const cc::DidOverscrollParams& params) { 380 void InputHandlerProxy::DidOverscroll(
381 const gfx::Vector2dF& accumulated_overscroll,
382 const gfx::Vector2dF& latest_overscroll_delta) {
379 DCHECK(client_); 383 DCHECK(client_);
384
385 DidOverscrollParams params;
386 params.accumulated_overscroll = accumulated_overscroll;
387 params.latest_overscroll_delta = latest_overscroll_delta;
388 params.current_fling_velocity = current_fling_velocity_;
389
380 if (fling_curve_) { 390 if (fling_curve_) {
381 static const int kFlingOverscrollThreshold = 1; 391 static const int kFlingOverscrollThreshold = 1;
382 disallow_horizontal_fling_scroll_ |= 392 disallow_horizontal_fling_scroll_ |=
383 std::abs(params.accumulated_overscroll.x()) >= 393 std::abs(params.accumulated_overscroll.x()) >=
384 kFlingOverscrollThreshold; 394 kFlingOverscrollThreshold;
385 disallow_vertical_fling_scroll_ |= 395 disallow_vertical_fling_scroll_ |=
386 std::abs(params.accumulated_overscroll.y()) >= 396 std::abs(params.accumulated_overscroll.y()) >=
387 kFlingOverscrollThreshold; 397 kFlingOverscrollThreshold;
388 } 398 }
389 399
(...skipping 12 matching lines...) Expand all
402 this); 412 this);
403 } 413 }
404 414
405 TRACE_EVENT_INSTANT1("input", 415 TRACE_EVENT_INSTANT1("input",
406 "InputHandlerProxy::CancelCurrentFling", 416 "InputHandlerProxy::CancelCurrentFling",
407 TRACE_EVENT_SCOPE_THREAD, 417 TRACE_EVENT_SCOPE_THREAD,
408 "had_fling_animation", 418 "had_fling_animation",
409 had_fling_animation); 419 had_fling_animation);
410 fling_curve_.reset(); 420 fling_curve_.reset();
411 gesture_scroll_on_impl_thread_ = false; 421 gesture_scroll_on_impl_thread_ = false;
422 current_fling_velocity_ = gfx::Vector2dF();
412 fling_parameters_ = blink::WebActiveWheelFlingParameters(); 423 fling_parameters_ = blink::WebActiveWheelFlingParameters();
413 if (send_fling_stopped_notification && had_fling_animation) 424 if (send_fling_stopped_notification && had_fling_animation)
414 client_->DidStopFlinging(); 425 client_->DidStopFlinging();
415 return had_fling_animation; 426 return had_fling_animation;
416 } 427 }
417 428
418 bool InputHandlerProxy::TouchpadFlingScroll( 429 bool InputHandlerProxy::TouchpadFlingScroll(
419 const WebFloatSize& increment) { 430 const WebFloatSize& increment) {
420 WebMouseWheelEvent synthetic_wheel; 431 WebMouseWheelEvent synthetic_wheel;
421 synthetic_wheel.type = WebInputEvent::MouseWheel; 432 synthetic_wheel.type = WebInputEvent::MouseWheel;
(...skipping 29 matching lines...) Expand all
451 break; 462 break;
452 } 463 }
453 464
454 return false; 465 return false;
455 } 466 }
456 467
457 static gfx::Vector2dF ToClientScrollIncrement(const WebFloatSize& increment) { 468 static gfx::Vector2dF ToClientScrollIncrement(const WebFloatSize& increment) {
458 return gfx::Vector2dF(-increment.width, -increment.height); 469 return gfx::Vector2dF(-increment.width, -increment.height);
459 } 470 }
460 471
461 void InputHandlerProxy::scrollBy(const WebFloatSize& increment) { 472 bool InputHandlerProxy::scrollBy(const WebFloatSize& increment,
473 const WebFloatSize& velocity) {
462 WebFloatSize clipped_increment; 474 WebFloatSize clipped_increment;
463 if (!disallow_horizontal_fling_scroll_) 475 WebFloatSize clipped_velocity;
476 if (!disallow_horizontal_fling_scroll_) {
464 clipped_increment.width = increment.width; 477 clipped_increment.width = increment.width;
465 if (!disallow_vertical_fling_scroll_) 478 clipped_velocity.width = velocity.width;
479 }
480 if (!disallow_vertical_fling_scroll_) {
466 clipped_increment.height = increment.height; 481 clipped_increment.height = increment.height;
482 clipped_velocity.height = velocity.height;
483 }
467 484
485 current_fling_velocity_ = clipped_velocity;
468 if (clipped_increment == WebFloatSize()) 486 if (clipped_increment == WebFloatSize())
469 return; 487 return false;
470 488
471 TRACE_EVENT2("input", 489 TRACE_EVENT2("input",
472 "InputHandlerProxy::scrollBy", 490 "InputHandlerProxy::scrollBy",
473 "x", 491 "x",
474 clipped_increment.width, 492 clipped_increment.width,
475 "y", 493 "y",
476 clipped_increment.height); 494 clipped_increment.height);
477 495
478 bool did_scroll = false; 496 bool did_scroll = false;
479 497
480 switch (fling_parameters_.sourceDevice) { 498 switch (fling_parameters_.sourceDevice) {
481 case WebGestureEvent::Touchpad: 499 case WebGestureEvent::Touchpad:
482 did_scroll = TouchpadFlingScroll(clipped_increment); 500 did_scroll = TouchpadFlingScroll(clipped_increment);
483 break; 501 break;
484 case WebGestureEvent::Touchscreen: 502 case WebGestureEvent::Touchscreen:
485 clipped_increment = ToClientScrollIncrement(clipped_increment); 503 clipped_increment = ToClientScrollIncrement(clipped_increment);
504 clipped_velocity = ToClientScrollIncrement(clipped_velocity);
486 did_scroll = input_handler_->ScrollBy(fling_parameters_.point, 505 did_scroll = input_handler_->ScrollBy(fling_parameters_.point,
487 clipped_increment); 506 clipped_increment);
488 break; 507 break;
489 } 508 }
490 509
491 if (did_scroll) { 510 if (did_scroll) {
492 fling_parameters_.cumulativeScroll.width += clipped_increment.width; 511 fling_parameters_.cumulativeScroll.width += clipped_increment.width;
493 fling_parameters_.cumulativeScroll.height += clipped_increment.height; 512 fling_parameters_.cumulativeScroll.height += clipped_increment.height;
494 } 513 }
495 }
496 514
497 void InputHandlerProxy::notifyCurrentFlingVelocity( 515 return did_scroll;
498 const WebFloatSize& velocity) {
499 TRACE_EVENT2("input",
500 "InputHandlerProxy::notifyCurrentFlingVelocity",
501 "vx",
502 velocity.width,
503 "vy",
504 velocity.height);
505 input_handler_->NotifyCurrentFlingVelocity(ToClientScrollIncrement(velocity));
506 } 516 }
507 517
508 } // namespace content 518 } // namespace content
OLDNEW
« no previous file with comments | « content/renderer/input/input_handler_proxy.h ('k') | content/renderer/input/input_handler_proxy_client.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698