| 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/DocumentUserGestureToken.h" | 7 #include "core/dom/DocumentUserGestureToken.h" |
| 8 #include "core/dom/ElementTraversal.h" | 8 #include "core/dom/ElementTraversal.h" |
| 9 #include "core/dom/shadow/FlatTreeTraversal.h" | 9 #include "core/dom/shadow/FlatTreeTraversal.h" |
| 10 #include "core/events/MouseEvent.h" | 10 #include "core/events/MouseEvent.h" |
| (...skipping 10 matching lines...) Expand all Loading... |
| 21 #include "platform/PlatformTouchEvent.h" | 21 #include "platform/PlatformTouchEvent.h" |
| 22 | 22 |
| 23 namespace blink { | 23 namespace blink { |
| 24 | 24 |
| 25 namespace { | 25 namespace { |
| 26 | 26 |
| 27 size_t toPointerTypeIndex(WebPointerProperties::PointerType t) { | 27 size_t toPointerTypeIndex(WebPointerProperties::PointerType t) { |
| 28 return static_cast<size_t>(t); | 28 return static_cast<size_t>(t); |
| 29 } | 29 } |
| 30 | 30 |
| 31 const AtomicString& pointerEventNameForTouchPointState( | |
| 32 PlatformTouchPoint::TouchState state) { | |
| 33 switch (state) { | |
| 34 case PlatformTouchPoint::TouchReleased: | |
| 35 return EventTypeNames::pointerup; | |
| 36 case PlatformTouchPoint::TouchCancelled: | |
| 37 return EventTypeNames::pointercancel; | |
| 38 case PlatformTouchPoint::TouchPressed: | |
| 39 return EventTypeNames::pointerdown; | |
| 40 case PlatformTouchPoint::TouchMoved: | |
| 41 return EventTypeNames::pointermove; | |
| 42 case PlatformTouchPoint::TouchStationary: | |
| 43 // Fall through to default | |
| 44 default: | |
| 45 NOTREACHED(); | |
| 46 return emptyAtom; | |
| 47 } | |
| 48 } | |
| 49 | |
| 50 bool isInDocument(EventTarget* n) { | 31 bool isInDocument(EventTarget* n) { |
| 51 return n && n->toNode() && n->toNode()->isConnected(); | 32 return n && n->toNode() && n->toNode()->isConnected(); |
| 52 } | 33 } |
| 53 | 34 |
| 35 Vector<PlatformTouchPoint> getCoalescedPoints( |
| 36 const Vector<PlatformTouchEvent>& coalescedEvents, |
| 37 int id) { |
| 38 Vector<PlatformTouchPoint> relatedPoints; |
| 39 for (const auto& touchEvent : coalescedEvents) { |
| 40 for (auto& point : touchEvent.touchPoints()) { |
| 41 // TODO(nzolghadr): Need to filter out stationary points |
| 42 if (point.id() == id) |
| 43 relatedPoints.append(point); |
| 44 } |
| 45 } |
| 46 return relatedPoints; |
| 47 } |
| 48 |
| 54 } // namespace | 49 } // namespace |
| 55 | 50 |
| 56 PointerEventManager::PointerEventManager(LocalFrame* frame, | 51 PointerEventManager::PointerEventManager(LocalFrame* frame, |
| 57 MouseEventManager* mouseEventManager) | 52 MouseEventManager* mouseEventManager) |
| 58 : m_frame(frame), | 53 : m_frame(frame), |
| 59 m_touchEventManager(new TouchEventManager(frame)), | 54 m_touchEventManager(new TouchEventManager(frame)), |
| 60 m_mouseEventManager(mouseEventManager) { | 55 m_mouseEventManager(mouseEventManager) { |
| 61 clear(); | 56 clear(); |
| 62 } | 57 } |
| 63 | 58 |
| (...skipping 127 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 191 return target; | 186 return target; |
| 192 } | 187 } |
| 193 | 188 |
| 194 void PointerEventManager::sendMouseAndPointerBoundaryEvents( | 189 void PointerEventManager::sendMouseAndPointerBoundaryEvents( |
| 195 Node* enteredNode, | 190 Node* enteredNode, |
| 196 const PlatformMouseEvent& mouseEvent) { | 191 const PlatformMouseEvent& mouseEvent) { |
| 197 // Mouse event type does not matter as this pointerevent will only be used | 192 // Mouse event type does not matter as this pointerevent will only be used |
| 198 // to create boundary pointer events and its type will be overridden in | 193 // to create boundary pointer events and its type will be overridden in |
| 199 // |sendBoundaryEvents| function. | 194 // |sendBoundaryEvents| function. |
| 200 PointerEvent* dummyPointerEvent = m_pointerEventFactory.create( | 195 PointerEvent* dummyPointerEvent = m_pointerEventFactory.create( |
| 201 EventTypeNames::mousedown, mouseEvent, m_frame->document()->domWindow()); | 196 EventTypeNames::mousedown, mouseEvent, Vector<PlatformMouseEvent>(), |
| 197 m_frame->document()->domWindow()); |
| 202 | 198 |
| 203 // TODO(crbug/545647): This state should reset with pointercancel too. | 199 // TODO(crbug/545647): This state should reset with pointercancel too. |
| 204 // This function also gets called for compat mouse events of touch at this | 200 // This function also gets called for compat mouse events of touch at this |
| 205 // stage. So if the event is not frame boundary transition it is only a | 201 // stage. So if the event is not frame boundary transition it is only a |
| 206 // compatibility mouse event and we do not need to change pointer event | 202 // compatibility mouse event and we do not need to change pointer event |
| 207 // behavior regarding preventMouseEvent state in that case. | 203 // behavior regarding preventMouseEvent state in that case. |
| 208 if (dummyPointerEvent->buttons() == 0 && dummyPointerEvent->isPrimary()) { | 204 if (dummyPointerEvent->buttons() == 0 && dummyPointerEvent->isPrimary()) { |
| 209 m_preventMouseEventForPointerType[toPointerTypeIndex( | 205 m_preventMouseEventForPointerType[toPointerTypeIndex( |
| 210 mouseEvent.pointerProperties().pointerType)] = false; | 206 mouseEvent.pointerProperties().pointerType)] = false; |
| 211 } | 207 } |
| (...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 288 | 284 |
| 289 removePointer(pointerEvent); | 285 removePointer(pointerEvent); |
| 290 } | 286 } |
| 291 } | 287 } |
| 292 | 288 |
| 293 void PointerEventManager::unblockTouchPointers() { | 289 void PointerEventManager::unblockTouchPointers() { |
| 294 m_inCanceledStateForPointerTypeTouch = false; | 290 m_inCanceledStateForPointerTypeTouch = false; |
| 295 } | 291 } |
| 296 | 292 |
| 297 WebInputEventResult PointerEventManager::handleTouchEvents( | 293 WebInputEventResult PointerEventManager::handleTouchEvents( |
| 298 const PlatformTouchEvent& event) { | 294 const PlatformTouchEvent& event, |
| 295 const Vector<PlatformTouchEvent>& coalescedEvents) { |
| 299 if (event.type() == PlatformEvent::TouchScrollStarted) { | 296 if (event.type() == PlatformEvent::TouchScrollStarted) { |
| 300 blockTouchPointers(); | 297 blockTouchPointers(); |
| 301 m_touchEventManager->setTouchScrollStarted(); | 298 m_touchEventManager->setTouchScrollStarted(); |
| 302 return WebInputEventResult::HandledSystem; | 299 return WebInputEventResult::HandledSystem; |
| 303 } | 300 } |
| 304 | 301 |
| 305 bool newTouchSequence = true; | 302 bool newTouchSequence = true; |
| 306 for (const auto& touchPoint : event.touchPoints()) { | 303 for (const auto& touchPoint : event.touchPoints()) { |
| 307 if (touchPoint.state() != PlatformTouchPoint::TouchPressed) { | 304 if (touchPoint.state() != PlatformTouchPoint::TouchPressed) { |
| 308 newTouchSequence = false; | 305 newTouchSequence = false; |
| 309 break; | 306 break; |
| 310 } | 307 } |
| 311 } | 308 } |
| 312 if (newTouchSequence) | 309 if (newTouchSequence) |
| 313 unblockTouchPointers(); | 310 unblockTouchPointers(); |
| 314 HeapVector<TouchEventManager::TouchInfo> touchInfos; | 311 HeapVector<TouchEventManager::TouchInfo> touchInfos; |
| 315 | 312 |
| 316 dispatchTouchPointerEvents(event, touchInfos); | 313 dispatchTouchPointerEvents(event, coalescedEvents, touchInfos); |
| 317 | 314 |
| 318 return m_touchEventManager->handleTouchEvent(event, touchInfos); | 315 return m_touchEventManager->handleTouchEvent(event, touchInfos); |
| 319 } | 316 } |
| 320 | 317 |
| 321 void PointerEventManager::dispatchTouchPointerEvents( | 318 void PointerEventManager::dispatchTouchPointerEvents( |
| 322 const PlatformTouchEvent& event, | 319 const PlatformTouchEvent& event, |
| 320 const Vector<PlatformTouchEvent>& coalescedEvents, |
| 323 HeapVector<TouchEventManager::TouchInfo>& touchInfos) { | 321 HeapVector<TouchEventManager::TouchInfo>& touchInfos) { |
| 324 // Iterate through the touch points, sending PointerEvents to the targets as | 322 // Iterate through the touch points, sending PointerEvents to the targets as |
| 325 // required. | 323 // required. |
| 326 for (const auto& touchPoint : event.touchPoints()) { | 324 for (const auto& touchPoint : event.touchPoints()) { |
| 327 TouchEventManager::TouchInfo touchInfo; | 325 TouchEventManager::TouchInfo touchInfo; |
| 328 touchInfo.point = touchPoint; | 326 touchInfo.point = touchPoint; |
| 329 | 327 |
| 330 int pointerId = | 328 int pointerId = |
| 331 m_pointerEventFactory.getPointerEventId(touchPoint.pointerProperties()); | 329 m_pointerEventFactory.getPointerEventId(touchPoint.pointerProperties()); |
| 332 // Do the hit test either when the touch first starts or when the touch | 330 // Do the hit test either when the touch first starts or when the touch |
| (...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 370 // and perform a hit-test. | 368 // and perform a hit-test. |
| 371 touchInfo.touchNode = | 369 touchInfo.touchNode = |
| 372 m_pendingPointerCaptureTarget.get(pointerId)->toNode(); | 370 m_pendingPointerCaptureTarget.get(pointerId)->toNode(); |
| 373 touchInfo.targetFrame = touchInfo.touchNode->document().frame(); | 371 touchInfo.targetFrame = touchInfo.touchNode->document().frame(); |
| 374 } | 372 } |
| 375 | 373 |
| 376 // Do not send pointer events for stationary touches or null targetFrame | 374 // Do not send pointer events for stationary touches or null targetFrame |
| 377 if (touchInfo.touchNode && touchInfo.targetFrame && | 375 if (touchInfo.touchNode && touchInfo.targetFrame && |
| 378 touchPoint.state() != PlatformTouchPoint::TouchStationary && | 376 touchPoint.state() != PlatformTouchPoint::TouchStationary && |
| 379 !m_inCanceledStateForPointerTypeTouch) { | 377 !m_inCanceledStateForPointerTypeTouch) { |
| 380 FloatPoint pagePoint = touchInfo.targetFrame->view()->rootFrameToContents( | |
| 381 touchInfo.point.pos()); | |
| 382 float scaleFactor = 1.0f / touchInfo.targetFrame->pageZoomFactor(); | |
| 383 FloatPoint scrollPosition(touchInfo.targetFrame->view()->scrollOffset()); | |
| 384 FloatPoint framePoint = pagePoint.scaledBy(scaleFactor); | |
| 385 framePoint.moveBy(scrollPosition.scaledBy(-scaleFactor)); | |
| 386 PointerEvent* pointerEvent = m_pointerEventFactory.create( | 378 PointerEvent* pointerEvent = m_pointerEventFactory.create( |
| 387 pointerEventNameForTouchPointState(touchPoint.state()), touchPoint, | 379 touchPoint, getCoalescedPoints(coalescedEvents, touchPoint.id()), |
| 388 event.getModifiers(), touchPoint.radius().scaledBy(scaleFactor), | 380 event.getModifiers(), touchInfo.targetFrame, |
| 389 framePoint, | |
| 390 touchInfo.touchNode ? touchInfo.touchNode->document().domWindow() | 381 touchInfo.touchNode ? touchInfo.touchNode->document().domWindow() |
| 391 : nullptr); | 382 : nullptr); |
| 392 | 383 |
| 393 WebInputEventResult result = | 384 WebInputEventResult result = |
| 394 sendTouchPointerEvent(touchInfo.touchNode, pointerEvent); | 385 sendTouchPointerEvent(touchInfo.touchNode, pointerEvent); |
| 395 | 386 |
| 396 // If a pointerdown has been canceled, queue the unique id to allow | 387 // If a pointerdown has been canceled, queue the unique id to allow |
| 397 // suppressing mouse events from gesture events. For mouse events | 388 // suppressing mouse events from gesture events. For mouse events |
| 398 // fired from GestureTap & GestureLongPress (which are triggered by | 389 // fired from GestureTap & GestureLongPress (which are triggered by |
| 399 // single touches only), it is enough to queue the ids only for | 390 // single touches only), it is enough to queue the ids only for |
| (...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 437 | 428 |
| 438 removePointer(pointerEvent); | 429 removePointer(pointerEvent); |
| 439 } | 430 } |
| 440 | 431 |
| 441 return result; | 432 return result; |
| 442 } | 433 } |
| 443 | 434 |
| 444 WebInputEventResult PointerEventManager::sendMousePointerEvent( | 435 WebInputEventResult PointerEventManager::sendMousePointerEvent( |
| 445 Node* target, | 436 Node* target, |
| 446 const AtomicString& mouseEventType, | 437 const AtomicString& mouseEventType, |
| 447 const PlatformMouseEvent& mouseEvent) { | 438 const PlatformMouseEvent& mouseEvent, |
| 448 PointerEvent* pointerEvent = m_pointerEventFactory.create( | 439 const Vector<PlatformMouseEvent>& coalescedEvents) { |
| 449 mouseEventType, mouseEvent, m_frame->document()->domWindow()); | 440 PointerEvent* pointerEvent = |
| 441 m_pointerEventFactory.create(mouseEventType, mouseEvent, coalescedEvents, |
| 442 m_frame->document()->domWindow()); |
| 450 | 443 |
| 451 // This is for when the mouse is released outside of the page. | 444 // This is for when the mouse is released outside of the page. |
| 452 if (pointerEvent->type() == EventTypeNames::pointermove && | 445 if (pointerEvent->type() == EventTypeNames::pointermove && |
| 453 !pointerEvent->buttons()) { | 446 !pointerEvent->buttons()) { |
| 454 releasePointerCapture(pointerEvent->pointerId()); | 447 releasePointerCapture(pointerEvent->pointerId()); |
| 455 // Send got/lostpointercapture rightaway if necessary. | 448 // Send got/lostpointercapture rightaway if necessary. |
| 456 processPendingPointerCapture(pointerEvent); | 449 processPendingPointerCapture(pointerEvent); |
| 457 | 450 |
| 458 if (pointerEvent->isPrimary()) { | 451 if (pointerEvent->isPrimary()) { |
| 459 m_preventMouseEventForPointerType[toPointerTypeIndex( | 452 m_preventMouseEventForPointerType[toPointerTypeIndex( |
| (...skipping 240 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 700 return true; | 693 return true; |
| 701 } | 694 } |
| 702 return false; | 695 return false; |
| 703 } | 696 } |
| 704 | 697 |
| 705 EventTarget* PointerEventManager::getMouseCapturingNode() { | 698 EventTarget* PointerEventManager::getMouseCapturingNode() { |
| 706 return getCapturingNode(PointerEventFactory::s_mouseId); | 699 return getCapturingNode(PointerEventFactory::s_mouseId); |
| 707 } | 700 } |
| 708 | 701 |
| 709 } // namespace blink | 702 } // namespace blink |
| OLD | NEW |