| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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 "ui/events/gesture_detection/gesture_provider.h" | 5 #include "ui/events/gesture_detection/gesture_provider.h" |
| 6 | 6 |
| 7 #include <cmath> | 7 #include <cmath> |
| 8 | 8 |
| 9 #include "base/auto_reset.h" | 9 #include "base/auto_reset.h" |
| 10 #include "base/debug/trace_event.h" | 10 #include "base/debug/trace_event.h" |
| (...skipping 227 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 238 // diminish as the touch moves away from the original double-tap focus. | 238 // diminish as the touch moves away from the original double-tap focus. |
| 239 // For historical reasons, Chrome has instead adopted a scale factor | 239 // For historical reasons, Chrome has instead adopted a scale factor |
| 240 // computation that is invariant to the focal distance, where | 240 // computation that is invariant to the focal distance, where |
| 241 // the scale delta remains constant if the touch velocity is constant. | 241 // the scale delta remains constant if the touch velocity is constant. |
| 242 float dy = | 242 float dy = |
| 243 (detector.GetCurrentSpanY() - detector.GetPreviousSpanY()) * 0.5f; | 243 (detector.GetCurrentSpanY() - detector.GetPreviousSpanY()) * 0.5f; |
| 244 scale = std::pow(scale > 1 ? 1.0f + kDoubleTapDragZoomSpeed | 244 scale = std::pow(scale > 1 ? 1.0f + kDoubleTapDragZoomSpeed |
| 245 : 1.0f - kDoubleTapDragZoomSpeed, | 245 : 1.0f - kDoubleTapDragZoomSpeed, |
| 246 std::abs(dy)); | 246 std::abs(dy)); |
| 247 } | 247 } |
| 248 GestureEventDetails pinch_details(ET_GESTURE_PINCH_UPDATE, scale, 0); | 248 GestureEventDetails pinch_details(ET_GESTURE_PINCH_UPDATE); |
| 249 pinch_details.set_scale(scale); |
| 249 Send(CreateGesture(pinch_details, | 250 Send(CreateGesture(pinch_details, |
| 250 e.GetId(), | 251 e.GetId(), |
| 251 e.GetToolType(), | 252 e.GetToolType(), |
| 252 detector.GetEventTime(), | 253 detector.GetEventTime(), |
| 253 detector.GetFocusX(), | 254 detector.GetFocusX(), |
| 254 detector.GetFocusY(), | 255 detector.GetFocusY(), |
| 255 detector.GetFocusX() + e.GetRawOffsetX(), | 256 detector.GetFocusX() + e.GetRawOffsetX(), |
| 256 detector.GetFocusY() + e.GetRawOffsetY(), | 257 detector.GetFocusY() + e.GetRawOffsetY(), |
| 257 e.GetPointerCount(), | 258 e.GetPointerCount(), |
| 258 GetBoundingBox(e, pinch_details.type()))); | 259 GetBoundingBox(e, pinch_details.type()))); |
| 259 return true; | 260 return true; |
| 260 } | 261 } |
| 261 | 262 |
| 262 // GestureDetector::GestureListener implementation. | 263 // GestureDetector::GestureListener implementation. |
| 263 virtual bool OnDown(const MotionEvent& e) OVERRIDE { | 264 virtual bool OnDown(const MotionEvent& e) OVERRIDE { |
| 264 GestureEventDetails tap_details(ET_GESTURE_TAP_DOWN, 0, 0); | 265 GestureEventDetails tap_details(ET_GESTURE_TAP_DOWN); |
| 265 Send(CreateGesture(tap_details, e)); | 266 Send(CreateGesture(tap_details, e)); |
| 266 | 267 |
| 267 // Return true to indicate that we want to handle touch. | 268 // Return true to indicate that we want to handle touch. |
| 268 return true; | 269 return true; |
| 269 } | 270 } |
| 270 | 271 |
| 271 virtual bool OnScroll(const MotionEvent& e1, | 272 virtual bool OnScroll(const MotionEvent& e1, |
| 272 const MotionEvent& e2, | 273 const MotionEvent& e2, |
| 273 float raw_distance_x, | 274 float raw_distance_x, |
| 274 float raw_distance_y) OVERRIDE { | 275 float raw_distance_y) OVERRIDE { |
| (...skipping 116 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 391 e1.GetX(), | 392 e1.GetX(), |
| 392 e1.GetY(), | 393 e1.GetY(), |
| 393 e1.GetRawX(), | 394 e1.GetRawX(), |
| 394 e1.GetRawY(), | 395 e1.GetRawY(), |
| 395 e2.GetPointerCount(), | 396 e2.GetPointerCount(), |
| 396 GetBoundingBox(e2, two_finger_tap_details.type()))); | 397 GetBoundingBox(e2, two_finger_tap_details.type()))); |
| 397 return true; | 398 return true; |
| 398 } | 399 } |
| 399 | 400 |
| 400 virtual void OnShowPress(const MotionEvent& e) OVERRIDE { | 401 virtual void OnShowPress(const MotionEvent& e) OVERRIDE { |
| 401 GestureEventDetails show_press_details(ET_GESTURE_SHOW_PRESS, 0, 0); | 402 GestureEventDetails show_press_details(ET_GESTURE_SHOW_PRESS); |
| 402 show_press_event_sent_ = true; | 403 show_press_event_sent_ = true; |
| 403 Send(CreateGesture(show_press_details, e)); | 404 Send(CreateGesture(show_press_details, e)); |
| 404 } | 405 } |
| 405 | 406 |
| 406 virtual bool OnSingleTapUp(const MotionEvent& e) OVERRIDE { | 407 virtual bool OnSingleTapUp(const MotionEvent& e) OVERRIDE { |
| 407 // This is a hack to address the issue where user hovers | 408 // This is a hack to address the issue where user hovers |
| 408 // over a link for longer than double_tap_timeout_, then | 409 // over a link for longer than double_tap_timeout_, then |
| 409 // OnSingleTapConfirmed() is not triggered. But we still | 410 // OnSingleTapConfirmed() is not triggered. But we still |
| 410 // want to trigger the tap event at UP. So we override | 411 // want to trigger the tap event at UP. So we override |
| 411 // OnSingleTapUp() in this case. This assumes singleTapUp | 412 // OnSingleTapUp() in this case. This assumes singleTapUp |
| 412 // gets always called before singleTapConfirmed. | 413 // gets always called before singleTapConfirmed. |
| 413 if (!ignore_single_tap_) { | 414 if (!ignore_single_tap_) { |
| 414 if (e.GetEventTime() - current_down_time_ > | 415 if (e.GetEventTime() - current_down_time_ > |
| 415 config_.gesture_detector_config.double_tap_timeout) { | 416 config_.gesture_detector_config.double_tap_timeout) { |
| 416 return OnSingleTapConfirmed(e); | 417 return OnSingleTapConfirmed(e); |
| 417 } else if (!IsDoubleTapEnabled() || config_.disable_click_delay) { | 418 } else if (!IsDoubleTapEnabled() || config_.disable_click_delay) { |
| 418 // If double-tap has been disabled, there is no need to wait | 419 // If double-tap has been disabled, there is no need to wait |
| 419 // for the double-tap timeout. | 420 // for the double-tap timeout. |
| 420 return OnSingleTapConfirmed(e); | 421 return OnSingleTapConfirmed(e); |
| 421 } else { | 422 } else { |
| 422 // Notify Blink about this tapUp event anyway, when none of the above | 423 // Notify Blink about this tapUp event anyway, when none of the above |
| 423 // conditions applied. | 424 // conditions applied. |
| 424 Send(CreateTapGesture(ET_GESTURE_TAP_UNCONFIRMED, e)); | 425 Send(CreateTapGesture(ET_GESTURE_TAP_UNCONFIRMED, e)); |
| 425 } | 426 } |
| 426 } | 427 } |
| 427 | 428 |
| 428 if (e.GetAction() == MotionEvent::ACTION_UP && | 429 if (e.GetAction() == MotionEvent::ACTION_UP && |
| 429 !current_longpress_time_.is_null() && | 430 !current_longpress_time_.is_null() && |
| 430 !IsScaleGestureDetectionInProgress()) { | 431 !IsScaleGestureDetectionInProgress()) { |
| 431 GestureEventDetails long_tap_details(ET_GESTURE_LONG_TAP, 0, 0); | 432 GestureEventDetails long_tap_details(ET_GESTURE_LONG_TAP); |
| 432 Send(CreateGesture(long_tap_details, e)); | 433 Send(CreateGesture(long_tap_details, e)); |
| 433 return true; | 434 return true; |
| 434 } | 435 } |
| 435 | 436 |
| 436 return false; | 437 return false; |
| 437 } | 438 } |
| 438 | 439 |
| 439 // GestureDetector::DoubleTapListener implementation. | 440 // GestureDetector::DoubleTapListener implementation. |
| 440 virtual bool OnSingleTapConfirmed(const MotionEvent& e) OVERRIDE { | 441 virtual bool OnSingleTapConfirmed(const MotionEvent& e) OVERRIDE { |
| 441 // Long taps in the edges of the screen have their events delayed by | 442 // Long taps in the edges of the screen have their events delayed by |
| (...skipping 28 matching lines...) Expand all Loading... |
| 470 | 471 |
| 471 default: | 472 default: |
| 472 break; | 473 break; |
| 473 } | 474 } |
| 474 return false; | 475 return false; |
| 475 } | 476 } |
| 476 | 477 |
| 477 virtual void OnLongPress(const MotionEvent& e) OVERRIDE { | 478 virtual void OnLongPress(const MotionEvent& e) OVERRIDE { |
| 478 DCHECK(!IsDoubleTapInProgress()); | 479 DCHECK(!IsDoubleTapInProgress()); |
| 479 SetIgnoreSingleTap(true); | 480 SetIgnoreSingleTap(true); |
| 480 GestureEventDetails long_press_details(ET_GESTURE_LONG_PRESS, 0, 0); | 481 GestureEventDetails long_press_details(ET_GESTURE_LONG_PRESS); |
| 481 Send(CreateGesture(long_press_details, e)); | 482 Send(CreateGesture(long_press_details, e)); |
| 482 } | 483 } |
| 483 | 484 |
| 484 GestureEventData CreateGesture(const GestureEventDetails& details, | 485 GestureEventData CreateGesture(const GestureEventDetails& details, |
| 485 int motion_event_id, | 486 int motion_event_id, |
| 486 MotionEvent::ToolType primary_tool_type, | 487 MotionEvent::ToolType primary_tool_type, |
| 487 base::TimeTicks time, | 488 base::TimeTicks time, |
| 488 float x, | 489 float x, |
| 489 float y, | 490 float y, |
| 490 float raw_x, | 491 float raw_x, |
| (...skipping 15 matching lines...) Expand all Loading... |
| 506 GestureEventData CreateGesture(EventType type, | 507 GestureEventData CreateGesture(EventType type, |
| 507 int motion_event_id, | 508 int motion_event_id, |
| 508 MotionEvent::ToolType primary_tool_type, | 509 MotionEvent::ToolType primary_tool_type, |
| 509 base::TimeTicks time, | 510 base::TimeTicks time, |
| 510 float x, | 511 float x, |
| 511 float y, | 512 float y, |
| 512 float raw_x, | 513 float raw_x, |
| 513 float raw_y, | 514 float raw_y, |
| 514 size_t touch_point_count, | 515 size_t touch_point_count, |
| 515 const gfx::RectF& bounding_box) { | 516 const gfx::RectF& bounding_box) { |
| 516 return GestureEventData(GestureEventDetails(type, 0, 0), | 517 return GestureEventData(GestureEventDetails(type), |
| 517 motion_event_id, | 518 motion_event_id, |
| 518 primary_tool_type, | 519 primary_tool_type, |
| 519 time, | 520 time, |
| 520 x, | 521 x, |
| 521 y, | 522 y, |
| 522 raw_x, | 523 raw_x, |
| 523 raw_y, | 524 raw_y, |
| 524 touch_point_count, | 525 touch_point_count, |
| 525 bounding_box); | 526 bounding_box); |
| 526 } | 527 } |
| 527 | 528 |
| 528 GestureEventData CreateGesture(const GestureEventDetails& details, | 529 GestureEventData CreateGesture(const GestureEventDetails& details, |
| 529 const MotionEvent& event) { | 530 const MotionEvent& event) { |
| 530 return GestureEventData(details, | 531 return GestureEventData(details, |
| 531 event.GetId(), | 532 event.GetId(), |
| 532 event.GetToolType(), | 533 event.GetToolType(), |
| 533 event.GetEventTime(), | 534 event.GetEventTime(), |
| 534 event.GetX(), | 535 event.GetX(), |
| 535 event.GetY(), | 536 event.GetY(), |
| 536 event.GetRawX(), | 537 event.GetRawX(), |
| 537 event.GetRawY(), | 538 event.GetRawY(), |
| 538 event.GetPointerCount(), | 539 event.GetPointerCount(), |
| 539 GetBoundingBox(event, details.type())); | 540 GetBoundingBox(event, details.type())); |
| 540 } | 541 } |
| 541 | 542 |
| 542 GestureEventData CreateGesture(EventType type, const MotionEvent& event) { | 543 GestureEventData CreateGesture(EventType type, const MotionEvent& event) { |
| 543 return CreateGesture(GestureEventDetails(type, 0, 0), event); | 544 return CreateGesture(GestureEventDetails(type), event); |
| 544 } | 545 } |
| 545 | 546 |
| 546 GestureEventData CreateTapGesture(EventType type, const MotionEvent& event) { | 547 GestureEventData CreateTapGesture(EventType type, const MotionEvent& event) { |
| 547 // Set the tap count to 1 even for ET_GESTURE_DOUBLE_TAP, in order to be | 548 // Set the tap count to 1 even for ET_GESTURE_DOUBLE_TAP, in order to be |
| 548 // consistent with double tap behavior on a mobile viewport. See | 549 // consistent with double tap behavior on a mobile viewport. See |
| 549 // crbug.com/234986 for context. | 550 // crbug.com/234986 for context. |
| 550 return CreateGesture(GestureEventDetails(type, 1, 0), event); | 551 GestureEventDetails details(type); |
| 552 details.set_tap_count(1); |
| 553 return CreateGesture(details, event); |
| 551 } | 554 } |
| 552 | 555 |
| 553 gfx::RectF GetBoundingBox(const MotionEvent& event, EventType type) { | 556 gfx::RectF GetBoundingBox(const MotionEvent& event, EventType type) { |
| 554 // Can't use gfx::RectF::Union, as it ignores touches with a radius of 0. | 557 // Can't use gfx::RectF::Union, as it ignores touches with a radius of 0. |
| 555 float left = std::numeric_limits<float>::max(); | 558 float left = std::numeric_limits<float>::max(); |
| 556 float top = std::numeric_limits<float>::max(); | 559 float top = std::numeric_limits<float>::max(); |
| 557 float right = -std::numeric_limits<float>::max(); | 560 float right = -std::numeric_limits<float>::max(); |
| 558 float bottom = -std::numeric_limits<float>::max(); | 561 float bottom = -std::numeric_limits<float>::max(); |
| 559 for (size_t i = 0; i < event.GetPointerCount(); ++i) { | 562 for (size_t i = 0; i < event.GetPointerCount(); ++i) { |
| 560 float x, y, diameter; | 563 float x, y, diameter; |
| (...skipping 237 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 798 // null'ing of the listener until the sequence has ended. | 801 // null'ing of the listener until the sequence has ended. |
| 799 if (current_down_event_) | 802 if (current_down_event_) |
| 800 return; | 803 return; |
| 801 | 804 |
| 802 const bool double_tap_enabled = | 805 const bool double_tap_enabled = |
| 803 double_tap_support_for_page_ && double_tap_support_for_platform_; | 806 double_tap_support_for_page_ && double_tap_support_for_platform_; |
| 804 gesture_listener_->SetDoubleTapEnabled(double_tap_enabled); | 807 gesture_listener_->SetDoubleTapEnabled(double_tap_enabled); |
| 805 } | 808 } |
| 806 | 809 |
| 807 } // namespace ui | 810 } // namespace ui |
| OLD | NEW |