Chromium Code Reviews| Index: third_party/WebKit/Source/core/input/PointerEventManager.cpp |
| diff --git a/third_party/WebKit/Source/core/input/PointerEventManager.cpp b/third_party/WebKit/Source/core/input/PointerEventManager.cpp |
| index a02f20fad3a146da235c5f0ef76b494a856972fb..266e75def39df2e1d7eddea10c5f7f850c35b005 100644 |
| --- a/third_party/WebKit/Source/core/input/PointerEventManager.cpp |
| +++ b/third_party/WebKit/Source/core/input/PointerEventManager.cpp |
| @@ -6,7 +6,10 @@ |
| #include "core/dom/shadow/FlatTreeTraversal.h" |
| #include "core/events/MouseEvent.h" |
| +#include "core/frame/FrameView.h" |
| +#include "core/html/HTMLCanvasElement.h" |
| #include "core/input/EventHandler.h" |
| +#include "platform/PlatformTouchEvent.h" |
| namespace blink { |
| @@ -328,20 +331,106 @@ void PointerEventManager::unblockTouchPointers() |
| m_inCanceledStateForPointerTypeTouch = false; |
| } |
| +WebInputEventResult PointerEventManager::handleTouchEvents( |
| + const PlatformTouchEvent& event) |
| +{ |
| + |
| + if (event.type() == PlatformEvent::TouchScrollStarted) { |
| + blockTouchPointers(); |
| + return WebInputEventResult::HandledSystem; |
|
mustaq
2016/04/20 15:40:01
This needs attention: the TouchScrollStarted event
Navid Zolghadr
2016/04/20 17:25:14
As we talked offline this behavior is okay and the
|
| + } |
| + |
| + bool newTouchSequence = true; |
| + for (const auto &touchPoint : event.touchPoints()) { |
| + if (touchPoint.state() != PlatformTouchPoint::TouchPressed) |
| + newTouchSequence = false; |
| + } |
| + if (newTouchSequence) |
| + unblockTouchPointers(); |
| + HeapVector<TouchEventManager::TouchInfo> touchInfos; |
| + dispatchTouchPointerEvents(event, touchInfos); |
| + |
| + return m_touchEventManager.handleTouchEvent(event, touchInfos); |
| +} |
| + |
| +void PointerEventManager::dispatchTouchPointerEvents( |
| + const PlatformTouchEvent& event, |
| + HeapVector<TouchEventManager::TouchInfo>& touchInfos) |
| +{ |
| + |
|
dtapuska
2016/04/15 01:30:50
Where is the runtime feature check?
Navid Zolghadr
2016/04/15 01:54:30
Just like before the checks for the feature being
|
| + // Iterate through the touch points, sending PointerEvents to the targets as required. |
| + for (const auto& touchPoint: event.touchPoints()) { |
| + Node* touchNode = nullptr; |
| + String region; |
| + |
| + WebInputEventResult result = WebInputEventResult::NotHandled; |
| + if (!m_inCanceledStateForPointerTypeTouch) { |
| + if (touchPoint.state() == PlatformTouchPoint::TouchPressed) { |
| + HitTestRequest::HitTestRequestType hitType = HitTestRequest::TouchEvent | HitTestRequest::ReadOnly | HitTestRequest::Active; |
| + LayoutPoint pagePoint = roundedLayoutPoint(m_frame->view()->rootFrameToContents(touchPoint.pos())); |
| + HitTestResult result = m_frame->eventHandler().hitTestResultAtPoint(pagePoint, hitType); |
| + |
| + Node* node = result.innerNode(); |
| + if (isHTMLCanvasElement(node)) { |
| + std::pair<Element*, String> regionInfo = toHTMLCanvasElement(node)->getControlAndIdIfHitRegionExists(result.pointInInnerNodeFrame()); |
| + if (regionInfo.first) |
| + node = regionInfo.first; |
| + region = regionInfo.second; |
| + } |
| + if (node) { |
| + // Touch events should not go to text nodes |
| + if (node->isTextNode()) |
| + node = FlatTreeTraversal::parent(*node); |
| + } |
| + touchNode = node; |
| + } |
| + |
| + // Do not send pointer events for stationary touches |
| + if (touchPoint.state() != PlatformTouchPoint::TouchStationary) { |
| + if (!touchNode) { |
| + int pointerId = m_pointerEventFactory |
| + .getPointerEventId(touchPoint.pointerProperties()); |
| + if (m_nodeUnderPointer.contains(pointerId)) { |
| + touchNode = |
| + m_nodeUnderPointer.get(pointerId).target->toNode(); |
| + } |
| + } |
| + if (touchNode) { |
| + LocalFrame* targetFrame = touchNode->document().frame(); |
| + if (targetFrame) { |
| + // pagePoint should always be in the target element's document coordinates. |
| + FloatPoint pagePoint = targetFrame->view()->rootFrameToContents(touchPoint.pos()); |
| + float scaleFactor = 1.0f / targetFrame->pageZoomFactor(); |
| + PointerEvent* pointerEvent = m_pointerEventFactory.create( |
| + pointerEventNameForTouchPointState(touchPoint.state()), |
| + touchPoint, event.getModifiers(), |
| + touchPoint.radius().scaledBy(scaleFactor), |
| + pagePoint.scaledBy(scaleFactor)); |
| + |
| + result = sendTouchPointerEvent(touchNode, pointerEvent); |
| + } |
| + } |
| + } |
| + } |
| + |
| + // Hide the touch point if its pointer event is anything but NotHandled |
| + // (e.g. preventDefault is called in the listener for the pointer event). |
| + if (result == WebInputEventResult::NotHandled) { |
| + TouchEventManager::TouchInfo touchInfo; |
| + touchInfo.point = touchPoint; |
| + touchInfo.touchNode = touchNode; |
| + touchInfo.region = region; |
| + touchInfos.append(touchInfo); |
| + } |
| + } |
| +} |
| + |
| WebInputEventResult PointerEventManager::sendTouchPointerEvent( |
| - EventTarget* target, |
| - const PlatformTouchPoint& touchPoint, PlatformEvent::Modifiers modifiers, |
| - const double width, const double height, |
| - const double clientX, const double clientY) |
| + EventTarget* target, PointerEvent* pointerEvent) |
| { |
| if (m_inCanceledStateForPointerTypeTouch) |
| return WebInputEventResult::NotHandled; |
| - PointerEvent* pointerEvent = |
| - m_pointerEventFactory.create( |
| - pointerEventNameForTouchPointState(touchPoint.state()), |
| - touchPoint, modifiers, width, height, clientX, clientY); |
| - |
| processCaptureAndPositionOfPointerEvent(pointerEvent, target); |
| // TODO(nzolghadr): crbug.com/579553 dealing with implicit touch capturing vs pointer event capturing |
| @@ -350,11 +439,11 @@ WebInputEventResult PointerEventManager::sendTouchPointerEvent( |
| pointerEvent); |
| // Setting the implicit capture for touch |
| - if (touchPoint.state() == PlatformTouchPoint::TouchPressed) |
| + if (pointerEvent->type() == EventTypeNames::pointerdown) |
| setPointerCapture(pointerEvent->pointerId(), target); |
| - if (touchPoint.state() == PlatformTouchPoint::TouchReleased |
| - || touchPoint.state() == PlatformTouchPoint::TouchCancelled) { |
| + if (pointerEvent->type() == EventTypeNames::pointerup |
| + || pointerEvent->type() == EventTypeNames::pointercancel) { |
| releasePointerCapture(pointerEvent->pointerId()); |
| // Sending the leave/out events and lostpointercapture |
| @@ -421,7 +510,9 @@ WebInputEventResult PointerEventManager::sendMousePointerEvent( |
| return result; |
| } |
| -PointerEventManager::PointerEventManager() |
| +PointerEventManager::PointerEventManager(LocalFrame* frame) |
| +: m_frame(frame) |
| +, m_touchEventManager(frame) |
| { |
| clear(); |
| } |
| @@ -434,6 +525,7 @@ void PointerEventManager::clear() |
| { |
| for (auto& entry : m_preventMouseEventForPointerType) |
| entry = false; |
| + m_touchEventManager.clear(); |
| m_inCanceledStateForPointerTypeTouch = false; |
| m_pointerEventFactory.clear(); |
| m_nodeUnderPointer.clear(); |
| @@ -605,11 +697,18 @@ WebPointerProperties::PointerType PointerEventManager::getPointerEventType( |
| return m_pointerEventFactory.getPointerType(pointerId); |
| } |
| +TouchEventManager& PointerEventManager::getTouchEventManager() |
| +{ |
| + return m_touchEventManager; |
| +} |
| + |
| DEFINE_TRACE(PointerEventManager) |
| { |
| + visitor->trace(m_frame); |
| visitor->trace(m_nodeUnderPointer); |
| visitor->trace(m_pointerCaptureTarget); |
| visitor->trace(m_pendingPointerCaptureTarget); |
| + visitor->trace(m_touchEventManager); |
| } |