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