OLD | NEW |
1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 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 "core/input/PointerEventManager.h" | 5 #include "core/input/PointerEventManager.h" |
6 | 6 |
7 #include "core/dom/ElementTraversal.h" | 7 #include "core/dom/ElementTraversal.h" |
8 #include "core/dom/shadow/FlatTreeTraversal.h" | 8 #include "core/dom/shadow/FlatTreeTraversal.h" |
9 #include "core/events/MouseEvent.h" | 9 #include "core/events/MouseEvent.h" |
10 #include "core/frame/FrameView.h" | 10 #include "core/frame/FrameView.h" |
(...skipping 437 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
448 } | 448 } |
449 } else { | 449 } else { |
450 // Set the target of pointer event to the captured node as this | 450 // Set the target of pointer event to the captured node as this |
451 // pointer is captured otherwise it would have gone to the if block | 451 // pointer is captured otherwise it would have gone to the if block |
452 // and perform a hit-test. | 452 // and perform a hit-test. |
453 touchInfo.touchNode = m_pendingPointerCaptureTarget | 453 touchInfo.touchNode = m_pendingPointerCaptureTarget |
454 .get(pointerId)->toNode(); | 454 .get(pointerId)->toNode(); |
455 touchInfo.targetFrame = touchInfo.touchNode->document().frame(); | 455 touchInfo.targetFrame = touchInfo.touchNode->document().frame(); |
456 } | 456 } |
457 | 457 |
458 WebInputEventResult result = WebInputEventResult::NotHandled; | |
459 | |
460 // Do not send pointer events for stationary touches or null targetFrame | 458 // Do not send pointer events for stationary touches or null targetFrame |
461 if (touchInfo.touchNode && touchInfo.targetFrame | 459 if (touchInfo.touchNode && touchInfo.targetFrame |
462 && touchPoint.state() != PlatformTouchPoint::TouchStationary | 460 && touchPoint.state() != PlatformTouchPoint::TouchStationary |
463 && !m_inCanceledStateForPointerTypeTouch) { | 461 && !m_inCanceledStateForPointerTypeTouch) { |
464 FloatPoint pagePoint = touchInfo.targetFrame->view() | 462 FloatPoint pagePoint = touchInfo.targetFrame->view() |
465 ->rootFrameToContents(touchInfo.point.pos()); | 463 ->rootFrameToContents(touchInfo.point.pos()); |
466 float scaleFactor = 1.0f / touchInfo.targetFrame->pageZoomFactor(); | 464 float scaleFactor = 1.0f / touchInfo.targetFrame->pageZoomFactor(); |
467 FloatPoint scrollPosition = touchInfo.targetFrame->view()->scrollPos
ition(); | 465 FloatPoint scrollPosition = touchInfo.targetFrame->view()->scrollPos
ition(); |
468 FloatPoint framePoint = pagePoint.scaledBy(scaleFactor); | 466 FloatPoint framePoint = pagePoint.scaledBy(scaleFactor); |
469 framePoint.moveBy(scrollPosition.scaledBy(-scaleFactor)); | 467 framePoint.moveBy(scrollPosition.scaledBy(-scaleFactor)); |
470 PointerEvent* pointerEvent = m_pointerEventFactory.create( | 468 PointerEvent* pointerEvent = m_pointerEventFactory.create( |
471 pointerEventNameForTouchPointState(touchPoint.state()), | 469 pointerEventNameForTouchPointState(touchPoint.state()), |
472 touchPoint, event.getModifiers(), | 470 touchPoint, event.getModifiers(), |
473 touchPoint.radius().scaledBy(scaleFactor), | 471 touchPoint.radius().scaledBy(scaleFactor), |
474 framePoint, | 472 framePoint, |
475 touchInfo.touchNode ? | 473 touchInfo.touchNode ? |
476 touchInfo.touchNode->document().domWindow() : nullptr); | 474 touchInfo.touchNode->document().domWindow() : nullptr); |
477 | 475 |
478 result = sendTouchPointerEvent(touchInfo.touchNode, pointerEvent); | 476 WebInputEventResult result = sendTouchPointerEvent(touchInfo.touchNo
de, pointerEvent); |
| 477 |
| 478 // If a pointerdown has been canceled, queue the unique id to allow |
| 479 // suppressing mouse events from gesture events. For mouse events |
| 480 // fired from GestureTap & GestureLongPress (which are triggered by |
| 481 // single touches only), it is enough to queue the ids only for |
| 482 // primary pointers. |
| 483 // TODO(mustaq): What about other cases (e.g. GestureTwoFingerTap)? |
| 484 if (result != WebInputEventResult::NotHandled |
| 485 && pointerEvent->type() == EventTypeNames::pointerdown |
| 486 && pointerEvent->isPrimary()) { |
| 487 m_touchIdsForCanceledPointerdowns.append(event.uniqueTouchEventI
d()); |
| 488 } |
479 } | 489 } |
480 // TODO(crbug.com/507408): Right now we add the touch point only if | 490 |
481 // its pointer event is NotHandled (e.g. preventDefault is called in | 491 touchInfos.append(touchInfo); |
482 // the pointer event listener). This behavior needs to change as it | |
483 // may create some inconsistent touch event sequence. | |
484 if (result == WebInputEventResult::NotHandled) { | |
485 touchInfos.append(touchInfo); | |
486 } | |
487 } | 492 } |
488 } | 493 } |
489 | 494 |
490 WebInputEventResult PointerEventManager::sendTouchPointerEvent( | 495 WebInputEventResult PointerEventManager::sendTouchPointerEvent( |
491 EventTarget* target, PointerEvent* pointerEvent) | 496 EventTarget* target, PointerEvent* pointerEvent) |
492 { | 497 { |
493 if (m_inCanceledStateForPointerTypeTouch) | 498 if (m_inCanceledStateForPointerTypeTouch) |
494 return WebInputEventResult::NotHandled; | 499 return WebInputEventResult::NotHandled; |
495 | 500 |
496 processCaptureAndPositionOfPointerEvent(pointerEvent, target); | 501 processCaptureAndPositionOfPointerEvent(pointerEvent, target); |
(...skipping 95 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
592 { | 597 { |
593 } | 598 } |
594 | 599 |
595 void PointerEventManager::clear() | 600 void PointerEventManager::clear() |
596 { | 601 { |
597 for (auto& entry : m_preventMouseEventForPointerType) | 602 for (auto& entry : m_preventMouseEventForPointerType) |
598 entry = false; | 603 entry = false; |
599 m_touchEventManager.clear(); | 604 m_touchEventManager.clear(); |
600 m_inCanceledStateForPointerTypeTouch = false; | 605 m_inCanceledStateForPointerTypeTouch = false; |
601 m_pointerEventFactory.clear(); | 606 m_pointerEventFactory.clear(); |
| 607 m_touchIdsForCanceledPointerdowns.clear(); |
602 m_nodeUnderPointer.clear(); | 608 m_nodeUnderPointer.clear(); |
603 m_pointerCaptureTarget.clear(); | 609 m_pointerCaptureTarget.clear(); |
604 m_pendingPointerCaptureTarget.clear(); | 610 m_pendingPointerCaptureTarget.clear(); |
605 } | 611 } |
606 | 612 |
607 void PointerEventManager::processCaptureAndPositionOfPointerEvent( | 613 void PointerEventManager::processCaptureAndPositionOfPointerEvent( |
608 PointerEvent* pointerEvent, | 614 PointerEvent* pointerEvent, |
609 EventTarget* hitTestTarget, | 615 EventTarget* hitTestTarget, |
610 EventTarget* lastNodeUnderMouse, | 616 EventTarget* lastNodeUnderMouse, |
611 const PlatformMouseEvent& mouseEvent, | 617 const PlatformMouseEvent& mouseEvent, |
(...skipping 155 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
767 bool PointerEventManager::isActive(const int pointerId) const | 773 bool PointerEventManager::isActive(const int pointerId) const |
768 { | 774 { |
769 return m_pointerEventFactory.isActive(pointerId); | 775 return m_pointerEventFactory.isActive(pointerId); |
770 } | 776 } |
771 | 777 |
772 bool PointerEventManager::isAnyTouchActive() const | 778 bool PointerEventManager::isAnyTouchActive() const |
773 { | 779 { |
774 return m_touchEventManager.isAnyTouchActive(); | 780 return m_touchEventManager.isAnyTouchActive(); |
775 } | 781 } |
776 | 782 |
| 783 bool PointerEventManager::primaryPointerdownCanceled(uint32_t uniqueTouchEventId
) |
| 784 { |
| 785 // It's safe to assume that uniqueTouchEventIds won't wrap back to 0 from |
| 786 // 2^32-1 (>4.2 billion): even with a generous 100 unique ids per touch |
| 787 // sequence & one sequence per 10 second, it takes 13+ years to wrap back. |
| 788 while (!m_touchIdsForCanceledPointerdowns.isEmpty()) { |
| 789 uint32_t firstId = m_touchIdsForCanceledPointerdowns.first(); |
| 790 if (firstId > uniqueTouchEventId) |
| 791 return false; |
| 792 m_touchIdsForCanceledPointerdowns.takeFirst(); |
| 793 if (firstId == uniqueTouchEventId) |
| 794 return true; |
| 795 } |
| 796 return false; |
| 797 } |
| 798 |
777 DEFINE_TRACE(PointerEventManager) | 799 DEFINE_TRACE(PointerEventManager) |
778 { | 800 { |
779 visitor->trace(m_frame); | 801 visitor->trace(m_frame); |
780 visitor->trace(m_nodeUnderPointer); | 802 visitor->trace(m_nodeUnderPointer); |
781 visitor->trace(m_pointerCaptureTarget); | 803 visitor->trace(m_pointerCaptureTarget); |
782 visitor->trace(m_pendingPointerCaptureTarget); | 804 visitor->trace(m_pendingPointerCaptureTarget); |
783 visitor->trace(m_touchEventManager); | 805 visitor->trace(m_touchEventManager); |
784 } | 806 } |
785 | 807 |
786 | 808 |
787 } // namespace blink | 809 } // namespace blink |
OLD | NEW |