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" |
| 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. | |
| 421 if (touchInfo.point.state() == PlatformTouchPoint::TouchPressed | |
| 422 || !m_pendingPointerCaptureTarget.contains(pointerId)) { | |
|
mustaq
2016/05/13 20:03:16
It took some time to realize why this is m_pending
Navid Zolghadr
2016/05/16 20:01:50
Done.
| |
| 423 HitTestRequest::HitTestRequestType hitType = HitTestRequest::TouchEv ent | HitTestRequest::ReadOnly | HitTestRequest::Active; | |
| 424 LayoutPoint pagePoint = roundedLayoutPoint(m_frame->view()->rootFram eToContents(touchInfo.point.pos())); | |
| 425 HitTestResult hitTestTesult = m_frame->eventHandler().hitTestResultA tPoint(pagePoint, hitType); | |
| 426 Node* node = hitTestTesult.innerNode(); | |
| 427 if (node) { | |
| 428 touchInfo.targetFrame = node->document().frame(); | |
| 429 if (isHTMLCanvasElement(node)) { | |
| 430 std::pair<Element*, String> regionInfo = toHTMLCanvasElement (node)->getControlAndIdIfHitRegionExists(hitTestTesult.pointInInnerNodeFrame()); | |
| 431 if (regionInfo.first) | |
| 432 node = regionInfo.first; | |
| 433 touchInfo.region = regionInfo.second; | |
| 434 } | |
| 435 // Touch events should not go to text nodes. | |
| 436 if (node->isTextNode()) | |
| 437 node = FlatTreeTraversal::parent(*node); | |
| 438 touchInfo.touchNode = node; | |
| 419 | 439 |
| 420 // Iterate through the touch points, sending PointerEvents to the targets as required. | 440 TouchAction effectiveTouchAction = |
|
dtapuska
2016/05/13 16:51:36
Is this correct to do here? What if the touch sequ
Navid Zolghadr
2016/05/13 17:27:55
I'm not sure. My understanding was that the toucha
mustaq
2016/05/13 19:18:01
The info in communicated back to browser through t
Navid Zolghadr
2016/05/16 20:01:50
Done.
| |
| 421 for (auto& touchInfo: touchInfos) { | 441 TouchActionUtil::computeEffectiveTouchAction( |
| 422 const PlatformTouchPoint &touchPoint = touchInfo.point; | 442 *touchInfo.touchNode); |
| 443 if (effectiveTouchAction != TouchActionAuto) | |
| 444 m_frame->page()->chromeClient().setTouchAction(effectiveTouc hAction); | |
| 445 } | |
| 446 } else { | |
| 447 touchInfo.touchNode = m_pendingPointerCaptureTarget.get(pointerId)-> toNode(); | |
|
mustaq
2016/05/13 20:03:16
If we remove/disable implicit touch capturing, I s
Navid Zolghadr
2016/05/16 20:01:50
That is right. But I also check for this condition
| |
| 448 touchInfo.targetFrame = touchInfo.touchNode->document().frame(); | |
| 449 } | |
| 450 | |
| 423 WebInputEventResult result = WebInputEventResult::NotHandled; | 451 WebInputEventResult result = WebInputEventResult::NotHandled; |
| 424 // Do not send pointer events for stationary touches. | |
| 425 if (touchPoint.state() != PlatformTouchPoint::TouchStationary) { | |
| 426 // TODO(crbug.com/608394): The adjustedPagePoint should be converted | |
| 427 // to client coordinates. | |
| 428 PointerEvent* pointerEvent = m_pointerEventFactory.create( | |
| 429 pointerEventNameForTouchPointState(touchPoint.state()), | |
| 430 touchPoint, event.getModifiers(), | |
| 431 touchInfo.adjustedRadius, | |
| 432 touchInfo.adjustedPagePoint); | |
| 433 | 452 |
| 434 // Consume the touch point if its pointer event is anything but NotH andled | 453 if (touchInfo.targetFrame) { |
| 435 // (e.g. preventDefault is called in the listener for the pointer ev ent). | 454 FloatPoint pagePoint = touchInfo.targetFrame->view() |
| 436 result = sendTouchPointerEvent(touchInfo.touchNode, pointerEvent); | 455 ->rootFrameToContents(touchInfo.point.pos()); |
| 437 touchInfo.consumed = result != WebInputEventResult::NotHandled; | 456 float scaleFactor = 1.0f / touchInfo.targetFrame->pageZoomFactor(); |
| 457 | |
| 458 touchInfo.adjustedPagePoint = pagePoint.scaledBy(scaleFactor); | |
| 459 touchInfo.adjustedRadius = touchInfo.point.radius().scaledBy(scaleFa ctor); | |
| 460 | |
| 461 // Do not send pointer events for stationary touches. | |
| 462 if (touchPoint.state() != PlatformTouchPoint::TouchStationary | |
| 463 && !m_inCanceledStateForPointerTypeTouch) { | |
| 464 // TODO(crbug.com/608394): The adjustedPagePoint should be conve rted | |
|
mustaq
2016/05/11 14:30:55
Isn't adjustedPagePoint now in client coordinates?
Navid Zolghadr
2016/05/11 16:43:42
I need to rebase this change to get the updates.
Navid Zolghadr
2016/05/16 20:01:50
Done.
| |
| 465 // to client coordinates. | |
| 466 PointerEvent* pointerEvent = m_pointerEventFactory.create( | |
| 467 pointerEventNameForTouchPointState(touchPoint.state()), | |
| 468 touchPoint, event.getModifiers(), | |
| 469 touchInfo.adjustedRadius, | |
| 470 touchInfo.adjustedPagePoint); | |
| 471 | |
| 472 // Consume the touch point if its pointer event is anything but NotHandled | |
| 473 // (e.g. preventDefault is called in the listener for the pointe r event). | |
| 474 result = sendTouchPointerEvent(touchInfo.touchNode, pointerEvent ); | |
|
mustaq
2016/05/11 14:30:55
This is now leaking PEs I believe! Please check if
Navid Zolghadr
2016/05/11 16:43:42
No. It does check the pointer enable at the last s
| |
| 475 } | |
| 476 } | |
| 477 if (result == WebInputEventResult::NotHandled) { | |
| 478 touchInfos.append(touchInfo); | |
| 438 } | 479 } |
| 439 } | 480 } |
| 440 } | 481 } |
| 441 | 482 |
| 442 WebInputEventResult PointerEventManager::sendTouchPointerEvent( | 483 WebInputEventResult PointerEventManager::sendTouchPointerEvent( |
| 443 EventTarget* target, PointerEvent* pointerEvent) | 484 EventTarget* target, PointerEvent* pointerEvent) |
| 444 { | 485 { |
| 445 if (m_inCanceledStateForPointerTypeTouch) | 486 if (m_inCanceledStateForPointerTypeTouch) |
| 446 return WebInputEventResult::NotHandled; | 487 return WebInputEventResult::NotHandled; |
| 447 | 488 |
| (...skipping 272 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 720 { | 761 { |
| 721 visitor->trace(m_frame); | 762 visitor->trace(m_frame); |
| 722 visitor->trace(m_nodeUnderPointer); | 763 visitor->trace(m_nodeUnderPointer); |
| 723 visitor->trace(m_pointerCaptureTarget); | 764 visitor->trace(m_pointerCaptureTarget); |
| 724 visitor->trace(m_pendingPointerCaptureTarget); | 765 visitor->trace(m_pendingPointerCaptureTarget); |
| 725 visitor->trace(m_touchEventManager); | 766 visitor->trace(m_touchEventManager); |
| 726 } | 767 } |
| 727 | 768 |
| 728 | 769 |
| 729 } // namespace blink | 770 } // namespace blink |
| OLD | NEW |