Chromium Code Reviews| 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 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 : public GarbageCollectedFinalized<MouseEven tManager> { | 32 class CORE_EXPORT MouseEventManager : public GarbageCollectedFinalized<MouseEven tManager> { |
| 22 WTF_MAKE_NONCOPYABLE(MouseEventManager); | 33 WTF_MAKE_NONCOPYABLE(MouseEventManager); |
| 23 | 34 |
| 24 public: | 35 public: |
| 25 explicit MouseEventManager(LocalFrame*); | 36 explicit MouseEventManager(LocalFrame*, ScrollManager*); |
| 37 ~MouseEventManager(); | |
| 26 DECLARE_TRACE(); | 38 DECLARE_TRACE(); |
| 27 | 39 |
| 28 WebInputEventResult dispatchMouseEvent( | 40 WebInputEventResult dispatchMouseEvent( |
| 29 EventTarget*, const AtomicString&, const PlatformMouseEvent&, | 41 EventTarget*, const AtomicString&, const PlatformMouseEvent&, |
| 30 EventTarget* relatedTarget, int detail = 0, | 42 EventTarget* relatedTarget, bool checkForListener = false); |
| 31 bool checkForListener = false); | 43 |
| 44 WebInputEventResult dispatchMouseEvent( | |
| 45 Node* targetNode, const AtomicString& eventType, | |
| 46 const PlatformMouseEvent&); | |
| 47 | |
| 48 WebInputEventResult dispatchMouseClickIfNeeded( | |
| 49 const MouseEventWithHitTestResults&); | |
| 50 | |
| 51 WebInputEventResult dispatchDragSrcEvent(const AtomicString& eventType, cons t PlatformMouseEvent&); | |
| 52 WebInputEventResult dispatchDragEvent(const AtomicString& eventType, Node* t arget, const PlatformMouseEvent&, DataTransfer*); | |
| 32 | 53 |
| 33 // Resets the internal state of this object. | 54 // Resets the internal state of this object. |
| 34 void clear(); | 55 void clear(); |
| 35 | 56 |
| 36 void sendBoundaryEvents( | 57 void sendBoundaryEvents( |
| 37 EventTarget* exitedTarget, | 58 EventTarget* exitedTarget, |
| 38 EventTarget* enteredTarget, | 59 EventTarget* enteredTarget, |
| 39 const PlatformMouseEvent& mousePlatformEvent); | 60 const PlatformMouseEvent& mousePlatformEvent); |
| 40 | 61 |
| 62 void setNodeUnderMouse(Node*, const PlatformMouseEvent&); | |
| 63 | |
| 64 WebInputEventResult handleMouseFocus(const HitTestResult&, InputDeviceCapabi lities* sourceCapabilities); | |
| 65 | |
| 66 void fakeMouseMoveEventTimerFired(TimerBase*); | |
| 67 | |
| 68 void cancelFakeMouseMoveEvent(); | |
| 69 void dispatchFakeMouseMoveEventSoon(); | |
| 70 void dispatchFakeMouseMoveEventSoonInQuad(const FloatQuad&); | |
| 71 | |
| 72 void setLastKnownMousePosition(const PlatformMouseEvent&); | |
| 73 | |
| 74 bool handleDragDropIfPossible(const GestureEventWithHitTestResults&); | |
| 75 | |
| 76 WebInputEventResult handleMouseDraggedEvent(const MouseEventWithHitTestResul ts&); | |
| 77 WebInputEventResult handleMousePressEvent(const MouseEventWithHitTestResults &); | |
| 78 WebInputEventResult handleMouseReleaseEvent(const MouseEventWithHitTestResul ts&); | |
| 79 | |
| 80 void nodeWillBeRemoved(Node& nodeToBeRemoved); | |
| 81 | |
| 82 static DragState& dragState(); | |
|
dtapuska
2016/09/21 17:07:44
Is the intended DragState supposed to be one per t
Navid Zolghadr
2016/09/21 17:17:30
Since the variable is defined in this way as stati
| |
| 83 | |
| 84 void focusDocumentView(); | |
| 85 | |
| 86 // Resets the state that indicates the next events could cause a drag. It is called when | |
| 87 // we realize the next events should not cause drag based on the drag heuris tics. | |
| 88 void clearDragHeuristicState(); | |
| 89 | |
| 90 void dragSourceEndedAt(const PlatformMouseEvent&, DragOperation); | |
| 91 | |
| 92 void updateSelectionForMouseDrag(); | |
| 93 | |
| 94 void handleMousePressEventUpdateStates(const PlatformMouseEvent&); | |
| 95 | |
| 96 // Returns whether pan is handled. | |
|
mustaq
2016/09/21 17:28:14
also say: resets the state on release.
Navid Zolghadr
2016/09/23 11:11:16
Done.
| |
| 97 bool handleSvgPanIfNeeded(bool isReleaseEvent); | |
| 98 | |
| 99 void invalidateClick(); | |
| 100 | |
| 101 | |
| 102 // TODO: These functions ideally should be private but the code needs more | |
| 103 // refactoring to be able to remove the dependency from EventHandler. | |
| 104 Node* getNodeUnderMouse(); | |
| 105 bool isMousePositionUnknown(); | |
| 106 IntPoint lastKnownMousePosition(); | |
| 107 | |
| 108 bool mousePressed(); | |
| 109 void setMousePressed(bool); | |
| 110 | |
| 111 bool capturesDragging() const; | |
| 112 void setCapturesDragging(bool); | |
| 113 | |
| 114 void setMouseDownMayStartAutoscroll() { m_mouseDownMayStartAutoscroll = true ; } | |
| 115 | |
| 116 Node* mousePressNode(); | |
| 117 void setMousePressNode(Node*); | |
| 118 | |
| 119 void setClickNode(Node*); | |
| 120 void setClickCount(int); | |
| 121 | |
| 122 bool mouseDownMayStartDrag(); | |
| 123 | |
| 41 private: | 124 private: |
| 42 class MouseEventBoundaryEventDispatcher : public BoundaryEventDispatcher { | 125 class MouseEventBoundaryEventDispatcher : public BoundaryEventDispatcher { |
| 43 WTF_MAKE_NONCOPYABLE(MouseEventBoundaryEventDispatcher); | 126 WTF_MAKE_NONCOPYABLE(MouseEventBoundaryEventDispatcher); |
| 44 | 127 |
| 45 public: | 128 public: |
| 46 MouseEventBoundaryEventDispatcher(MouseEventManager*, | 129 MouseEventBoundaryEventDispatcher(MouseEventManager*, |
| 47 const PlatformMouseEvent*, EventTarget* exitedTarget); | 130 const PlatformMouseEvent*, EventTarget* exitedTarget); |
| 48 | 131 |
| 49 protected: | 132 protected: |
| 50 void dispatchOut(EventTarget*, EventTarget* relatedTarget) override; | 133 void dispatchOut(EventTarget*, EventTarget* relatedTarget) override; |
| 51 void dispatchOver(EventTarget*, EventTarget* relatedTarget) override; | 134 void dispatchOver(EventTarget*, EventTarget* relatedTarget) override; |
| 52 void dispatchLeave(EventTarget*, EventTarget* relatedTarget, bool checkF orListener) override; | 135 void dispatchLeave(EventTarget*, EventTarget* relatedTarget, bool checkF orListener) override; |
| 53 void dispatchEnter(EventTarget*, EventTarget* relatedTarget, bool checkF orListener) override; | 136 void dispatchEnter(EventTarget*, EventTarget* relatedTarget, bool checkF orListener) override; |
| 54 AtomicString getLeaveEvent() override; | 137 AtomicString getLeaveEvent() override; |
| 55 AtomicString getEnterEvent() override; | 138 AtomicString getEnterEvent() override; |
| 56 | 139 |
| 57 private: | 140 private: |
| 58 void dispatch(EventTarget*, EventTarget* relatedTarget, | 141 void dispatch(EventTarget*, EventTarget* relatedTarget, |
| 59 const AtomicString&, const PlatformMouseEvent&, | 142 const AtomicString&, const PlatformMouseEvent&, |
| 60 bool checkForListener); | 143 bool checkForListener); |
| 61 Member<MouseEventManager> m_mouseEventManager; | 144 Member<MouseEventManager> m_mouseEventManager; |
| 62 const PlatformMouseEvent* m_platformMouseEvent; | 145 const PlatformMouseEvent* m_platformMouseEvent; |
| 63 Member<EventTarget> m_exitedTarget; | 146 Member<EventTarget> m_exitedTarget; |
| 64 }; | 147 }; |
| 65 | 148 |
| 149 // If the given element is a shadow host and its root has delegatesFocus=fal se flag, | |
| 150 // slide focus to its inner element. Returns true if the resulting focus is different from | |
| 151 // the given element. | |
| 152 bool slideFocusOnShadowHostIfNecessary(const Element&); | |
| 153 | |
| 154 bool dragHysteresisExceeded(const IntPoint&) const; | |
| 155 bool handleDrag(const MouseEventWithHitTestResults&, DragInitiator); | |
| 156 bool tryStartDrag(const MouseEventWithHitTestResults&); | |
| 157 void clearDragDataTransfer(); | |
| 158 DataTransfer* createDraggingDataTransfer() const; | |
| 159 | |
| 66 // NOTE: If adding a new field to this class please ensure that it is | 160 // NOTE: If adding a new field to this class please ensure that it is |
| 67 // cleared in |MouseEventManager::clear()|. | 161 // cleared in |MouseEventManager::clear()|. |
| 68 | 162 |
| 69 const Member<LocalFrame> m_frame; | 163 const Member<LocalFrame> m_frame; |
| 164 Member<ScrollManager> m_scrollManager; | |
| 70 | 165 |
| 71 // The effective position of the mouse pointer. | 166 // The effective position of the mouse pointer. |
| 72 // See https://w3c.github.io/pointerevents/#dfn-tracking-the-effective-posit ion-of-the-legacy-mouse-pointer. | 167 // See https://w3c.github.io/pointerevents/#dfn-tracking-the-effective-posit ion-of-the-legacy-mouse-pointer. |
| 73 Member<Node> m_nodeUnderMouse; | 168 Member<Node> m_nodeUnderMouse; |
| 169 | |
| 170 bool m_isMousePositionUnknown; | |
|
dtapuska
2016/09/21 17:07:44
We should probably use unsigned m_ : 1 for all the
Navid Zolghadr
2016/09/21 17:17:30
Sure. I'll do that.
| |
| 171 // The last mouse movement position this frame has seen in root frame coordi nates. | |
| 172 IntPoint m_lastKnownMousePosition; | |
| 173 IntPoint m_lastKnownMouseGlobalPosition; | |
| 174 | |
| 175 // Current button-press state for mouse/mouse-like-stylus. | |
| 176 // TODO(crbug.com/563676): Buggy for chorded buttons. | |
| 177 bool m_mousePressed; | |
| 178 | |
| 179 bool m_mouseDownMayStartAutoscroll; | |
| 180 | |
| 181 bool m_capturesDragging; | |
| 182 Member<Node> m_mousePressNode; | |
| 183 | |
| 184 bool m_mouseDownMayStartDrag; | |
| 185 | |
| 186 int m_clickCount; | |
| 187 Member<Node> m_clickNode; | |
| 188 | |
| 189 IntPoint m_mouseDownPos; // In our view's coords. | |
| 190 double m_mouseDownTimestamp; | |
| 191 PlatformMouseEvent m_mouseDown; | |
| 192 | |
| 193 bool m_svgPan; | |
| 194 | |
| 195 LayoutPoint m_dragStartPos; | |
| 196 | |
| 197 Timer<MouseEventManager> m_fakeMouseMoveEventTimer; | |
| 198 | |
| 74 }; | 199 }; |
| 75 | 200 |
| 76 } // namespace blink | 201 } // namespace blink |
| 77 | 202 |
| 78 #endif // MouseEventManager_h | 203 #endif // MouseEventManager_h |
| OLD | NEW |