]> git.saurik.com Git - iphone-api.git/blob - WebCore/EventHandler.h
Adding the WebCore headers (for Cydget).
[iphone-api.git] / WebCore / EventHandler.h
1 /*
2 * Copyright (C) 2006, 2007 Apple Inc. All rights reserved.
3 *
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions
6 * are met:
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.
12 *
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.
24 */
25
26 #ifndef EventHandler_h
27 #define EventHandler_h
28
29 #include "DragActions.h"
30 #include "FocusDirection.h"
31 #include "PlatformMouseEvent.h"
32 #include "ScrollTypes.h"
33 #include "Timer.h"
34 #include <wtf/Forward.h>
35 #include <wtf/Noncopyable.h>
36 #include <wtf/Platform.h>
37 #include <wtf/RefPtr.h>
38
39 #include <wtf/HashMap.h>
40 #include <wtf/HashSet.h>
41
42 #if PLATFORM(MAC)
43 #include "WebCoreKeyboardUIMode.h"
44 #ifndef __OBJC__
45 class NSEvent;
46 class NSView;
47 #endif
48 #endif
49
50 #ifdef __OBJC__
51 @class WAKView;
52 #endif
53
54 namespace WebCore {
55
56 class AtomicString;
57 class Clipboard;
58 class Cursor;
59 class EventTargetNode;
60 class Event;
61 class FloatPoint;
62 class FloatRect;
63 class Frame;
64 class HitTestResult;
65 class HTMLFrameSetElement;
66 class KeyboardEvent;
67 class MouseEventWithHitTestResults;
68 class Node;
69 class PlatformKeyboardEvent;
70 class PlatformWheelEvent;
71 class RenderLayer;
72 class RenderObject;
73 class RenderWidget;
74 class Scrollbar;
75 class String;
76 class SVGElementInstance;
77 class TextEvent;
78 class VisiblePosition;
79 class Widget;
80 #if ENABLE(TOUCH_EVENTS)
81 class PlatformTouchEvent;
82 class Touch;
83 class EventTarget;
84 #endif
85
86 struct HitTestRequest;
87
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;
94 #endif
95
96 class EventHandler : Noncopyable {
97 public:
98 EventHandler(Frame*);
99 ~EventHandler();
100
101 void clear();
102
103 void updateSelectionForMouseDrag();
104
105 Node* mousePressNode() const;
106 void setMousePressNode(PassRefPtr<Node>);
107
108 bool panScrollInProgress() { return m_panScrollInProgress; }
109 void setPanScrollInProgress(bool inProgress) { m_panScrollInProgress = inProgress; }
110
111 void stopAutoscrollTimer(bool rendererIsBeingDestroyed = false);
112 RenderObject* autoscrollRenderer() const;
113 void updateAutoscrollRenderer();
114
115 HitTestResult hitTestResultAtPoint(const IntPoint&, bool allowShadowContent);
116
117 bool mousePressed() const { return m_mousePressed; }
118 void setMousePressed(bool pressed) { m_mousePressed = pressed; }
119
120 void setCapturingMouseEventsNode(PassRefPtr<Node>);
121
122 bool updateDragAndDrop(const PlatformMouseEvent&, Clipboard*);
123 void cancelDragAndDrop(const PlatformMouseEvent&, Clipboard*);
124 bool performDragAndDrop(const PlatformMouseEvent&, Clipboard*);
125
126 void scheduleHoverStateUpdate();
127
128 void setResizingFrameSet(HTMLFrameSetElement*);
129
130 void resizeLayerDestroyed();
131
132 IntPoint currentMousePosition() const;
133
134 void setIgnoreWheelEvents(bool);
135
136 bool scrollOverflow(ScrollDirection, ScrollGranularity);
137
138 bool shouldDragAutoNode(Node*, const IntPoint&) const; // -webkit-user-drag == auto
139
140 bool tabsToLinks(KeyboardEvent*) const;
141 bool tabsToAllControls(KeyboardEvent*) const;
142
143 bool mouseDownMayStartSelect() const { return m_mouseDownMayStartSelect; }
144
145 bool mouseMoved(const PlatformMouseEvent&);
146
147 bool handleMousePressEvent(const PlatformMouseEvent&);
148 bool handleMouseMoveEvent(const PlatformMouseEvent&, HitTestResult* hoveredNode = 0);
149 bool handleMouseReleaseEvent(const PlatformMouseEvent&);
150 bool handleWheelEvent(PlatformWheelEvent&);
151
152 #if ENABLE(TOUCH_EVENTS)
153 typedef HashSet< RefPtr<Touch> > TouchSet;
154 typedef HashMap< EventTarget*, TouchSet* > EventTargetTouchMap;
155 typedef HashSet< RefPtr<EventTarget> > EventTargetSet;
156
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&);
160 #endif
161
162 bool sendContextMenuEvent(const PlatformMouseEvent&);
163
164 void setMouseDownMayStartAutoscroll() { m_mouseDownMayStartAutoscroll = true; }
165
166 bool needsKeyboardEventDisambiguationQuirks() const;
167
168 static unsigned accessKeyModifiers();
169 bool handleAccessKey(const PlatformKeyboardEvent&);
170 bool keyEvent(const PlatformKeyboardEvent&);
171 void defaultKeyboardEventHandler(KeyboardEvent*);
172
173 bool handleTextInputEvent(const String& text, Event* underlyingEvent = 0,
174 bool isLineBreak = false, bool isBackTab = false);
175 void defaultTextInputEventHandler(TextEvent*);
176
177
178 void focusDocumentView();
179
180 void capsLockStateMayHaveChanged();
181
182 unsigned pendingFrameUnloadEventCount();
183 void addPendingFrameUnloadEventCount();
184 void removePendingFrameUnloadEventCount();
185 void clearPendingFrameUnloadEventCount();
186 unsigned pendingFrameBeforeUnloadEventCount();
187 void addPendingFrameBeforeUnloadEventCount();
188 void removePendingFrameBeforeUnloadEventCount();
189 void clearPendingFrameBeforeUnloadEventCount();
190
191 #if PLATFORM(MAC)
192 PassRefPtr<KeyboardEvent> currentKeyboardEvent() const;
193
194 void mouseDown(GSEventRef);
195 void mouseDragged(GSEventRef);
196 void mouseUp(GSEventRef);
197 void mouseMoved(GSEventRef);
198 bool keyEvent(GSEventRef);
199 bool wheelEvent(GSEventRef);
200
201 #if ENABLE(TOUCH_EVENTS)
202 void touchEvent(GSEventRef);
203 #endif
204
205 void sendFakeEventsAfterWidgetTracking(GSEventRef initiatingEvent);
206
207 #endif
208
209 void invalidateClick();
210
211 private:
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;
220 };
221 static EventHandlerDragState& dragState();
222 static const double TextDragDelay;
223
224
225 bool eventActivatedView(const PlatformMouseEvent&) const;
226 void selectClosestWordFromMouseEvent(const MouseEventWithHitTestResults& event);
227 void selectClosestWordOrLinkFromMouseEvent(const MouseEventWithHitTestResults& event);
228
229 bool handleMouseDoubleClickEvent(const PlatformMouseEvent&);
230
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&);
237
238 void handleKeyboardSelectionMovement(KeyboardEvent*);
239
240 Cursor selectCursor(const MouseEventWithHitTestResults&, Scrollbar*);
241 void setPanScrollCursor();
242
243 void hoverTimerFired(Timer<EventHandler>*);
244
245 static bool canMouseDownStartSelect(Node*);
246 static bool canMouseDragExtendSelect(Node*);
247
248 void handleAutoscroll(RenderObject*);
249 void startAutoscrollTimer();
250 void setAutoscrollRenderer(RenderObject*);
251 void autoscrollTimerFired(Timer<EventHandler>*);
252
253
254 Node* nodeUnderMouse() const;
255
256 void updateMouseEventTargetNode(Node*, const PlatformMouseEvent&, bool fireMouseOverOut);
257 void fireMouseOverOut(bool fireMouseOver = true, bool fireMouseOut = true, bool updateLastNodeUnderMouse = true);
258
259 MouseEventWithHitTestResults prepareMouseEvent(const HitTestRequest&, const PlatformMouseEvent&);
260
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*);
263
264
265 bool handleMouseUp(const MouseEventWithHitTestResults&);
266 void clearDragState();
267
268 bool dispatchDragSrcEvent(const AtomicString& eventType, const PlatformMouseEvent&);
269
270 bool dragHysteresisExceeded(const FloatPoint&) const;
271 bool dragHysteresisExceeded(const IntPoint&) const;
272
273 bool passMousePressEventToSubframe(MouseEventWithHitTestResults&, Frame* subframe);
274 bool passMouseMoveEventToSubframe(MouseEventWithHitTestResults&, Frame* subframe, HitTestResult* hoveredNode = 0);
275 bool passMouseReleaseEventToSubframe(MouseEventWithHitTestResults&, Frame* subframe);
276
277 bool passSubframeEventToSubframe(MouseEventWithHitTestResults&, Frame* subframe, HitTestResult* hoveredNode = 0);
278
279 bool passMousePressEventToScrollbar(MouseEventWithHitTestResults&, Scrollbar*);
280
281 bool passWidgetMouseDownEventToWidget(const MouseEventWithHitTestResults&);
282 bool passWidgetMouseDownEventToWidget(RenderWidget*);
283
284 bool passMouseDownEventToWidget(Widget*);
285 bool passWheelEventToWidget(PlatformWheelEvent&, Widget*);
286
287 void defaultSpaceEventHandler(KeyboardEvent*);
288 void defaultTabEventHandler(KeyboardEvent*);
289
290 void allowDHTMLDrag(bool& flagDHTML, bool& flagUA) const;
291
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.
294 #if PLATFORM(MAC)
295 bool eventLoopHandleMouseUp(const MouseEventWithHitTestResults&);
296 bool eventLoopHandleMouseDragged(const MouseEventWithHitTestResults&);
297 NSView *mouseDownViewIfStillGood();
298 #else
299 bool eventLoopHandleMouseUp(const MouseEventWithHitTestResults&) { return false; }
300 bool eventLoopHandleMouseDragged(const MouseEventWithHitTestResults&) { return false; }
301 #endif
302
303 bool invertSenseOfTabsToLinks(KeyboardEvent*) const;
304
305 void updateSelectionForMouseDrag(Node* targetNode, const IntPoint& localPoint);
306
307 Frame* m_frame;
308
309 bool m_mousePressed;
310 RefPtr<Node> m_mousePressNode;
311
312 bool m_mouseDownMayStartSelect;
313 bool m_mouseDownMayStartDrag;
314 bool m_mouseDownWasSingleClickInSelection;
315 bool m_beganSelectingText;
316
317 IntPoint m_dragStartPos;
318
319 IntPoint m_panScrollStartPos;
320 bool m_panScrollInProgress;
321
322 Timer<EventHandler> m_hoverTimer;
323
324 Timer<EventHandler> m_autoscrollTimer;
325 RenderObject* m_autoscrollRenderer;
326 bool m_autoscrollInProgress;
327 bool m_mouseDownMayStartAutoscroll;
328 bool m_mouseDownWasInSubframe;
329 #if ENABLE(SVG)
330 bool m_svgPan;
331 RefPtr<SVGElementInstance> m_instanceUnderMouse;
332 RefPtr<SVGElementInstance> m_lastInstanceUnderMouse;
333 #endif
334
335 RenderLayer* m_resizeLayer;
336
337 RefPtr<Node> m_capturingMouseEventsNode;
338
339 RefPtr<Node> m_nodeUnderMouse;
340 RefPtr<Node> m_lastNodeUnderMouse;
341 RefPtr<Frame> m_lastMouseMoveEventSubframe;
342 RefPtr<Scrollbar> m_lastScrollbarUnderMouse;
343
344 int m_clickCount;
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;
354 #endif
355
356 RefPtr<Node> m_dragTarget;
357
358 RefPtr<HTMLFrameSetElement> m_frameSetBeingResized;
359
360 IntSize m_offsetFromResizeCorner; // in the coords of m_resizeLayer
361
362 IntPoint m_currentMousePosition;
363 IntPoint m_mouseDownPos; // in our view's coords
364 double m_mouseDownTimestamp;
365 PlatformMouseEvent m_mouseDown;
366
367 unsigned m_pendingFrameUnloadEventCount;
368 unsigned m_pendingFrameBeforeUnloadEventCount;
369
370 #if PLATFORM(MAC)
371 NSView *m_mouseDownView;
372 bool m_sendingEventToSubview;
373 #endif
374
375 };
376
377 } // namespace WebCore
378
379 #endif // EventHandler_h