| 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 #ifndef PointerEventManager_h | 5 #ifndef PointerEventManager_h |
| 6 #define PointerEventManager_h | 6 #define PointerEventManager_h |
| 7 | 7 |
| 8 #include "core/CoreExport.h" | 8 #include "core/CoreExport.h" |
| 9 #include "core/events/PointerEvent.h" | 9 #include "core/events/PointerEvent.h" |
| 10 #include "core/events/PointerEventFactory.h" | 10 #include "core/events/PointerEventFactory.h" |
| 11 #include "public/platform/WebInputEventResult.h" | 11 #include "public/platform/WebInputEventResult.h" |
| 12 #include "public/platform/WebPointerProperties.h" | 12 #include "public/platform/WebPointerProperties.h" |
| 13 #include "wtf/Allocator.h" | 13 #include "wtf/Allocator.h" |
| 14 #include "wtf/HashMap.h" | 14 #include "wtf/HashMap.h" |
| 15 | 15 |
| 16 namespace blink { | 16 namespace blink { |
| 17 | 17 |
| 18 | 18 |
| 19 // This class takes care of dispatching all pointer events and keeps track of | 19 // This class takes care of dispatching all pointer events and keeps track of |
| 20 // properties of active pointer events. | 20 // properties of active pointer events. |
| 21 class CORE_EXPORT PointerEventManager { | 21 class CORE_EXPORT PointerEventManager { |
| 22 DISALLOW_NEW(); | 22 DISALLOW_NEW(); |
| 23 public: | 23 public: |
| 24 PointerEventManager(); | 24 PointerEventManager(); |
| 25 ~PointerEventManager(); | 25 ~PointerEventManager(); |
| 26 DECLARE_TRACE(); | 26 DECLARE_TRACE(); |
| 27 | 27 |
| 28 WebInputEventResult sendMousePointerEvent( | 28 WebInputEventResult sendMousePointerEvent( |
| 29 PassRefPtrWillBeRawPtr<Node>, const AtomicString& type, | 29 RawPtr<Node>, const AtomicString& type, |
| 30 int clickCount, const PlatformMouseEvent&, | 30 int clickCount, const PlatformMouseEvent&, |
| 31 PassRefPtrWillBeRawPtr<Node> relatedTarget, | 31 RawPtr<Node> relatedTarget, |
| 32 PassRefPtrWillBeRawPtr<AbstractView>, | 32 RawPtr<AbstractView>, |
| 33 PassRefPtrWillBeRawPtr<Node> lastNodeUnderMouse); | 33 RawPtr<Node> lastNodeUnderMouse); |
| 34 | 34 |
| 35 // Returns whether the event is consumed or not | 35 // Returns whether the event is consumed or not |
| 36 WebInputEventResult sendTouchPointerEvent( | 36 WebInputEventResult sendTouchPointerEvent( |
| 37 PassRefPtrWillBeRawPtr<EventTarget>, | 37 RawPtr<EventTarget>, |
| 38 const PlatformTouchPoint&, PlatformEvent::Modifiers, | 38 const PlatformTouchPoint&, PlatformEvent::Modifiers, |
| 39 const double width, const double height, | 39 const double width, const double height, |
| 40 const double clientX, const double clientY); | 40 const double clientX, const double clientY); |
| 41 | 41 |
| 42 void sendTouchCancelPointerEvent(PassRefPtrWillBeRawPtr<EventTarget>, | 42 void sendTouchCancelPointerEvent(RawPtr<EventTarget>, |
| 43 const PlatformTouchPoint&); | 43 const PlatformTouchPoint&); |
| 44 | 44 |
| 45 // Sends node transition events mouseout/leave/over/enter to the | 45 // Sends node transition events mouseout/leave/over/enter to the |
| 46 // corresponding targets. This function sends pointerout/leave/over/enter | 46 // corresponding targets. This function sends pointerout/leave/over/enter |
| 47 // only when isFrameBoundaryTransition is true which indicates the | 47 // only when isFrameBoundaryTransition is true which indicates the |
| 48 // transition is over the document boundary and not only the elements border | 48 // transition is over the document boundary and not only the elements border |
| 49 // inside the document. If isFrameBoundaryTransition is false, | 49 // inside the document. If isFrameBoundaryTransition is false, |
| 50 // then the event is a compatibility event like those created by touch | 50 // then the event is a compatibility event like those created by touch |
| 51 // and in that case the corresponding pointer events will be handled by | 51 // and in that case the corresponding pointer events will be handled by |
| 52 // sendTouchPointerEvent for example and there is no need to send pointer | 52 // sendTouchPointerEvent for example and there is no need to send pointer |
| 53 // transition events. Note that normal mouse events (e.g. mousemove/down/up) | 53 // transition events. Note that normal mouse events (e.g. mousemove/down/up) |
| 54 // and their corresponding transition events will be handled altogether by | 54 // and their corresponding transition events will be handled altogether by |
| 55 // sendMousePointerEvent function. | 55 // sendMousePointerEvent function. |
| 56 void sendMouseAndPossiblyPointerNodeTransitionEvents( | 56 void sendMouseAndPossiblyPointerNodeTransitionEvents( |
| 57 PassRefPtrWillBeRawPtr<Node> exitedNode, | 57 RawPtr<Node> exitedNode, |
| 58 PassRefPtrWillBeRawPtr<Node> enteredNode, | 58 RawPtr<Node> enteredNode, |
| 59 const PlatformMouseEvent&, | 59 const PlatformMouseEvent&, |
| 60 PassRefPtrWillBeRawPtr<AbstractView>, bool isFrameBoundaryTransition); | 60 RawPtr<AbstractView>, bool isFrameBoundaryTransition); |
| 61 | 61 |
| 62 // Clear all the existing ids. | 62 // Clear all the existing ids. |
| 63 void clear(); | 63 void clear(); |
| 64 | 64 |
| 65 void elementRemoved(EventTarget*); | 65 void elementRemoved(EventTarget*); |
| 66 void setPointerCapture(int, EventTarget*); | 66 void setPointerCapture(int, EventTarget*); |
| 67 void releasePointerCapture(int, EventTarget*); | 67 void releasePointerCapture(int, EventTarget*); |
| 68 bool isActive(const int); | 68 bool isActive(const int); |
| 69 | 69 |
| 70 private: | 70 private: |
| 71 typedef WillBeHeapHashMap<int, RefPtrWillBeMember<EventTarget>> PointerCaptu
ringMap; | 71 typedef HeapHashMap<int, Member<EventTarget>> PointerCapturingMap; |
| 72 class EventTargetAttributes { | 72 class EventTargetAttributes { |
| 73 DISALLOW_NEW_EXCEPT_PLACEMENT_NEW(); | 73 DISALLOW_NEW_EXCEPT_PLACEMENT_NEW(); |
| 74 public: | 74 public: |
| 75 DEFINE_INLINE_TRACE() | 75 DEFINE_INLINE_TRACE() |
| 76 { | 76 { |
| 77 visitor->trace(target); | 77 visitor->trace(target); |
| 78 } | 78 } |
| 79 RefPtrWillBeMember<EventTarget> target; | 79 Member<EventTarget> target; |
| 80 bool hasRecievedOverEvent; | 80 bool hasRecievedOverEvent; |
| 81 EventTargetAttributes() | 81 EventTargetAttributes() |
| 82 : target(nullptr) | 82 : target(nullptr) |
| 83 , hasRecievedOverEvent(false) {} | 83 , hasRecievedOverEvent(false) {} |
| 84 EventTargetAttributes(PassRefPtrWillBeRawPtr<EventTarget> target, | 84 EventTargetAttributes(RawPtr<EventTarget> target, |
| 85 bool hasRecievedOverEvent) | 85 bool hasRecievedOverEvent) |
| 86 : target(target) | 86 : target(target) |
| 87 , hasRecievedOverEvent(hasRecievedOverEvent) {} | 87 , hasRecievedOverEvent(hasRecievedOverEvent) {} |
| 88 }; | 88 }; |
| 89 | 89 |
| 90 void sendNodeTransitionEvents( | 90 void sendNodeTransitionEvents( |
| 91 PassRefPtrWillBeRawPtr<EventTarget> exitedTarget, | 91 RawPtr<EventTarget> exitedTarget, |
| 92 PassRefPtrWillBeRawPtr<EventTarget> enteredTarget, | 92 RawPtr<EventTarget> enteredTarget, |
| 93 PassRefPtrWillBeRawPtr<PointerEvent>, | 93 RawPtr<PointerEvent>, |
| 94 const PlatformMouseEvent& = PlatformMouseEvent(), | 94 const PlatformMouseEvent& = PlatformMouseEvent(), |
| 95 bool sendMouseEvent = false); | 95 bool sendMouseEvent = false); |
| 96 void setNodeUnderPointer(PassRefPtrWillBeRawPtr<PointerEvent>, | 96 void setNodeUnderPointer(RawPtr<PointerEvent>, |
| 97 PassRefPtrWillBeRawPtr<EventTarget>, bool sendEvent = true); | 97 RawPtr<EventTarget>, bool sendEvent = true); |
| 98 | 98 |
| 99 // Returns whether the pointer capture is changed. In this case this | 99 // Returns whether the pointer capture is changed. In this case this |
| 100 // function will take care of transition events and setNodeUnderPointer | 100 // function will take care of transition events and setNodeUnderPointer |
| 101 // should not send transition events. | 101 // should not send transition events. |
| 102 bool processPendingPointerCapture( | 102 bool processPendingPointerCapture( |
| 103 const PassRefPtrWillBeRawPtr<PointerEvent>, | 103 const RawPtr<PointerEvent>, |
| 104 const PassRefPtrWillBeRawPtr<EventTarget>, | 104 const RawPtr<EventTarget>, |
| 105 const PlatformMouseEvent& = PlatformMouseEvent(), | 105 const PlatformMouseEvent& = PlatformMouseEvent(), |
| 106 bool sendMouseEvent = false); | 106 bool sendMouseEvent = false); |
| 107 | 107 |
| 108 // Processes the capture state of a pointer, updates node under | 108 // Processes the capture state of a pointer, updates node under |
| 109 // pointer, and sends corresponding transition events for pointer if | 109 // pointer, and sends corresponding transition events for pointer if |
| 110 // setPointerPosition is true. It also sends corresponding transition events | 110 // setPointerPosition is true. It also sends corresponding transition events |
| 111 // for mouse if sendMouseEvent is true. | 111 // for mouse if sendMouseEvent is true. |
| 112 void processCaptureAndPositionOfPointerEvent( | 112 void processCaptureAndPositionOfPointerEvent( |
| 113 const PassRefPtrWillBeRawPtr<PointerEvent>, | 113 const RawPtr<PointerEvent>, |
| 114 const PassRefPtrWillBeRawPtr<EventTarget> hitTestTarget, | 114 const RawPtr<EventTarget> hitTestTarget, |
| 115 const PassRefPtrWillBeRawPtr<EventTarget> lastNodeUnderMouse = nullptr, | 115 const RawPtr<EventTarget> lastNodeUnderMouse = nullptr, |
| 116 const PlatformMouseEvent& = PlatformMouseEvent(), | 116 const PlatformMouseEvent& = PlatformMouseEvent(), |
| 117 bool sendMouseEvent = false, | 117 bool sendMouseEvent = false, |
| 118 bool setPointerPosition = true); | 118 bool setPointerPosition = true); |
| 119 | 119 |
| 120 void removeTargetFromPointerCapturingMapping( | 120 void removeTargetFromPointerCapturingMapping( |
| 121 PointerCapturingMap&, const EventTarget*); | 121 PointerCapturingMap&, const EventTarget*); |
| 122 PassRefPtrWillBeRawPtr<EventTarget> getEffectiveTargetForPointerEvent( | 122 RawPtr<EventTarget> getEffectiveTargetForPointerEvent( |
| 123 PassRefPtrWillBeRawPtr<EventTarget>, int); | 123 RawPtr<EventTarget>, int); |
| 124 EventTarget* getCapturingNode(int); | 124 EventTarget* getCapturingNode(int); |
| 125 void removePointer(const PassRefPtrWillBeRawPtr<PointerEvent>); | 125 void removePointer(const RawPtr<PointerEvent>); |
| 126 WebInputEventResult dispatchPointerEvent( | 126 WebInputEventResult dispatchPointerEvent( |
| 127 PassRefPtrWillBeRawPtr<EventTarget>, | 127 RawPtr<EventTarget>, |
| 128 PassRefPtrWillBeRawPtr<PointerEvent>, | 128 RawPtr<PointerEvent>, |
| 129 bool checkForListener = false); | 129 bool checkForListener = false); |
| 130 void releasePointerCapture(int); | 130 void releasePointerCapture(int); |
| 131 | 131 |
| 132 // Prevents firing mousedown, mousemove & mouseup in-between a canceled poin
terdown and next pointerup/pointercancel. | 132 // Prevents firing mousedown, mousemove & mouseup in-between a canceled poin
terdown and next pointerup/pointercancel. |
| 133 // See "PREVENT MOUSE EVENT flag" in the spec: | 133 // See "PREVENT MOUSE EVENT flag" in the spec: |
| 134 // https://w3c.github.io/pointerevents/#compatibility-mapping-with-mouse-e
vents | 134 // https://w3c.github.io/pointerevents/#compatibility-mapping-with-mouse-e
vents |
| 135 bool m_preventMouseEventForPointerTypeMouse; | 135 bool m_preventMouseEventForPointerTypeMouse; |
| 136 | 136 |
| 137 // Note that this map keeps track of node under pointer with id=1 as well | 137 // Note that this map keeps track of node under pointer with id=1 as well |
| 138 // which might be different than m_nodeUnderMouse in EventHandler. That one | 138 // which might be different than m_nodeUnderMouse in EventHandler. That one |
| 139 // keeps track of any compatibility mouse event positions but this map for | 139 // keeps track of any compatibility mouse event positions but this map for |
| 140 // the pointer with id=1 is only taking care of true mouse related events. | 140 // the pointer with id=1 is only taking care of true mouse related events. |
| 141 WillBeHeapHashMap<int, EventTargetAttributes> m_nodeUnderPointer; | 141 HeapHashMap<int, EventTargetAttributes> m_nodeUnderPointer; |
| 142 | 142 |
| 143 PointerCapturingMap m_pointerCaptureTarget; | 143 PointerCapturingMap m_pointerCaptureTarget; |
| 144 PointerCapturingMap m_pendingPointerCaptureTarget; | 144 PointerCapturingMap m_pendingPointerCaptureTarget; |
| 145 PointerEventFactory m_pointerEventFactory; | 145 PointerEventFactory m_pointerEventFactory; |
| 146 }; | 146 }; |
| 147 | 147 |
| 148 } // namespace blink | 148 } // namespace blink |
| 149 | 149 |
| 150 #endif // PointerEventManager_h | 150 #endif // PointerEventManager_h |
| OLD | NEW |