| OLD | NEW |
| 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/auto_reset.h" |
| 8 #include "base/debug/trace_event.h" | 8 #include "base/debug/trace_event.h" |
| 9 #include "base/logging.h" | 9 #include "base/logging.h" |
| 10 #include "base/metrics/histogram.h" | 10 #include "base/metrics/histogram.h" |
| (...skipping 341 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 352 } | 352 } |
| 353 | 353 |
| 354 return DID_NOT_HANDLE; | 354 return DID_NOT_HANDLE; |
| 355 } | 355 } |
| 356 | 356 |
| 357 InputHandlerProxy::EventDisposition | 357 InputHandlerProxy::EventDisposition |
| 358 InputHandlerProxy::HandleGestureFling( | 358 InputHandlerProxy::HandleGestureFling( |
| 359 const WebGestureEvent& gesture_event) { | 359 const WebGestureEvent& gesture_event) { |
| 360 cc::InputHandler::ScrollStatus scroll_status; | 360 cc::InputHandler::ScrollStatus scroll_status; |
| 361 | 361 |
| 362 if (gesture_event.sourceDevice == WebGestureEvent::Touchpad) { | 362 if (gesture_event.sourceDevice == blink::WebGestureDeviceTouchpad) { |
| 363 scroll_status = input_handler_->ScrollBegin( | 363 scroll_status = input_handler_->ScrollBegin( |
| 364 gfx::Point(gesture_event.x, gesture_event.y), | 364 gfx::Point(gesture_event.x, gesture_event.y), |
| 365 cc::InputHandler::NonBubblingGesture); | 365 cc::InputHandler::NonBubblingGesture); |
| 366 } else { | 366 } else { |
| 367 if (!gesture_scroll_on_impl_thread_) | 367 if (!gesture_scroll_on_impl_thread_) |
| 368 scroll_status = cc::InputHandler::ScrollOnMainThread; | 368 scroll_status = cc::InputHandler::ScrollOnMainThread; |
| 369 else | 369 else |
| 370 scroll_status = input_handler_->FlingScrollBegin(); | 370 scroll_status = input_handler_->FlingScrollBegin(); |
| 371 } | 371 } |
| 372 | 372 |
| 373 #ifndef NDEBUG | 373 #ifndef NDEBUG |
| 374 expect_scroll_update_end_ = false; | 374 expect_scroll_update_end_ = false; |
| 375 #endif | 375 #endif |
| 376 | 376 |
| 377 switch (scroll_status) { | 377 switch (scroll_status) { |
| 378 case cc::InputHandler::ScrollStarted: { | 378 case cc::InputHandler::ScrollStarted: { |
| 379 if (gesture_event.sourceDevice == WebGestureEvent::Touchpad) | 379 if (gesture_event.sourceDevice == blink::WebGestureDeviceTouchpad) |
| 380 input_handler_->ScrollEnd(); | 380 input_handler_->ScrollEnd(); |
| 381 | 381 |
| 382 const float vx = gesture_event.data.flingStart.velocityX; | 382 const float vx = gesture_event.data.flingStart.velocityX; |
| 383 const float vy = gesture_event.data.flingStart.velocityY; | 383 const float vy = gesture_event.data.flingStart.velocityY; |
| 384 current_fling_velocity_ = gfx::Vector2dF(vx, vy); | 384 current_fling_velocity_ = gfx::Vector2dF(vx, vy); |
| 385 // TODO(rjkroege): Remove cast after landing 3rd patch for |
| 386 // http://crbug.com/343327 |
| 385 fling_curve_.reset(client_->CreateFlingAnimationCurve( | 387 fling_curve_.reset(client_->CreateFlingAnimationCurve( |
| 386 gesture_event.sourceDevice, WebFloatPoint(vx, vy), blink::WebSize())); | 388 (blink::WebGestureDevice)gesture_event.sourceDevice, |
| 389 WebFloatPoint(vx, vy), |
| 390 blink::WebSize())); |
| 387 disallow_horizontal_fling_scroll_ = !vx; | 391 disallow_horizontal_fling_scroll_ = !vx; |
| 388 disallow_vertical_fling_scroll_ = !vy; | 392 disallow_vertical_fling_scroll_ = !vy; |
| 389 TRACE_EVENT_ASYNC_BEGIN2("input", | 393 TRACE_EVENT_ASYNC_BEGIN2("input", |
| 390 "InputHandlerProxy::HandleGestureFling::started", | 394 "InputHandlerProxy::HandleGestureFling::started", |
| 391 this, | 395 this, |
| 392 "vx", | 396 "vx", |
| 393 vx, | 397 vx, |
| 394 "vy", | 398 "vy", |
| 395 vy); | 399 vy); |
| 396 // Note that the timestamp will only be used to kickstart the animation if | 400 // Note that the timestamp will only be used to kickstart the animation if |
| (...skipping 16 matching lines...) Expand all Loading... |
| 413 "scroll_on_main_thread", | 417 "scroll_on_main_thread", |
| 414 TRACE_EVENT_SCOPE_THREAD); | 418 TRACE_EVENT_SCOPE_THREAD); |
| 415 fling_may_be_active_on_main_thread_ = true; | 419 fling_may_be_active_on_main_thread_ = true; |
| 416 return DID_NOT_HANDLE; | 420 return DID_NOT_HANDLE; |
| 417 } | 421 } |
| 418 case cc::InputHandler::ScrollIgnored: { | 422 case cc::InputHandler::ScrollIgnored: { |
| 419 TRACE_EVENT_INSTANT0( | 423 TRACE_EVENT_INSTANT0( |
| 420 "input", | 424 "input", |
| 421 "InputHandlerProxy::HandleGestureFling::ignored", | 425 "InputHandlerProxy::HandleGestureFling::ignored", |
| 422 TRACE_EVENT_SCOPE_THREAD); | 426 TRACE_EVENT_SCOPE_THREAD); |
| 423 if (gesture_event.sourceDevice == WebGestureEvent::Touchpad) { | 427 if (gesture_event.sourceDevice == blink::WebGestureDeviceTouchpad) { |
| 424 // We still pass the curve to the main thread if there's nothing | 428 // We still pass the curve to the main thread if there's nothing |
| 425 // scrollable, in case something | 429 // scrollable, in case something |
| 426 // registers a handler before the curve is over. | 430 // registers a handler before the curve is over. |
| 427 return DID_NOT_HANDLE; | 431 return DID_NOT_HANDLE; |
| 428 } | 432 } |
| 429 return DROP_EVENT; | 433 return DROP_EVENT; |
| 430 } | 434 } |
| 431 case cc::InputHandler::ScrollStatusCount: | 435 case cc::InputHandler::ScrollStatusCount: |
| 432 NOTREACHED(); | 436 NOTREACHED(); |
| 433 break; | 437 break; |
| (...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 471 } | 475 } |
| 472 | 476 |
| 473 switch (gesture_event.type) { | 477 switch (gesture_event.type) { |
| 474 case WebInputEvent::GestureTapCancel: | 478 case WebInputEvent::GestureTapCancel: |
| 475 case WebInputEvent::GestureTapDown: | 479 case WebInputEvent::GestureTapDown: |
| 476 return false; | 480 return false; |
| 477 | 481 |
| 478 case WebInputEvent::GestureScrollBegin: | 482 case WebInputEvent::GestureScrollBegin: |
| 479 if (!input_handler_->IsCurrentlyScrollingLayerAt( | 483 if (!input_handler_->IsCurrentlyScrollingLayerAt( |
| 480 gfx::Point(gesture_event.x, gesture_event.y), | 484 gfx::Point(gesture_event.x, gesture_event.y), |
| 481 fling_parameters_.sourceDevice == WebGestureEvent::Touchpad | 485 fling_parameters_.sourceDevice == blink::WebGestureDeviceTouchpad |
| 482 ? cc::InputHandler::NonBubblingGesture | 486 ? cc::InputHandler::NonBubblingGesture |
| 483 : cc::InputHandler::Gesture)) { | 487 : cc::InputHandler::Gesture)) { |
| 484 CancelCurrentFling(true); | 488 CancelCurrentFling(true); |
| 485 return false; | 489 return false; |
| 486 } | 490 } |
| 487 | 491 |
| 488 // TODO(jdduke): Use |gesture_event.data.scrollBegin.delta{X,Y}Hint| to | 492 // TODO(jdduke): Use |gesture_event.data.scrollBegin.delta{X,Y}Hint| to |
| 489 // determine if the ScrollBegin should immediately cancel the fling. | 493 // determine if the ScrollBegin should immediately cancel the fling. |
| 490 FlingBoostExtend(gesture_event); | 494 FlingBoostExtend(gesture_event); |
| 491 return true; | 495 return true; |
| (...skipping 29 matching lines...) Expand all Loading... |
| 521 | 525 |
| 522 if (fling_boosted) | 526 if (fling_boosted) |
| 523 current_fling_velocity_ += new_fling_velocity; | 527 current_fling_velocity_ += new_fling_velocity; |
| 524 else | 528 else |
| 525 current_fling_velocity_ = new_fling_velocity; | 529 current_fling_velocity_ = new_fling_velocity; |
| 526 | 530 |
| 527 WebFloatPoint velocity(current_fling_velocity_.x(), | 531 WebFloatPoint velocity(current_fling_velocity_.x(), |
| 528 current_fling_velocity_.y()); | 532 current_fling_velocity_.y()); |
| 529 deferred_fling_cancel_time_seconds_ = 0; | 533 deferred_fling_cancel_time_seconds_ = 0; |
| 530 last_fling_boost_event_ = WebGestureEvent(); | 534 last_fling_boost_event_ = WebGestureEvent(); |
| 535 // TODO(rjkroege): Remove cast after 3rd patch of http://crbug.com/343327 |
| 531 fling_curve_.reset(client_->CreateFlingAnimationCurve( | 536 fling_curve_.reset(client_->CreateFlingAnimationCurve( |
| 532 gesture_event.sourceDevice, velocity, blink::WebSize())); | 537 (blink::WebGestureDevice)gesture_event.sourceDevice, |
| 538 velocity, |
| 539 blink::WebSize())); |
| 533 fling_parameters_.startTime = gesture_event.timeStampSeconds; | 540 fling_parameters_.startTime = gesture_event.timeStampSeconds; |
| 534 fling_parameters_.delta = velocity; | 541 fling_parameters_.delta = velocity; |
| 535 fling_parameters_.point = WebPoint(gesture_event.x, gesture_event.y); | 542 fling_parameters_.point = WebPoint(gesture_event.x, gesture_event.y); |
| 536 fling_parameters_.globalPoint = | 543 fling_parameters_.globalPoint = |
| 537 WebPoint(gesture_event.globalX, gesture_event.globalY); | 544 WebPoint(gesture_event.globalX, gesture_event.globalY); |
| 538 | 545 |
| 539 TRACE_EVENT_INSTANT2("input", | 546 TRACE_EVENT_INSTANT2("input", |
| 540 fling_boosted ? "InputHandlerProxy::FlingBoosted" | 547 fling_boosted ? "InputHandlerProxy::FlingBoosted" |
| 541 : "InputHandlerProxy::FlingReplaced", | 548 : "InputHandlerProxy::FlingReplaced", |
| 542 TRACE_EVENT_SCOPE_THREAD, | 549 TRACE_EVENT_SCOPE_THREAD, |
| (...skipping 118 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 661 kFlingOverscrollThreshold; | 668 kFlingOverscrollThreshold; |
| 662 } | 669 } |
| 663 | 670 |
| 664 client_->DidOverscroll(params); | 671 client_->DidOverscroll(params); |
| 665 } | 672 } |
| 666 | 673 |
| 667 bool InputHandlerProxy::CancelCurrentFling( | 674 bool InputHandlerProxy::CancelCurrentFling( |
| 668 bool send_fling_stopped_notification) { | 675 bool send_fling_stopped_notification) { |
| 669 bool had_fling_animation = fling_curve_; | 676 bool had_fling_animation = fling_curve_; |
| 670 if (had_fling_animation && | 677 if (had_fling_animation && |
| 671 fling_parameters_.sourceDevice == WebGestureEvent::Touchscreen) { | 678 fling_parameters_.sourceDevice == blink::WebGestureDeviceTouchpad) { |
| 672 input_handler_->ScrollEnd(); | 679 input_handler_->ScrollEnd(); |
| 673 TRACE_EVENT_ASYNC_END0( | 680 TRACE_EVENT_ASYNC_END0( |
| 674 "input", | 681 "input", |
| 675 "InputHandlerProxy::HandleGestureFling::started", | 682 "InputHandlerProxy::HandleGestureFling::started", |
| 676 this); | 683 this); |
| 677 } | 684 } |
| 678 | 685 |
| 679 TRACE_EVENT_INSTANT1("input", | 686 TRACE_EVENT_INSTANT1("input", |
| 680 "InputHandlerProxy::CancelCurrentFling", | 687 "InputHandlerProxy::CancelCurrentFling", |
| 681 TRACE_EVENT_SCOPE_THREAD, | 688 TRACE_EVENT_SCOPE_THREAD, |
| (...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 755 TRACE_EVENT2("input", | 762 TRACE_EVENT2("input", |
| 756 "InputHandlerProxy::scrollBy", | 763 "InputHandlerProxy::scrollBy", |
| 757 "x", | 764 "x", |
| 758 clipped_increment.width, | 765 clipped_increment.width, |
| 759 "y", | 766 "y", |
| 760 clipped_increment.height); | 767 clipped_increment.height); |
| 761 | 768 |
| 762 bool did_scroll = false; | 769 bool did_scroll = false; |
| 763 | 770 |
| 764 switch (fling_parameters_.sourceDevice) { | 771 switch (fling_parameters_.sourceDevice) { |
| 765 case WebGestureEvent::Touchpad: | 772 case blink::WebGestureDeviceTouchpad: |
| 766 did_scroll = TouchpadFlingScroll(clipped_increment); | 773 did_scroll = TouchpadFlingScroll(clipped_increment); |
| 767 break; | 774 break; |
| 768 case WebGestureEvent::Touchscreen: | 775 case blink::WebGestureDeviceTouchscreen: |
| 769 clipped_increment = ToClientScrollIncrement(clipped_increment); | 776 clipped_increment = ToClientScrollIncrement(clipped_increment); |
| 770 did_scroll = input_handler_->ScrollBy(fling_parameters_.point, | 777 did_scroll = input_handler_->ScrollBy(fling_parameters_.point, |
| 771 clipped_increment); | 778 clipped_increment); |
| 772 break; | 779 break; |
| 773 } | 780 } |
| 774 | 781 |
| 775 if (did_scroll) { | 782 if (did_scroll) { |
| 776 fling_parameters_.cumulativeScroll.width += clipped_increment.width; | 783 fling_parameters_.cumulativeScroll.width += clipped_increment.width; |
| 777 fling_parameters_.cumulativeScroll.height += clipped_increment.height; | 784 fling_parameters_.cumulativeScroll.height += clipped_increment.height; |
| 778 } | 785 } |
| 779 | 786 |
| 780 // It's possible the provided |increment| is sufficiently small as to not | 787 // It's possible the provided |increment| is sufficiently small as to not |
| 781 // trigger a scroll, e.g., with a trivial time delta between fling updates. | 788 // trigger a scroll, e.g., with a trivial time delta between fling updates. |
| 782 // Return true in this case to prevent early fling termination. | 789 // Return true in this case to prevent early fling termination. |
| 783 if (std::abs(clipped_increment.width) < kScrollEpsilon && | 790 if (std::abs(clipped_increment.width) < kScrollEpsilon && |
| 784 std::abs(clipped_increment.height) < kScrollEpsilon) | 791 std::abs(clipped_increment.height) < kScrollEpsilon) |
| 785 return true; | 792 return true; |
| 786 | 793 |
| 787 return did_scroll; | 794 return did_scroll; |
| 788 } | 795 } |
| 789 | 796 |
| 790 } // namespace content | 797 } // namespace content |
| OLD | NEW |