Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(11)

Side by Side Diff: third_party/WebKit/Source/core/events/EventTarget.h

Issue 1857143002: Oilpan: Remove RefCountedGarbageCollectedEventTargetWithInlineData (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 67 matching lines...) Expand 10 before | Expand all | Expand 10 after
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 (only in rare cases should you use
87 // EventTarget directly); or, if you want YourClass to be inherited from 87 // EventTarget directly); or, if you want YourClass to be inherited from
88 // RefCountedGarbageCollected<YourClass> in addition to EventTargetWithInlineD ata, 88 // RefCountedGarbageCollected<YourClass> in addition to EventTargetWithInlineD ata,
sof 2016/04/05 07:52:13 Could you adjust this comment a bit?
89 // inherit from RefCountedGarbageCollectedEventTargetWithInlineData<YourClass> . 89 // inherit from EventTargetWithInlineData<YourClass>.
90 // - In your class declaration, EventTargetWithInlineData (or 90 // - In your class declaration, EventTargetWithInlineData (or
91 // RefCountedGarbageCollectedEventTargetWithInlineData<>) must come first in 91 // EventTargetWithInlineData<>) must come first in
92 // the base class list. If your class is non-final, classes inheriting from 92 // the base class list. If your class is non-final, classes inheriting from
93 // your class need to come first, too. 93 // your class need to come first, too.
94 // - Figure out if you now need to inherit from ActiveDOMObject as well. 94 // - Figure out if you now need to inherit from ActiveDOMObject as well.
95 // - In your class declaration, you will typically use 95 // - In your class declaration, you will typically use
96 // REFCOUNTED_EVENT_TARGET(YourClass) if YourClass is a RefCounted<>, 96 // REFCOUNTED_EVENT_TARGET(YourClass) if YourClass is a RefCounted<>,
97 // or REFCOUNTED_GARBAGE_COLLECTED_EVENT_TARGET(OtherRefCounted<YourClass>) 97 // or REFCOUNTED_GARBAGE_COLLECTED_EVENT_TARGET(OtherRefCounted<YourClass>)
98 // if YourClass uses a different kind of reference counting template such as 98 // if YourClass uses a different kind of reference counting template such as
99 // RefCountedGarbageCollected<YourClass>. 99 // RefCountedGarbageCollected<YourClass>.
100 // - Make sure to include this header file in your .h file, or you will get 100 // - Make sure to include this header file in your .h file, or you will get
101 // very strange compiler errors. 101 // very strange compiler errors.
102 // - If you added an onfoo attribute, use DEFINE_ATTRIBUTE_EVENT_LISTENER(foo) 102 // - If you added an onfoo attribute, use DEFINE_ATTRIBUTE_EVENT_LISTENER(foo)
103 // in your class declaration. 103 // in your class declaration.
104 // - Override EventTarget::interfaceName() and getExecutionContext(). The former 104 // - Override EventTarget::interfaceName() and getExecutionContext(). The former
105 // will typically return EventTargetNames::YourClassName. The latter will 105 // will typically return EventTargetNames::YourClassName. The latter will
106 // return ActiveDOMObject::executionContext (if you are an ActiveDOMObject) 106 // return ActiveDOMObject::executionContext (if you are an ActiveDOMObject)
107 // or the document you're in. 107 // or the document you're in.
108 // - Your trace() method will need to call EventTargetWithInlineData::trace 108 // - Your trace() method will need to call EventTargetWithInlineData::trace
109 // or RefCountedGarbageCollectedEventTargetWithInlineData<YourClass>::trace, 109 // or EventTargetWithInlineData<YourClass>::trace,
110 // depending on the base class of your class. 110 // depending on the base class of your class.
111 // 111 //
112 // Optionally, add a FooEvent.idl class, but that's outside the scope of this 112 // Optionally, add a FooEvent.idl class, but that's outside the scope of this
113 // comment (and much more straightforward). 113 // comment (and much more straightforward).
114 class CORE_EXPORT EventTarget : public GarbageCollectedFinalized<EventTarget>, p ublic ScriptWrappable { 114 class CORE_EXPORT EventTarget : public GarbageCollectedFinalized<EventTarget>, p ublic ScriptWrappable {
115 DEFINE_WRAPPERTYPEINFO(); 115 DEFINE_WRAPPERTYPEINFO();
116 public: 116 public:
117 virtual ~EventTarget(); 117 virtual ~EventTarget();
118 118
119 #if !ENABLE(OILPAN) 119 #if !ENABLE(OILPAN)
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after
188 188
189 bool clearAttributeEventListener(const AtomicString& eventType); 189 bool clearAttributeEventListener(const AtomicString& eventType);
190 190
191 friend class EventListenerIterator; 191 friend class EventListenerIterator;
192 }; 192 };
193 193
194 // EventTargetData is a GCed object, so it should not be used as a part of 194 // 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, 195 // object. However, we intentionally use it as a part of object for performance,
196 // assuming that no one extracts a pointer of 196 // assuming that no one extracts a pointer of
197 // EventTargetWithInlineData::m_eventTargetData and store it to a Member etc. 197 // EventTargetWithInlineData::m_eventTargetData and store it to a Member etc.
198 template <typename T>
198 class GC_PLUGIN_IGNORE("513199") CORE_EXPORT EventTargetWithInlineData : public EventTarget { 199 class GC_PLUGIN_IGNORE("513199") CORE_EXPORT EventTargetWithInlineData : public EventTarget {
199 public: 200 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") 201 GC_PLUGIN_IGNORE("491488")
227 void* operator new(size_t size) 202 void* operator new(size_t size)
228 { 203 {
229 // If T is eagerly finalized, it needs to be allocated accordingly. 204 // If T is eagerly finalized, it needs to be allocated accordingly.
230 // Redefinition of the operator is needed to accomplish that, as otherwi se 205 // Redefinition of the operator is needed to accomplish that, as otherwi se
231 // it would be allocated using GarbageCollected<EventTarget>'s operator new. 206 // it would be allocated using GarbageCollected<EventTarget>'s operator new.
232 // EventTarget is not eagerly finalized. 207 // EventTarget is not eagerly finalized.
233 return allocateObject(size, IsEagerlyFinalizedType<T>::value); 208 return allocateObject(size, IsEagerlyFinalizedType<T>::value);
234 } 209 }
235 210
236 DEFINE_INLINE_VIRTUAL_TRACE() 211 DEFINE_INLINE_VIRTUAL_TRACE()
237 { 212 {
238 EventTargetWithInlineData::trace(visitor); 213 visitor->trace(m_eventTargetData);
214 EventTarget::trace(visitor);
239 } 215 }
216
217 protected:
218 EventTargetData* eventTargetData() final { return &m_eventTargetData; }
219 EventTargetData& ensureEventTargetData() final { return m_eventTargetData; }
220
221 private:
222 EventTargetData m_eventTargetData;
240 }; 223 };
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 224
249 // FIXME: These macros should be split into separate DEFINE and DECLARE 225 // FIXME: These macros should be split into separate DEFINE and DECLARE
250 // macros to avoid causing so many header includes. 226 // macros to avoid causing so many header includes.
251 #define DEFINE_ATTRIBUTE_EVENT_LISTENER(attribute) \ 227 #define DEFINE_ATTRIBUTE_EVENT_LISTENER(attribute) \
252 EventListener* on##attribute() { return this->getAttributeEventListener(Even tTypeNames::attribute); } \ 228 EventListener* on##attribute() { return this->getAttributeEventListener(Even tTypeNames::attribute); } \
253 void setOn##attribute(EventListener* listener) { this->setAttributeEventList ener(EventTypeNames::attribute, listener); } \ 229 void setOn##attribute(EventListener* listener) { this->setAttributeEventList ener(EventTypeNames::attribute, listener); } \
254 230
255 #define DEFINE_STATIC_ATTRIBUTE_EVENT_LISTENER(attribute) \ 231 #define DEFINE_STATIC_ATTRIBUTE_EVENT_LISTENER(attribute) \
256 static EventListener* on##attribute(EventTarget& eventTarget) { return event Target.getAttributeEventListener(EventTypeNames::attribute); } \ 232 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) ; } \ 233 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
321 using baseClass::deref; \ 297 using baseClass::deref; \
322 private: \ 298 private: \
323 void refEventTarget() final { ref(); } \ 299 void refEventTarget() final { ref(); } \
324 void derefEventTarget() final { deref(); } \ 300 void derefEventTarget() final { deref(); } \
325 typedef int thisIsHereToForceASemiColonAfterThisEventTargetMacro 301 typedef int thisIsHereToForceASemiColonAfterThisEventTargetMacro
326 #define REFCOUNTED_EVENT_TARGET(baseClass) DEFINE_EVENT_TARGET_REFCOUNTING(RefCo unted<baseClass>) 302 #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>) 303 #define REFCOUNTED_GARBAGE_COLLECTED_EVENT_TARGET(baseClass) DEFINE_EVENT_TARGET _REFCOUNTING(RefCountedGarbageCollected<baseClass>)
328 #endif // ENABLE(OILPAN) 304 #endif // ENABLE(OILPAN)
329 305
330 #endif // EventTarget_h 306 #endif // EventTarget_h
OLDNEW
« no previous file with comments | « third_party/WebKit/Source/core/dom/MessagePort.cpp ('k') | third_party/WebKit/Source/core/fileapi/FileReader.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698