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

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, 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 void dispatchTouchPointerEvents(
dtapuska 2016/04/27 17:07:04 Is it possible for HeapVector to be const? I'm no
Navid Zolghadr 2016/04/28 15:13:11 It is kind of an output parameter in the sense tha
dtapuska 2016/04/29 14:56:54 Can we add a comment to the file describing what i
99 const PlatformTouchEvent&, HeapVector<TouchEventManager::TouchInfo>&);
100
101 // Returns whether the event is consumed or not.
102 WebInputEventResult sendTouchPointerEvent(
103 EventTarget*, PointerEvent*);
104
96 void sendNodeTransitionEvents( 105 void sendNodeTransitionEvents(
97 EventTarget* exitedTarget, 106 EventTarget* exitedTarget,
98 EventTarget* enteredTarget, 107 EventTarget* enteredTarget,
99 PointerEvent*, 108 PointerEvent*,
100 const PlatformMouseEvent& = PlatformMouseEvent(), 109 const PlatformMouseEvent& = PlatformMouseEvent(),
101 bool sendMouseEvent = false); 110 bool sendMouseEvent = false);
102 void setNodeUnderPointer(PointerEvent*, 111 void setNodeUnderPointer(PointerEvent*,
103 EventTarget*, bool sendEvent = true); 112 EventTarget*, bool sendEvent = true);
104 113
105 // Returns whether the pointer capture is changed. In this case this 114 // Returns whether the pointer capture is changed. In this case this
(...skipping 22 matching lines...) Expand all
128 EventTarget* getEffectiveTargetForPointerEvent( 137 EventTarget* getEffectiveTargetForPointerEvent(
129 EventTarget*, int); 138 EventTarget*, int);
130 EventTarget* getCapturingNode(int); 139 EventTarget* getCapturingNode(int);
131 void removePointer(PointerEvent*); 140 void removePointer(PointerEvent*);
132 WebInputEventResult dispatchPointerEvent( 141 WebInputEventResult dispatchPointerEvent(
133 EventTarget*, 142 EventTarget*,
134 PointerEvent*, 143 PointerEvent*,
135 bool checkForListener = false); 144 bool checkForListener = false);
136 void releasePointerCapture(int); 145 void releasePointerCapture(int);
137 146
147 // NOTE: If adding a new field to this class please ensure that it is
148 // cleared in |PointerEventManager::clear()|.
149
150 const Member<LocalFrame> m_frame;
151
138 // Prevents firing mousedown, mousemove & mouseup in-between a canceled poin terdown and next pointerup/pointercancel. 152 // Prevents firing mousedown, mousemove & mouseup in-between a canceled poin terdown and next pointerup/pointercancel.
139 // See "PREVENT MOUSE EVENT flag" in the spec: 153 // See "PREVENT MOUSE EVENT flag" in the spec:
140 // https://w3c.github.io/pointerevents/#compatibility-mapping-with-mouse-e vents 154 // https://w3c.github.io/pointerevents/#compatibility-mapping-with-mouse-e vents
141 bool m_preventMouseEventForPointerType[static_cast<size_t>(WebPointerPropert ies::PointerType::LastEntry) + 1]; 155 bool m_preventMouseEventForPointerType[static_cast<size_t>(WebPointerPropert ies::PointerType::LastEntry) + 1];
142 156
143 // Set upon sending a pointercancel for touch, prevents PE dispatches for to uches until 157 // Set upon sending a pointercancel for touch, prevents PE dispatches for to uches until
144 // all touch-points become inactive. 158 // all touch-points become inactive.
145 bool m_inCanceledStateForPointerTypeTouch; 159 bool m_inCanceledStateForPointerTypeTouch;
146 160
147 // Note that this map keeps track of node under pointer with id=1 as well 161 // 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 162 // which might be different than m_nodeUnderMouse in EventHandler. That one
149 // keeps track of any compatibility mouse event positions but this map for 163 // 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. 164 // the pointer with id=1 is only taking care of true mouse related events.
151 HeapHashMap<int, EventTargetAttributes> m_nodeUnderPointer; 165 using NodeUnderPointerMap = HeapHashMap<int, EventTargetAttributes,
166 WTF::IntHash<int>, WTF::UnsignedWithZeroKeyHashTraits<int>>;
167 NodeUnderPointerMap m_nodeUnderPointer;
152 168
153 PointerCapturingMap m_pointerCaptureTarget; 169 PointerCapturingMap m_pointerCaptureTarget;
154 PointerCapturingMap m_pendingPointerCaptureTarget; 170 PointerCapturingMap m_pendingPointerCaptureTarget;
155 PointerEventFactory m_pointerEventFactory; 171 PointerEventFactory m_pointerEventFactory;
172
dtapuska 2016/04/27 17:07:04 If there isn't a comment I don't think it needs a
Navid Zolghadr 2016/04/28 15:13:11 Done.
173 TouchEventManager m_touchEventManager;
174
156 }; 175 };
157 176
158 } // namespace blink 177 } // namespace blink
159 178
160 #endif // PointerEventManager_h 179 #endif // PointerEventManager_h
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698