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