Chromium Code Reviews| 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 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 47 float x = event.GetX(i) - diameter / 2; | 47 float x = event.GetX(i) - diameter / 2; |
| 48 float y = event.GetY(i) - diameter / 2; | 48 float y = event.GetY(i) - diameter / 2; |
| 49 left = std::min(left, x); | 49 left = std::min(left, x); |
| 50 right = std::max(right, x + diameter); | 50 right = std::max(right, x + diameter); |
| 51 top = std::min(top, y); | 51 top = std::min(top, y); |
| 52 bottom = std::max(bottom, y + diameter); | 52 bottom = std::max(bottom, y + diameter); |
| 53 } | 53 } |
| 54 return gfx::RectF(left, top, right - left, bottom - top); | 54 return gfx::RectF(left, top, right - left, bottom - top); |
| 55 } | 55 } |
| 56 | 56 |
| 57 gfx::RectF GetBoundingBox(float x, float y, float max_diameter) { | |
| 58 // Can't use gfx::RectF::Union, as it ignores touches with a radius of 0. | |
| 59 float left = x - max_diameter / 2; | |
| 60 float top = y - max_diameter / 2; | |
| 61 return gfx::RectF(left, top, max_diameter, max_diameter); | |
| 62 } | |
| 63 | |
| 57 GestureEventData CreateGesture(const GestureEventDetails& details, | 64 GestureEventData CreateGesture(const GestureEventDetails& details, |
| 58 int motion_event_id, | 65 int motion_event_id, |
| 59 MotionEvent::ToolType primary_tool_type, | 66 MotionEvent::ToolType primary_tool_type, |
| 60 base::TimeTicks time, | 67 base::TimeTicks time, |
| 61 float x, | 68 float x, |
| 62 float y, | 69 float y, |
| 63 float raw_x, | 70 float raw_x, |
| 64 float raw_y, | 71 float raw_y, |
| 65 size_t touch_point_count, | 72 size_t touch_point_count, |
| 66 const gfx::RectF& bounding_box) { | 73 const gfx::RectF& bounding_box) { |
| (...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 109 event.GetRawX(), | 116 event.GetRawX(), |
| 110 event.GetRawY(), | 117 event.GetRawY(), |
| 111 event.GetPointerCount(), | 118 event.GetPointerCount(), |
| 112 GetBoundingBox(event)); | 119 GetBoundingBox(event)); |
| 113 } | 120 } |
| 114 | 121 |
| 115 GestureEventData CreateGesture(EventType type, const MotionEvent& event) { | 122 GestureEventData CreateGesture(EventType type, const MotionEvent& event) { |
| 116 return CreateGesture(GestureEventDetails(type, 0, 0), event); | 123 return CreateGesture(GestureEventDetails(type, 0, 0), event); |
| 117 } | 124 } |
| 118 | 125 |
| 126 GestureEventData CreateGesture(const GestureEventDetails& details, | |
|
tdresser
2014/09/04 13:54:00
Hmmm, I don't really like adding even more |Create
| |
| 127 const MotionEvent& event, | |
| 128 float max_diameter) { | |
| 129 return GestureEventData( | |
| 130 details, | |
| 131 event.GetId(), | |
| 132 event.GetToolType(), | |
| 133 event.GetEventTime(), | |
| 134 event.GetX(), | |
| 135 event.GetY(), | |
| 136 event.GetRawX(), | |
| 137 event.GetRawY(), | |
| 138 event.GetPointerCount(), | |
| 139 GetBoundingBox(event.GetX(), event.GetY(), max_diameter)); | |
| 140 } | |
| 141 | |
| 142 GestureEventData CreateGesture(const GestureEventDetails& details, | |
| 143 const MotionEvent& event, | |
| 144 float x, | |
| 145 float y, | |
| 146 float max_diameter) { | |
| 147 return GestureEventData(details, | |
| 148 event.GetId(), | |
| 149 event.GetToolType(), | |
| 150 event.GetEventTime(), | |
| 151 event.GetX(), | |
| 152 event.GetY(), | |
| 153 event.GetRawX(), | |
| 154 event.GetRawY(), | |
| 155 event.GetPointerCount(), | |
| 156 GetBoundingBox(x, y, max_diameter)); | |
| 157 } | |
| 158 | |
| 159 GestureEventData CreateTapGesture(EventType type, | |
| 160 const MotionEvent& event, | |
| 161 float x, | |
| 162 float y, | |
| 163 float max_diameter) { | |
| 164 return CreateGesture( | |
| 165 GestureEventDetails(type, 1, 0), event, x, y, max_diameter); | |
| 166 } | |
| 167 | |
| 119 GestureEventData CreateTapGesture(EventType type, const MotionEvent& event) { | 168 GestureEventData CreateTapGesture(EventType type, const MotionEvent& event) { |
| 120 // Set the tap count to 1 even for ET_GESTURE_DOUBLE_TAP, in order to be | 169 // Set the tap count to 1 even for ET_GESTURE_DOUBLE_TAP, in order to be |
| 121 // consistent with double tap behavior on a mobile viewport. See | 170 // consistent with double tap behavior on a mobile viewport. See |
| 122 // crbug.com/234986 for context. | 171 // crbug.com/234986 for context. |
| 123 return CreateGesture(GestureEventDetails(type, 1, 0), event); | 172 return CreateGesture(GestureEventDetails(type, 1, 0), event); |
| 124 } | 173 } |
| 125 | 174 |
| 126 gfx::RectF ClampBoundingBox(const gfx::RectF& bounds, | 175 gfx::RectF ClampBoundingBox(const gfx::RectF& bounds, |
| 127 float min_length, | 176 float min_length, |
| 128 float max_length) { | 177 float max_length) { |
| (...skipping 336 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 465 e2.GetEventTime(), | 514 e2.GetEventTime(), |
| 466 e1.GetX(), | 515 e1.GetX(), |
| 467 e1.GetY(), | 516 e1.GetY(), |
| 468 e1.GetRawX(), | 517 e1.GetRawX(), |
| 469 e1.GetRawY(), | 518 e1.GetRawY(), |
| 470 e2.GetPointerCount(), | 519 e2.GetPointerCount(), |
| 471 GetBoundingBox(e2))); | 520 GetBoundingBox(e2))); |
| 472 return true; | 521 return true; |
| 473 } | 522 } |
| 474 | 523 |
| 475 virtual void OnShowPress(const MotionEvent& e) OVERRIDE { | 524 virtual void OnShowPress(const MotionEvent& e, float max_diameter) OVERRIDE { |
| 476 GestureEventDetails show_press_details(ET_GESTURE_SHOW_PRESS, 0, 0); | 525 GestureEventDetails show_press_details(ET_GESTURE_SHOW_PRESS, 0, 0); |
| 477 Send(CreateGesture(show_press_details, e)); | 526 Send(CreateGesture(show_press_details, e, max_diameter)); |
| 478 } | 527 } |
| 479 | 528 |
| 480 virtual bool OnSingleTapUp(const MotionEvent& e) OVERRIDE { | 529 virtual bool OnSingleTapUp(const MotionEvent& e, |
| 530 float x, | |
| 531 float y, | |
| 532 float max_diameter) OVERRIDE { | |
| 481 // This is a hack to address the issue where user hovers | 533 // This is a hack to address the issue where user hovers |
| 482 // over a link for longer than double_tap_timeout_, then | 534 // over a link for longer than double_tap_timeout_, then |
| 483 // OnSingleTapConfirmed() is not triggered. But we still | 535 // OnSingleTapConfirmed() is not triggered. But we still |
| 484 // want to trigger the tap event at UP. So we override | 536 // want to trigger the tap event at UP. So we override |
| 485 // OnSingleTapUp() in this case. This assumes singleTapUp | 537 // OnSingleTapUp() in this case. This assumes singleTapUp |
| 486 // gets always called before singleTapConfirmed. | 538 // gets always called before singleTapConfirmed. |
| 487 if (!ignore_single_tap_) { | 539 if (!ignore_single_tap_) { |
| 488 if (e.GetEventTime() - current_down_time_ > | 540 if (e.GetEventTime() - current_down_time_ > |
| 489 config_.gesture_detector_config.double_tap_timeout) { | 541 config_.gesture_detector_config.double_tap_timeout) { |
| 490 return OnSingleTapConfirmed(e); | 542 return OnSingleTapConfirmed(e, x, y, max_diameter); |
| 491 } else if (!IsDoubleTapEnabled() || config_.disable_click_delay) { | 543 } else if (!IsDoubleTapEnabled() || config_.disable_click_delay) { |
| 492 // If double-tap has been disabled, there is no need to wait | 544 // If double-tap has been disabled, there is no need to wait |
| 493 // for the double-tap timeout. | 545 // for the double-tap timeout. |
| 494 return OnSingleTapConfirmed(e); | 546 return OnSingleTapConfirmed(e, x, y, max_diameter); |
| 495 } else { | 547 } else { |
| 496 // Notify Blink about this tapUp event anyway, when none of the above | 548 // Notify Blink about this tapUp event anyway, when none of the above |
| 497 // conditions applied. | 549 // conditions applied. |
| 498 Send(CreateTapGesture(ET_GESTURE_TAP_UNCONFIRMED, e)); | 550 Send(CreateTapGesture( |
| 551 ET_GESTURE_TAP_UNCONFIRMED, e, x, y, max_diameter)); | |
|
tdresser
2014/09/04 13:54:01
Add a space to line up with "Create"
| |
| 499 } | 552 } |
| 500 } | 553 } |
| 501 | 554 |
| 502 if (e.GetAction() == MotionEvent::ACTION_UP && | 555 if (e.GetAction() == MotionEvent::ACTION_UP && |
| 503 !current_longpress_time_.is_null() && | 556 !current_longpress_time_.is_null() && |
| 504 !IsScaleGestureDetectionInProgress()) { | 557 !IsScaleGestureDetectionInProgress()) { |
| 505 GestureEventDetails long_tap_details(ET_GESTURE_LONG_TAP, 0, 0); | 558 GestureEventDetails long_tap_details(ET_GESTURE_LONG_TAP, 0, 0); |
| 506 Send(CreateGesture(long_tap_details, e)); | 559 Send(CreateGesture(long_tap_details, e)); |
| 507 return true; | 560 return true; |
| 508 } | 561 } |
| 509 | 562 |
| 510 return false; | 563 return false; |
| 511 } | 564 } |
| 512 | 565 |
| 513 // GestureDetector::DoubleTapListener implementation. | 566 // GestureDetector::DoubleTapListener implementation. |
| 514 virtual bool OnSingleTapConfirmed(const MotionEvent& e) OVERRIDE { | 567 virtual bool OnSingleTapConfirmed(const MotionEvent& e, |
| 568 float x, | |
| 569 float y, | |
| 570 float max_diameter) OVERRIDE { | |
| 515 // Long taps in the edges of the screen have their events delayed by | 571 // Long taps in the edges of the screen have their events delayed by |
| 516 // ContentViewHolder for tab swipe operations. As a consequence of the delay | 572 // ContentViewHolder for tab swipe operations. As a consequence of the delay |
| 517 // this method might be called after receiving the up event. | 573 // this method might be called after receiving the up event. |
| 518 // These corner cases should be ignored. | 574 // These corner cases should be ignored. |
| 519 if (ignore_single_tap_) | 575 if (ignore_single_tap_) |
| 520 return true; | 576 return true; |
| 521 | 577 |
| 522 ignore_single_tap_ = true; | 578 ignore_single_tap_ = true; |
| 523 | 579 |
| 524 Send(CreateTapGesture(ET_GESTURE_TAP, e)); | 580 Send(CreateTapGesture(ET_GESTURE_TAP, e, x, y, max_diameter)); |
| 525 return true; | 581 return true; |
| 526 } | 582 } |
| 527 | 583 |
| 528 virtual bool OnDoubleTap(const MotionEvent& e) OVERRIDE { | 584 virtual bool OnDoubleTap(const MotionEvent& e) OVERRIDE { |
| 529 return scale_gesture_detector_.OnDoubleTap(e); | 585 return scale_gesture_detector_.OnDoubleTap(e); |
| 530 } | 586 } |
| 531 | 587 |
| 532 virtual bool OnDoubleTapEvent(const MotionEvent& e) OVERRIDE { | 588 virtual bool OnDoubleTapEvent(const MotionEvent& e) OVERRIDE { |
| 533 switch (e.GetAction()) { | 589 switch (e.GetAction()) { |
| 534 case MotionEvent::ACTION_DOWN: | 590 case MotionEvent::ACTION_DOWN: |
| (...skipping 221 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 756 // null'ing of the listener until the sequence has ended. | 812 // null'ing of the listener until the sequence has ended. |
| 757 if (current_down_event_) | 813 if (current_down_event_) |
| 758 return; | 814 return; |
| 759 | 815 |
| 760 const bool double_tap_enabled = | 816 const bool double_tap_enabled = |
| 761 double_tap_support_for_page_ && double_tap_support_for_platform_; | 817 double_tap_support_for_page_ && double_tap_support_for_platform_; |
| 762 gesture_listener_->SetDoubleTapEnabled(double_tap_enabled); | 818 gesture_listener_->SetDoubleTapEnabled(double_tap_enabled); |
| 763 } | 819 } |
| 764 | 820 |
| 765 } // namespace ui | 821 } // namespace ui |
| OLD | NEW |