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 712022e55c13220628f6958281bc4a4cfa3fba15..8d8a22bc4cc44829d8d798452c52dd0712cc96c4 100644 |
| --- a/third_party/WebKit/Source/core/input/PointerEventManager.cpp |
| +++ b/third_party/WebKit/Source/core/input/PointerEventManager.cpp |
| @@ -7,8 +7,10 @@ |
| #include "core/dom/ElementTraversal.h" |
| #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 { |
| @@ -353,20 +355,106 @@ void PointerEventManager::unblockTouchPointers() |
| m_inCanceledStateForPointerTypeTouch = false; |
| } |
| +WebInputEventResult PointerEventManager::handleTouchEvents( |
| + const PlatformTouchEvent& event) |
| +{ |
| + |
| + if (event.type() == PlatformEvent::TouchScrollStarted) { |
| + blockTouchPointers(); |
| + return WebInputEventResult::HandledSystem; |
| + } |
| + |
| + 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) |
| +{ |
| + |
| + // Iterate through the touch points, sending PointerEvents to the targets as required. |
|
dtapuska
2016/04/25 20:15:00
So do we expect any performance regressions here?
Navid Zolghadr
2016/04/26 21:57:51
I did the early exit in the new patch with kind of
|
| + 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 |
|
dtapuska
2016/04/25 20:15:00
period.
Navid Zolghadr
2016/04/26 21:57:51
:D. I should be more careful about these dots. I s
|
| + 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 |
| @@ -375,11 +463,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 |
| @@ -446,7 +534,9 @@ WebInputEventResult PointerEventManager::sendMousePointerEvent( |
| return result; |
| } |
| -PointerEventManager::PointerEventManager() |
| +PointerEventManager::PointerEventManager(LocalFrame* frame) |
| +: m_frame(frame) |
| +, m_touchEventManager(frame) |
| { |
| clear(); |
| } |
| @@ -459,6 +549,7 @@ void PointerEventManager::clear() |
| { |
| for (auto& entry : m_preventMouseEventForPointerType) |
| entry = false; |
| + m_touchEventManager.clear(); |
| m_inCanceledStateForPointerTypeTouch = false; |
| m_pointerEventFactory.clear(); |
| m_nodeUnderPointer.clear(); |
| @@ -630,11 +721,18 @@ WebPointerProperties::PointerType PointerEventManager::getPointerEventType( |
| return m_pointerEventFactory.getPointerType(pointerId); |
| } |
| +bool PointerEventManager::isAnyTouchActive() |
| +{ |
| + return m_touchEventManager.isAnyTouchActive(); |
| +} |
| + |
| DEFINE_TRACE(PointerEventManager) |
| { |
| + visitor->trace(m_frame); |
| visitor->trace(m_nodeUnderPointer); |
| visitor->trace(m_pointerCaptureTarget); |
| visitor->trace(m_pendingPointerCaptureTarget); |
| + visitor->trace(m_touchEventManager); |
| } |