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

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: Created 4 years, 8 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);
74 WebPointerProperties::PointerType getPointerEventType(const int); 64 WebPointerProperties::PointerType getPointerEventType(const int);
75 65
66 TouchEventManager& getTouchEventManager();
dtapuska 2016/04/15 01:30:50 exposing this API seems odd. There is only one API
Navid Zolghadr 2016/04/15 01:54:30 Sure. I'll do that.
67
76 private: 68 private:
77 typedef HeapHashMap<int, Member<EventTarget>> PointerCapturingMap; 69 typedef HeapHashMap<int, Member<EventTarget>, WTF::IntHash<int>,
70 WTF::UnsignedWithZeroKeyHashTraits<int>> PointerCapturingMap;
78 class EventTargetAttributes { 71 class EventTargetAttributes {
79 DISALLOW_NEW_EXCEPT_PLACEMENT_NEW(); 72 DISALLOW_NEW_EXCEPT_PLACEMENT_NEW();
80 public: 73 public:
81 DEFINE_INLINE_TRACE() 74 DEFINE_INLINE_TRACE()
82 { 75 {
83 visitor->trace(target); 76 visitor->trace(target);
84 } 77 }
85 Member<EventTarget> target; 78 Member<EventTarget> target;
86 bool hasRecievedOverEvent; 79 bool hasRecievedOverEvent;
87 EventTargetAttributes() 80 EventTargetAttributes()
88 : target(nullptr) 81 : target(nullptr)
89 , hasRecievedOverEvent(false) {} 82 , hasRecievedOverEvent(false) {}
90 EventTargetAttributes(EventTarget* target, 83 EventTargetAttributes(EventTarget* target,
91 bool hasRecievedOverEvent) 84 bool hasRecievedOverEvent)
92 : target(target) 85 : target(target)
93 , hasRecievedOverEvent(hasRecievedOverEvent) {} 86 , hasRecievedOverEvent(hasRecievedOverEvent) {}
94 }; 87 };
95 88
89 // Inhibits firing of touch-type PointerEvents until unblocked by unblockTou chPointers(). Also
90 // sends pointercancels for existing touch-type PointerEvents.
91 // See: www.w3.org/TR/pointerevents/#declaring-candidate-regions-for-default -touch-behaviors
92 void blockTouchPointers();
93
94 // Enables firing of touch-type PointerEvents after they were inhibited by b lockTouchPointers().
95 void unblockTouchPointers();
96
97 void dispatchTouchPointerEvents(
98 const PlatformTouchEvent&,
99 HeapVector<TouchEventManager::TouchInfo>&);
100
101 // Returns whether the event is consumed or not
102 WebInputEventResult sendTouchPointerEvent(
103 EventTarget*,
104 PointerEvent*);
105
96 void sendNodeTransitionEvents( 106 void sendNodeTransitionEvents(
97 EventTarget* exitedTarget, 107 EventTarget* exitedTarget,
98 EventTarget* enteredTarget, 108 EventTarget* enteredTarget,
99 PointerEvent*, 109 PointerEvent*,
100 const PlatformMouseEvent& = PlatformMouseEvent(), 110 const PlatformMouseEvent& = PlatformMouseEvent(),
101 bool sendMouseEvent = false); 111 bool sendMouseEvent = false);
102 void setNodeUnderPointer(PointerEvent*, 112 void setNodeUnderPointer(PointerEvent*,
103 EventTarget*, bool sendEvent = true); 113 EventTarget*, bool sendEvent = true);
104 114
105 // Returns whether the pointer capture is changed. In this case this 115 // Returns whether the pointer capture is changed. In this case this
(...skipping 22 matching lines...) Expand all
128 EventTarget* getEffectiveTargetForPointerEvent( 138 EventTarget* getEffectiveTargetForPointerEvent(
129 EventTarget*, int); 139 EventTarget*, int);
130 EventTarget* getCapturingNode(int); 140 EventTarget* getCapturingNode(int);
131 void removePointer(PointerEvent*); 141 void removePointer(PointerEvent*);
132 WebInputEventResult dispatchPointerEvent( 142 WebInputEventResult dispatchPointerEvent(
133 EventTarget*, 143 EventTarget*,
134 PointerEvent*, 144 PointerEvent*,
135 bool checkForListener = false); 145 bool checkForListener = false);
136 void releasePointerCapture(int); 146 void releasePointerCapture(int);
137 147
148 // NOTE: If adding a new field to this class please ensure that it is
149 // cleared in |PointerEventManager::clear()|.
150
151 const Member<LocalFrame> m_frame;
152
138 // Prevents firing mousedown, mousemove & mouseup in-between a canceled poin terdown and next pointerup/pointercancel. 153 // Prevents firing mousedown, mousemove & mouseup in-between a canceled poin terdown and next pointerup/pointercancel.
139 // See "PREVENT MOUSE EVENT flag" in the spec: 154 // See "PREVENT MOUSE EVENT flag" in the spec:
140 // https://w3c.github.io/pointerevents/#compatibility-mapping-with-mouse-e vents 155 // https://w3c.github.io/pointerevents/#compatibility-mapping-with-mouse-e vents
141 bool m_preventMouseEventForPointerType[static_cast<size_t>(WebPointerPropert ies::PointerType::LastEntry) + 1]; 156 bool m_preventMouseEventForPointerType[static_cast<size_t>(WebPointerPropert ies::PointerType::LastEntry) + 1];
142 157
143 // Set upon sending a pointercancel for touch, prevents PE dispatches for to uches until 158 // Set upon sending a pointercancel for touch, prevents PE dispatches for to uches until
144 // all touch-points become inactive. 159 // all touch-points become inactive.
145 bool m_inCanceledStateForPointerTypeTouch; 160 bool m_inCanceledStateForPointerTypeTouch;
146 161
147 // Note that this map keeps track of node under pointer with id=1 as well 162 // 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 163 // which might be different than m_nodeUnderMouse in EventHandler. That one
149 // keeps track of any compatibility mouse event positions but this map for 164 // 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. 165 // the pointer with id=1 is only taking care of true mouse related events.
151 HeapHashMap<int, EventTargetAttributes> m_nodeUnderPointer; 166 using NodeUnderPointerMap = HeapHashMap<int, EventTargetAttributes,
167 WTF::IntHash<int>, WTF::UnsignedWithZeroKeyHashTraits<int>>;
168 NodeUnderPointerMap m_nodeUnderPointer;
152 169
153 PointerCapturingMap m_pointerCaptureTarget; 170 PointerCapturingMap m_pointerCaptureTarget;
154 PointerCapturingMap m_pendingPointerCaptureTarget; 171 PointerCapturingMap m_pendingPointerCaptureTarget;
155 PointerEventFactory m_pointerEventFactory; 172 PointerEventFactory m_pointerEventFactory;
173
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

Powered by Google App Engine
This is Rietveld 408576698