Chromium Code Reviews| 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 436 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 447 } | 447 } |
| 448 } else { | 448 } else { |
| 449 // Set the target of pointer event to the captured node as this | 449 // Set the target of pointer event to the captured node as this |
| 450 // pointer is captured otherwise it would have gone to the if block | 450 // pointer is captured otherwise it would have gone to the if block |
| 451 // and perform a hit-test. | 451 // and perform a hit-test. |
| 452 touchInfo.touchNode = m_pendingPointerCaptureTarget | 452 touchInfo.touchNode = m_pendingPointerCaptureTarget |
| 453 .get(pointerId)->toNode(); | 453 .get(pointerId)->toNode(); |
| 454 touchInfo.targetFrame = touchInfo.touchNode->document().frame(); | 454 touchInfo.targetFrame = touchInfo.touchNode->document().frame(); |
| 455 } | 455 } |
| 456 | 456 |
| 457 WebInputEventResult result = WebInputEventResult::NotHandled; | |
| 458 | |
| 459 // Do not send pointer events for stationary touches or null targetFrame | 457 // Do not send pointer events for stationary touches or null targetFrame |
| 460 if (touchInfo.touchNode | 458 if (touchInfo.touchNode |
| 461 && touchPoint.state() != PlatformTouchPoint::TouchStationary | 459 && touchPoint.state() != PlatformTouchPoint::TouchStationary |
| 462 && !m_inCanceledStateForPointerTypeTouch) { | 460 && !m_inCanceledStateForPointerTypeTouch) { |
| 463 FloatPoint pagePoint = touchInfo.targetFrame->view() | 461 FloatPoint pagePoint = touchInfo.targetFrame->view() |
| 464 ->rootFrameToContents(touchInfo.point.pos()); | 462 ->rootFrameToContents(touchInfo.point.pos()); |
| 465 float scaleFactor = 1.0f / touchInfo.targetFrame->pageZoomFactor(); | 463 float scaleFactor = 1.0f / touchInfo.targetFrame->pageZoomFactor(); |
| 466 FloatPoint scrollPosition = touchInfo.targetFrame->view()->scrollPos ition(); | 464 FloatPoint scrollPosition = touchInfo.targetFrame->view()->scrollPos ition(); |
| 467 FloatPoint framePoint = pagePoint.scaledBy(scaleFactor); | 465 FloatPoint framePoint = pagePoint.scaledBy(scaleFactor); |
| 468 framePoint.moveBy(scrollPosition.scaledBy(-scaleFactor)); | 466 framePoint.moveBy(scrollPosition.scaledBy(-scaleFactor)); |
| 469 PointerEvent* pointerEvent = m_pointerEventFactory.create( | 467 PointerEvent* pointerEvent = m_pointerEventFactory.create( |
| 470 pointerEventNameForTouchPointState(touchPoint.state()), | 468 pointerEventNameForTouchPointState(touchPoint.state()), |
| 471 touchPoint, event.getModifiers(), | 469 touchPoint, event.getModifiers(), |
| 472 touchPoint.radius().scaledBy(scaleFactor), | 470 touchPoint.radius().scaledBy(scaleFactor), |
| 473 framePoint, | 471 framePoint, |
| 474 touchInfo.touchNode ? | 472 touchInfo.touchNode ? |
| 475 touchInfo.touchNode->document().domWindow() : nullptr); | 473 touchInfo.touchNode->document().domWindow() : nullptr); |
| 476 | 474 |
| 477 result = sendTouchPointerEvent(touchInfo.touchNode, pointerEvent); | 475 WebInputEventResult result = sendTouchPointerEvent(touchInfo.touchNo de, pointerEvent); |
| 476 | |
| 477 // If a pointerdown has been canceled, queue the unique id to allow | |
| 478 // suppressing mouse events from gesture events. For mouse events | |
| 479 // fired from GestureTap & GestureLongPress (which are triggered by | |
| 480 // single touches only), it is enough to queue the ids only for | |
| 481 // primary pointers. | |
| 482 // TODO(mustaq): What about other cases (e.g. GestureTwoFingerTap)? | |
| 483 if (result != WebInputEventResult::NotHandled | |
| 484 && pointerEvent->type() == EventTypeNames::pointerdown | |
| 485 && pointerEvent->isPrimary()) { | |
| 486 m_touchIdsForCanceledPointerdowns.append(event.uniqueTouchEventI d()); | |
| 487 } | |
| 478 } | 488 } |
| 479 // TODO(crbug.com/507408): Right now we add the touch point only if | 489 |
| 480 // its pointer event is NotHandled (e.g. preventDefault is called in | 490 touchInfos.append(touchInfo); |
| 481 // the pointer event listener). This behavior needs to change as it | |
| 482 // may create some inconsistent touch event sequence. | |
| 483 if (result == WebInputEventResult::NotHandled) { | |
| 484 touchInfos.append(touchInfo); | |
| 485 } | |
| 486 } | 491 } |
| 487 } | 492 } |
| 488 | 493 |
| 489 WebInputEventResult PointerEventManager::sendTouchPointerEvent( | 494 WebInputEventResult PointerEventManager::sendTouchPointerEvent( |
| 490 EventTarget* target, PointerEvent* pointerEvent) | 495 EventTarget* target, PointerEvent* pointerEvent) |
| 491 { | 496 { |
| 492 if (m_inCanceledStateForPointerTypeTouch) | 497 if (m_inCanceledStateForPointerTypeTouch) |
| 493 return WebInputEventResult::NotHandled; | 498 return WebInputEventResult::NotHandled; |
| 494 | 499 |
| 495 processCaptureAndPositionOfPointerEvent(pointerEvent, target); | 500 processCaptureAndPositionOfPointerEvent(pointerEvent, target); |
| (...skipping 96 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 154 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 766 const int pointerId) const | 772 const int pointerId) const |
| 767 { | 773 { |
| 768 return m_pointerEventFactory.getPointerType(pointerId); | 774 return m_pointerEventFactory.getPointerType(pointerId); |
| 769 } | 775 } |
| 770 | 776 |
| 771 bool PointerEventManager::isAnyTouchActive() const | 777 bool PointerEventManager::isAnyTouchActive() const |
| 772 { | 778 { |
| 773 return m_touchEventManager.isAnyTouchActive(); | 779 return m_touchEventManager.isAnyTouchActive(); |
| 774 } | 780 } |
| 775 | 781 |
| 782 bool PointerEventManager::primaryPointerdownCanceled(uint32_t uniqueTouchEventId ) | |
| 783 { | |
| 784 while (!m_touchIdsForCanceledPointerdowns.isEmpty()) { | |
|
dtapuska
2016/06/03 15:02:11
Can we add a comment that we never expect wrap aro
mustaq
2016/06/03 20:34:45
Done (but didn't mention you would be dead :-P).
| |
| 785 uint32_t firstId = m_touchIdsForCanceledPointerdowns.first(); | |
| 786 if (firstId > uniqueTouchEventId) | |
| 787 return false; | |
| 788 m_touchIdsForCanceledPointerdowns.takeFirst(); | |
| 789 if (firstId == uniqueTouchEventId) | |
| 790 return true; | |
| 791 } | |
| 792 return false; | |
| 793 } | |
| 794 | |
| 776 DEFINE_TRACE(PointerEventManager) | 795 DEFINE_TRACE(PointerEventManager) |
| 777 { | 796 { |
| 778 visitor->trace(m_frame); | 797 visitor->trace(m_frame); |
| 779 visitor->trace(m_nodeUnderPointer); | 798 visitor->trace(m_nodeUnderPointer); |
| 780 visitor->trace(m_pointerCaptureTarget); | 799 visitor->trace(m_pointerCaptureTarget); |
| 781 visitor->trace(m_pendingPointerCaptureTarget); | 800 visitor->trace(m_pendingPointerCaptureTarget); |
| 782 visitor->trace(m_touchEventManager); | 801 visitor->trace(m_touchEventManager); |
| 783 } | 802 } |
| 784 | 803 |
| 785 | 804 |
| 786 } // namespace blink | 805 } // namespace blink |
| OLD | NEW |