| 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 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 56 , end(end) | 56 , end(end) |
| 57 { | 57 { |
| 58 } | 58 } |
| 59 | 59 |
| 60 const AtomicString& eventType; | 60 const AtomicString& eventType; |
| 61 size_t& iterator; | 61 size_t& iterator; |
| 62 size_t& end; | 62 size_t& end; |
| 63 }; | 63 }; |
| 64 typedef Vector<FiringEventIterator, 1> FiringEventIteratorVector; | 64 typedef Vector<FiringEventIterator, 1> FiringEventIteratorVector; |
| 65 | 65 |
| 66 struct CORE_EXPORT EventTargetData { | 66 class CORE_EXPORT EventTargetData final : public NoBaseWillBeGarbageCollectedFin
alized<EventTargetData> { |
| 67 WTF_MAKE_NONCOPYABLE(EventTargetData); WTF_MAKE_FAST_ALLOCATED(EventTargetDa
ta); | 67 WTF_MAKE_NONCOPYABLE(EventTargetData); |
| 68 WTF_MAKE_FAST_ALLOCATED_WILL_BE_REMOVED(EventTargetData); |
| 68 public: | 69 public: |
| 69 EventTargetData(); | 70 EventTargetData(); |
| 70 ~EventTargetData(); | 71 ~EventTargetData(); |
| 71 | 72 |
| 73 DECLARE_TRACE(); |
| 74 |
| 72 EventListenerMap eventListenerMap; | 75 EventListenerMap eventListenerMap; |
| 73 OwnPtr<FiringEventIteratorVector> firingEventIterators; | 76 OwnPtr<FiringEventIteratorVector> firingEventIterators; |
| 74 }; | 77 }; |
| 75 | 78 |
| 76 // This is the base class for all DOM event targets. To make your class an | 79 // This is the base class for all DOM event targets. To make your class an |
| 77 // EventTarget, follow these steps: | 80 // EventTarget, follow these steps: |
| 78 // - Make your IDL interface inherit from EventTarget. | 81 // - Make your IDL interface inherit from EventTarget. |
| 79 // Optionally add "attribute EventHandler onfoo;" attributes. | 82 // Optionally add "attribute EventHandler onfoo;" attributes. |
| 80 // - Inherit from EventTargetWithInlineData (only in rare cases should you use | 83 // - Inherit from EventTargetWithInlineData (only in rare cases should you use |
| 81 // EventTarget directly); or, if you want YourClass to be inherited from | 84 // EventTarget directly); or, if you want YourClass to be inherited from |
| (...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 115 void deref() { derefEventTarget(); } | 118 void deref() { derefEventTarget(); } |
| 116 #endif | 119 #endif |
| 117 | 120 |
| 118 virtual const AtomicString& interfaceName() const = 0; | 121 virtual const AtomicString& interfaceName() const = 0; |
| 119 virtual ExecutionContext* executionContext() const = 0; | 122 virtual ExecutionContext* executionContext() const = 0; |
| 120 | 123 |
| 121 virtual Node* toNode(); | 124 virtual Node* toNode(); |
| 122 virtual LocalDOMWindow* toDOMWindow(); | 125 virtual LocalDOMWindow* toDOMWindow(); |
| 123 virtual MessagePort* toMessagePort(); | 126 virtual MessagePort* toMessagePort(); |
| 124 | 127 |
| 125 virtual bool addEventListener(const AtomicString& eventType, PassRefPtr<Even
tListener>, bool useCapture); | 128 virtual bool addEventListener(const AtomicString& eventType, PassRefPtrWillB
eRawPtr<EventListener>, bool useCapture); |
| 126 virtual bool removeEventListener(const AtomicString& eventType, PassRefPtr<E
ventListener>, bool useCapture); | 129 virtual bool removeEventListener(const AtomicString& eventType, PassRefPtrWi
llBeRawPtr<EventListener>, bool useCapture); |
| 127 virtual void removeAllEventListeners(); | 130 virtual void removeAllEventListeners(); |
| 128 | 131 |
| 129 bool dispatchEvent(PassRefPtrWillBeRawPtr<Event>); | 132 bool dispatchEvent(PassRefPtrWillBeRawPtr<Event>); |
| 130 | 133 |
| 131 // dispatchEventForBindings is intended to only be called from | 134 // dispatchEventForBindings is intended to only be called from |
| 132 // javascript originated calls. This method will validate and may adjust | 135 // javascript originated calls. This method will validate and may adjust |
| 133 // the Event object before dispatching. | 136 // the Event object before dispatching. |
| 134 bool dispatchEventForBindings(PassRefPtrWillBeRawPtr<Event>, ExceptionState&
); | 137 bool dispatchEventForBindings(PassRefPtrWillBeRawPtr<Event>, ExceptionState&
); |
| 135 virtual void uncaughtExceptionInEventHandler(); | 138 virtual void uncaughtExceptionInEventHandler(); |
| 136 | 139 |
| 137 // Used for legacy "onEvent" attribute APIs. | 140 // Used for legacy "onEvent" attribute APIs. |
| 138 bool setAttributeEventListener(const AtomicString& eventType, PassRefPtr<Eve
ntListener>); | 141 bool setAttributeEventListener(const AtomicString& eventType, PassRefPtrWill
BeRawPtr<EventListener>); |
| 139 EventListener* getAttributeEventListener(const AtomicString& eventType); | 142 EventListener* getAttributeEventListener(const AtomicString& eventType); |
| 140 | 143 |
| 141 bool hasEventListeners() const; | 144 bool hasEventListeners() const; |
| 142 bool hasEventListeners(const AtomicString& eventType) const; | 145 bool hasEventListeners(const AtomicString& eventType) const; |
| 143 bool hasCapturingEventListeners(const AtomicString& eventType); | 146 bool hasCapturingEventListeners(const AtomicString& eventType); |
| 144 const EventListenerVector& getEventListeners(const AtomicString& eventType); | 147 EventListenerVector* getEventListeners(const AtomicString& eventType); |
| 145 Vector<AtomicString> eventTypes(); | 148 Vector<AtomicString> eventTypes(); |
| 146 | 149 |
| 147 bool fireEventListeners(Event*); | 150 bool fireEventListeners(Event*); |
| 148 | 151 |
| 149 DEFINE_INLINE_VIRTUAL_TRACE() { } | 152 DEFINE_INLINE_VIRTUAL_TRACE() { } |
| 150 | 153 |
| 151 virtual bool keepEventInNode(Event*) { return false; } | 154 virtual bool keepEventInNode(Event*) { return false; } |
| 152 | 155 |
| 153 protected: | 156 protected: |
| 154 EventTarget(); | 157 EventTarget(); |
| (...skipping 13 matching lines...) Expand all Loading... |
| 168 | 171 |
| 169 LocalDOMWindow* executingWindow(); | 172 LocalDOMWindow* executingWindow(); |
| 170 void fireEventListeners(Event*, EventTargetData*, EventListenerVector&); | 173 void fireEventListeners(Event*, EventTargetData*, EventListenerVector&); |
| 171 void countLegacyEvents(const AtomicString& legacyTypeName, EventListenerVect
or*, EventListenerVector*); | 174 void countLegacyEvents(const AtomicString& legacyTypeName, EventListenerVect
or*, EventListenerVector*); |
| 172 | 175 |
| 173 bool clearAttributeEventListener(const AtomicString& eventType); | 176 bool clearAttributeEventListener(const AtomicString& eventType); |
| 174 | 177 |
| 175 friend class EventListenerIterator; | 178 friend class EventListenerIterator; |
| 176 }; | 179 }; |
| 177 | 180 |
| 178 class CORE_EXPORT EventTargetWithInlineData : public EventTarget { | 181 // EventTargetData is a GCed object, so it should not be used as a part of |
| 182 // object. However, we intentionally use it as a part of object for performance, |
| 183 // assuming that no one extracts a pointer of |
| 184 // EventTargetWithInlineData::m_eventTargetData and store it to a Member etc. |
| 185 class GC_PLUGIN_IGNORE("513199") CORE_EXPORT EventTargetWithInlineData : public
EventTarget { |
| 186 public: |
| 187 DEFINE_INLINE_VIRTUAL_TRACE() |
| 188 { |
| 189 visitor->trace(m_eventTargetData); |
| 190 EventTarget::trace(visitor); |
| 191 } |
| 192 |
| 179 protected: | 193 protected: |
| 180 EventTargetData* eventTargetData() final { return &m_eventTargetData; } | 194 EventTargetData* eventTargetData() final { return &m_eventTargetData; } |
| 181 EventTargetData& ensureEventTargetData() final { return m_eventTargetData; } | 195 EventTargetData& ensureEventTargetData() final { return m_eventTargetData; } |
| 196 |
| 182 private: | 197 private: |
| 183 EventTargetData m_eventTargetData; | 198 EventTargetData m_eventTargetData; |
| 184 }; | 199 }; |
| 185 | 200 |
| 186 // Base class for classes that wish to inherit from RefCountedGarbageCollected (
in non-Oilpan world) and | 201 // Base class for classes that wish to inherit from RefCountedGarbageCollected (
in non-Oilpan world) and |
| 187 // EventTargetWithInlineData (in both worlds). For details about how to use this
class template, see the comments for | 202 // EventTargetWithInlineData (in both worlds). For details about how to use this
class template, see the comments for |
| 188 // EventTargetWithInlineData above. | 203 // EventTargetWithInlineData above. |
| 189 // | 204 // |
| 190 // This class template exists to circumvent Oilpan's "leftmost class rule", wher
e the Oilpan classes must come first in | 205 // This class template exists to circumvent Oilpan's "leftmost class rule", wher
e the Oilpan classes must come first in |
| 191 // the base class list to avoid memory offset adjustment. In non-Oilpan world, R
efCountedGarbageCollected<T> must come | 206 // the base class list to avoid memory offset adjustment. In non-Oilpan world, R
efCountedGarbageCollected<T> must come |
| 192 // first, but in Oilpan world EventTargetWithInlineData needs to come first. Thi
s class templates does the required | 207 // first, but in Oilpan world EventTargetWithInlineData needs to come first. Thi
s class templates does the required |
| 193 // #if-switch here, in order to avoid a lot of "#if ENABLE(OILPAN)"-s sprinkled
in the derived classes. | 208 // #if-switch here, in order to avoid a lot of "#if ENABLE(OILPAN)"-s sprinkled
in the derived classes. |
| 194 #if ENABLE(OILPAN) | 209 #if ENABLE(OILPAN) |
| 195 template <typename T> | 210 template <typename T> |
| 196 class RefCountedGarbageCollectedEventTargetWithInlineData : public EventTargetWi
thInlineData { | 211 class RefCountedGarbageCollectedEventTargetWithInlineData : public EventTargetWi
thInlineData { |
| 197 public: | 212 public: |
| 198 GC_PLUGIN_IGNORE("491488") | 213 GC_PLUGIN_IGNORE("491488") |
| 199 void* operator new(size_t size) | 214 void* operator new(size_t size) |
| 200 { | 215 { |
| 201 // If T is eagerly finalized, it needs to be allocated accordingly. | 216 // If T is eagerly finalized, it needs to be allocated accordingly. |
| 202 // Redefinition of the operator is needed to accomplish that, as otherwi
se | 217 // Redefinition of the operator is needed to accomplish that, as otherwi
se |
| 203 // it would be allocated using GarbageCollected<EventTarget>'s operator
new. | 218 // it would be allocated using GarbageCollected<EventTarget>'s operator
new. |
| 204 // EventTarget is not eagerly finalized. | 219 // EventTarget is not eagerly finalized. |
| 205 return allocateObject(size, IsEagerlyFinalizedType<T>::value); | 220 return allocateObject(size, IsEagerlyFinalizedType<T>::value); |
| 206 } | 221 } |
| 222 |
| 223 DEFINE_INLINE_VIRTUAL_TRACE() |
| 224 { |
| 225 EventTargetWithInlineData::trace(visitor); |
| 226 } |
| 207 }; | 227 }; |
| 208 #else | 228 #else |
| 209 template <typename T> | 229 template <typename T> |
| 210 class RefCountedGarbageCollectedEventTargetWithInlineData : public RefCountedGar
bageCollected<T>, public EventTargetWithInlineData { | 230 class RefCountedGarbageCollectedEventTargetWithInlineData : public RefCountedGar
bageCollected<T>, public EventTargetWithInlineData { |
| 211 public: | 231 public: |
| 212 DEFINE_INLINE_VIRTUAL_TRACE() { EventTargetWithInlineData::trace(visitor); } | 232 DEFINE_INLINE_VIRTUAL_TRACE() { EventTargetWithInlineData::trace(visitor); } |
| 213 }; | 233 }; |
| 214 #endif | 234 #endif |
| 215 | 235 |
| 216 // FIXME: These macros should be split into separate DEFINE and DECLARE | 236 // FIXME: These macros should be split into separate DEFINE and DECLARE |
| 217 // macros to avoid causing so many header includes. | 237 // macros to avoid causing so many header includes. |
| 218 #define DEFINE_ATTRIBUTE_EVENT_LISTENER(attribute) \ | 238 #define DEFINE_ATTRIBUTE_EVENT_LISTENER(attribute) \ |
| 219 EventListener* on##attribute() { return getAttributeEventListener(EventTypeN
ames::attribute); } \ | 239 EventListener* on##attribute() { return getAttributeEventListener(EventTypeN
ames::attribute); } \ |
| 220 void setOn##attribute(PassRefPtr<EventListener> listener) { setAttributeEven
tListener(EventTypeNames::attribute, listener); } \ | 240 void setOn##attribute(PassRefPtrWillBeRawPtr<EventListener> listener) { setA
ttributeEventListener(EventTypeNames::attribute, listener); } \ |
| 221 | 241 |
| 222 #define DEFINE_STATIC_ATTRIBUTE_EVENT_LISTENER(attribute) \ | 242 #define DEFINE_STATIC_ATTRIBUTE_EVENT_LISTENER(attribute) \ |
| 223 static EventListener* on##attribute(EventTarget& eventTarget) { return event
Target.getAttributeEventListener(EventTypeNames::attribute); } \ | 243 static EventListener* on##attribute(EventTarget& eventTarget) { return event
Target.getAttributeEventListener(EventTypeNames::attribute); } \ |
| 224 static void setOn##attribute(EventTarget& eventTarget, PassRefPtr<EventListe
ner> listener) { eventTarget.setAttributeEventListener(EventTypeNames::attribute
, listener); } \ | 244 static void setOn##attribute(EventTarget& eventTarget, PassRefPtrWillBeRawPt
r<EventListener> listener) { eventTarget.setAttributeEventListener(EventTypeName
s::attribute, listener); } \ |
| 225 | 245 |
| 226 #define DEFINE_WINDOW_ATTRIBUTE_EVENT_LISTENER(attribute) \ | 246 #define DEFINE_WINDOW_ATTRIBUTE_EVENT_LISTENER(attribute) \ |
| 227 EventListener* on##attribute() { return document().getWindowAttributeEventLi
stener(EventTypeNames::attribute); } \ | 247 EventListener* on##attribute() { return document().getWindowAttributeEventLi
stener(EventTypeNames::attribute); } \ |
| 228 void setOn##attribute(PassRefPtr<EventListener> listener) { document().setWi
ndowAttributeEventListener(EventTypeNames::attribute, listener); } \ | 248 void setOn##attribute(PassRefPtrWillBeRawPtr<EventListener> listener) { docu
ment().setWindowAttributeEventListener(EventTypeNames::attribute, listener); } \ |
| 229 | 249 |
| 230 #define DEFINE_STATIC_WINDOW_ATTRIBUTE_EVENT_LISTENER(attribute) \ | 250 #define DEFINE_STATIC_WINDOW_ATTRIBUTE_EVENT_LISTENER(attribute) \ |
| 231 static EventListener* on##attribute(EventTarget& eventTarget) { \ | 251 static EventListener* on##attribute(EventTarget& eventTarget) { \ |
| 232 if (Node* node = eventTarget.toNode()) \ | 252 if (Node* node = eventTarget.toNode()) \ |
| 233 return node->document().getWindowAttributeEventListener(EventTypeNam
es::attribute); \ | 253 return node->document().getWindowAttributeEventListener(EventTypeNam
es::attribute); \ |
| 234 ASSERT(eventTarget.toDOMWindow()); \ | 254 ASSERT(eventTarget.toDOMWindow()); \ |
| 235 return eventTarget.getAttributeEventListener(EventTypeNames::attribute);
\ | 255 return eventTarget.getAttributeEventListener(EventTypeNames::attribute);
\ |
| 236 } \ | 256 } \ |
| 237 static void setOn##attribute(EventTarget& eventTarget, PassRefPtr<EventListe
ner> listener) { \ | 257 static void setOn##attribute(EventTarget& eventTarget, PassRefPtrWillBeRawPt
r<EventListener> listener) { \ |
| 238 if (Node* node = eventTarget.toNode()) \ | 258 if (Node* node = eventTarget.toNode()) \ |
| 239 node->document().setWindowAttributeEventListener(EventTypeNames::att
ribute, listener); \ | 259 node->document().setWindowAttributeEventListener(EventTypeNames::att
ribute, listener); \ |
| 240 else { \ | 260 else { \ |
| 241 ASSERT(eventTarget.toDOMWindow()); \ | 261 ASSERT(eventTarget.toDOMWindow()); \ |
| 242 eventTarget.setAttributeEventListener(EventTypeNames::attribute, lis
tener); \ | 262 eventTarget.setAttributeEventListener(EventTypeNames::attribute, lis
tener); \ |
| 243 } \ | 263 } \ |
| 244 } | 264 } |
| 245 | 265 |
| 246 #define DEFINE_MAPPED_ATTRIBUTE_EVENT_LISTENER(attribute, eventName) \ | 266 #define DEFINE_MAPPED_ATTRIBUTE_EVENT_LISTENER(attribute, eventName) \ |
| 247 EventListener* on##attribute() { return getAttributeEventListener(EventTypeN
ames::eventName); } \ | 267 EventListener* on##attribute() { return getAttributeEventListener(EventTypeN
ames::eventName); } \ |
| 248 void setOn##attribute(PassRefPtr<EventListener> listener) { setAttributeEven
tListener(EventTypeNames::eventName, listener); } \ | 268 void setOn##attribute(PassRefPtrWillBeRawPtr<EventListener> listener) { setA
ttributeEventListener(EventTypeNames::eventName, listener); } \ |
| 249 | 269 |
| 250 #define DECLARE_FORWARDING_ATTRIBUTE_EVENT_LISTENER(recipient, attribute) \ | 270 #define DECLARE_FORWARDING_ATTRIBUTE_EVENT_LISTENER(recipient, attribute) \ |
| 251 EventListener* on##attribute(); \ | 271 EventListener* on##attribute(); \ |
| 252 void setOn##attribute(PassRefPtr<EventListener> listener); | 272 void setOn##attribute(PassRefPtrWillBeRawPtr<EventListener> listener); |
| 253 | 273 |
| 254 #define DEFINE_FORWARDING_ATTRIBUTE_EVENT_LISTENER(type, recipient, attribute) \ | 274 #define DEFINE_FORWARDING_ATTRIBUTE_EVENT_LISTENER(type, recipient, attribute) \ |
| 255 EventListener* type::on##attribute() { return recipient ? recipient->getAttr
ibuteEventListener(EventTypeNames::attribute) : 0; } \ | 275 EventListener* type::on##attribute() { return recipient ? recipient->getAttr
ibuteEventListener(EventTypeNames::attribute) : 0; } \ |
| 256 void type::setOn##attribute(PassRefPtr<EventListener> listener) \ | 276 void type::setOn##attribute(PassRefPtrWillBeRawPtr<EventListener> listener)
\ |
| 257 { \ | 277 { \ |
| 258 if (recipient) \ | 278 if (recipient) \ |
| 259 recipient->setAttributeEventListener(EventTypeNames::attribute, list
ener); \ | 279 recipient->setAttributeEventListener(EventTypeNames::attribute, list
ener); \ |
| 260 } | 280 } |
| 261 | 281 |
| 262 inline bool EventTarget::hasEventListeners() const | 282 inline bool EventTarget::hasEventListeners() const |
| 263 { | 283 { |
| 264 // FIXME: We should have a const version of eventTargetData. | 284 // FIXME: We should have a const version of eventTargetData. |
| 265 if (const EventTargetData* d = const_cast<EventTarget*>(this)->eventTargetDa
ta()) | 285 if (const EventTargetData* d = const_cast<EventTarget*>(this)->eventTargetDa
ta()) |
| 266 return !d->eventListenerMap.isEmpty(); | 286 return !d->eventListenerMap.isEmpty(); |
| (...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 300 using baseClass::deref; \ | 320 using baseClass::deref; \ |
| 301 private: \ | 321 private: \ |
| 302 void refEventTarget() final { ref(); } \ | 322 void refEventTarget() final { ref(); } \ |
| 303 void derefEventTarget() final { deref(); } \ | 323 void derefEventTarget() final { deref(); } \ |
| 304 typedef int thisIsHereToForceASemiColonAfterThisEventTargetMacro | 324 typedef int thisIsHereToForceASemiColonAfterThisEventTargetMacro |
| 305 #define REFCOUNTED_EVENT_TARGET(baseClass) DEFINE_EVENT_TARGET_REFCOUNTING(RefCo
unted<baseClass>) | 325 #define REFCOUNTED_EVENT_TARGET(baseClass) DEFINE_EVENT_TARGET_REFCOUNTING(RefCo
unted<baseClass>) |
| 306 #define REFCOUNTED_GARBAGE_COLLECTED_EVENT_TARGET(baseClass) DEFINE_EVENT_TARGET
_REFCOUNTING(RefCountedGarbageCollected<baseClass>) | 326 #define REFCOUNTED_GARBAGE_COLLECTED_EVENT_TARGET(baseClass) DEFINE_EVENT_TARGET
_REFCOUNTING(RefCountedGarbageCollected<baseClass>) |
| 307 #endif // ENABLE(OILPAN) | 327 #endif // ENABLE(OILPAN) |
| 308 | 328 |
| 309 #endif // EventTarget_h | 329 #endif // EventTarget_h |
| OLD | NEW |