OLD | NEW |
1 /* | 1 /* |
2 * Copyright (C) 1999 Lars Knoll (knoll@kde.org) | 2 * Copyright (C) 1999 Lars Knoll (knoll@kde.org) |
3 * (C) 1999 Antti Koivisto (koivisto@kde.org) | 3 * (C) 1999 Antti Koivisto (koivisto@kde.org) |
4 * (C) 2001 Dirk Mueller (mueller@kde.org) | 4 * (C) 2001 Dirk Mueller (mueller@kde.org) |
5 * Copyright (C) 2004, 2005, 2006, 2007, 2008 Apple Inc. All rights reserved. | 5 * Copyright (C) 2004, 2005, 2006, 2007, 2008 Apple Inc. All rights reserved. |
6 * Copyright (C) 2006 Alexey Proskuryakov (ap@webkit.org) | 6 * Copyright (C) 2006 Alexey Proskuryakov (ap@webkit.org) |
7 * (C) 2007, 2008 Nikolas Zimmermann <zimmermann@kde.org> | 7 * (C) 2007, 2008 Nikolas Zimmermann <zimmermann@kde.org> |
8 * | 8 * |
9 * Redistribution and use in source and binary forms, with or without | 9 * Redistribution and use in source and binary forms, with or without |
10 * modification, are permitted provided that the following conditions | 10 * modification, are permitted provided that the following conditions |
(...skipping 102 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
113 virtual DOMWindow* toDOMWindow(); | 113 virtual DOMWindow* toDOMWindow(); |
114 | 114 |
115 virtual bool addEventListener(const AtomicString& eventType, PassRefPtr<
EventListener>, bool useCapture); | 115 virtual bool addEventListener(const AtomicString& eventType, PassRefPtr<
EventListener>, bool useCapture); |
116 virtual bool removeEventListener(const AtomicString& eventType, EventLis
tener*, bool useCapture); | 116 virtual bool removeEventListener(const AtomicString& eventType, EventLis
tener*, bool useCapture); |
117 virtual void removeAllEventListeners(); | 117 virtual void removeAllEventListeners(); |
118 virtual bool dispatchEvent(PassRefPtr<Event>); | 118 virtual bool dispatchEvent(PassRefPtr<Event>); |
119 bool dispatchEvent(PassRefPtr<Event>, ExceptionCode&); // DOM API | 119 bool dispatchEvent(PassRefPtr<Event>, ExceptionCode&); // DOM API |
120 virtual void uncaughtExceptionInEventHandler(); | 120 virtual void uncaughtExceptionInEventHandler(); |
121 | 121 |
122 // Used for legacy "onEvent" attribute APIs. | 122 // Used for legacy "onEvent" attribute APIs. |
123 bool setAttributeEventListener(const AtomicString& eventType, PassRefPtr
<EventListener>); | 123 bool setAttributeEventListener(const AtomicString& eventType, PassRefPtr
<EventListener>, DOMWrapperWorld* isolatedWorld = 0); |
124 bool clearAttributeEventListener(const AtomicString& eventType); | 124 EventListener* getAttributeEventListener(const AtomicString& eventType,
DOMWrapperWorld* isolatedWorld = 0); |
125 EventListener* getAttributeEventListener(const AtomicString& eventType); | |
126 | 125 |
127 bool hasEventListeners(); | 126 bool hasEventListeners(); |
128 bool hasEventListeners(const AtomicString& eventType); | 127 bool hasEventListeners(const AtomicString& eventType); |
129 const EventListenerVector& getEventListeners(const AtomicString& eventTy
pe); | 128 const EventListenerVector& getEventListeners(const AtomicString& eventTy
pe); |
130 | 129 |
131 bool fireEventListeners(Event*); | 130 bool fireEventListeners(Event*); |
132 bool isFiringEventListeners(); | 131 bool isFiringEventListeners(); |
133 | 132 |
134 protected: | 133 protected: |
135 virtual ~EventTarget(); | 134 virtual ~EventTarget(); |
136 | 135 |
137 virtual EventTargetData* eventTargetData() = 0; | 136 virtual EventTargetData* eventTargetData() = 0; |
138 virtual EventTargetData* ensureEventTargetData() = 0; | 137 virtual EventTargetData* ensureEventTargetData() = 0; |
139 | 138 |
140 private: | 139 private: |
141 virtual void refEventTarget() = 0; | 140 virtual void refEventTarget() = 0; |
142 virtual void derefEventTarget() = 0; | 141 virtual void derefEventTarget() = 0; |
143 | 142 |
144 void fireEventListeners(Event*, EventTargetData*, EventListenerVector&); | 143 void fireEventListeners(Event*, EventTargetData*, EventListenerVector&); |
145 | 144 |
| 145 bool clearAttributeEventListener(const AtomicString& eventType, DOMWrapp
erWorld* isolatedWorld); |
| 146 |
146 friend class EventListenerIterator; | 147 friend class EventListenerIterator; |
147 }; | 148 }; |
148 | 149 |
149 // FIXME: These macros should be split into separate DEFINE and DECLARE | 150 // FIXME: These macros should be split into separate DEFINE and DECLARE |
150 // macros to avoid causing so many header includes. | 151 // macros to avoid causing so many header includes. |
151 #define DEFINE_ATTRIBUTE_EVENT_LISTENER(attribute) \ | 152 #define DEFINE_ATTRIBUTE_EVENT_LISTENER(attribute) \ |
152 EventListener* on##attribute() { return getAttributeEventListener(eventN
ames().attribute##Event); } \ | 153 EventListener* on##attribute(DOMWrapperWorld* isolatedWorld) { return ge
tAttributeEventListener(eventNames().attribute##Event, isolatedWorld); } \ |
153 void setOn##attribute(PassRefPtr<EventListener> listener) { setAttribute
EventListener(eventNames().attribute##Event, listener); } \ | 154 void setOn##attribute(PassRefPtr<EventListener> listener, DOMWrapperWorl
d* isolatedWorld = 0) { setAttributeEventListener(eventNames().attribute##Event,
listener, isolatedWorld); } \ |
154 | 155 |
155 #define DECLARE_VIRTUAL_ATTRIBUTE_EVENT_LISTENER(attribute) \ | 156 #define DECLARE_VIRTUAL_ATTRIBUTE_EVENT_LISTENER(attribute) \ |
156 virtual EventListener* on##attribute(); \ | 157 virtual EventListener* on##attribute(DOMWrapperWorld* isolatedWorld); \ |
157 virtual void setOn##attribute(PassRefPtr<EventListener> listener); \ | 158 virtual void setOn##attribute(PassRefPtr<EventListener>, DOMWrapperWorld
* isolatedWorld); \ |
158 | 159 |
159 #define DEFINE_VIRTUAL_ATTRIBUTE_EVENT_LISTENER(type, attribute) \ | 160 #define DEFINE_VIRTUAL_ATTRIBUTE_EVENT_LISTENER(type, attribute) \ |
160 EventListener* type::on##attribute() { return getAttributeEventListener(
eventNames().attribute##Event); } \ | 161 EventListener* type::on##attribute(DOMWrapperWorld* isolatedWorld) { ret
urn getAttributeEventListener(eventNames().attribute##Event, isolatedWorld); } \ |
161 void type::setOn##attribute(PassRefPtr<EventListener> listener) { setAtt
ributeEventListener(eventNames().attribute##Event, listener); } \ | 162 void type::setOn##attribute(PassRefPtr<EventListener> listener, DOMWrapp
erWorld* isolatedWorld) { setAttributeEventListener(eventNames().attribute##Even
t, listener, isolatedWorld); } \ |
162 | 163 |
163 #define DEFINE_WINDOW_ATTRIBUTE_EVENT_LISTENER(attribute) \ | 164 #define DEFINE_WINDOW_ATTRIBUTE_EVENT_LISTENER(attribute) \ |
164 EventListener* on##attribute() { return document()->getWindowAttributeEv
entListener(eventNames().attribute##Event); } \ | 165 EventListener* on##attribute(DOMWrapperWorld* isolatedWorld) { return do
cument()->getWindowAttributeEventListener(eventNames().attribute##Event, isolate
dWorld); } \ |
165 void setOn##attribute(PassRefPtr<EventListener> listener) { document()->
setWindowAttributeEventListener(eventNames().attribute##Event, listener); } \ | 166 void setOn##attribute(PassRefPtr<EventListener> listener, DOMWrapperWorl
d* isolatedWorld) { document()->setWindowAttributeEventListener(eventNames().att
ribute##Event, listener, isolatedWorld); } \ |
166 | 167 |
167 #define DEFINE_MAPPED_ATTRIBUTE_EVENT_LISTENER(attribute, eventName) \ | 168 #define DEFINE_MAPPED_ATTRIBUTE_EVENT_LISTENER(attribute, eventName) \ |
168 EventListener* on##attribute() { return getAttributeEventListener(eventN
ames().eventName##Event); } \ | 169 EventListener* on##attribute(DOMWrapperWorld* isolatedWorld) { return ge
tAttributeEventListener(eventNames().eventName##Event, isolatedWorld); } \ |
169 void setOn##attribute(PassRefPtr<EventListener> listener) { setAttribute
EventListener(eventNames().eventName##Event, listener); } \ | 170 void setOn##attribute(PassRefPtr<EventListener> listener, DOMWrapperWorl
d* isolatedWorld) { setAttributeEventListener(eventNames().eventName##Event, lis
tener, isolatedWorld); } \ |
170 | 171 |
171 #define DEFINE_FORWARDING_ATTRIBUTE_EVENT_LISTENER(recipient, attribute) \ | 172 #define DEFINE_FORWARDING_ATTRIBUTE_EVENT_LISTENER(recipient, attribute) \ |
172 EventListener* on##attribute() { return recipient ? recipient->getAttrib
uteEventListener(eventNames().attribute##Event) : 0; } \ | 173 EventListener* on##attribute(DOMWrapperWorld* isolatedWorld) { return re
cipient ? recipient->getAttributeEventListener(eventNames().attribute##Event, is
olatedWorld) : 0; } \ |
173 void setOn##attribute(PassRefPtr<EventListener> listener) { if (recipien
t) recipient->setAttributeEventListener(eventNames().attribute##Event, listener)
; } \ | 174 void setOn##attribute(PassRefPtr<EventListener> listener, DOMWrapperWorl
d* isolatedWorld) { if (recipient) recipient->setAttributeEventListener(eventNam
es().attribute##Event, listener, isolatedWorld); } \ |
174 | 175 |
175 inline bool EventTarget::isFiringEventListeners() | 176 inline bool EventTarget::isFiringEventListeners() |
176 { | 177 { |
177 EventTargetData* d = eventTargetData(); | 178 EventTargetData* d = eventTargetData(); |
178 if (!d) | 179 if (!d) |
179 return false; | 180 return false; |
180 return d->firingEventIterators && !d->firingEventIterators->isEmpty(); | 181 return d->firingEventIterators && !d->firingEventIterators->isEmpty(); |
181 } | 182 } |
182 | 183 |
183 inline bool EventTarget::hasEventListeners() | 184 inline bool EventTarget::hasEventListeners() |
184 { | 185 { |
185 EventTargetData* d = eventTargetData(); | 186 EventTargetData* d = eventTargetData(); |
186 if (!d) | 187 if (!d) |
187 return false; | 188 return false; |
188 return !d->eventListenerMap.isEmpty(); | 189 return !d->eventListenerMap.isEmpty(); |
189 } | 190 } |
190 | 191 |
191 inline bool EventTarget::hasEventListeners(const AtomicString& eventType) | 192 inline bool EventTarget::hasEventListeners(const AtomicString& eventType) |
192 { | 193 { |
193 EventTargetData* d = eventTargetData(); | 194 EventTargetData* d = eventTargetData(); |
194 if (!d) | 195 if (!d) |
195 return false; | 196 return false; |
196 return d->eventListenerMap.contains(eventType); | 197 return d->eventListenerMap.contains(eventType); |
197 } | 198 } |
198 | 199 |
199 } // namespace WebCore | 200 } // namespace WebCore |
200 | 201 |
201 #endif // EventTarget_h | 202 #endif // EventTarget_h |
OLD | NEW |