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. |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 // Touch events should not go to text nodes. | |
|
Rick Byers
2016/05/17 14:20:01
update comment, probably even file a bug to track
Navid Zolghadr
2016/05/17 16:40:44
I don't know to be honest with you. This is the be
| |
| 439 if (node->isTextNode()) | |
| 440 node = FlatTreeTraversal::parent(*node); | |
| 441 touchInfo.touchNode = node; | |
| 419 | 442 |
| 420 // Iterate through the touch points, sending PointerEvents to the targets as required. | 443 } |
| 421 for (auto& touchInfo: touchInfos) { | 444 } else { |
| 422 const PlatformTouchPoint &touchPoint = touchInfo.point; | 445 // Set the target of pointer event to the captured node as this |
| 446 // pointer is captured otherwise it would have gone to the if block | |
| 447 // and perform a hit-test. | |
| 448 touchInfo.touchNode = m_pendingPointerCaptureTarget | |
| 449 .get(pointerId)->toNode(); | |
| 450 touchInfo.targetFrame = touchInfo.touchNode->document().frame(); | |
| 451 } | |
| 452 | |
| 423 WebInputEventResult result = WebInputEventResult::NotHandled; | 453 WebInputEventResult result = WebInputEventResult::NotHandled; |
| 424 // Do not send pointer events for stationary touches. | 454 |
| 425 if (touchPoint.state() != PlatformTouchPoint::TouchStationary) { | 455 // Do not send pointer events for stationary touches or null targetFrame |
| 456 if (touchInfo.touchNode | |
| 457 && touchPoint.state() != PlatformTouchPoint::TouchStationary | |
| 458 && !m_inCanceledStateForPointerTypeTouch) { | |
| 459 FloatPoint pagePoint = touchInfo.targetFrame->view() | |
| 460 ->rootFrameToContents(touchInfo.point.pos()); | |
| 426 float scaleFactor = 1.0f / touchInfo.targetFrame->pageZoomFactor(); | 461 float scaleFactor = 1.0f / touchInfo.targetFrame->pageZoomFactor(); |
| 427 FloatPoint scrollPosition = touchInfo.targetFrame->view()->scrollPos ition(); | 462 FloatPoint scrollPosition = touchInfo.targetFrame->view()->scrollPos ition(); |
| 428 FloatPoint framePoint = touchInfo.contentPoint; | 463 FloatPoint framePoint = pagePoint.scaledBy(scaleFactor); |
| 429 framePoint.moveBy(scrollPosition.scaledBy(-scaleFactor)); | 464 framePoint.moveBy(scrollPosition.scaledBy(-scaleFactor)); |
| 430 PointerEvent* pointerEvent = m_pointerEventFactory.create( | 465 PointerEvent* pointerEvent = m_pointerEventFactory.create( |
| 431 pointerEventNameForTouchPointState(touchPoint.state()), | 466 pointerEventNameForTouchPointState(touchPoint.state()), |
| 432 touchPoint, event.getModifiers(), | 467 touchPoint, event.getModifiers(), |
| 433 touchInfo.adjustedRadius, | 468 touchPoint.radius().scaledBy(scaleFactor), |
| 434 framePoint); | 469 framePoint); |
| 435 | 470 |
| 436 // Consume the touch point if its pointer event is anything but NotH andled | 471 // Consume the touch point if its pointer event is anything but NotH andled |
| 437 // (e.g. preventDefault is called in the listener for the pointer ev ent). | 472 // (e.g. preventDefault is called in the listener for the pointer ev ent). |
| 438 result = sendTouchPointerEvent(touchInfo.touchNode, pointerEvent); | 473 result = sendTouchPointerEvent(touchInfo.touchNode, pointerEvent); |
| 439 touchInfo.consumed = result != WebInputEventResult::NotHandled; | 474 } |
| 475 if (result == WebInputEventResult::NotHandled) { | |
| 476 touchInfos.append(touchInfo); | |
|
Rick Byers
2016/05/17 14:20:01
So the touchinfos are now just the data needed for
mustaq
2016/05/17 14:40:14
We already have a p1 bug for this: crbug.com/60758
Navid Zolghadr
2016/05/17 16:40:44
Yup. I haven't changed the behavior here and just
| |
| 440 } | 477 } |
| 441 } | 478 } |
| 442 } | 479 } |
| 443 | 480 |
| 444 WebInputEventResult PointerEventManager::sendTouchPointerEvent( | 481 WebInputEventResult PointerEventManager::sendTouchPointerEvent( |
| 445 EventTarget* target, PointerEvent* pointerEvent) | 482 EventTarget* target, PointerEvent* pointerEvent) |
| 446 { | 483 { |
| 447 if (m_inCanceledStateForPointerTypeTouch) | 484 if (m_inCanceledStateForPointerTypeTouch) |
| 448 return WebInputEventResult::NotHandled; | 485 return WebInputEventResult::NotHandled; |
| 449 | 486 |
| (...skipping 282 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 732 { | 769 { |
| 733 visitor->trace(m_frame); | 770 visitor->trace(m_frame); |
| 734 visitor->trace(m_nodeUnderPointer); | 771 visitor->trace(m_nodeUnderPointer); |
| 735 visitor->trace(m_pointerCaptureTarget); | 772 visitor->trace(m_pointerCaptureTarget); |
| 736 visitor->trace(m_pendingPointerCaptureTarget); | 773 visitor->trace(m_pendingPointerCaptureTarget); |
| 737 visitor->trace(m_touchEventManager); | 774 visitor->trace(m_touchEventManager); |
| 738 } | 775 } |
| 739 | 776 |
| 740 | 777 |
| 741 } // namespace blink | 778 } // namespace blink |
| OLD | NEW |