Chromium Code Reviews| 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 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 76 DECLARE_TRACE(); | 76 DECLARE_TRACE(); |
| 77 | 77 |
| 78 EventListenerMap eventListenerMap; | 78 EventListenerMap eventListenerMap; |
| 79 OwnPtr<FiringEventIteratorVector> firingEventIterators; | 79 OwnPtr<FiringEventIteratorVector> firingEventIterators; |
| 80 }; | 80 }; |
| 81 | 81 |
| 82 // This is the base class for all DOM event targets. To make your class an | 82 // This is the base class for all DOM event targets. To make your class an |
| 83 // EventTarget, follow these steps: | 83 // EventTarget, follow these steps: |
| 84 // - Make your IDL interface inherit from EventTarget. | 84 // - Make your IDL interface inherit from EventTarget. |
| 85 // Optionally add "attribute EventHandler onfoo;" attributes. | 85 // Optionally add "attribute EventHandler onfoo;" attributes. |
| 86 // - Inherit from EventTargetWithInlineData (only in rare cases should you use | 86 // - Inherit from EventTargetWithInlineData<YourClass> (only in rare cases |
| 87 // EventTarget directly); or, if you want YourClass to be inherited from | 87 // should you use EventTarget directly). |
| 88 // RefCountedGarbageCollected<YourClass> in addition to EventTargetWithInlineD ata, | |
| 89 // inherit from RefCountedGarbageCollectedEventTargetWithInlineData<YourClass> . | |
| 90 // - In your class declaration, EventTargetWithInlineData (or | 88 // - In your class declaration, EventTargetWithInlineData (or |
| 91 // RefCountedGarbageCollectedEventTargetWithInlineData<>) must come first in | 89 // EventTargetWithInlineData<>) must come first in |
| 92 // the base class list. If your class is non-final, classes inheriting from | 90 // the base class list. If your class is non-final, classes inheriting from |
| 93 // your class need to come first, too. | 91 // your class need to come first, too. |
| 94 // - Figure out if you now need to inherit from ActiveDOMObject as well. | 92 // - Figure out if you now need to inherit from ActiveDOMObject as well. |
| 95 // - In your class declaration, you will typically use | 93 // - In your class declaration, you will typically use |
| 96 // REFCOUNTED_EVENT_TARGET(YourClass) if YourClass is a RefCounted<>, | 94 // REFCOUNTED_EVENT_TARGET(YourClass) if YourClass is a RefCounted<>, |
| 97 // or REFCOUNTED_GARBAGE_COLLECTED_EVENT_TARGET(OtherRefCounted<YourClass>) | 95 // or REFCOUNTED_GARBAGE_COLLECTED_EVENT_TARGET(OtherRefCounted<YourClass>) |
| 98 // if YourClass uses a different kind of reference counting template such as | 96 // if YourClass uses a different kind of reference counting template such as |
| 99 // RefCountedGarbageCollected<YourClass>. | 97 // RefCountedGarbageCollected<YourClass>. |
| 100 // - Make sure to include this header file in your .h file, or you will get | 98 // - Make sure to include this header file in your .h file, or you will get |
| 101 // very strange compiler errors. | 99 // very strange compiler errors. |
| 102 // - If you added an onfoo attribute, use DEFINE_ATTRIBUTE_EVENT_LISTENER(foo) | 100 // - If you added an onfoo attribute, use DEFINE_ATTRIBUTE_EVENT_LISTENER(foo) |
| 103 // in your class declaration. | 101 // in your class declaration. |
| 104 // - Override EventTarget::interfaceName() and getExecutionContext(). The former | 102 // - Override EventTarget::interfaceName() and getExecutionContext(). The former |
| 105 // will typically return EventTargetNames::YourClassName. The latter will | 103 // will typically return EventTargetNames::YourClassName. The latter will |
| 106 // return ActiveDOMObject::executionContext (if you are an ActiveDOMObject) | 104 // return ActiveDOMObject::executionContext (if you are an ActiveDOMObject) |
| 107 // or the document you're in. | 105 // or the document you're in. |
| 108 // - Your trace() method will need to call EventTargetWithInlineData::trace | 106 // - Your trace() method will need to call EventTargetWithInlineData::trace |
| 109 // or RefCountedGarbageCollectedEventTargetWithInlineData<YourClass>::trace, | 107 // or EventTargetWithInlineData<YourClass>::trace, |
| 110 // depending on the base class of your class. | 108 // depending on the base class of your class. |
| 111 // | 109 // |
| 112 // Optionally, add a FooEvent.idl class, but that's outside the scope of this | 110 // Optionally, add a FooEvent.idl class, but that's outside the scope of this |
| 113 // comment (and much more straightforward). | 111 // comment (and much more straightforward). |
| 114 class CORE_EXPORT EventTarget : public GarbageCollectedFinalized<EventTarget>, p ublic ScriptWrappable { | 112 class CORE_EXPORT EventTarget : public GarbageCollectedFinalized<EventTarget>, p ublic ScriptWrappable { |
| 115 DEFINE_WRAPPERTYPEINFO(); | 113 DEFINE_WRAPPERTYPEINFO(); |
| 116 public: | 114 public: |
| 117 virtual ~EventTarget(); | 115 virtual ~EventTarget(); |
| 118 | 116 |
| 119 #if !ENABLE(OILPAN) | 117 #if !ENABLE(OILPAN) |
| (...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 188 | 186 |
| 189 bool clearAttributeEventListener(const AtomicString& eventType); | 187 bool clearAttributeEventListener(const AtomicString& eventType); |
| 190 | 188 |
| 191 friend class EventListenerIterator; | 189 friend class EventListenerIterator; |
| 192 }; | 190 }; |
| 193 | 191 |
| 194 // EventTargetData is a GCed object, so it should not be used as a part of | 192 // EventTargetData is a GCed object, so it should not be used as a part of |
| 195 // object. However, we intentionally use it as a part of object for performance, | 193 // object. However, we intentionally use it as a part of object for performance, |
| 196 // assuming that no one extracts a pointer of | 194 // assuming that no one extracts a pointer of |
| 197 // EventTargetWithInlineData::m_eventTargetData and store it to a Member etc. | 195 // EventTargetWithInlineData::m_eventTargetData and store it to a Member etc. |
| 196 template <typename T> | |
| 198 class GC_PLUGIN_IGNORE("513199") CORE_EXPORT EventTargetWithInlineData : public EventTarget { | 197 class GC_PLUGIN_IGNORE("513199") CORE_EXPORT EventTargetWithInlineData : public EventTarget { |
|
haraken
2016/04/06 11:23:56
tasak@ told me that this doesn't work because of M
| |
| 199 public: | 198 public: |
| 200 DEFINE_INLINE_VIRTUAL_TRACE() | |
| 201 { | |
| 202 visitor->trace(m_eventTargetData); | |
| 203 EventTarget::trace(visitor); | |
| 204 } | |
| 205 | |
| 206 protected: | |
| 207 EventTargetData* eventTargetData() final { return &m_eventTargetData; } | |
| 208 EventTargetData& ensureEventTargetData() final { return m_eventTargetData; } | |
| 209 | |
| 210 private: | |
| 211 EventTargetData m_eventTargetData; | |
| 212 }; | |
| 213 | |
| 214 // Base class for classes that wish to inherit from RefCountedGarbageCollected ( in non-Oilpan world) and | |
| 215 // EventTargetWithInlineData (in both worlds). For details about how to use this class template, see the comments for | |
| 216 // EventTargetWithInlineData above. | |
| 217 // | |
| 218 // This class template exists to circumvent Oilpan's "leftmost class rule", wher e the Oilpan classes must come first in | |
| 219 // the base class list to avoid memory offset adjustment. In non-Oilpan world, R efCountedGarbageCollected<T> must come | |
| 220 // first, but in Oilpan world EventTargetWithInlineData needs to come first. Thi s class templates does the required | |
| 221 // #if-switch here, in order to avoid a lot of "#if ENABLE(OILPAN)"-s sprinkled in the derived classes. | |
| 222 #if ENABLE(OILPAN) | |
| 223 template <typename T> | |
| 224 class RefCountedGarbageCollectedEventTargetWithInlineData : public EventTargetWi thInlineData { | |
| 225 public: | |
| 226 GC_PLUGIN_IGNORE("491488") | 199 GC_PLUGIN_IGNORE("491488") |
| 227 void* operator new(size_t size) | 200 void* operator new(size_t size) |
| 228 { | 201 { |
| 229 // If T is eagerly finalized, it needs to be allocated accordingly. | 202 // If T is eagerly finalized, it needs to be allocated accordingly. |
| 230 // Redefinition of the operator is needed to accomplish that, as otherwi se | 203 // Redefinition of the operator is needed to accomplish that, as otherwi se |
| 231 // it would be allocated using GarbageCollected<EventTarget>'s operator new. | 204 // it would be allocated using GarbageCollected<EventTarget>'s operator new. |
| 232 // EventTarget is not eagerly finalized. | 205 // EventTarget is not eagerly finalized. |
| 233 return allocateObject(size, IsEagerlyFinalizedType<T>::value); | 206 return allocateObject(size, IsEagerlyFinalizedType<T>::value); |
| 234 } | 207 } |
| 235 | 208 |
| 236 DEFINE_INLINE_VIRTUAL_TRACE() | 209 DEFINE_INLINE_VIRTUAL_TRACE() |
| 237 { | 210 { |
| 238 EventTargetWithInlineData::trace(visitor); | 211 visitor->trace(m_eventTargetData); |
| 212 EventTarget::trace(visitor); | |
| 239 } | 213 } |
| 214 | |
| 215 protected: | |
| 216 EventTargetData* eventTargetData() final { return &m_eventTargetData; } | |
| 217 EventTargetData& ensureEventTargetData() final { return m_eventTargetData; } | |
| 218 | |
| 219 private: | |
| 220 EventTargetData m_eventTargetData; | |
| 240 }; | 221 }; |
| 241 #else | |
| 242 template <typename T> | |
| 243 class RefCountedGarbageCollectedEventTargetWithInlineData : public RefCountedGar bageCollected<T>, public EventTargetWithInlineData { | |
| 244 public: | |
| 245 DEFINE_INLINE_VIRTUAL_TRACE() { EventTargetWithInlineData::trace(visitor); } | |
| 246 }; | |
| 247 #endif | |
| 248 | 222 |
| 249 // FIXME: These macros should be split into separate DEFINE and DECLARE | 223 // FIXME: These macros should be split into separate DEFINE and DECLARE |
| 250 // macros to avoid causing so many header includes. | 224 // macros to avoid causing so many header includes. |
| 251 #define DEFINE_ATTRIBUTE_EVENT_LISTENER(attribute) \ | 225 #define DEFINE_ATTRIBUTE_EVENT_LISTENER(attribute) \ |
| 252 EventListener* on##attribute() { return this->getAttributeEventListener(Even tTypeNames::attribute); } \ | 226 EventListener* on##attribute() { return this->getAttributeEventListener(Even tTypeNames::attribute); } \ |
| 253 void setOn##attribute(EventListener* listener) { this->setAttributeEventList ener(EventTypeNames::attribute, listener); } \ | 227 void setOn##attribute(EventListener* listener) { this->setAttributeEventList ener(EventTypeNames::attribute, listener); } \ |
| 254 | 228 |
| 255 #define DEFINE_STATIC_ATTRIBUTE_EVENT_LISTENER(attribute) \ | 229 #define DEFINE_STATIC_ATTRIBUTE_EVENT_LISTENER(attribute) \ |
| 256 static EventListener* on##attribute(EventTarget& eventTarget) { return event Target.getAttributeEventListener(EventTypeNames::attribute); } \ | 230 static EventListener* on##attribute(EventTarget& eventTarget) { return event Target.getAttributeEventListener(EventTypeNames::attribute); } \ |
| 257 static void setOn##attribute(EventTarget& eventTarget, EventListener* listen er) { eventTarget.setAttributeEventListener(EventTypeNames::attribute, listener) ; } \ | 231 static void setOn##attribute(EventTarget& eventTarget, EventListener* listen er) { eventTarget.setAttributeEventListener(EventTypeNames::attribute, listener) ; } \ |
| (...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 321 using baseClass::deref; \ | 295 using baseClass::deref; \ |
| 322 private: \ | 296 private: \ |
| 323 void refEventTarget() final { ref(); } \ | 297 void refEventTarget() final { ref(); } \ |
| 324 void derefEventTarget() final { deref(); } \ | 298 void derefEventTarget() final { deref(); } \ |
| 325 typedef int thisIsHereToForceASemiColonAfterThisEventTargetMacro | 299 typedef int thisIsHereToForceASemiColonAfterThisEventTargetMacro |
| 326 #define REFCOUNTED_EVENT_TARGET(baseClass) DEFINE_EVENT_TARGET_REFCOUNTING(RefCo unted<baseClass>) | 300 #define REFCOUNTED_EVENT_TARGET(baseClass) DEFINE_EVENT_TARGET_REFCOUNTING(RefCo unted<baseClass>) |
| 327 #define REFCOUNTED_GARBAGE_COLLECTED_EVENT_TARGET(baseClass) DEFINE_EVENT_TARGET _REFCOUNTING(RefCountedGarbageCollected<baseClass>) | 301 #define REFCOUNTED_GARBAGE_COLLECTED_EVENT_TARGET(baseClass) DEFINE_EVENT_TARGET _REFCOUNTING(RefCountedGarbageCollected<baseClass>) |
| 328 #endif // ENABLE(OILPAN) | 302 #endif // ENABLE(OILPAN) |
| 329 | 303 |
| 330 #endif // EventTarget_h | 304 #endif // EventTarget_h |
| OLD | NEW |