Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 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/gpu/input_handler_proxy.h" | 5 #include "content/renderer/gpu/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 "content/renderer/gpu/input_handler_proxy_client.h" | 9 #include "content/renderer/gpu/input_handler_proxy_client.h" |
| 10 #include "third_party/WebKit/Source/Platform/chromium/public/Platform.h" | 10 #include "third_party/WebKit/Source/Platform/chromium/public/Platform.h" |
| (...skipping 11 matching lines...) Expand all Loading... | |
| 22 | 22 |
| 23 InputHandlerProxy::InputHandlerProxy(cc::InputHandler* input_handler) | 23 InputHandlerProxy::InputHandlerProxy(cc::InputHandler* input_handler) |
| 24 : client_(NULL), | 24 : client_(NULL), |
| 25 input_handler_(input_handler), | 25 input_handler_(input_handler), |
| 26 #ifndef NDEBUG | 26 #ifndef NDEBUG |
| 27 expect_scroll_update_end_(false), | 27 expect_scroll_update_end_(false), |
| 28 expect_pinch_update_end_(false), | 28 expect_pinch_update_end_(false), |
| 29 #endif | 29 #endif |
| 30 gesture_scroll_on_impl_thread_(false), | 30 gesture_scroll_on_impl_thread_(false), |
| 31 gesture_pinch_on_impl_thread_(false), | 31 gesture_pinch_on_impl_thread_(false), |
| 32 fling_may_be_active_on_main_thread_(false) { | 32 fling_may_be_active_on_main_thread_(false), |
| 33 fling_overscrolled_horizontally_(false), | |
| 34 fling_overscrolled_vertically_(false) { | |
| 33 input_handler_->BindToClient(this); | 35 input_handler_->BindToClient(this); |
| 34 } | 36 } |
| 35 | 37 |
| 36 InputHandlerProxy::~InputHandlerProxy() {} | 38 InputHandlerProxy::~InputHandlerProxy() {} |
| 37 | 39 |
| 38 void InputHandlerProxy::WillShutdown() { | 40 void InputHandlerProxy::WillShutdown() { |
| 39 input_handler_ = NULL; | 41 input_handler_ = NULL; |
| 40 DCHECK(client_); | 42 DCHECK(client_); |
| 41 client_->WillShutdown(); | 43 client_->WillShutdown(); |
| 42 } | 44 } |
| (...skipping 181 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 224 switch (scroll_status) { | 226 switch (scroll_status) { |
| 225 case cc::InputHandler::ScrollStarted: { | 227 case cc::InputHandler::ScrollStarted: { |
| 226 if (gesture_event.sourceDevice == WebGestureEvent::Touchpad) | 228 if (gesture_event.sourceDevice == WebGestureEvent::Touchpad) |
| 227 input_handler_->ScrollEnd(); | 229 input_handler_->ScrollEnd(); |
| 228 | 230 |
| 229 fling_curve_.reset(client_->CreateFlingAnimationCurve( | 231 fling_curve_.reset(client_->CreateFlingAnimationCurve( |
| 230 gesture_event.sourceDevice, | 232 gesture_event.sourceDevice, |
| 231 WebFloatPoint(gesture_event.data.flingStart.velocityX, | 233 WebFloatPoint(gesture_event.data.flingStart.velocityX, |
| 232 gesture_event.data.flingStart.velocityY), | 234 gesture_event.data.flingStart.velocityY), |
| 233 WebKit::WebSize())); | 235 WebKit::WebSize())); |
| 236 fling_overscrolled_horizontally_ = false; | |
| 237 fling_overscrolled_vertically_ = false; | |
| 234 TRACE_EVENT_ASYNC_BEGIN0( | 238 TRACE_EVENT_ASYNC_BEGIN0( |
| 235 "renderer", | 239 "renderer", |
| 236 "InputHandlerProxy::HandleGestureFling::started", | 240 "InputHandlerProxy::HandleGestureFling::started", |
| 237 this); | 241 this); |
| 238 fling_parameters_.delta = | 242 fling_parameters_.delta = |
| 239 WebFloatPoint(gesture_event.data.flingStart.velocityX, | 243 WebFloatPoint(gesture_event.data.flingStart.velocityX, |
| 240 gesture_event.data.flingStart.velocityY); | 244 gesture_event.data.flingStart.velocityY); |
| 241 fling_parameters_.point = WebPoint(gesture_event.x, gesture_event.y); | 245 fling_parameters_.point = WebPoint(gesture_event.x, gesture_event.y); |
| 242 fling_parameters_.globalPoint = | 246 fling_parameters_.globalPoint = |
| 243 WebPoint(gesture_event.globalX, gesture_event.globalY); | 247 WebPoint(gesture_event.globalX, gesture_event.globalY); |
| (...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 293 } | 297 } |
| 294 } | 298 } |
| 295 | 299 |
| 296 void InputHandlerProxy::MainThreadHasStoppedFlinging() { | 300 void InputHandlerProxy::MainThreadHasStoppedFlinging() { |
| 297 fling_may_be_active_on_main_thread_ = false; | 301 fling_may_be_active_on_main_thread_ = false; |
| 298 } | 302 } |
| 299 | 303 |
| 300 void InputHandlerProxy::DidOverscroll(gfx::Vector2dF accumulated_overscroll, | 304 void InputHandlerProxy::DidOverscroll(gfx::Vector2dF accumulated_overscroll, |
| 301 gfx::Vector2dF current_fling_velocity) { | 305 gfx::Vector2dF current_fling_velocity) { |
| 302 DCHECK(client_); | 306 DCHECK(client_); |
| 307 if (fling_curve_) { | |
| 308 const int kFlingOverscrollThreshold = 1; | |
|
jamesr
2013/05/31 18:23:28
why not static?
| |
| 309 fling_overscrolled_horizontally_ |= | |
| 310 std::abs(accumulated_overscroll.x()) >= kFlingOverscrollThreshold; | |
| 311 fling_overscrolled_vertically_ |= | |
| 312 std::abs(accumulated_overscroll.y()) >= kFlingOverscrollThreshold; | |
| 313 } | |
| 314 | |
| 303 client_->DidOverscroll(accumulated_overscroll, current_fling_velocity); | 315 client_->DidOverscroll(accumulated_overscroll, current_fling_velocity); |
| 304 } | 316 } |
| 305 | 317 |
| 306 bool InputHandlerProxy::CancelCurrentFling() { | 318 bool InputHandlerProxy::CancelCurrentFling() { |
| 307 bool had_fling_animation = fling_curve_; | 319 bool had_fling_animation = fling_curve_; |
| 308 if (had_fling_animation && | 320 if (had_fling_animation && |
| 309 fling_parameters_.sourceDevice == WebGestureEvent::Touchscreen) { | 321 fling_parameters_.sourceDevice == WebGestureEvent::Touchscreen) { |
| 310 input_handler_->ScrollEnd(); | 322 input_handler_->ScrollEnd(); |
| 311 TRACE_EVENT_ASYNC_END0( | 323 TRACE_EVENT_ASYNC_END0( |
| 312 "renderer", | 324 "renderer", |
| (...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 362 } | 374 } |
| 363 | 375 |
| 364 return false; | 376 return false; |
| 365 } | 377 } |
| 366 | 378 |
| 367 static gfx::Vector2dF ToClientScrollIncrement(const WebFloatSize& increment) { | 379 static gfx::Vector2dF ToClientScrollIncrement(const WebFloatSize& increment) { |
| 368 return gfx::Vector2dF(-increment.width, -increment.height); | 380 return gfx::Vector2dF(-increment.width, -increment.height); |
| 369 } | 381 } |
| 370 | 382 |
| 371 void InputHandlerProxy::scrollBy(const WebFloatSize& increment) { | 383 void InputHandlerProxy::scrollBy(const WebFloatSize& increment) { |
| 372 if (increment == WebFloatSize()) | 384 WebFloatSize clipped_increment; |
| 385 if (!fling_overscrolled_horizontally_) | |
| 386 clipped_increment.width = increment.width; | |
| 387 if (!fling_overscrolled_vertically_) | |
| 388 clipped_increment.height = increment.height; | |
| 389 | |
| 390 if (clipped_increment == WebFloatSize()) | |
| 373 return; | 391 return; |
| 374 | 392 |
| 375 TRACE_EVENT2("renderer", | 393 TRACE_EVENT2("renderer", |
| 376 "InputHandlerProxy::scrollBy", | 394 "InputHandlerProxy::scrollBy", |
| 377 "x", | 395 "x", |
| 378 increment.width, | 396 clipped_increment.width, |
| 379 "y", | 397 "y", |
| 380 increment.height); | 398 clipped_increment.height); |
| 381 | 399 |
| 382 bool did_scroll = false; | 400 bool did_scroll = false; |
| 383 | 401 |
| 384 switch (fling_parameters_.sourceDevice) { | 402 switch (fling_parameters_.sourceDevice) { |
| 385 case WebGestureEvent::Touchpad: | 403 case WebGestureEvent::Touchpad: |
| 386 did_scroll = TouchpadFlingScroll(increment); | 404 did_scroll = TouchpadFlingScroll(clipped_increment); |
| 387 break; | 405 break; |
| 388 case WebGestureEvent::Touchscreen: | 406 case WebGestureEvent::Touchscreen: |
| 407 clipped_increment = ToClientScrollIncrement(clipped_increment); | |
| 389 did_scroll = input_handler_->ScrollBy(fling_parameters_.point, | 408 did_scroll = input_handler_->ScrollBy(fling_parameters_.point, |
| 390 ToClientScrollIncrement(increment)); | 409 clipped_increment); |
| 391 break; | 410 break; |
| 392 } | 411 } |
| 393 | 412 |
| 394 if (did_scroll) { | 413 if (did_scroll) { |
| 395 fling_parameters_.cumulativeScroll.width += increment.width; | 414 fling_parameters_.cumulativeScroll.width += clipped_increment.width; |
| 396 fling_parameters_.cumulativeScroll.height += increment.height; | 415 fling_parameters_.cumulativeScroll.height += clipped_increment.height; |
| 397 } | 416 } |
| 398 } | 417 } |
| 399 | 418 |
| 400 void InputHandlerProxy::notifyCurrentFlingVelocity( | 419 void InputHandlerProxy::notifyCurrentFlingVelocity( |
| 401 const WebFloatSize& velocity) { | 420 const WebFloatSize& velocity) { |
| 402 TRACE_EVENT2("renderer", | 421 TRACE_EVENT2("renderer", |
| 403 "InputHandlerProxy::notifyCurrentFlingVelocity", | 422 "InputHandlerProxy::notifyCurrentFlingVelocity", |
| 404 "vx", | 423 "vx", |
| 405 velocity.width, | 424 velocity.width, |
| 406 "vy", | 425 "vy", |
| 407 velocity.height); | 426 velocity.height); |
| 408 input_handler_->NotifyCurrentFlingVelocity(ToClientScrollIncrement(velocity)); | 427 input_handler_->NotifyCurrentFlingVelocity(ToClientScrollIncrement(velocity)); |
| 409 } | 428 } |
| 410 | 429 |
| 411 } // namespace content | 430 } // namespace content |
| OLD | NEW |