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

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

Issue 2350433002: Extract more of the mouse logic from EventHandler (Closed)
Patch Set: Yet another rebase because of a presubmit rule bug Created 4 years, 2 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 MouseEventManager_h 5 #ifndef MouseEventManager_h
6 #define MouseEventManager_h 6 #define MouseEventManager_h
7 7
8 #include "core/CoreExport.h" 8 #include "core/CoreExport.h"
9 #include "core/frame/LocalFrame.h"
10 #include "core/input/BoundaryEventDispatcher.h" 9 #include "core/input/BoundaryEventDispatcher.h"
10 #include "core/page/DragActions.h"
11 #include "core/page/EventWithHitTestResults.h"
11 #include "platform/PlatformMouseEvent.h" 12 #include "platform/PlatformMouseEvent.h"
13 #include "platform/Timer.h"
12 #include "public/platform/WebInputEventResult.h" 14 #include "public/platform/WebInputEventResult.h"
13 #include "wtf/Allocator.h" 15 #include "wtf/Allocator.h"
14 16
15 namespace blink { 17 namespace blink {
16 18
19 class DragState;
20 class DataTransfer;
21 class Element;
22 class FloatQuad;
23 class HitTestResult;
24 class InputDeviceCapabilities;
17 class LocalFrame; 25 class LocalFrame;
26 class ScrollManager;
27
28 enum class DragInitiator;
18 29
19 // This class takes care of dispatching all mouse events and keeps track of 30 // This class takes care of dispatching all mouse events and keeps track of
20 // positions and states of mouse. 31 // positions and states of mouse.
21 class CORE_EXPORT MouseEventManager 32 class CORE_EXPORT MouseEventManager
22 : public GarbageCollectedFinalized<MouseEventManager> { 33 : public GarbageCollectedFinalized<MouseEventManager> {
23 WTF_MAKE_NONCOPYABLE(MouseEventManager); 34 WTF_MAKE_NONCOPYABLE(MouseEventManager);
24 35
25 public: 36 public:
26 explicit MouseEventManager(LocalFrame*); 37 MouseEventManager(LocalFrame*, ScrollManager*);
27 DECLARE_TRACE(); 38 DECLARE_TRACE();
28 39
29 WebInputEventResult dispatchMouseEvent(EventTarget*, 40 WebInputEventResult dispatchMouseEvent(EventTarget*,
30 const AtomicString&, 41 const AtomicString&,
31 const PlatformMouseEvent&, 42 const PlatformMouseEvent&,
32 EventTarget* relatedTarget, 43 EventTarget* relatedTarget,
33 int detail = 0,
34 bool checkForListener = false); 44 bool checkForListener = false);
35 45
46 WebInputEventResult setMousePositionAndDispatchMouseEvent(
47 Node* targetNode,
48 const AtomicString& eventType,
49 const PlatformMouseEvent&);
50
51 WebInputEventResult dispatchMouseClickIfNeeded(
52 const MouseEventWithHitTestResults&);
53
54 WebInputEventResult dispatchDragSrcEvent(const AtomicString& eventType,
55 const PlatformMouseEvent&);
56 WebInputEventResult dispatchDragEvent(const AtomicString& eventType,
57 Node* target,
58 const PlatformMouseEvent&,
59 DataTransfer*);
60
36 // Resets the internal state of this object. 61 // Resets the internal state of this object.
37 void clear(); 62 void clear();
38 63
39 void sendBoundaryEvents(EventTarget* exitedTarget, 64 void sendBoundaryEvents(EventTarget* exitedTarget,
40 EventTarget* enteredTarget, 65 EventTarget* enteredTarget,
41 const PlatformMouseEvent& mousePlatformEvent); 66 const PlatformMouseEvent& mousePlatformEvent);
42 67
68 void setNodeUnderMouse(Node*, const PlatformMouseEvent&);
69
70 WebInputEventResult handleMouseFocus(
71 const HitTestResult&,
72 InputDeviceCapabilities* sourceCapabilities);
73
74 void fakeMouseMoveEventTimerFired(TimerBase*);
75
76 void cancelFakeMouseMoveEvent();
77 void dispatchFakeMouseMoveEventSoon();
78 void dispatchFakeMouseMoveEventSoonInQuad(const FloatQuad&);
79
80 void setLastKnownMousePosition(const PlatformMouseEvent&);
81
82 bool handleDragDropIfPossible(const GestureEventWithHitTestResults&);
83
84 WebInputEventResult handleMouseDraggedEvent(
85 const MouseEventWithHitTestResults&);
86 WebInputEventResult handleMousePressEvent(
87 const MouseEventWithHitTestResults&);
88 WebInputEventResult handleMouseReleaseEvent(
89 const MouseEventWithHitTestResults&);
90
91 void nodeWillBeRemoved(Node& nodeToBeRemoved);
92
93 static DragState& dragState();
94
95 void focusDocumentView();
96
97 // Resets the state that indicates the next events could cause a drag. It is c alled when
98 // we realize the next events should not cause drag based on the drag heuristi cs.
99 void clearDragHeuristicState();
100
101 void dragSourceEndedAt(const PlatformMouseEvent&, DragOperation);
102
103 void updateSelectionForMouseDrag();
104
105 void handleMousePressEventUpdateStates(const PlatformMouseEvent&);
106
107 // Returns whether pan is handled and resets the state on release.
108 bool handleSvgPanIfNeeded(bool isReleaseEvent);
109
110 void invalidateClick();
111
112 // TODO: These functions ideally should be private but the code needs more
113 // refactoring to be able to remove the dependency from EventHandler.
114 Node* getNodeUnderMouse();
115 bool isMousePositionUnknown();
116 IntPoint lastKnownMousePosition();
117
118 bool mousePressed();
119 void setMousePressed(bool);
120
121 bool capturesDragging() const;
122 void setCapturesDragging(bool);
123
124 void setMouseDownMayStartAutoscroll() {
125 m_mouseDownMayStartAutoscroll = true;
126 }
127
128 Node* mousePressNode();
129 void setMousePressNode(Node*);
130
131 void setClickNode(Node*);
132 void setClickCount(int);
133
134 bool mouseDownMayStartDrag();
135
43 private: 136 private:
44 class MouseEventBoundaryEventDispatcher : public BoundaryEventDispatcher { 137 class MouseEventBoundaryEventDispatcher : public BoundaryEventDispatcher {
45 WTF_MAKE_NONCOPYABLE(MouseEventBoundaryEventDispatcher); 138 WTF_MAKE_NONCOPYABLE(MouseEventBoundaryEventDispatcher);
46 139
47 public: 140 public:
48 MouseEventBoundaryEventDispatcher(MouseEventManager*, 141 MouseEventBoundaryEventDispatcher(MouseEventManager*,
49 const PlatformMouseEvent*, 142 const PlatformMouseEvent*,
50 EventTarget* exitedTarget); 143 EventTarget* exitedTarget);
51 144
52 protected: 145 protected:
(...skipping 12 matching lines...) Expand all
65 void dispatch(EventTarget*, 158 void dispatch(EventTarget*,
66 EventTarget* relatedTarget, 159 EventTarget* relatedTarget,
67 const AtomicString&, 160 const AtomicString&,
68 const PlatformMouseEvent&, 161 const PlatformMouseEvent&,
69 bool checkForListener); 162 bool checkForListener);
70 Member<MouseEventManager> m_mouseEventManager; 163 Member<MouseEventManager> m_mouseEventManager;
71 const PlatformMouseEvent* m_platformMouseEvent; 164 const PlatformMouseEvent* m_platformMouseEvent;
72 Member<EventTarget> m_exitedTarget; 165 Member<EventTarget> m_exitedTarget;
73 }; 166 };
74 167
168 // If the given element is a shadow host and its root has delegatesFocus=false flag,
169 // slide focus to its inner element. Returns true if the resulting focus is di fferent from
170 // the given element.
171 bool slideFocusOnShadowHostIfNecessary(const Element&);
172
173 bool dragHysteresisExceeded(const IntPoint&) const;
174 bool handleDrag(const MouseEventWithHitTestResults&, DragInitiator);
175 bool tryStartDrag(const MouseEventWithHitTestResults&);
176 void clearDragDataTransfer();
177 DataTransfer* createDraggingDataTransfer() const;
178
75 // NOTE: If adding a new field to this class please ensure that it is 179 // NOTE: If adding a new field to this class please ensure that it is
76 // cleared in |MouseEventManager::clear()|. 180 // cleared in |MouseEventManager::clear()|.
77 181
78 const Member<LocalFrame> m_frame; 182 const Member<LocalFrame> m_frame;
183 Member<ScrollManager> m_scrollManager;
79 184
80 // The effective position of the mouse pointer. 185 // The effective position of the mouse pointer.
81 // See https://w3c.github.io/pointerevents/#dfn-tracking-the-effective-positio n-of-the-legacy-mouse-pointer. 186 // See https://w3c.github.io/pointerevents/#dfn-tracking-the-effective-positio n-of-the-legacy-mouse-pointer.
82 Member<Node> m_nodeUnderMouse; 187 Member<Node> m_nodeUnderMouse;
188
189 // The last mouse movement position this frame has seen in root frame coordina tes.
190 IntPoint m_lastKnownMousePosition;
191 IntPoint m_lastKnownMouseGlobalPosition;
192
193 unsigned m_isMousePositionUnknown : 1;
194 // Current button-press state for mouse/mouse-like-stylus.
195 // TODO(crbug.com/563676): Buggy for chorded buttons.
196 unsigned m_mousePressed : 1;
197
198 unsigned m_mouseDownMayStartAutoscroll : 1;
199 unsigned m_svgPan : 1;
200 unsigned m_capturesDragging : 1;
201 unsigned m_mouseDownMayStartDrag : 1;
202
203 Member<Node> m_mousePressNode;
204
205 int m_clickCount;
206 Member<Node> m_clickNode;
207
208 IntPoint m_mouseDownPos; // In our view's coords.
209 double m_mouseDownTimestamp;
210 PlatformMouseEvent m_mouseDown;
211
212 LayoutPoint m_dragStartPos;
213
214 Timer<MouseEventManager> m_fakeMouseMoveEventTimer;
83 }; 215 };
84 216
85 } // namespace blink 217 } // namespace blink
86 218
87 #endif // MouseEventManager_h 219 #endif // MouseEventManager_h
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698