| 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" |
| 11 #include "core/html/HTMLCanvasElement.h" | 11 #include "core/html/HTMLCanvasElement.h" |
| 12 #include "core/input/EventHandler.h" | 12 #include "core/input/EventHandler.h" |
| 13 #include "core/input/TouchActionUtil.h" |
| 14 #include "core/page/ChromeClient.h" |
| 15 #include "core/page/Page.h" |
| 13 #include "platform/PlatformTouchEvent.h" | 16 #include "platform/PlatformTouchEvent.h" |
| 14 | 17 |
| 15 namespace blink { | 18 namespace blink { |
| 16 | 19 |
| 17 namespace { | 20 namespace { |
| 18 | 21 |
| 19 size_t toPointerTypeIndex(WebPointerProperties::PointerType t) { return static_c
ast<size_t>(t); } | 22 size_t toPointerTypeIndex(WebPointerProperties::PointerType t) { return static_c
ast<size_t>(t); } |
| 20 | 23 |
| 21 const AtomicString& pointerEventNameForTouchPointState(PlatformTouchPoint::Touch
State state) | 24 const AtomicString& pointerEventNameForTouchPointState(PlatformTouchPoint::Touch
State state) |
| 22 { | 25 { |
| (...skipping 367 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 390 for (const auto &touchPoint : event.touchPoints()) { | 393 for (const auto &touchPoint : event.touchPoints()) { |
| 391 if (touchPoint.state() != PlatformTouchPoint::TouchPressed) { | 394 if (touchPoint.state() != PlatformTouchPoint::TouchPressed) { |
| 392 newTouchSequence = false; | 395 newTouchSequence = false; |
| 393 break; | 396 break; |
| 394 } | 397 } |
| 395 } | 398 } |
| 396 if (newTouchSequence) | 399 if (newTouchSequence) |
| 397 unblockTouchPointers(); | 400 unblockTouchPointers(); |
| 398 HeapVector<TouchEventManager::TouchInfo> touchInfos; | 401 HeapVector<TouchEventManager::TouchInfo> touchInfos; |
| 399 | 402 |
| 400 // TODO(crbug.com/606822): This will be moved after pointer events so | |
| 401 // pointer event operations will get the first shot to fill up this array. | |
| 402 if (!m_touchEventManager.generateTouchInfosAfterHittest(event, touchInfos)) | |
| 403 return WebInputEventResult::NotHandled; | |
| 404 | |
| 405 dispatchTouchPointerEvents(event, touchInfos); | 403 dispatchTouchPointerEvents(event, touchInfos); |
| 406 | 404 |
| 407 return m_touchEventManager.handleTouchEvent(event, touchInfos); | 405 return m_touchEventManager.handleTouchEvent(event, touchInfos); |
| 408 } | 406 } |
| 409 | 407 |
| 410 void PointerEventManager::dispatchTouchPointerEvents( | 408 void PointerEventManager::dispatchTouchPointerEvents( |
| 411 const PlatformTouchEvent& event, | 409 const PlatformTouchEvent& event, |
| 412 HeapVector<TouchEventManager::TouchInfo>& touchInfos) | 410 HeapVector<TouchEventManager::TouchInfo>& touchInfos) |
| 413 { | 411 { |
| 414 if (!RuntimeEnabledFeatures::pointerEventEnabled()) | 412 // Iterate through the touch points, sending PointerEvents to the targets as
required. |
| 415 return; | 413 for (const auto& touchPoint : event.touchPoints()) { |
| 414 TouchEventManager::TouchInfo touchInfo; |
| 415 touchInfo.point = touchPoint; |
| 416 | 416 |
| 417 if (m_inCanceledStateForPointerTypeTouch) | 417 int pointerId = m_pointerEventFactory.getPointerEventId( |
| 418 return; | 418 touchPoint.pointerProperties()); |
| 419 // Do the hit test either when the touch first starts or when the touch |
| 420 // is not captured. |m_pendingPointerCaptureTarget| indicates the target |
| 421 // that will be capturing this event. |m_pointerCaptureTarget| may not |
| 422 // have this target yet since the processing of that will be done right |
| 423 // before firing the event. |
| 424 if (touchInfo.point.state() == PlatformTouchPoint::TouchPressed |
| 425 || !m_pendingPointerCaptureTarget.contains(pointerId)) { |
| 426 HitTestRequest::HitTestRequestType hitType = HitTestRequest::TouchEv
ent | HitTestRequest::ReadOnly | HitTestRequest::Active; |
| 427 LayoutPoint pagePoint = roundedLayoutPoint(m_frame->view()->rootFram
eToContents(touchInfo.point.pos())); |
| 428 HitTestResult hitTestTesult = m_frame->eventHandler().hitTestResultA
tPoint(pagePoint, hitType); |
| 429 Node* node = hitTestTesult.innerNode(); |
| 430 if (node) { |
| 431 touchInfo.targetFrame = node->document().frame(); |
| 432 if (isHTMLCanvasElement(node)) { |
| 433 std::pair<Element*, String> regionInfo = toHTMLCanvasElement
(node)->getControlAndIdIfHitRegionExists(hitTestTesult.pointInInnerNodeFrame()); |
| 434 if (regionInfo.first) |
| 435 node = regionInfo.first; |
| 436 touchInfo.region = regionInfo.second; |
| 437 } |
| 438 // TODO(crbug.com/612456): We need to investigate whether pointe
r |
| 439 // events should go to text nodes or not. If so we need to |
| 440 // update the mouse code as well. Also this logic looks similar |
| 441 // to the one in TouchEventManager. We should be able to |
| 442 // refactor it better after this investigation. |
| 443 if (node->isTextNode()) |
| 444 node = FlatTreeTraversal::parent(*node); |
| 445 touchInfo.touchNode = node; |
| 419 | 446 |
| 420 // Iterate through the touch points, sending PointerEvents to the targets as
required. | 447 } |
| 421 for (auto& touchInfo: touchInfos) { | 448 } else { |
| 422 const PlatformTouchPoint &touchPoint = touchInfo.point; | 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 |
| 451 // and perform a hit-test. |
| 452 touchInfo.touchNode = m_pendingPointerCaptureTarget |
| 453 .get(pointerId)->toNode(); |
| 454 touchInfo.targetFrame = touchInfo.touchNode->document().frame(); |
| 455 } |
| 456 |
| 423 WebInputEventResult result = WebInputEventResult::NotHandled; | 457 WebInputEventResult result = WebInputEventResult::NotHandled; |
| 424 // Do not send pointer events for stationary touches. | 458 |
| 425 if (touchPoint.state() != PlatformTouchPoint::TouchStationary) { | 459 // Do not send pointer events for stationary touches or null targetFrame |
| 460 if (touchInfo.touchNode |
| 461 && touchPoint.state() != PlatformTouchPoint::TouchStationary |
| 462 && !m_inCanceledStateForPointerTypeTouch) { |
| 463 FloatPoint pagePoint = touchInfo.targetFrame->view() |
| 464 ->rootFrameToContents(touchInfo.point.pos()); |
| 426 float scaleFactor = 1.0f / touchInfo.targetFrame->pageZoomFactor(); | 465 float scaleFactor = 1.0f / touchInfo.targetFrame->pageZoomFactor(); |
| 427 FloatPoint scrollPosition = touchInfo.targetFrame->view()->scrollPos
ition(); | 466 FloatPoint scrollPosition = touchInfo.targetFrame->view()->scrollPos
ition(); |
| 428 FloatPoint framePoint = touchInfo.contentPoint; | 467 FloatPoint framePoint = pagePoint.scaledBy(scaleFactor); |
| 429 framePoint.moveBy(scrollPosition.scaledBy(-scaleFactor)); | 468 framePoint.moveBy(scrollPosition.scaledBy(-scaleFactor)); |
| 430 PointerEvent* pointerEvent = m_pointerEventFactory.create( | 469 PointerEvent* pointerEvent = m_pointerEventFactory.create( |
| 431 pointerEventNameForTouchPointState(touchPoint.state()), | 470 pointerEventNameForTouchPointState(touchPoint.state()), |
| 432 touchPoint, event.getModifiers(), | 471 touchPoint, event.getModifiers(), |
| 433 touchInfo.adjustedRadius, | 472 touchPoint.radius().scaledBy(scaleFactor), |
| 434 framePoint, | 473 framePoint, |
| 435 touchInfo.touchNode ? | 474 touchInfo.touchNode ? |
| 436 touchInfo.touchNode->document().domWindow() : nullptr); | 475 touchInfo.touchNode->document().domWindow() : nullptr); |
| 437 | 476 |
| 438 // Consume the touch point if its pointer event is anything but NotH
andled | |
| 439 // (e.g. preventDefault is called in the listener for the pointer ev
ent). | |
| 440 result = sendTouchPointerEvent(touchInfo.touchNode, pointerEvent); | 477 result = sendTouchPointerEvent(touchInfo.touchNode, pointerEvent); |
| 441 touchInfo.consumed = result != WebInputEventResult::NotHandled; | 478 } |
| 479 // TODO(crbug.com/507408): Right now we add the touch point only if |
| 480 // its pointer event is NotHandled (e.g. preventDefault is called in |
| 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); |
| 442 } | 485 } |
| 443 } | 486 } |
| 444 } | 487 } |
| 445 | 488 |
| 446 WebInputEventResult PointerEventManager::sendTouchPointerEvent( | 489 WebInputEventResult PointerEventManager::sendTouchPointerEvent( |
| 447 EventTarget* target, PointerEvent* pointerEvent) | 490 EventTarget* target, PointerEvent* pointerEvent) |
| 448 { | 491 { |
| 449 if (m_inCanceledStateForPointerTypeTouch) | 492 if (m_inCanceledStateForPointerTypeTouch) |
| 450 return WebInputEventResult::NotHandled; | 493 return WebInputEventResult::NotHandled; |
| 451 | 494 |
| (...skipping 282 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 734 { | 777 { |
| 735 visitor->trace(m_frame); | 778 visitor->trace(m_frame); |
| 736 visitor->trace(m_nodeUnderPointer); | 779 visitor->trace(m_nodeUnderPointer); |
| 737 visitor->trace(m_pointerCaptureTarget); | 780 visitor->trace(m_pointerCaptureTarget); |
| 738 visitor->trace(m_pendingPointerCaptureTarget); | 781 visitor->trace(m_pendingPointerCaptureTarget); |
| 739 visitor->trace(m_touchEventManager); | 782 visitor->trace(m_touchEventManager); |
| 740 } | 783 } |
| 741 | 784 |
| 742 | 785 |
| 743 } // namespace blink | 786 } // namespace blink |
| OLD | NEW |