• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 
create()65         static PassRefPtr<Event> create()
66         {
67             return adoptRef(new Event);
68         }
create(const AtomicString & type,bool canBubble,bool cancelable)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 
type()77         const AtomicString& type() const { return m_type; }
78 
target()79         EventTarget* target() const { return m_target.get(); }
80         void setTarget(PassRefPtr<EventTarget>);
81 
currentTarget()82         EventTarget* currentTarget() const { return m_currentTarget; }
setCurrentTarget(EventTarget * currentTarget)83         void setCurrentTarget(EventTarget* currentTarget) { m_currentTarget = currentTarget; }
84 
eventPhase()85         unsigned short eventPhase() const { return m_eventPhase; }
setEventPhase(unsigned short eventPhase)86         void setEventPhase(unsigned short eventPhase) { m_eventPhase = eventPhase; }
87 
bubbles()88         bool bubbles() const { return m_canBubble; }
cancelable()89         bool cancelable() const { return m_cancelable; }
timeStamp()90         DOMTimeStamp timeStamp() const { return m_createTime; }
stopPropagation()91         void stopPropagation() { m_propagationStopped = true; }
92 
93         // IE Extensions
srcElement()94         EventTarget* srcElement() const { return target(); } // MSIE extension - "the object that fired the event"
95 
returnValue()96         bool returnValue() const { return !defaultPrevented(); }
setReturnValue(bool returnValue)97         void setReturnValue(bool returnValue) { setDefaultPrevented(!returnValue); }
98 
clipboardData()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 isCompositionEvent() const;
107         virtual bool isDragEvent() const; // a subset of mouse events
108         virtual bool isClipboardEvent() const;
109         virtual bool isMessageEvent() const;
110         virtual bool isWheelEvent() const;
111         virtual bool isBeforeTextInsertedEvent() const;
112         virtual bool isOverflowEvent() const;
113         virtual bool isPageTransitionEvent() const;
114         virtual bool isPopStateEvent() const;
115         virtual bool isProgressEvent() const;
116         virtual bool isXMLHttpRequestProgressEvent() const;
117         virtual bool isWebKitAnimationEvent() const;
118         virtual bool isWebKitTransitionEvent() const;
119         virtual bool isBeforeLoadEvent() const;
120 #if ENABLE(SVG)
121         virtual bool isSVGZoomEvent() const;
122 #endif
123 #if ENABLE(DOM_STORAGE)
124         virtual bool isStorageEvent() const;
125 #endif
126 #if ENABLE(WORKERS)
127         virtual bool isErrorEvent() const;
128 #endif
129 #if ENABLE(TOUCH_EVENTS)
130         virtual bool isTouchEvent() const;
131 #endif
132         bool fromUserGesture();
133 
propagationStopped()134         bool propagationStopped() const { return m_propagationStopped; }
135 
defaultPrevented()136         bool defaultPrevented() const { return m_defaultPrevented; }
preventDefault()137         void preventDefault() { if (m_cancelable) m_defaultPrevented = true; }
setDefaultPrevented(bool defaultPrevented)138         void setDefaultPrevented(bool defaultPrevented) { m_defaultPrevented = defaultPrevented; }
139 
defaultHandled()140         bool defaultHandled() const { return m_defaultHandled; }
setDefaultHandled()141         void setDefaultHandled() { m_defaultHandled = true; }
142 
cancelBubble()143         bool cancelBubble() const { return m_cancelBubble; }
setCancelBubble(bool cancel)144         void setCancelBubble(bool cancel) { m_cancelBubble = cancel; }
145 
underlyingEvent()146         Event* underlyingEvent() const { return m_underlyingEvent.get(); }
147         void setUnderlyingEvent(PassRefPtr<Event>);
148 
149         virtual bool storesResultAsString() const;
150         virtual void storeResult(const String&);
151 
clipboard()152         virtual Clipboard* clipboard() const { return 0; }
153 
createdByDOM()154         bool createdByDOM() const { return m_createdByDOM; }
setCreatedByDOM(bool createdByDOM)155         void setCreatedByDOM(bool createdByDOM) { m_createdByDOM = createdByDOM; }
156 
157     protected:
158         Event();
159         Event(const AtomicString& type, bool canBubble, bool cancelable);
160 
161         virtual void receivedTarget();
dispatched()162         bool dispatched() const { return m_target; }
163 
164     private:
165         AtomicString m_type;
166         bool m_canBubble;
167         bool m_cancelable;
168 
169         bool m_propagationStopped;
170         bool m_defaultPrevented;
171         bool m_defaultHandled;
172         bool m_cancelBubble;
173 
174         // Whether this event was created by document.createEvent().
175         bool m_createdByDOM;
176 
177         unsigned short m_eventPhase;
178         EventTarget* m_currentTarget;
179         RefPtr<EventTarget> m_target;
180         DOMTimeStamp m_createTime;
181 
182         RefPtr<Event> m_underlyingEvent;
183     };
184 
185 } // namespace WebCore
186 
187 #endif // Event_h
188