]> git.saurik.com Git - iphone-api.git/blob - WebCore/Event.h
Add support for new WinterBoard Settings features.
[iphone-api.git] / WebCore / Event.h
1 /*
2 * Copyright (C) 2001 Peter Kelly (pmk@post.com)
3 * Copyright (C) 2001 Tobias Anton (anton@stud.fbi.fh-darmstadt.de)
4 * Copyright (C) 2006 Samuel Weinig (sam.weinig@gmail.com)
5 * Copyright (C) 2003, 2004, 2005, 2006, 2007, 2008 Apple Inc. All rights reserved.
6 *
7 * This library is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU Library General Public
9 * License as published by the Free Software Foundation; either
10 * version 2 of the License, or (at your option) any later version.
11 *
12 * This library is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * Library General Public License for more details.
16 *
17 * You should have received a copy of the GNU Library General Public License
18 * along with this library; see the file COPYING.LIB. If not, write to
19 * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
20 * Boston, MA 02110-1301, USA.
21 *
22 */
23
24 #ifndef Event_h
25 #define Event_h
26
27 #include "AtomicString.h"
28 #include "EventTarget.h"
29 #include <wtf/RefCounted.h>
30
31 namespace WebCore {
32
33 class Clipboard;
34
35 // FIXME: this should probably defined elsewhere.
36 typedef unsigned long long DOMTimeStamp;
37
38 class Event : public RefCounted<Event> {
39 public:
40 enum PhaseType {
41 CAPTURING_PHASE = 1,
42 AT_TARGET = 2,
43 BUBBLING_PHASE = 3
44 };
45
46 enum EventType {
47 MOUSEDOWN = 1,
48 MOUSEUP = 2,
49 MOUSEOVER = 4,
50 MOUSEOUT = 8,
51 MOUSEMOVE = 16,
52 MOUSEDRAG = 32,
53 CLICK = 64,
54 DBLCLICK = 128,
55 KEYDOWN = 256,
56 KEYUP = 512,
57 KEYPRESS = 1024,
58 DRAGDROP = 2048,
59 FOCUS = 4096,
60 BLUR = 8192,
61 SELECT = 16384,
62 CHANGE = 32768
63 };
64
65 static PassRefPtr<Event> create()
66 {
67 return adoptRef(new Event);
68 }
69 static PassRefPtr<Event> create(const AtomicString& type, bool canBubble, bool cancelable)
70 {
71 return adoptRef(new Event(type, canBubble, cancelable));
72 }
73 virtual ~Event();
74
75 void initEvent(const AtomicString& type, bool canBubble, bool cancelable);
76
77 const AtomicString& type() const { return m_type; }
78
79 EventTarget* target() const { return m_target.get(); }
80 void setTarget(PassRefPtr<EventTarget>);
81
82 EventTarget* currentTarget() const { return m_currentTarget; }
83 void setCurrentTarget(EventTarget* currentTarget) { m_currentTarget = currentTarget; }
84
85 unsigned short eventPhase() const { return m_eventPhase; }
86 void setEventPhase(unsigned short eventPhase) { m_eventPhase = eventPhase; }
87
88 bool bubbles() const { return m_canBubble; }
89 bool cancelable() const { return m_cancelable; }
90 DOMTimeStamp timeStamp() const { return m_createTime; }
91 void stopPropagation() { m_propagationStopped = true; }
92
93 // IE Extensions
94 EventTarget* srcElement() const { return target(); } // MSIE extension - "the object that fired the event"
95
96 bool returnValue() const { return !defaultPrevented(); }
97 void setReturnValue(bool returnValue) { setDefaultPrevented(!returnValue); }
98
99 Clipboard* clipboardData() const { return isClipboardEvent() ? clipboard() : 0; }
100
101 virtual bool isUIEvent() const;
102 virtual bool isMouseEvent() const;
103 virtual bool isMutationEvent() const;
104 virtual bool isKeyboardEvent() const;
105 virtual bool isTextEvent() const;
106 virtual bool isDragEvent() const; // a subset of mouse events
107 virtual bool isClipboardEvent() const;
108 virtual bool isMessageEvent() const;
109 virtual bool isWheelEvent() const;
110 virtual bool isBeforeTextInsertedEvent() const;
111 virtual bool isOverflowEvent() const;
112 virtual bool isProgressEvent() const;
113 virtual bool isXMLHttpRequestProgressEvent() const;
114 virtual bool isWebKitAnimationEvent() const;
115 virtual bool isWebKitTransitionEvent() const;
116 #if ENABLE(SVG)
117 virtual bool isSVGZoomEvent() const;
118 #endif
119 #if ENABLE(DOM_STORAGE)
120 virtual bool isStorageEvent() const;
121 #endif
122
123 #if ENABLE(TOUCH_EVENTS)
124 virtual bool isTouchEvent() const;
125 virtual bool isGestureEvent() const;
126 #endif
127
128 bool propagationStopped() const { return m_propagationStopped; }
129
130 bool defaultPrevented() const { return m_defaultPrevented; }
131 void preventDefault() { if (m_cancelable) m_defaultPrevented = true; }
132 void setDefaultPrevented(bool defaultPrevented) { m_defaultPrevented = defaultPrevented; }
133
134 bool defaultHandled() const { return m_defaultHandled; }
135 void setDefaultHandled() { m_defaultHandled = true; }
136
137 bool cancelBubble() const { return m_cancelBubble; }
138 void setCancelBubble(bool cancel) { m_cancelBubble = cancel; }
139
140 Event* underlyingEvent() const { return m_underlyingEvent.get(); }
141 void setUnderlyingEvent(PassRefPtr<Event>);
142
143 virtual bool storesResultAsString() const;
144 virtual void storeResult(const String&);
145
146 virtual Clipboard* clipboard() const { return 0; }
147
148 protected:
149 Event();
150 Event(const AtomicString& type, bool canBubble, bool cancelable);
151
152 virtual void receivedTarget();
153 bool dispatched() const { return m_target; }
154
155 private:
156 AtomicString m_type;
157 bool m_canBubble;
158 bool m_cancelable;
159
160 bool m_propagationStopped;
161 bool m_defaultPrevented;
162 bool m_defaultHandled;
163 bool m_cancelBubble;
164
165 EventTarget* m_currentTarget;
166 unsigned short m_eventPhase;
167 RefPtr<EventTarget> m_target;
168 DOMTimeStamp m_createTime;
169
170 RefPtr<Event> m_underlyingEvent;
171 };
172
173 } // namespace WebCore
174
175 #endif // Event_h