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/public/platform/Platform.h" | 10 #include "third_party/WebKit/public/platform/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 172 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
215 switch (scroll_status) { | 217 switch (scroll_status) { |
216 case cc::InputHandler::ScrollStarted: { | 218 case cc::InputHandler::ScrollStarted: { |
217 if (gesture_event.sourceDevice == WebGestureEvent::Touchpad) | 219 if (gesture_event.sourceDevice == WebGestureEvent::Touchpad) |
218 input_handler_->ScrollEnd(); | 220 input_handler_->ScrollEnd(); |
219 | 221 |
220 fling_curve_.reset(client_->CreateFlingAnimationCurve( | 222 fling_curve_.reset(client_->CreateFlingAnimationCurve( |
221 gesture_event.sourceDevice, | 223 gesture_event.sourceDevice, |
222 WebFloatPoint(gesture_event.data.flingStart.velocityX, | 224 WebFloatPoint(gesture_event.data.flingStart.velocityX, |
223 gesture_event.data.flingStart.velocityY), | 225 gesture_event.data.flingStart.velocityY), |
224 WebKit::WebSize())); | 226 WebKit::WebSize())); |
| 227 fling_overscrolled_horizontally_ = false; |
| 228 fling_overscrolled_vertically_ = false; |
225 TRACE_EVENT_ASYNC_BEGIN0( | 229 TRACE_EVENT_ASYNC_BEGIN0( |
226 "renderer", | 230 "renderer", |
227 "InputHandlerProxy::HandleGestureFling::started", | 231 "InputHandlerProxy::HandleGestureFling::started", |
228 this); | 232 this); |
229 fling_parameters_.delta = | 233 fling_parameters_.delta = |
230 WebFloatPoint(gesture_event.data.flingStart.velocityX, | 234 WebFloatPoint(gesture_event.data.flingStart.velocityX, |
231 gesture_event.data.flingStart.velocityY); | 235 gesture_event.data.flingStart.velocityY); |
232 fling_parameters_.point = WebPoint(gesture_event.x, gesture_event.y); | 236 fling_parameters_.point = WebPoint(gesture_event.x, gesture_event.y); |
233 fling_parameters_.globalPoint = | 237 fling_parameters_.globalPoint = |
234 WebPoint(gesture_event.globalX, gesture_event.globalY); | 238 WebPoint(gesture_event.globalX, gesture_event.globalY); |
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
284 } | 288 } |
285 } | 289 } |
286 | 290 |
287 void InputHandlerProxy::MainThreadHasStoppedFlinging() { | 291 void InputHandlerProxy::MainThreadHasStoppedFlinging() { |
288 fling_may_be_active_on_main_thread_ = false; | 292 fling_may_be_active_on_main_thread_ = false; |
289 } | 293 } |
290 | 294 |
291 void InputHandlerProxy::DidOverscroll(gfx::Vector2dF accumulated_overscroll, | 295 void InputHandlerProxy::DidOverscroll(gfx::Vector2dF accumulated_overscroll, |
292 gfx::Vector2dF current_fling_velocity) { | 296 gfx::Vector2dF current_fling_velocity) { |
293 DCHECK(client_); | 297 DCHECK(client_); |
| 298 if (fling_curve_) { |
| 299 static const int kFlingOverscrollThreshold = 1; |
| 300 fling_overscrolled_horizontally_ |= |
| 301 std::abs(accumulated_overscroll.x()) >= kFlingOverscrollThreshold; |
| 302 fling_overscrolled_vertically_ |= |
| 303 std::abs(accumulated_overscroll.y()) >= kFlingOverscrollThreshold; |
| 304 } |
| 305 |
294 client_->DidOverscroll(accumulated_overscroll, current_fling_velocity); | 306 client_->DidOverscroll(accumulated_overscroll, current_fling_velocity); |
295 } | 307 } |
296 | 308 |
297 bool InputHandlerProxy::CancelCurrentFling() { | 309 bool InputHandlerProxy::CancelCurrentFling() { |
298 bool had_fling_animation = fling_curve_; | 310 bool had_fling_animation = fling_curve_; |
299 if (had_fling_animation && | 311 if (had_fling_animation && |
300 fling_parameters_.sourceDevice == WebGestureEvent::Touchscreen) { | 312 fling_parameters_.sourceDevice == WebGestureEvent::Touchscreen) { |
301 input_handler_->ScrollEnd(); | 313 input_handler_->ScrollEnd(); |
302 TRACE_EVENT_ASYNC_END0( | 314 TRACE_EVENT_ASYNC_END0( |
303 "renderer", | 315 "renderer", |
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
353 } | 365 } |
354 | 366 |
355 return false; | 367 return false; |
356 } | 368 } |
357 | 369 |
358 static gfx::Vector2dF ToClientScrollIncrement(const WebFloatSize& increment) { | 370 static gfx::Vector2dF ToClientScrollIncrement(const WebFloatSize& increment) { |
359 return gfx::Vector2dF(-increment.width, -increment.height); | 371 return gfx::Vector2dF(-increment.width, -increment.height); |
360 } | 372 } |
361 | 373 |
362 void InputHandlerProxy::scrollBy(const WebFloatSize& increment) { | 374 void InputHandlerProxy::scrollBy(const WebFloatSize& increment) { |
363 if (increment == WebFloatSize()) | 375 WebFloatSize clipped_increment; |
| 376 if (!fling_overscrolled_horizontally_) |
| 377 clipped_increment.width = increment.width; |
| 378 if (!fling_overscrolled_vertically_) |
| 379 clipped_increment.height = increment.height; |
| 380 |
| 381 if (clipped_increment == WebFloatSize()) |
364 return; | 382 return; |
365 | 383 |
366 TRACE_EVENT2("renderer", | 384 TRACE_EVENT2("renderer", |
367 "InputHandlerProxy::scrollBy", | 385 "InputHandlerProxy::scrollBy", |
368 "x", | 386 "x", |
369 increment.width, | 387 clipped_increment.width, |
370 "y", | 388 "y", |
371 increment.height); | 389 clipped_increment.height); |
372 | 390 |
373 bool did_scroll = false; | 391 bool did_scroll = false; |
374 | 392 |
375 switch (fling_parameters_.sourceDevice) { | 393 switch (fling_parameters_.sourceDevice) { |
376 case WebGestureEvent::Touchpad: | 394 case WebGestureEvent::Touchpad: |
377 did_scroll = TouchpadFlingScroll(increment); | 395 did_scroll = TouchpadFlingScroll(clipped_increment); |
378 break; | 396 break; |
379 case WebGestureEvent::Touchscreen: | 397 case WebGestureEvent::Touchscreen: |
| 398 clipped_increment = ToClientScrollIncrement(clipped_increment); |
380 did_scroll = input_handler_->ScrollBy(fling_parameters_.point, | 399 did_scroll = input_handler_->ScrollBy(fling_parameters_.point, |
381 ToClientScrollIncrement(increment)); | 400 clipped_increment); |
382 break; | 401 break; |
383 } | 402 } |
384 | 403 |
385 if (did_scroll) { | 404 if (did_scroll) { |
386 fling_parameters_.cumulativeScroll.width += increment.width; | 405 fling_parameters_.cumulativeScroll.width += clipped_increment.width; |
387 fling_parameters_.cumulativeScroll.height += increment.height; | 406 fling_parameters_.cumulativeScroll.height += clipped_increment.height; |
388 } | 407 } |
389 } | 408 } |
390 | 409 |
391 void InputHandlerProxy::notifyCurrentFlingVelocity( | 410 void InputHandlerProxy::notifyCurrentFlingVelocity( |
392 const WebFloatSize& velocity) { | 411 const WebFloatSize& velocity) { |
393 TRACE_EVENT2("renderer", | 412 TRACE_EVENT2("renderer", |
394 "InputHandlerProxy::notifyCurrentFlingVelocity", | 413 "InputHandlerProxy::notifyCurrentFlingVelocity", |
395 "vx", | 414 "vx", |
396 velocity.width, | 415 velocity.width, |
397 "vy", | 416 "vy", |
398 velocity.height); | 417 velocity.height); |
399 input_handler_->NotifyCurrentFlingVelocity(ToClientScrollIncrement(velocity)); | 418 input_handler_->NotifyCurrentFlingVelocity(ToClientScrollIncrement(velocity)); |
400 } | 419 } |
401 | 420 |
402 } // namespace content | 421 } // namespace content |
OLD | NEW |