2 * Copyright (C) 2006, 2007 Apple Inc. All rights reserved.
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions
7 * 1. Redistributions of source code must retain the above copyright
8 * notice, this list of conditions and the following disclaimer.
9 * 2. Redistributions in binary form must reproduce the above copyright
10 * notice, this list of conditions and the following disclaimer in the
11 * documentation and/or other materials provided with the distribution.
13 * THIS SOFTWARE IS PROVIDED BY APPLE COMPUTER, INC. ``AS IS'' AND ANY
14 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
15 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
16 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE COMPUTER, INC. OR
17 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
18 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
19 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
20 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
21 * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
22 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
23 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26 #ifndef EventHandler_h
27 #define EventHandler_h
29 #include "DragActions.h"
30 #include "FocusDirection.h"
31 #include "PlatformMouseEvent.h"
32 #include "ScrollTypes.h"
34 #include <wtf/Forward.h>
35 #include <wtf/Noncopyable.h>
36 #include <wtf/Platform.h>
37 #include <wtf/RefPtr.h>
39 #include <wtf/HashMap.h>
40 #include <wtf/HashSet.h>
43 #include "WebCoreKeyboardUIMode.h"
59 class EventTargetNode
;
65 class HTMLFrameSetElement
;
67 class MouseEventWithHitTestResults
;
69 class PlatformKeyboardEvent
;
70 class PlatformWheelEvent
;
76 class SVGElementInstance
;
78 class VisiblePosition
;
80 #if ENABLE(TOUCH_EVENTS)
81 class PlatformTouchEvent
;
86 struct HitTestRequest
;
88 extern const int LinkDragHysteresis
;
89 extern const int ImageDragHysteresis
;
90 extern const int TextDragHysteresis
;
91 extern const int GeneralDragHysteresis
;
92 #if ENABLE(TOUCH_EVENTS)
93 extern const float GestureUnknown
;
96 class EventHandler
: Noncopyable
{
103 void updateSelectionForMouseDrag();
105 Node
* mousePressNode() const;
106 void setMousePressNode(PassRefPtr
<Node
>);
108 bool panScrollInProgress() { return m_panScrollInProgress
; }
109 void setPanScrollInProgress(bool inProgress
) { m_panScrollInProgress
= inProgress
; }
111 void stopAutoscrollTimer(bool rendererIsBeingDestroyed
= false);
112 RenderObject
* autoscrollRenderer() const;
113 void updateAutoscrollRenderer();
115 HitTestResult
hitTestResultAtPoint(const IntPoint
&, bool allowShadowContent
);
117 bool mousePressed() const { return m_mousePressed
; }
118 void setMousePressed(bool pressed
) { m_mousePressed
= pressed
; }
120 void setCapturingMouseEventsNode(PassRefPtr
<Node
>);
122 bool updateDragAndDrop(const PlatformMouseEvent
&, Clipboard
*);
123 void cancelDragAndDrop(const PlatformMouseEvent
&, Clipboard
*);
124 bool performDragAndDrop(const PlatformMouseEvent
&, Clipboard
*);
126 void scheduleHoverStateUpdate();
128 void setResizingFrameSet(HTMLFrameSetElement
*);
130 void resizeLayerDestroyed();
132 IntPoint
currentMousePosition() const;
134 void setIgnoreWheelEvents(bool);
136 bool scrollOverflow(ScrollDirection
, ScrollGranularity
);
138 bool shouldDragAutoNode(Node
*, const IntPoint
&) const; // -webkit-user-drag == auto
140 bool tabsToLinks(KeyboardEvent
*) const;
141 bool tabsToAllControls(KeyboardEvent
*) const;
143 bool mouseDownMayStartSelect() const { return m_mouseDownMayStartSelect
; }
145 bool mouseMoved(const PlatformMouseEvent
&);
147 bool handleMousePressEvent(const PlatformMouseEvent
&);
148 bool handleMouseMoveEvent(const PlatformMouseEvent
&, HitTestResult
* hoveredNode
= 0);
149 bool handleMouseReleaseEvent(const PlatformMouseEvent
&);
150 bool handleWheelEvent(PlatformWheelEvent
&);
152 #if ENABLE(TOUCH_EVENTS)
153 typedef HashSet
< RefPtr
<Touch
> > TouchSet
;
154 typedef HashMap
< EventTarget
*, TouchSet
* > EventTargetTouchMap
;
155 typedef HashSet
< RefPtr
<EventTarget
> > EventTargetSet
;
157 void dispatchTouchEvent(const PlatformTouchEvent
&, const AtomicString
&, const EventTargetTouchMap
&, float, float);
158 void dispatchGestureEvent(const PlatformTouchEvent
&, const AtomicString
&, const EventTargetSet
&, float, float);
159 void handleTouchEvent(const PlatformTouchEvent
&);
162 bool sendContextMenuEvent(const PlatformMouseEvent
&);
164 void setMouseDownMayStartAutoscroll() { m_mouseDownMayStartAutoscroll
= true; }
166 bool needsKeyboardEventDisambiguationQuirks() const;
168 static unsigned accessKeyModifiers();
169 bool handleAccessKey(const PlatformKeyboardEvent
&);
170 bool keyEvent(const PlatformKeyboardEvent
&);
171 void defaultKeyboardEventHandler(KeyboardEvent
*);
173 bool handleTextInputEvent(const String
& text
, Event
* underlyingEvent
= 0,
174 bool isLineBreak
= false, bool isBackTab
= false);
175 void defaultTextInputEventHandler(TextEvent
*);
178 void focusDocumentView();
180 void capsLockStateMayHaveChanged();
182 unsigned pendingFrameUnloadEventCount();
183 void addPendingFrameUnloadEventCount();
184 void removePendingFrameUnloadEventCount();
185 void clearPendingFrameUnloadEventCount();
186 unsigned pendingFrameBeforeUnloadEventCount();
187 void addPendingFrameBeforeUnloadEventCount();
188 void removePendingFrameBeforeUnloadEventCount();
189 void clearPendingFrameBeforeUnloadEventCount();
192 PassRefPtr
<KeyboardEvent
> currentKeyboardEvent() const;
194 void mouseDown(GSEventRef
);
195 void mouseDragged(GSEventRef
);
196 void mouseUp(GSEventRef
);
197 void mouseMoved(GSEventRef
);
198 bool keyEvent(GSEventRef
);
199 bool wheelEvent(GSEventRef
);
201 #if ENABLE(TOUCH_EVENTS)
202 void touchEvent(GSEventRef
);
205 void sendFakeEventsAfterWidgetTracking(GSEventRef initiatingEvent
);
209 void invalidateClick();
212 struct EventHandlerDragState
{
213 RefPtr
<Node
> m_dragSrc
; // element that may be a drag source, for the current mouse gesture
214 bool m_dragSrcIsLink
;
215 bool m_dragSrcIsImage
;
216 bool m_dragSrcInSelection
;
217 bool m_dragSrcMayBeDHTML
;
218 bool m_dragSrcMayBeUA
; // Are DHTML and/or the UserAgent allowed to drag out?
219 bool m_dragSrcIsDHTML
;
221 static EventHandlerDragState
& dragState();
222 static const double TextDragDelay
;
225 bool eventActivatedView(const PlatformMouseEvent
&) const;
226 void selectClosestWordFromMouseEvent(const MouseEventWithHitTestResults
& event
);
227 void selectClosestWordOrLinkFromMouseEvent(const MouseEventWithHitTestResults
& event
);
229 bool handleMouseDoubleClickEvent(const PlatformMouseEvent
&);
231 bool handleMousePressEvent(const MouseEventWithHitTestResults
&);
232 bool handleMousePressEventSingleClick(const MouseEventWithHitTestResults
&);
233 bool handleMousePressEventDoubleClick(const MouseEventWithHitTestResults
&);
234 bool handleMousePressEventTripleClick(const MouseEventWithHitTestResults
&);
235 bool handleMouseDraggedEvent(const MouseEventWithHitTestResults
&);
236 bool handleMouseReleaseEvent(const MouseEventWithHitTestResults
&);
238 void handleKeyboardSelectionMovement(KeyboardEvent
*);
240 Cursor
selectCursor(const MouseEventWithHitTestResults
&, Scrollbar
*);
241 void setPanScrollCursor();
243 void hoverTimerFired(Timer
<EventHandler
>*);
245 static bool canMouseDownStartSelect(Node
*);
246 static bool canMouseDragExtendSelect(Node
*);
248 void handleAutoscroll(RenderObject
*);
249 void startAutoscrollTimer();
250 void setAutoscrollRenderer(RenderObject
*);
251 void autoscrollTimerFired(Timer
<EventHandler
>*);
254 Node
* nodeUnderMouse() const;
256 void updateMouseEventTargetNode(Node
*, const PlatformMouseEvent
&, bool fireMouseOverOut
);
257 void fireMouseOverOut(bool fireMouseOver
= true, bool fireMouseOut
= true, bool updateLastNodeUnderMouse
= true);
259 MouseEventWithHitTestResults
prepareMouseEvent(const HitTestRequest
&, const PlatformMouseEvent
&);
261 bool dispatchMouseEvent(const AtomicString
& eventType
, Node
* target
, bool cancelable
, int clickCount
, const PlatformMouseEvent
&, bool setUnder
);
262 bool dispatchDragEvent(const AtomicString
& eventType
, Node
* target
, const PlatformMouseEvent
&, Clipboard
*);
265 bool handleMouseUp(const MouseEventWithHitTestResults
&);
266 void clearDragState();
268 bool dispatchDragSrcEvent(const AtomicString
& eventType
, const PlatformMouseEvent
&);
270 bool dragHysteresisExceeded(const FloatPoint
&) const;
271 bool dragHysteresisExceeded(const IntPoint
&) const;
273 bool passMousePressEventToSubframe(MouseEventWithHitTestResults
&, Frame
* subframe
);
274 bool passMouseMoveEventToSubframe(MouseEventWithHitTestResults
&, Frame
* subframe
, HitTestResult
* hoveredNode
= 0);
275 bool passMouseReleaseEventToSubframe(MouseEventWithHitTestResults
&, Frame
* subframe
);
277 bool passSubframeEventToSubframe(MouseEventWithHitTestResults
&, Frame
* subframe
, HitTestResult
* hoveredNode
= 0);
279 bool passMousePressEventToScrollbar(MouseEventWithHitTestResults
&, Scrollbar
*);
281 bool passWidgetMouseDownEventToWidget(const MouseEventWithHitTestResults
&);
282 bool passWidgetMouseDownEventToWidget(RenderWidget
*);
284 bool passMouseDownEventToWidget(Widget
*);
285 bool passWheelEventToWidget(PlatformWheelEvent
&, Widget
*);
287 void defaultSpaceEventHandler(KeyboardEvent
*);
288 void defaultTabEventHandler(KeyboardEvent
*);
290 void allowDHTMLDrag(bool& flagDHTML
, bool& flagUA
) const;
292 // The following are called at the beginning of handleMouseUp and handleDrag.
293 // If they return true it indicates that they have consumed the event.
295 bool eventLoopHandleMouseUp(const MouseEventWithHitTestResults
&);
296 bool eventLoopHandleMouseDragged(const MouseEventWithHitTestResults
&);
297 NSView
*mouseDownViewIfStillGood();
299 bool eventLoopHandleMouseUp(const MouseEventWithHitTestResults
&) { return false; }
300 bool eventLoopHandleMouseDragged(const MouseEventWithHitTestResults
&) { return false; }
303 bool invertSenseOfTabsToLinks(KeyboardEvent
*) const;
305 void updateSelectionForMouseDrag(Node
* targetNode
, const IntPoint
& localPoint
);
310 RefPtr
<Node
> m_mousePressNode
;
312 bool m_mouseDownMayStartSelect
;
313 bool m_mouseDownMayStartDrag
;
314 bool m_mouseDownWasSingleClickInSelection
;
315 bool m_beganSelectingText
;
317 IntPoint m_dragStartPos
;
319 IntPoint m_panScrollStartPos
;
320 bool m_panScrollInProgress
;
322 Timer
<EventHandler
> m_hoverTimer
;
324 Timer
<EventHandler
> m_autoscrollTimer
;
325 RenderObject
* m_autoscrollRenderer
;
326 bool m_autoscrollInProgress
;
327 bool m_mouseDownMayStartAutoscroll
;
328 bool m_mouseDownWasInSubframe
;
331 RefPtr
<SVGElementInstance
> m_instanceUnderMouse
;
332 RefPtr
<SVGElementInstance
> m_lastInstanceUnderMouse
;
335 RenderLayer
* m_resizeLayer
;
337 RefPtr
<Node
> m_capturingMouseEventsNode
;
339 RefPtr
<Node
> m_nodeUnderMouse
;
340 RefPtr
<Node
> m_lastNodeUnderMouse
;
341 RefPtr
<Frame
> m_lastMouseMoveEventSubframe
;
342 RefPtr
<Scrollbar
> m_lastScrollbarUnderMouse
;
345 RefPtr
<Node
> m_clickNode
;
346 #if ENABLE(TOUCH_EVENTS)
347 float m_gestureInitialDiameter
;
348 float m_gestureLastDiameter
;
349 float m_gestureInitialRotation
;
350 float m_gestureLastRotation
;
351 unsigned m_firstTouchID
;
352 HashMap
< unsigned, RefPtr
<Touch
> > m_touchesByID
;
353 EventTargetSet m_gestureTargets
;
356 RefPtr
<Node
> m_dragTarget
;
358 RefPtr
<HTMLFrameSetElement
> m_frameSetBeingResized
;
360 IntSize m_offsetFromResizeCorner
; // in the coords of m_resizeLayer
362 IntPoint m_currentMousePosition
;
363 IntPoint m_mouseDownPos
; // in our view's coords
364 double m_mouseDownTimestamp
;
365 PlatformMouseEvent m_mouseDown
;
367 unsigned m_pendingFrameUnloadEventCount
;
368 unsigned m_pendingFrameBeforeUnloadEventCount
;
371 NSView
*m_mouseDownView
;
372 bool m_sendingEventToSubview
;
377 } // namespace WebCore
379 #endif // EventHandler_h