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.
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.
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.
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.
27 #include "AtomicString.h"
28 #include "EventTarget.h"
29 #include <wtf/RefCounted.h>
35 // FIXME: this should probably defined elsewhere.
36 typedef unsigned long long DOMTimeStamp
;
38 class Event
: public RefCounted
<Event
> {
65 static PassRefPtr
<Event
> create()
67 return adoptRef(new Event
);
69 static PassRefPtr
<Event
> create(const AtomicString
& type
, bool canBubble
, bool cancelable
)
71 return adoptRef(new Event(type
, canBubble
, cancelable
));
75 void initEvent(const AtomicString
& type
, bool canBubble
, bool cancelable
);
77 const AtomicString
& type() const { return m_type
; }
79 EventTarget
* target() const { return m_target
.get(); }
80 void setTarget(PassRefPtr
<EventTarget
>);
82 EventTarget
* currentTarget() const { return m_currentTarget
; }
83 void setCurrentTarget(EventTarget
* currentTarget
) { m_currentTarget
= currentTarget
; }
85 unsigned short eventPhase() const { return m_eventPhase
; }
86 void setEventPhase(unsigned short eventPhase
) { m_eventPhase
= eventPhase
; }
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; }
94 EventTarget
* srcElement() const { return target(); } // MSIE extension - "the object that fired the event"
96 bool returnValue() const { return !defaultPrevented(); }
97 void setReturnValue(bool returnValue
) { setDefaultPrevented(!returnValue
); }
99 Clipboard
* clipboardData() const { return isClipboardEvent() ? clipboard() : 0; }
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;
117 virtual bool isSVGZoomEvent() const;
119 #if ENABLE(DOM_STORAGE)
120 virtual bool isStorageEvent() const;
123 #if ENABLE(TOUCH_EVENTS)
124 virtual bool isTouchEvent() const;
125 virtual bool isGestureEvent() const;
128 bool propagationStopped() const { return m_propagationStopped
; }
130 bool defaultPrevented() const { return m_defaultPrevented
; }
131 void preventDefault() { if (m_cancelable
) m_defaultPrevented
= true; }
132 void setDefaultPrevented(bool defaultPrevented
) { m_defaultPrevented
= defaultPrevented
; }
134 bool defaultHandled() const { return m_defaultHandled
; }
135 void setDefaultHandled() { m_defaultHandled
= true; }
137 bool cancelBubble() const { return m_cancelBubble
; }
138 void setCancelBubble(bool cancel
) { m_cancelBubble
= cancel
; }
140 Event
* underlyingEvent() const { return m_underlyingEvent
.get(); }
141 void setUnderlyingEvent(PassRefPtr
<Event
>);
143 virtual bool storesResultAsString() const;
144 virtual void storeResult(const String
&);
146 virtual Clipboard
* clipboard() const { return 0; }
150 Event(const AtomicString
& type
, bool canBubble
, bool cancelable
);
152 virtual void receivedTarget();
153 bool dispatched() const { return m_target
; }
160 bool m_propagationStopped
;
161 bool m_defaultPrevented
;
162 bool m_defaultHandled
;
165 EventTarget
* m_currentTarget
;
166 unsigned short m_eventPhase
;
167 RefPtr
<EventTarget
> m_target
;
168 DOMTimeStamp m_createTime
;
170 RefPtr
<Event
> m_underlyingEvent
;
173 } // namespace WebCore