| 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/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 342 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 362 TRACE_EVENT_SCOPE_THREAD); | 364 TRACE_EVENT_SCOPE_THREAD); |
| 363 CancelCurrentFling(true); | 365 CancelCurrentFling(true); |
| 364 } | 366 } |
| 365 } | 367 } |
| 366 | 368 |
| 367 void InputHandlerProxy::MainThreadHasStoppedFlinging() { | 369 void InputHandlerProxy::MainThreadHasStoppedFlinging() { |
| 368 fling_may_be_active_on_main_thread_ = false; | 370 fling_may_be_active_on_main_thread_ = false; |
| 369 client_->DidStopFlinging(); | 371 client_->DidStopFlinging(); |
| 370 } | 372 } |
| 371 | 373 |
| 372 void InputHandlerProxy::DidOverscroll(const cc::DidOverscrollParams& params) { | 374 void InputHandlerProxy::DidOverscroll( |
| 375 const gfx::Vector2dF& accumulated_overscroll, |
| 376 const gfx::Vector2dF& latest_overscroll_delta) { |
| 373 DCHECK(client_); | 377 DCHECK(client_); |
| 378 |
| 379 DidOverscrollParams params; |
| 380 params.accumulated_overscroll = accumulated_overscroll; |
| 381 params.latest_overscroll_delta = latest_overscroll_delta; |
| 382 params.current_fling_velocity = current_fling_velocity_; |
| 383 |
| 374 if (fling_curve_) { | 384 if (fling_curve_) { |
| 375 static const int kFlingOverscrollThreshold = 1; | 385 static const int kFlingOverscrollThreshold = 1; |
| 376 disallow_horizontal_fling_scroll_ |= | 386 disallow_horizontal_fling_scroll_ |= |
| 377 std::abs(params.accumulated_overscroll.x()) >= | 387 std::abs(params.accumulated_overscroll.x()) >= |
| 378 kFlingOverscrollThreshold; | 388 kFlingOverscrollThreshold; |
| 379 disallow_vertical_fling_scroll_ |= | 389 disallow_vertical_fling_scroll_ |= |
| 380 std::abs(params.accumulated_overscroll.y()) >= | 390 std::abs(params.accumulated_overscroll.y()) >= |
| 381 kFlingOverscrollThreshold; | 391 kFlingOverscrollThreshold; |
| 382 } | 392 } |
| 383 | 393 |
| (...skipping 12 matching lines...) Expand all Loading... |
| 396 this); | 406 this); |
| 397 } | 407 } |
| 398 | 408 |
| 399 TRACE_EVENT_INSTANT1("input", | 409 TRACE_EVENT_INSTANT1("input", |
| 400 "InputHandlerProxy::CancelCurrentFling", | 410 "InputHandlerProxy::CancelCurrentFling", |
| 401 TRACE_EVENT_SCOPE_THREAD, | 411 TRACE_EVENT_SCOPE_THREAD, |
| 402 "had_fling_animation", | 412 "had_fling_animation", |
| 403 had_fling_animation); | 413 had_fling_animation); |
| 404 fling_curve_.reset(); | 414 fling_curve_.reset(); |
| 405 gesture_scroll_on_impl_thread_ = false; | 415 gesture_scroll_on_impl_thread_ = false; |
| 416 current_fling_velocity_ = gfx::Vector2dF(); |
| 406 fling_parameters_ = blink::WebActiveWheelFlingParameters(); | 417 fling_parameters_ = blink::WebActiveWheelFlingParameters(); |
| 407 if (send_fling_stopped_notification && had_fling_animation) | 418 if (send_fling_stopped_notification && had_fling_animation) |
| 408 client_->DidStopFlinging(); | 419 client_->DidStopFlinging(); |
| 409 return had_fling_animation; | 420 return had_fling_animation; |
| 410 } | 421 } |
| 411 | 422 |
| 412 bool InputHandlerProxy::TouchpadFlingScroll( | 423 bool InputHandlerProxy::TouchpadFlingScroll( |
| 413 const WebFloatSize& increment) { | 424 const WebFloatSize& increment) { |
| 414 WebMouseWheelEvent synthetic_wheel; | 425 WebMouseWheelEvent synthetic_wheel; |
| 415 synthetic_wheel.type = WebInputEvent::MouseWheel; | 426 synthetic_wheel.type = WebInputEvent::MouseWheel; |
| (...skipping 29 matching lines...) Expand all Loading... |
| 445 break; | 456 break; |
| 446 } | 457 } |
| 447 | 458 |
| 448 return false; | 459 return false; |
| 449 } | 460 } |
| 450 | 461 |
| 451 static gfx::Vector2dF ToClientScrollIncrement(const WebFloatSize& increment) { | 462 static gfx::Vector2dF ToClientScrollIncrement(const WebFloatSize& increment) { |
| 452 return gfx::Vector2dF(-increment.width, -increment.height); | 463 return gfx::Vector2dF(-increment.width, -increment.height); |
| 453 } | 464 } |
| 454 | 465 |
| 455 void InputHandlerProxy::scrollBy(const WebFloatSize& increment) { | 466 bool InputHandlerProxy::scrollBy(const WebFloatSize& increment, |
| 467 const WebFloatSize& velocity) { |
| 456 WebFloatSize clipped_increment; | 468 WebFloatSize clipped_increment; |
| 457 if (!disallow_horizontal_fling_scroll_) | 469 WebFloatSize clipped_velocity; |
| 470 if (!disallow_horizontal_fling_scroll_) { |
| 458 clipped_increment.width = increment.width; | 471 clipped_increment.width = increment.width; |
| 459 if (!disallow_vertical_fling_scroll_) | 472 clipped_velocity.width = velocity.width; |
| 473 } |
| 474 if (!disallow_vertical_fling_scroll_) { |
| 460 clipped_increment.height = increment.height; | 475 clipped_increment.height = increment.height; |
| 476 clipped_velocity.height = velocity.height; |
| 477 } |
| 461 | 478 |
| 479 current_fling_velocity_ = clipped_velocity; |
| 462 if (clipped_increment == WebFloatSize()) | 480 if (clipped_increment == WebFloatSize()) |
| 463 return; | 481 return false; |
| 464 | 482 |
| 465 TRACE_EVENT2("input", | 483 TRACE_EVENT2("input", |
| 466 "InputHandlerProxy::scrollBy", | 484 "InputHandlerProxy::scrollBy", |
| 467 "x", | 485 "x", |
| 468 clipped_increment.width, | 486 clipped_increment.width, |
| 469 "y", | 487 "y", |
| 470 clipped_increment.height); | 488 clipped_increment.height); |
| 471 | 489 |
| 472 bool did_scroll = false; | 490 bool did_scroll = false; |
| 473 | 491 |
| 474 switch (fling_parameters_.sourceDevice) { | 492 switch (fling_parameters_.sourceDevice) { |
| 475 case WebGestureEvent::Touchpad: | 493 case WebGestureEvent::Touchpad: |
| 476 did_scroll = TouchpadFlingScroll(clipped_increment); | 494 did_scroll = TouchpadFlingScroll(clipped_increment); |
| 477 break; | 495 break; |
| 478 case WebGestureEvent::Touchscreen: | 496 case WebGestureEvent::Touchscreen: |
| 479 clipped_increment = ToClientScrollIncrement(clipped_increment); | 497 clipped_increment = ToClientScrollIncrement(clipped_increment); |
| 498 clipped_velocity = ToClientScrollIncrement(clipped_velocity); |
| 480 did_scroll = input_handler_->ScrollBy(fling_parameters_.point, | 499 did_scroll = input_handler_->ScrollBy(fling_parameters_.point, |
| 481 clipped_increment); | 500 clipped_increment); |
| 482 break; | 501 break; |
| 483 } | 502 } |
| 484 | 503 |
| 485 if (did_scroll) { | 504 if (did_scroll) { |
| 486 fling_parameters_.cumulativeScroll.width += clipped_increment.width; | 505 fling_parameters_.cumulativeScroll.width += clipped_increment.width; |
| 487 fling_parameters_.cumulativeScroll.height += clipped_increment.height; | 506 fling_parameters_.cumulativeScroll.height += clipped_increment.height; |
| 488 } | 507 } |
| 489 } | |
| 490 | 508 |
| 491 void InputHandlerProxy::notifyCurrentFlingVelocity( | 509 return did_scroll; |
| 492 const WebFloatSize& velocity) { | |
| 493 TRACE_EVENT2("input", | |
| 494 "InputHandlerProxy::notifyCurrentFlingVelocity", | |
| 495 "vx", | |
| 496 velocity.width, | |
| 497 "vy", | |
| 498 velocity.height); | |
| 499 input_handler_->NotifyCurrentFlingVelocity(ToClientScrollIncrement(velocity)); | |
| 500 } | 510 } |
| 501 | 511 |
| 502 } // namespace content | 512 } // namespace content |
| OLD | NEW |