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

Side by Side Diff: sky/engine/core/events/EventTarget.h

Issue 671173006: Remove lots of machinery related to inline event handlers. (Closed) Base URL: git@github.com:domokit/mojo.git@master
Patch Set: Created 6 years, 1 month 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
« no previous file with comments | « sky/engine/core/events/EventListenerMap.cpp ('k') | sky/engine/core/events/EventTarget.cpp » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 53 matching lines...) Expand 10 before | Expand all | Expand 10 after
64 EventTargetData(); 64 EventTargetData();
65 ~EventTargetData(); 65 ~EventTargetData();
66 66
67 EventListenerMap eventListenerMap; 67 EventListenerMap eventListenerMap;
68 OwnPtr<FiringEventIteratorVector> firingEventIterators; 68 OwnPtr<FiringEventIteratorVector> firingEventIterators;
69 }; 69 };
70 70
71 // This is the base class for all DOM event targets. To make your class an 71 // This is the base class for all DOM event targets. To make your class an
72 // EventTarget, follow these steps: 72 // EventTarget, follow these steps:
73 // - Make your IDL interface inherit from EventTarget. 73 // - Make your IDL interface inherit from EventTarget.
74 // Optionally add "attribute EventHandler onfoo;" attributes.
75 // - Inherit from EventTargetWithInlineData (only in rare cases should you use 74 // - Inherit from EventTargetWithInlineData (only in rare cases should you use
76 // EventTarget directly). 75 // EventTarget directly).
77 // - Figure out if you now need to inherit from ActiveDOMObject as well. 76 // - Figure out if you now need to inherit from ActiveDOMObject as well.
78 // - In your class declaration, you will typically use 77 // - In your class declaration, you will typically use
79 // REFCOUNTED_EVENT_TARGET(YourClassName) and 78 // REFCOUNTED_EVENT_TARGET(YourClassName) and
80 // WILL_BE_USING_GARBAGE_COLLECTED_MIXIN(YourClassName). Make sure to include 79 // WILL_BE_USING_GARBAGE_COLLECTED_MIXIN(YourClassName). Make sure to include
81 // this header file in your .h file, or you will get very strange compiler 80 // this header file in your .h file, or you will get very strange compiler
82 // errors. 81 // errors.
83 // - If you added an onfoo attribute, use DEFINE_ATTRIBUTE_EVENT_LISTENER(foo)
84 // in your class declaration.
85 // - Call ScriptWrappable::init(this) in your constructor, unless you are alread y 82 // - Call ScriptWrappable::init(this) in your constructor, unless you are alread y
86 // doing so. 83 // doing so.
87 // - Override EventTarget::interfaceName() and executionContext(). The former 84 // - Override EventTarget::interfaceName() and executionContext(). The former
88 // will typically return EventTargetNames::YourClassName. The latter will 85 // will typically return EventTargetNames::YourClassName. The latter will
89 // return ActiveDOMObject::executionContext (if you are an ActiveDOMObject) 86 // return ActiveDOMObject::executionContext (if you are an ActiveDOMObject)
90 // or the document you're in. 87 // or the document you're in.
91 // - Your trace() method will need to call EventTargetWithInlineData::trace. 88 // - Your trace() method will need to call EventTargetWithInlineData::trace.
92 // 89 //
93 // Optionally, add a FooEvent.idl class, but that's outside the scope of this 90 // Optionally, add a FooEvent.idl class, but that's outside the scope of this
94 // comment (and much more straightforward). 91 // comment (and much more straightforward).
(...skipping 18 matching lines...) Expand all
113 bool addEventListener(const AtomicString& eventType) { return false; } 110 bool addEventListener(const AtomicString& eventType) { return false; }
114 virtual bool addEventListener(const AtomicString& eventType, PassRefPtr<Even tListener>, bool useCapture = false); 111 virtual bool addEventListener(const AtomicString& eventType, PassRefPtr<Even tListener>, bool useCapture = false);
115 bool removeEventListener() { return false; } 112 bool removeEventListener() { return false; }
116 bool removeEventListener(const AtomicString& eventType) { return false; } 113 bool removeEventListener(const AtomicString& eventType) { return false; }
117 virtual bool removeEventListener(const AtomicString& eventType, PassRefPtr<E ventListener>, bool useCapture = false); 114 virtual bool removeEventListener(const AtomicString& eventType, PassRefPtr<E ventListener>, bool useCapture = false);
118 virtual void removeAllEventListeners(); 115 virtual void removeAllEventListeners();
119 virtual bool dispatchEvent(PassRefPtrWillBeRawPtr<Event>); 116 virtual bool dispatchEvent(PassRefPtrWillBeRawPtr<Event>);
120 bool dispatchEvent(PassRefPtrWillBeRawPtr<Event>, ExceptionState&); // DOM A PI 117 bool dispatchEvent(PassRefPtrWillBeRawPtr<Event>, ExceptionState&); // DOM A PI
121 virtual void uncaughtExceptionInEventHandler(); 118 virtual void uncaughtExceptionInEventHandler();
122 119
123 // Used for legacy "onEvent" attribute APIs.
124 bool setAttributeEventListener(const AtomicString& eventType, PassRefPtr<Eve ntListener>);
125 EventListener* getAttributeEventListener(const AtomicString& eventType);
126
127 bool hasEventListeners() const; 120 bool hasEventListeners() const;
128 bool hasEventListeners(const AtomicString& eventType) const; 121 bool hasEventListeners(const AtomicString& eventType) const;
129 bool hasCapturingEventListeners(const AtomicString& eventType); 122 bool hasCapturingEventListeners(const AtomicString& eventType);
130 const EventListenerVector& getEventListeners(const AtomicString& eventType); 123 const EventListenerVector& getEventListeners(const AtomicString& eventType);
131 Vector<AtomicString> eventTypes(); 124 Vector<AtomicString> eventTypes();
132 125
133 bool fireEventListeners(Event*); 126 bool fireEventListeners(Event*);
134 127
135 virtual void trace(Visitor*) { } 128 virtual void trace(Visitor*) { }
136 129
(...skipping 11 matching lines...) Expand all
148 #if !ENABLE(OILPAN) 141 #if !ENABLE(OILPAN)
149 // Subclasses should likely not override these themselves; instead, they sho uld use the REFCOUNTED_EVENT_TARGET() macro. 142 // Subclasses should likely not override these themselves; instead, they sho uld use the REFCOUNTED_EVENT_TARGET() macro.
150 virtual void refEventTarget() = 0; 143 virtual void refEventTarget() = 0;
151 virtual void derefEventTarget() = 0; 144 virtual void derefEventTarget() = 0;
152 #endif 145 #endif
153 146
154 LocalDOMWindow* executingWindow(); 147 LocalDOMWindow* executingWindow();
155 void fireEventListeners(Event*, EventTargetData*, EventListenerVector&); 148 void fireEventListeners(Event*, EventTargetData*, EventListenerVector&);
156 void countLegacyEvents(const AtomicString& legacyTypeName, EventListenerVect or*, EventListenerVector*); 149 void countLegacyEvents(const AtomicString& legacyTypeName, EventListenerVect or*, EventListenerVector*);
157 150
158 bool clearAttributeEventListener(const AtomicString& eventType);
159
160 friend class EventListenerIterator; 151 friend class EventListenerIterator;
161 }; 152 };
162 153
163 class EventTargetWithInlineData : public EventTarget { 154 class EventTargetWithInlineData : public EventTarget {
164 protected: 155 protected:
165 virtual EventTargetData* eventTargetData() OVERRIDE FINAL { return &m_eventT argetData; } 156 virtual EventTargetData* eventTargetData() OVERRIDE FINAL { return &m_eventT argetData; }
166 virtual EventTargetData& ensureEventTargetData() OVERRIDE FINAL { return m_e ventTargetData; } 157 virtual EventTargetData& ensureEventTargetData() OVERRIDE FINAL { return m_e ventTargetData; }
167 private: 158 private:
168 EventTargetData m_eventTargetData; 159 EventTargetData m_eventTargetData;
169 }; 160 };
170 161
171 // FIXME: These macros should be split into separate DEFINE and DECLARE
172 // macros to avoid causing so many header includes.
173 #define DEFINE_ATTRIBUTE_EVENT_LISTENER(attribute) \
174 EventListener* on##attribute() { return getAttributeEventListener(EventTypeN ames::attribute); } \
175 void setOn##attribute(PassRefPtr<EventListener> listener) { setAttributeEven tListener(EventTypeNames::attribute, listener); } \
176
177 #define DEFINE_STATIC_ATTRIBUTE_EVENT_LISTENER(attribute) \
178 static EventListener* on##attribute(EventTarget& eventTarget) { return event Target.getAttributeEventListener(EventTypeNames::attribute); } \
179 static void setOn##attribute(EventTarget& eventTarget, PassRefPtr<EventListe ner> listener) { eventTarget.setAttributeEventListener(EventTypeNames::attribute , listener); } \
180
181 #define DEFINE_WINDOW_ATTRIBUTE_EVENT_LISTENER(attribute) \
182 EventListener* on##attribute() { return document().getWindowAttributeEventLi stener(EventTypeNames::attribute); } \
183 void setOn##attribute(PassRefPtr<EventListener> listener) { document().setWi ndowAttributeEventListener(EventTypeNames::attribute, listener); } \
184
185 #define DEFINE_STATIC_WINDOW_ATTRIBUTE_EVENT_LISTENER(attribute) \
186 static EventListener* on##attribute(EventTarget& eventTarget) { \
187 if (Node* node = eventTarget.toNode()) \
188 return node->document().getWindowAttributeEventListener(EventTypeNam es::attribute); \
189 ASSERT(eventTarget.toDOMWindow()); \
190 return eventTarget.getAttributeEventListener(EventTypeNames::attribute); \
191 } \
192 static void setOn##attribute(EventTarget& eventTarget, PassRefPtr<EventListe ner> listener) { \
193 if (Node* node = eventTarget.toNode()) \
194 node->document().setWindowAttributeEventListener(EventTypeNames::att ribute, listener); \
195 else { \
196 ASSERT(eventTarget.toDOMWindow()); \
197 eventTarget.setAttributeEventListener(EventTypeNames::attribute, lis tener); \
198 } \
199 }
200
201 #define DEFINE_MAPPED_ATTRIBUTE_EVENT_LISTENER(attribute, eventName) \
202 EventListener* on##attribute() { return getAttributeEventListener(EventTypeN ames::eventName); } \
203 void setOn##attribute(PassRefPtr<EventListener> listener) { setAttributeEven tListener(EventTypeNames::eventName, listener); } \
204
205 #define DECLARE_FORWARDING_ATTRIBUTE_EVENT_LISTENER(recipient, attribute) \
206 EventListener* on##attribute(); \
207 void setOn##attribute(PassRefPtr<EventListener> listener);
208
209 #define DEFINE_FORWARDING_ATTRIBUTE_EVENT_LISTENER(type, recipient, attribute) \
210 EventListener* type::on##attribute() { return recipient ? recipient->getAttr ibuteEventListener(EventTypeNames::attribute) : 0; } \
211 void type::setOn##attribute(PassRefPtr<EventListener> listener) \
212 { \
213 if (recipient) \
214 recipient->setAttributeEventListener(EventTypeNames::attribute, list ener); \
215 }
216
217 inline bool EventTarget::hasEventListeners() const 162 inline bool EventTarget::hasEventListeners() const
218 { 163 {
219 // FIXME: We should have a const version of eventTargetData. 164 // FIXME: We should have a const version of eventTargetData.
220 if (const EventTargetData* d = const_cast<EventTarget*>(this)->eventTargetDa ta()) 165 if (const EventTargetData* d = const_cast<EventTarget*>(this)->eventTargetDa ta())
221 return !d->eventListenerMap.isEmpty(); 166 return !d->eventListenerMap.isEmpty();
222 return false; 167 return false;
223 } 168 }
224 169
225 inline bool EventTarget::hasEventListeners(const AtomicString& eventType) const 170 inline bool EventTarget::hasEventListeners(const AtomicString& eventType) const
226 { 171 {
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
259 typedef int thisIsHereToForceASemiColonAfterThisEventTargetMacro 204 typedef int thisIsHereToForceASemiColonAfterThisEventTargetMacro
260 #define DEFINE_EVENT_TARGET_REFCOUNTING_WILL_BE_REMOVED(baseClass) DEFINE_EVENT_ TARGET_REFCOUNTING(baseClass) 205 #define DEFINE_EVENT_TARGET_REFCOUNTING_WILL_BE_REMOVED(baseClass) DEFINE_EVENT_ TARGET_REFCOUNTING(baseClass)
261 #endif 206 #endif
262 207
263 // Use this macro if your EventTarget subclass is also a subclass of WTF::RefCou nted. 208 // Use this macro if your EventTarget subclass is also a subclass of WTF::RefCou nted.
264 // A ref-counted class that uses a different method of refcounting should use DE FINE_EVENT_TARGET_REFCOUNTING directly. 209 // A ref-counted class that uses a different method of refcounting should use DE FINE_EVENT_TARGET_REFCOUNTING directly.
265 // Both of these macros are meant to be placed just before the "public:" section of the class declaration. 210 // Both of these macros are meant to be placed just before the "public:" section of the class declaration.
266 #define REFCOUNTED_EVENT_TARGET(className) DEFINE_EVENT_TARGET_REFCOUNTING_WILL_ BE_REMOVED(RefCounted<className>) 211 #define REFCOUNTED_EVENT_TARGET(className) DEFINE_EVENT_TARGET_REFCOUNTING_WILL_ BE_REMOVED(RefCounted<className>)
267 212
268 #endif // EventTarget_h 213 #endif // EventTarget_h
OLDNEW
« no previous file with comments | « sky/engine/core/events/EventListenerMap.cpp ('k') | sky/engine/core/events/EventTarget.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698