Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(287)

Side by Side Diff: third_party/WebKit/Source/core/input/PointerEventManager.h

Issue 1892653003: Extract touch handling logic from EventHandler (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Add TODO Created 4 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 "core/input/TouchEventManager.h"
11 #include "public/platform/WebInputEventResult.h" 12 #include "public/platform/WebInputEventResult.h"
12 #include "public/platform/WebPointerProperties.h" 13 #include "public/platform/WebPointerProperties.h"
13 #include "wtf/Allocator.h" 14 #include "wtf/Allocator.h"
14 #include "wtf/HashMap.h" 15 #include "wtf/HashMap.h"
15 16
16 namespace blink { 17 namespace blink {
17 18
19 class LocalFrame;
18 20
19 // This class takes care of dispatching all pointer events and keeps track of 21 // This class takes care of dispatching all pointer events and keeps track of
20 // properties of active pointer events. 22 // properties of active pointer events.
21 class CORE_EXPORT PointerEventManager { 23 class CORE_EXPORT PointerEventManager {
22 DISALLOW_NEW(); 24 DISALLOW_NEW();
23 public: 25 public:
24 PointerEventManager(); 26 explicit PointerEventManager(LocalFrame*);
25 ~PointerEventManager(); 27 ~PointerEventManager();
26 DECLARE_TRACE(); 28 DECLARE_TRACE();
27 29
28 WebInputEventResult sendMousePointerEvent( 30 WebInputEventResult sendMousePointerEvent(
29 Node*, const AtomicString& type, 31 Node*, const AtomicString& type,
30 int clickCount, const PlatformMouseEvent&, 32 int clickCount, const PlatformMouseEvent&,
31 Node* relatedTarget, 33 Node* relatedTarget,
32 AbstractView*, 34 AbstractView*,
33 Node* lastNodeUnderMouse); 35 Node* lastNodeUnderMouse);
34 36
35 // Returns whether the event is consumed or not 37 WebInputEventResult handleTouchEvents(
36 WebInputEventResult sendTouchPointerEvent( 38 const PlatformTouchEvent&);
37 EventTarget*,
38 const PlatformTouchPoint&, PlatformEvent::Modifiers,
39 const double width, const double height,
40 const double clientX, const double clientY);
41
42 // Inhibits firing of touch-type PointerEvents until unblocked by unblockTou chPointers(). Also
43 // sends pointercancels for existing touch-type PointerEvents.
44 // See: www.w3.org/TR/pointerevents/#declaring-candidate-regions-for-default -touch-behaviors
45 void blockTouchPointers();
46
47 // Enables firing of touch-type PointerEvents after they were inhibited by b lockTouchPointers().
48 void unblockTouchPointers();
49 39
50 // Sends node transition events mouseout/leave/over/enter to the 40 // Sends node transition events mouseout/leave/over/enter to the
51 // corresponding targets. This function sends pointerout/leave/over/enter 41 // corresponding targets. This function sends pointerout/leave/over/enter
52 // only when isFrameBoundaryTransition is true which indicates the 42 // only when isFrameBoundaryTransition is true which indicates the
53 // transition is over the document boundary and not only the elements border 43 // transition is over the document boundary and not only the elements border
54 // inside the document. If isFrameBoundaryTransition is false, 44 // inside the document. If isFrameBoundaryTransition is false,
55 // then the event is a compatibility event like those created by touch 45 // then the event is a compatibility event like those created by touch
56 // and in that case the corresponding pointer events will be handled by 46 // and in that case the corresponding pointer events will be handled by
57 // sendTouchPointerEvent for example and there is no need to send pointer 47 // sendTouchPointerEvent for example and there is no need to send pointer
58 // transition events. Note that normal mouse events (e.g. mousemove/down/up) 48 // transition events. Note that normal mouse events (e.g. mousemove/down/up)
59 // and their corresponding transition events will be handled altogether by 49 // and their corresponding transition events will be handled altogether by
60 // sendMousePointerEvent function. 50 // sendMousePointerEvent function.
61 void sendMouseAndPossiblyPointerNodeTransitionEvents( 51 void sendMouseAndPossiblyPointerNodeTransitionEvents(
62 Node* exitedNode, 52 Node* exitedNode,
63 Node* enteredNode, 53 Node* enteredNode,
64 const PlatformMouseEvent&, 54 const PlatformMouseEvent&,
65 AbstractView*, bool isFrameBoundaryTransition); 55 AbstractView*, bool isFrameBoundaryTransition);
66 56
67 // Clear all the existing ids. 57 // Resets the internal state of this object.
68 void clear(); 58 void clear();
69 59
70 void elementRemoved(EventTarget*); 60 void elementRemoved(EventTarget*);
71 void setPointerCapture(int, EventTarget*); 61 void setPointerCapture(int, EventTarget*);
72 void releasePointerCapture(int, EventTarget*); 62 void releasePointerCapture(int, EventTarget*);
73 bool isActive(const int); 63 bool isActive(const int) const;
74 WebPointerProperties::PointerType getPointerEventType(const int); 64 WebPointerProperties::PointerType getPointerEventType(const int) const;
65
66 // Returns whether there is any touch on the screen.
67 bool isAnyTouchActive() const;
75 68
76 private: 69 private:
77 typedef HeapHashMap<int, Member<EventTarget>> PointerCapturingMap; 70 typedef HeapHashMap<int, Member<EventTarget>, WTF::IntHash<int>,
71 WTF::UnsignedWithZeroKeyHashTraits<int>> PointerCapturingMap;
78 class EventTargetAttributes { 72 class EventTargetAttributes {
79 DISALLOW_NEW_EXCEPT_PLACEMENT_NEW(); 73 DISALLOW_NEW_EXCEPT_PLACEMENT_NEW();
80 public: 74 public:
81 DEFINE_INLINE_TRACE() 75 DEFINE_INLINE_TRACE()
82 { 76 {
83 visitor->trace(target); 77 visitor->trace(target);
84 } 78 }
85 Member<EventTarget> target; 79 Member<EventTarget> target;
86 bool hasRecievedOverEvent; 80 bool hasRecievedOverEvent;
87 EventTargetAttributes() 81 EventTargetAttributes()
88 : target(nullptr) 82 : target(nullptr)
89 , hasRecievedOverEvent(false) {} 83 , hasRecievedOverEvent(false) {}
90 EventTargetAttributes(EventTarget* target, 84 EventTargetAttributes(EventTarget* target,
91 bool hasRecievedOverEvent) 85 bool hasRecievedOverEvent)
92 : target(target) 86 : target(target)
93 , hasRecievedOverEvent(hasRecievedOverEvent) {} 87 , hasRecievedOverEvent(hasRecievedOverEvent) {}
94 }; 88 };
95 89
90 // Inhibits firing of touch-type PointerEvents until unblocked by unblockTou chPointers(). Also
91 // sends pointercancels for existing touch-type PointerEvents.
92 // See: www.w3.org/TR/pointerevents/#declaring-candidate-regions-for-default -touch-behaviors
93 void blockTouchPointers();
94
95 // Enables firing of touch-type PointerEvents after they were inhibited by b lockTouchPointers().
96 void unblockTouchPointers();
97
98 // Sends touch pointer events and sets consumed bits in TouchInfo array
99 // based on the return value of pointer event handlers.
100 void dispatchTouchPointerEvents(
101 const PlatformTouchEvent&,
102 HeapVector<TouchEventManager::TouchInfo>&);
103
104 // Returns whether the event is consumed or not.
105 WebInputEventResult sendTouchPointerEvent(EventTarget*, PointerEvent*);
106
96 void sendNodeTransitionEvents( 107 void sendNodeTransitionEvents(
97 EventTarget* exitedTarget, 108 EventTarget* exitedTarget,
98 EventTarget* enteredTarget, 109 EventTarget* enteredTarget,
99 PointerEvent*, 110 PointerEvent*,
100 const PlatformMouseEvent& = PlatformMouseEvent(), 111 const PlatformMouseEvent& = PlatformMouseEvent(),
101 bool sendMouseEvent = false); 112 bool sendMouseEvent = false);
102 void setNodeUnderPointer(PointerEvent*, 113 void setNodeUnderPointer(PointerEvent*,
103 EventTarget*, bool sendEvent = true); 114 EventTarget*, bool sendEvent = true);
104 115
105 // Returns whether the pointer capture is changed. In this case this 116 // Returns whether the pointer capture is changed. In this case this
(...skipping 22 matching lines...) Expand all
128 EventTarget* getEffectiveTargetForPointerEvent( 139 EventTarget* getEffectiveTargetForPointerEvent(
129 EventTarget*, int); 140 EventTarget*, int);
130 EventTarget* getCapturingNode(int); 141 EventTarget* getCapturingNode(int);
131 void removePointer(PointerEvent*); 142 void removePointer(PointerEvent*);
132 WebInputEventResult dispatchPointerEvent( 143 WebInputEventResult dispatchPointerEvent(
133 EventTarget*, 144 EventTarget*,
134 PointerEvent*, 145 PointerEvent*,
135 bool checkForListener = false); 146 bool checkForListener = false);
136 void releasePointerCapture(int); 147 void releasePointerCapture(int);
137 148
149 // NOTE: If adding a new field to this class please ensure that it is
150 // cleared in |PointerEventManager::clear()|.
151
152 const Member<LocalFrame> m_frame;
153
138 // Prevents firing mousedown, mousemove & mouseup in-between a canceled poin terdown and next pointerup/pointercancel. 154 // Prevents firing mousedown, mousemove & mouseup in-between a canceled poin terdown and next pointerup/pointercancel.
139 // See "PREVENT MOUSE EVENT flag" in the spec: 155 // See "PREVENT MOUSE EVENT flag" in the spec:
140 // https://w3c.github.io/pointerevents/#compatibility-mapping-with-mouse-e vents 156 // https://w3c.github.io/pointerevents/#compatibility-mapping-with-mouse-e vents
141 bool m_preventMouseEventForPointerType[static_cast<size_t>(WebPointerPropert ies::PointerType::LastEntry) + 1]; 157 bool m_preventMouseEventForPointerType[static_cast<size_t>(WebPointerPropert ies::PointerType::LastEntry) + 1];
142 158
143 // Set upon sending a pointercancel for touch, prevents PE dispatches for to uches until 159 // Set upon sending a pointercancel for touch, prevents PE dispatches for to uches until
144 // all touch-points become inactive. 160 // all touch-points become inactive.
145 bool m_inCanceledStateForPointerTypeTouch; 161 bool m_inCanceledStateForPointerTypeTouch;
146 162
147 // Note that this map keeps track of node under pointer with id=1 as well 163 // Note that this map keeps track of node under pointer with id=1 as well
148 // which might be different than m_nodeUnderMouse in EventHandler. That one 164 // which might be different than m_nodeUnderMouse in EventHandler. That one
149 // keeps track of any compatibility mouse event positions but this map for 165 // keeps track of any compatibility mouse event positions but this map for
150 // the pointer with id=1 is only taking care of true mouse related events. 166 // the pointer with id=1 is only taking care of true mouse related events.
151 HeapHashMap<int, EventTargetAttributes> m_nodeUnderPointer; 167 using NodeUnderPointerMap = HeapHashMap<int, EventTargetAttributes,
168 WTF::IntHash<int>, WTF::UnsignedWithZeroKeyHashTraits<int>>;
169 NodeUnderPointerMap m_nodeUnderPointer;
152 170
153 PointerCapturingMap m_pointerCaptureTarget; 171 PointerCapturingMap m_pointerCaptureTarget;
154 PointerCapturingMap m_pendingPointerCaptureTarget; 172 PointerCapturingMap m_pendingPointerCaptureTarget;
155 PointerEventFactory m_pointerEventFactory; 173 PointerEventFactory m_pointerEventFactory;
174 TouchEventManager m_touchEventManager;
175
156 }; 176 };
157 177
158 } // namespace blink 178 } // namespace blink
159 179
160 #endif // PointerEventManager_h 180 #endif // PointerEventManager_h
OLDNEW
« no previous file with comments | « third_party/WebKit/Source/core/input/EventHandler.cpp ('k') | third_party/WebKit/Source/core/input/PointerEventManager.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698