| 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/debug/trace_event.h" | 7 #include "base/debug/trace_event.h" |
| 8 #include "base/logging.h" | 8 #include "base/logging.h" |
| 9 #include "base/metrics/histogram.h" | 9 #include "base/metrics/histogram.h" |
| 10 #include "content/renderer/input/input_handler_proxy_client.h" | 10 #include "content/renderer/input/input_handler_proxy_client.h" |
| (...skipping 194 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 205 *static_cast<const WebGestureEvent*>(&event); | 205 *static_cast<const WebGestureEvent*>(&event); |
| 206 input_handler_->PinchGestureUpdate( | 206 input_handler_->PinchGestureUpdate( |
| 207 gesture_event.data.pinchUpdate.scale, | 207 gesture_event.data.pinchUpdate.scale, |
| 208 gfx::Point(gesture_event.x, gesture_event.y)); | 208 gfx::Point(gesture_event.x, gesture_event.y)); |
| 209 return DID_HANDLE; | 209 return DID_HANDLE; |
| 210 } else if (event.type == WebInputEvent::GestureFlingStart) { | 210 } else if (event.type == WebInputEvent::GestureFlingStart) { |
| 211 const WebGestureEvent& gesture_event = | 211 const WebGestureEvent& gesture_event = |
| 212 *static_cast<const WebGestureEvent*>(&event); | 212 *static_cast<const WebGestureEvent*>(&event); |
| 213 return HandleGestureFling(gesture_event); | 213 return HandleGestureFling(gesture_event); |
| 214 } else if (event.type == WebInputEvent::GestureFlingCancel) { | 214 } else if (event.type == WebInputEvent::GestureFlingCancel) { |
| 215 if (CancelCurrentFling()) | 215 if (CancelCurrentFling(true)) |
| 216 return DID_HANDLE; | 216 return DID_HANDLE; |
| 217 else if (!fling_may_be_active_on_main_thread_) | 217 else if (!fling_may_be_active_on_main_thread_) |
| 218 return DROP_EVENT; | 218 return DROP_EVENT; |
| 219 } else if (event.type == WebInputEvent::TouchStart) { | 219 } else if (event.type == WebInputEvent::TouchStart) { |
| 220 const WebTouchEvent& touch_event = | 220 const WebTouchEvent& touch_event = |
| 221 *static_cast<const WebTouchEvent*>(&event); | 221 *static_cast<const WebTouchEvent*>(&event); |
| 222 for (size_t i = 0; i < touch_event.touchesLength; ++i) { | 222 for (size_t i = 0; i < touch_event.touchesLength; ++i) { |
| 223 if (touch_event.touches[i].state != WebTouchPoint::StatePressed) | 223 if (touch_event.touches[i].state != WebTouchPoint::StatePressed) |
| 224 continue; | 224 continue; |
| 225 if (input_handler_->HaveTouchEventHandlersAt(touch_event.touches[i] | 225 if (input_handler_->HaveTouchEventHandlersAt(touch_event.touches[i] |
| 226 .position)) | 226 .position)) |
| 227 return DID_NOT_HANDLE; | 227 return DID_NOT_HANDLE; |
| 228 } | 228 } |
| 229 return DROP_EVENT; | 229 return DROP_EVENT; |
| 230 } else if (WebInputEvent::isKeyboardEventType(event.type)) { | 230 } else if (WebInputEvent::isKeyboardEventType(event.type)) { |
| 231 CancelCurrentFling(); | 231 CancelCurrentFling(true); |
| 232 } else if (event.type == WebInputEvent::MouseMove) { | 232 } else if (event.type == WebInputEvent::MouseMove) { |
| 233 const WebMouseEvent& mouse_event = | 233 const WebMouseEvent& mouse_event = |
| 234 *static_cast<const WebMouseEvent*>(&event); | 234 *static_cast<const WebMouseEvent*>(&event); |
| 235 // TODO(tony): Ignore when mouse buttons are down? | 235 // TODO(tony): Ignore when mouse buttons are down? |
| 236 // TODO(davemoore): This should never happen, but bug #326635 showed some | 236 // TODO(davemoore): This should never happen, but bug #326635 showed some |
| 237 // surprising crashes. | 237 // surprising crashes. |
| 238 CHECK(input_handler_); | 238 CHECK(input_handler_); |
| 239 input_handler_->MouseMoveAt(gfx::Point(mouse_event.x, mouse_event.y)); | 239 input_handler_->MouseMoveAt(gfx::Point(mouse_event.x, mouse_event.y)); |
| 240 } | 240 } |
| 241 | 241 |
| (...skipping 97 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 339 | 339 |
| 340 if (disallow_vertical_fling_scroll_ && disallow_horizontal_fling_scroll_) | 340 if (disallow_vertical_fling_scroll_ && disallow_horizontal_fling_scroll_) |
| 341 fling_is_active = false; | 341 fling_is_active = false; |
| 342 | 342 |
| 343 if (fling_is_active) { | 343 if (fling_is_active) { |
| 344 input_handler_->ScheduleAnimation(); | 344 input_handler_->ScheduleAnimation(); |
| 345 } else { | 345 } else { |
| 346 TRACE_EVENT_INSTANT0("renderer", | 346 TRACE_EVENT_INSTANT0("renderer", |
| 347 "InputHandlerProxy::animate::flingOver", | 347 "InputHandlerProxy::animate::flingOver", |
| 348 TRACE_EVENT_SCOPE_THREAD); | 348 TRACE_EVENT_SCOPE_THREAD); |
| 349 CancelCurrentFling(); | 349 CancelCurrentFling(true); |
| 350 } | 350 } |
| 351 } | 351 } |
| 352 | 352 |
| 353 void InputHandlerProxy::MainThreadHasStoppedFlinging() { | 353 void InputHandlerProxy::MainThreadHasStoppedFlinging() { |
| 354 fling_may_be_active_on_main_thread_ = false; | 354 fling_may_be_active_on_main_thread_ = false; |
| 355 client_->DidStopFlinging(); |
| 355 } | 356 } |
| 356 | 357 |
| 357 void InputHandlerProxy::DidOverscroll(const cc::DidOverscrollParams& params) { | 358 void InputHandlerProxy::DidOverscroll(const cc::DidOverscrollParams& params) { |
| 358 DCHECK(client_); | 359 DCHECK(client_); |
| 359 if (fling_curve_) { | 360 if (fling_curve_) { |
| 360 static const int kFlingOverscrollThreshold = 1; | 361 static const int kFlingOverscrollThreshold = 1; |
| 361 disallow_horizontal_fling_scroll_ |= | 362 disallow_horizontal_fling_scroll_ |= |
| 362 std::abs(params.accumulated_overscroll.x()) >= | 363 std::abs(params.accumulated_overscroll.x()) >= |
| 363 kFlingOverscrollThreshold; | 364 kFlingOverscrollThreshold; |
| 364 disallow_vertical_fling_scroll_ |= | 365 disallow_vertical_fling_scroll_ |= |
| 365 std::abs(params.accumulated_overscroll.y()) >= | 366 std::abs(params.accumulated_overscroll.y()) >= |
| 366 kFlingOverscrollThreshold; | 367 kFlingOverscrollThreshold; |
| 367 } | 368 } |
| 368 | 369 |
| 369 client_->DidOverscroll(params); | 370 client_->DidOverscroll(params); |
| 370 } | 371 } |
| 371 | 372 |
| 372 bool InputHandlerProxy::CancelCurrentFling() { | 373 bool InputHandlerProxy::CancelCurrentFling( |
| 374 bool send_fling_stopped_notification) { |
| 373 bool had_fling_animation = fling_curve_; | 375 bool had_fling_animation = fling_curve_; |
| 374 if (had_fling_animation && | 376 if (had_fling_animation && |
| 375 fling_parameters_.sourceDevice == WebGestureEvent::Touchscreen) { | 377 fling_parameters_.sourceDevice == WebGestureEvent::Touchscreen) { |
| 376 input_handler_->ScrollEnd(); | 378 input_handler_->ScrollEnd(); |
| 377 TRACE_EVENT_ASYNC_END0( | 379 TRACE_EVENT_ASYNC_END0( |
| 378 "renderer", | 380 "renderer", |
| 379 "InputHandlerProxy::HandleGestureFling::started", | 381 "InputHandlerProxy::HandleGestureFling::started", |
| 380 this); | 382 this); |
| 381 } | 383 } |
| 382 | 384 |
| 383 TRACE_EVENT_INSTANT1("renderer", | 385 TRACE_EVENT_INSTANT1("renderer", |
| 384 "InputHandlerProxy::CancelCurrentFling", | 386 "InputHandlerProxy::CancelCurrentFling", |
| 385 TRACE_EVENT_SCOPE_THREAD, | 387 TRACE_EVENT_SCOPE_THREAD, |
| 386 "had_fling_animation", | 388 "had_fling_animation", |
| 387 had_fling_animation); | 389 had_fling_animation); |
| 388 fling_curve_.reset(); | 390 fling_curve_.reset(); |
| 389 gesture_scroll_on_impl_thread_ = false; | 391 gesture_scroll_on_impl_thread_ = false; |
| 390 fling_parameters_ = blink::WebActiveWheelFlingParameters(); | 392 fling_parameters_ = blink::WebActiveWheelFlingParameters(); |
| 393 if (send_fling_stopped_notification && had_fling_animation) |
| 394 client_->DidStopFlinging(); |
| 391 return had_fling_animation; | 395 return had_fling_animation; |
| 392 } | 396 } |
| 393 | 397 |
| 394 bool InputHandlerProxy::TouchpadFlingScroll( | 398 bool InputHandlerProxy::TouchpadFlingScroll( |
| 395 const WebFloatSize& increment) { | 399 const WebFloatSize& increment) { |
| 396 WebMouseWheelEvent synthetic_wheel; | 400 WebMouseWheelEvent synthetic_wheel; |
| 397 synthetic_wheel.type = WebInputEvent::MouseWheel; | 401 synthetic_wheel.type = WebInputEvent::MouseWheel; |
| 398 synthetic_wheel.deltaX = increment.width; | 402 synthetic_wheel.deltaX = increment.width; |
| 399 synthetic_wheel.deltaY = increment.height; | 403 synthetic_wheel.deltaY = increment.height; |
| 400 synthetic_wheel.hasPreciseScrollingDeltas = true; | 404 synthetic_wheel.hasPreciseScrollingDeltas = true; |
| (...skipping 15 matching lines...) Expand all Loading... |
| 416 "InputHandlerProxy::scrollBy::AbortFling", | 420 "InputHandlerProxy::scrollBy::AbortFling", |
| 417 TRACE_EVENT_SCOPE_THREAD); | 421 TRACE_EVENT_SCOPE_THREAD); |
| 418 // If we got a DID_NOT_HANDLE, that means we need to deliver wheels on the | 422 // If we got a DID_NOT_HANDLE, that means we need to deliver wheels on the |
| 419 // main thread. In this case we need to schedule a commit and transfer the | 423 // main thread. In this case we need to schedule a commit and transfer the |
| 420 // fling curve over to the main thread and run the rest of the wheels from | 424 // fling curve over to the main thread and run the rest of the wheels from |
| 421 // there. This can happen when flinging a page that contains a scrollable | 425 // there. This can happen when flinging a page that contains a scrollable |
| 422 // subarea that we can't scroll on the thread if the fling starts outside | 426 // subarea that we can't scroll on the thread if the fling starts outside |
| 423 // the subarea but then is flung "under" the pointer. | 427 // the subarea but then is flung "under" the pointer. |
| 424 client_->TransferActiveWheelFlingAnimation(fling_parameters_); | 428 client_->TransferActiveWheelFlingAnimation(fling_parameters_); |
| 425 fling_may_be_active_on_main_thread_ = true; | 429 fling_may_be_active_on_main_thread_ = true; |
| 426 CancelCurrentFling(); | 430 CancelCurrentFling(false); |
| 427 break; | 431 break; |
| 428 } | 432 } |
| 429 | 433 |
| 430 return false; | 434 return false; |
| 431 } | 435 } |
| 432 | 436 |
| 433 static gfx::Vector2dF ToClientScrollIncrement(const WebFloatSize& increment) { | 437 static gfx::Vector2dF ToClientScrollIncrement(const WebFloatSize& increment) { |
| 434 return gfx::Vector2dF(-increment.width, -increment.height); | 438 return gfx::Vector2dF(-increment.width, -increment.height); |
| 435 } | 439 } |
| 436 | 440 |
| (...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 475 TRACE_EVENT2("renderer", | 479 TRACE_EVENT2("renderer", |
| 476 "InputHandlerProxy::notifyCurrentFlingVelocity", | 480 "InputHandlerProxy::notifyCurrentFlingVelocity", |
| 477 "vx", | 481 "vx", |
| 478 velocity.width, | 482 velocity.width, |
| 479 "vy", | 483 "vy", |
| 480 velocity.height); | 484 velocity.height); |
| 481 input_handler_->NotifyCurrentFlingVelocity(ToClientScrollIncrement(velocity)); | 485 input_handler_->NotifyCurrentFlingVelocity(ToClientScrollIncrement(velocity)); |
| 482 } | 486 } |
| 483 | 487 |
| 484 } // namespace content | 488 } // namespace content |
| OLD | NEW |