Changeset 181216 in webkit
- Timestamp:
- Mar 7, 2015 5:37:26 PM (9 years ago)
- Location:
- trunk/Source/WebCore
- Files:
-
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/Source/WebCore/ChangeLog
r181215 r181216 1 2015-03-07 Darin Adler <darin@apple.com> 2 3 Unindent EventTarget, EventListener, JSEventLister.h files 4 https://bugs.webkit.org/show_bug.cgi?id=142440 5 6 Reviewed by Alexey Proskuryakov. 7 8 * bindings/js/JSEventListener.h: 9 * dom/EventListener.h: 10 * dom/EventTarget.h: 11 Change indentation to match coding style rules. 12 1 13 2015-03-07 Geoffrey Garen <ggaren@apple.com> 2 14 -
trunk/Source/WebCore/bindings/js/JSEventListener.h
r181156 r181216 30 30 namespace WebCore { 31 31 32 33 34 32 class EventTarget; 33 class HTMLElement; 34 class JSDOMGlobalObject; 35 35 36 class JSEventListener : public EventListener { 37 public: 38 static Ref<JSEventListener> create(JSC::JSObject* listener, JSC::JSObject* wrapper, bool isAttribute, DOMWrapperWorld& world) 39 { 40 return adoptRef(*new JSEventListener(listener, wrapper, isAttribute, world)); 41 } 42 43 static const JSEventListener* cast(const EventListener* listener) 44 { 45 return listener->type() == JSEventListenerType 46 ? static_cast<const JSEventListener*>(listener) 47 : 0; 48 } 49 50 virtual ~JSEventListener(); 51 52 virtual bool operator==(const EventListener& other) override; 53 54 // Returns true if this event listener was created for an event handler attribute, like "onload" or "onclick". 55 bool isAttribute() const { return m_isAttribute; } 56 57 JSC::JSObject* jsFunction(ScriptExecutionContext*) const; 58 DOMWrapperWorld& isolatedWorld() const { return *m_isolatedWorld; } 59 60 JSC::JSObject* wrapper() const { return m_wrapper.get(); } 61 void setWrapper(JSC::VM&, JSC::JSObject* wrapper) const { m_wrapper = JSC::Weak<JSC::JSObject>(wrapper); } 62 63 private: 64 virtual JSC::JSObject* initializeJSFunction(ScriptExecutionContext*) const; 65 virtual void visitJSFunction(JSC::SlotVisitor&) override; 66 virtual bool virtualisAttribute() const override; 67 68 protected: 69 JSEventListener(JSC::JSObject* function, JSC::JSObject* wrapper, bool isAttribute, DOMWrapperWorld&); 70 virtual void handleEvent(ScriptExecutionContext*, Event*) override; 71 72 private: 73 mutable JSC::Weak<JSC::JSObject> m_jsFunction; 74 mutable JSC::Weak<JSC::JSObject> m_wrapper; 75 76 bool m_isAttribute; 77 RefPtr<DOMWrapperWorld> m_isolatedWorld; 78 }; 79 80 // For "onxxx" attributes that automatically set up JavaScript event listeners. 81 JSC::JSValue eventHandlerAttribute(EventTarget&, const AtomicString& eventType); 82 void setEventHandlerAttribute(JSC::ExecState&, JSC::JSObject&, EventTarget&, const AtomicString& eventType, JSC::JSValue); 83 84 // Like the functions above, but for attributes that forward event handlers to the window object rather than setting them on the target. 85 JSC::JSValue windowForwardedEventHandlerAttribute(HTMLElement&, const AtomicString& eventType); 86 void setWindowForwardedEventHandlerAttribute(JSC::ExecState&, JSC::JSObject&, HTMLElement&, const AtomicString& eventType, JSC::JSValue); 87 88 Ref<JSEventListener> createJSEventListenerForAdd(JSC::ExecState&, JSC::JSObject& listener, JSC::JSObject& wrapper); 89 Ref<JSEventListener> createJSEventListenerForRemove(JSC::ExecState&, JSC::JSObject& listener, JSC::JSObject& wrapper); 90 91 inline JSC::JSObject* JSEventListener::jsFunction(ScriptExecutionContext* scriptExecutionContext) const 36 class JSEventListener : public EventListener { 37 public: 38 static Ref<JSEventListener> create(JSC::JSObject* listener, JSC::JSObject* wrapper, bool isAttribute, DOMWrapperWorld& world) 92 39 { 93 // initializeJSFunction can trigger code that deletes this event listener 94 // before we're done. It should always return 0 in this case. 95 Ref<JSEventListener> protect(const_cast<JSEventListener&>(*this)); 96 JSC::Strong<JSC::JSObject> wrapper(m_isolatedWorld->vm(), m_wrapper.get()); 97 98 if (!m_jsFunction) { 99 JSC::JSObject* function = initializeJSFunction(scriptExecutionContext); 100 JSC::JSObject* wrapper = m_wrapper.get(); 101 if (wrapper) 102 JSC::Heap::heap(wrapper)->writeBarrier(wrapper, function); 103 m_jsFunction = JSC::Weak<JSC::JSObject>(function); 104 } 105 106 // Verify that we have a valid wrapper protecting our function from 107 // garbage collection. That is except for when we're not in the normal 108 // world and can have zombie m_jsFunctions. 109 ASSERT(!m_isolatedWorld->isNormal() || m_wrapper || !m_jsFunction); 110 111 // If m_wrapper is 0, then m_jsFunction is zombied, and should never be accessed. 112 if (!m_wrapper) 113 return 0; 114 115 // Try to verify that m_jsFunction wasn't recycled. (Not exact, since an 116 // event listener can be almost anything, but this makes test-writing easier). 117 ASSERT(!m_jsFunction || static_cast<JSC::JSCell*>(m_jsFunction.get())->isObject()); 118 119 return m_jsFunction.get(); 40 return adoptRef(*new JSEventListener(listener, wrapper, isAttribute, world)); 120 41 } 121 42 122 inline Ref<JSEventListener> createJSEventListenerForRemove(JSC::ExecState& state, JSC::JSObject& listener, JSC::JSObject& wrapper)43 static const JSEventListener* cast(const EventListener* listener) 123 44 { 124 return createJSEventListenerForAdd(state, listener, wrapper); 45 return listener->type() == JSEventListenerType 46 ? static_cast<const JSEventListener*>(listener) 47 : 0; 125 48 } 49 50 virtual ~JSEventListener(); 51 52 virtual bool operator==(const EventListener& other) override; 53 54 // Returns true if this event listener was created for an event handler attribute, like "onload" or "onclick". 55 bool isAttribute() const { return m_isAttribute; } 56 57 JSC::JSObject* jsFunction(ScriptExecutionContext*) const; 58 DOMWrapperWorld& isolatedWorld() const { return *m_isolatedWorld; } 59 60 JSC::JSObject* wrapper() const { return m_wrapper.get(); } 61 void setWrapper(JSC::VM&, JSC::JSObject* wrapper) const { m_wrapper = JSC::Weak<JSC::JSObject>(wrapper); } 62 63 private: 64 virtual JSC::JSObject* initializeJSFunction(ScriptExecutionContext*) const; 65 virtual void visitJSFunction(JSC::SlotVisitor&) override; 66 virtual bool virtualisAttribute() const override; 67 68 protected: 69 JSEventListener(JSC::JSObject* function, JSC::JSObject* wrapper, bool isAttribute, DOMWrapperWorld&); 70 virtual void handleEvent(ScriptExecutionContext*, Event*) override; 71 72 private: 73 mutable JSC::Weak<JSC::JSObject> m_jsFunction; 74 mutable JSC::Weak<JSC::JSObject> m_wrapper; 75 76 bool m_isAttribute; 77 RefPtr<DOMWrapperWorld> m_isolatedWorld; 78 }; 79 80 // For "onxxx" attributes that automatically set up JavaScript event listeners. 81 JSC::JSValue eventHandlerAttribute(EventTarget&, const AtomicString& eventType); 82 void setEventHandlerAttribute(JSC::ExecState&, JSC::JSObject&, EventTarget&, const AtomicString& eventType, JSC::JSValue); 83 84 // Like the functions above, but for attributes that forward event handlers to the window object rather than setting them on the target. 85 JSC::JSValue windowForwardedEventHandlerAttribute(HTMLElement&, const AtomicString& eventType); 86 void setWindowForwardedEventHandlerAttribute(JSC::ExecState&, JSC::JSObject&, HTMLElement&, const AtomicString& eventType, JSC::JSValue); 87 88 Ref<JSEventListener> createJSEventListenerForAdd(JSC::ExecState&, JSC::JSObject& listener, JSC::JSObject& wrapper); 89 Ref<JSEventListener> createJSEventListenerForRemove(JSC::ExecState&, JSC::JSObject& listener, JSC::JSObject& wrapper); 90 91 inline JSC::JSObject* JSEventListener::jsFunction(ScriptExecutionContext* scriptExecutionContext) const 92 { 93 // initializeJSFunction can trigger code that deletes this event listener 94 // before we're done. It should always return 0 in this case. 95 Ref<JSEventListener> protect(const_cast<JSEventListener&>(*this)); 96 JSC::Strong<JSC::JSObject> wrapper(m_isolatedWorld->vm(), m_wrapper.get()); 97 98 if (!m_jsFunction) { 99 JSC::JSObject* function = initializeJSFunction(scriptExecutionContext); 100 JSC::JSObject* wrapper = m_wrapper.get(); 101 if (wrapper) 102 JSC::Heap::heap(wrapper)->writeBarrier(wrapper, function); 103 m_jsFunction = JSC::Weak<JSC::JSObject>(function); 104 } 105 106 // Verify that we have a valid wrapper protecting our function from 107 // garbage collection. That is except for when we're not in the normal 108 // world and can have zombie m_jsFunctions. 109 ASSERT(!m_isolatedWorld->isNormal() || m_wrapper || !m_jsFunction); 110 111 // If m_wrapper is 0, then m_jsFunction is zombied, and should never be accessed. 112 if (!m_wrapper) 113 return 0; 114 115 // Try to verify that m_jsFunction wasn't recycled. (Not exact, since an 116 // event listener can be almost anything, but this makes test-writing easier). 117 ASSERT(!m_jsFunction || static_cast<JSC::JSCell*>(m_jsFunction.get())->isObject()); 118 119 return m_jsFunction.get(); 120 } 121 122 inline Ref<JSEventListener> createJSEventListenerForRemove(JSC::ExecState& state, JSC::JSObject& listener, JSC::JSObject& wrapper) 123 { 124 return createJSEventListenerForAdd(state, listener, wrapper); 125 } 126 126 127 127 } // namespace WebCore -
trunk/Source/WebCore/dom/EventListener.h
r152814 r181216 25 25 26 26 namespace JSC { 27 28 27 class JSObject; 28 class SlotVisitor; 29 29 } 30 30 31 31 namespace WebCore { 32 32 33 34 33 class ScriptExecutionContext; 34 class Event; 35 35 36 37 38 39 40 41 42 43 44 45 46 47 48 36 class EventListener : public RefCounted<EventListener> { 37 public: 38 enum Type { 39 JSEventListenerType, 40 ImageEventListenerType, 41 ObjCEventListenerType, 42 CPPEventListenerType, 43 ConditionEventListenerType, 44 GObjectEventListenerType, 45 NativeEventListenerType, 46 SVGTRefTargetEventListenerType, 47 MediaControlsAppleEventListenerType 48 }; 49 49 50 51 52 53 50 virtual ~EventListener() { } 51 virtual bool operator==(const EventListener&) = 0; 52 virtual void handleEvent(ScriptExecutionContext*, Event*) = 0; 53 virtual bool wasCreatedFromMarkup() const { return false; } 54 54 55 55 virtual void visitJSFunction(JSC::SlotVisitor&) { } 56 56 57 58 57 bool isAttribute() const { return virtualisAttribute(); } 58 Type type() const { return m_type; } 59 59 60 61 62 63 64 60 protected: 61 explicit EventListener(Type type) 62 : m_type(type) 63 { 64 } 65 65 66 67 68 69 70 66 private: 67 virtual bool virtualisAttribute() const { return false; } 68 69 Type m_type; 70 }; 71 71 72 72 } -
trunk/Source/WebCore/dom/EventTarget.h
r181169 r181216 26 26 * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 27 27 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 28 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 29 * 28 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 30 29 */ 31 30 … … 45 44 46 45 namespace WebCore { 46 47 class AudioNode; 48 class AudioContext; 49 class AudioTrackList; 50 class DedicatedWorkerGlobalScope; 51 class DOMApplicationCache; 52 class DOMWindow; 53 class Event; 54 class EventListener; 55 class EventSource; 56 class FileReader; 57 class FileWriter; 58 class IDBDatabase; 59 class IDBRequest; 60 class IDBTransaction; 61 class ScriptProcessorNode; 62 class MediaController; 63 class MediaStream; 64 class MessagePort; 65 class Node; 66 class Notification; 67 class ScriptExecutionContext; 68 class TextTrack; 69 class TextTrackCue; 70 class VideoTrackList; 71 class WebSocket; 72 class WebKitNamedFlow; 73 class Worker; 74 class XMLHttpRequest; 75 class XMLHttpRequestUpload; 76 77 typedef int ExceptionCode; 78 79 struct FiringEventIterator { 80 FiringEventIterator(const AtomicString& eventType, size_t& iterator, size_t& size) 81 : eventType(eventType) 82 , iterator(iterator) 83 , size(size) 84 { 85 } 86 87 const AtomicString& eventType; 88 size_t& iterator; 89 size_t& size; 90 }; 91 typedef Vector<FiringEventIterator, 1> FiringEventIteratorVector; 92 93 struct EventTargetData { 94 WTF_MAKE_NONCOPYABLE(EventTargetData); WTF_MAKE_FAST_ALLOCATED; 95 public: 96 EventTargetData(); 97 ~EventTargetData(); 98 99 EventListenerMap eventListenerMap; 100 std::unique_ptr<FiringEventIteratorVector> firingEventIterators; 101 }; 102 103 enum EventTargetInterface { 104 105 #define DOM_EVENT_INTERFACE_DECLARE(name) name##EventTargetInterfaceType, 106 DOM_EVENT_TARGET_INTERFACES_FOR_EACH(DOM_EVENT_INTERFACE_DECLARE) 107 #undef DOM_EVENT_INTERFACE_DECLARE 108 109 }; 110 111 class EventTarget { 112 public: 113 void ref() { refEventTarget(); } 114 void deref() { derefEventTarget(); } 115 116 virtual EventTargetInterface eventTargetInterface() const = 0; 117 virtual ScriptExecutionContext* scriptExecutionContext() const = 0; 118 119 virtual Node* toNode(); 120 virtual DOMWindow* toDOMWindow(); 121 virtual bool isMessagePort() const; 122 123 virtual bool addEventListener(const AtomicString& eventType, PassRefPtr<EventListener>, bool useCapture); 124 virtual bool removeEventListener(const AtomicString& eventType, EventListener*, bool useCapture); 125 virtual void removeAllEventListeners(); 126 virtual bool dispatchEvent(PassRefPtr<Event>); 127 bool dispatchEvent(PassRefPtr<Event>, ExceptionCode&); // DOM API 128 virtual void uncaughtExceptionInEventHandler(); 129 130 // Used for legacy "onEvent" attribute APIs. 131 bool setAttributeEventListener(const AtomicString& eventType, PassRefPtr<EventListener>); 132 bool clearAttributeEventListener(const AtomicString& eventType); 133 EventListener* getAttributeEventListener(const AtomicString& eventType); 134 135 bool hasEventListeners() const; 136 bool hasEventListeners(const AtomicString& eventType); 137 bool hasCapturingEventListeners(const AtomicString& eventType); 138 const EventListenerVector& getEventListeners(const AtomicString& eventType); 139 140 bool fireEventListeners(Event*); 141 bool isFiringEventListeners(); 142 143 void visitJSEventListeners(JSC::SlotVisitor&); 144 void invalidateJSEventListeners(JSC::JSObject*); 145 146 protected: 147 virtual ~EventTarget(); 47 148 48 class AudioNode; 49 class AudioContext; 50 class AudioTrackList; 51 class DedicatedWorkerGlobalScope; 52 class DOMApplicationCache; 53 class DOMWindow; 54 class Event; 55 class EventListener; 56 class EventSource; 57 class FileReader; 58 class FileWriter; 59 class IDBDatabase; 60 class IDBRequest; 61 class IDBTransaction; 62 class ScriptProcessorNode; 63 class MediaController; 64 class MediaStream; 65 class MessagePort; 66 class Node; 67 class Notification; 68 class ScriptExecutionContext; 69 class TextTrack; 70 class TextTrackCue; 71 class VideoTrackList; 72 class WebSocket; 73 class WebKitNamedFlow; 74 class Worker; 75 class XMLHttpRequest; 76 class XMLHttpRequestUpload; 77 78 typedef int ExceptionCode; 79 80 struct FiringEventIterator { 81 FiringEventIterator(const AtomicString& eventType, size_t& iterator, size_t& size) 82 : eventType(eventType) 83 , iterator(iterator) 84 , size(size) 85 { 86 } 87 88 const AtomicString& eventType; 89 size_t& iterator; 90 size_t& size; 91 }; 92 typedef Vector<FiringEventIterator, 1> FiringEventIteratorVector; 93 94 struct EventTargetData { 95 WTF_MAKE_NONCOPYABLE(EventTargetData); WTF_MAKE_FAST_ALLOCATED; 96 public: 97 EventTargetData(); 98 ~EventTargetData(); 99 100 EventListenerMap eventListenerMap; 101 std::unique_ptr<FiringEventIteratorVector> firingEventIterators; 102 }; 103 104 enum EventTargetInterface { 105 106 #define DOM_EVENT_INTERFACE_DECLARE(name) name##EventTargetInterfaceType, 107 DOM_EVENT_TARGET_INTERFACES_FOR_EACH(DOM_EVENT_INTERFACE_DECLARE) 108 #undef DOM_EVENT_INTERFACE_DECLARE 109 110 }; 111 112 class EventTarget { 113 public: 114 void ref() { refEventTarget(); } 115 void deref() { derefEventTarget(); } 116 117 virtual EventTargetInterface eventTargetInterface() const = 0; 118 virtual ScriptExecutionContext* scriptExecutionContext() const = 0; 119 120 virtual Node* toNode(); 121 virtual DOMWindow* toDOMWindow(); 122 virtual bool isMessagePort() const; 123 124 virtual bool addEventListener(const AtomicString& eventType, PassRefPtr<EventListener>, bool useCapture); 125 virtual bool removeEventListener(const AtomicString& eventType, EventListener*, bool useCapture); 126 virtual void removeAllEventListeners(); 127 virtual bool dispatchEvent(PassRefPtr<Event>); 128 bool dispatchEvent(PassRefPtr<Event>, ExceptionCode&); // DOM API 129 virtual void uncaughtExceptionInEventHandler(); 130 131 // Used for legacy "onEvent" attribute APIs. 132 bool setAttributeEventListener(const AtomicString& eventType, PassRefPtr<EventListener>); 133 bool clearAttributeEventListener(const AtomicString& eventType); 134 EventListener* getAttributeEventListener(const AtomicString& eventType); 135 136 bool hasEventListeners() const; 137 bool hasEventListeners(const AtomicString& eventType); 138 bool hasCapturingEventListeners(const AtomicString& eventType); 139 const EventListenerVector& getEventListeners(const AtomicString& eventType); 140 141 bool fireEventListeners(Event*); 142 bool isFiringEventListeners(); 143 144 void visitJSEventListeners(JSC::SlotVisitor&); 145 void invalidateJSEventListeners(JSC::JSObject*); 146 147 protected: 148 virtual ~EventTarget(); 149 150 virtual EventTargetData* eventTargetData() = 0; 151 virtual EventTargetData& ensureEventTargetData() = 0; 152 153 private: 154 virtual void refEventTarget() = 0; 155 virtual void derefEventTarget() = 0; 156 157 void fireEventListeners(Event*, EventTargetData*, EventListenerVector&); 158 159 friend class EventListenerIterator; 160 }; 161 162 class EventTargetWithInlineData : public EventTarget { 163 protected: 164 virtual EventTargetData* eventTargetData() override final { return &m_eventTargetData; } 165 virtual EventTargetData& ensureEventTargetData() override final { return m_eventTargetData; } 166 private: 167 EventTargetData m_eventTargetData; 168 }; 169 170 inline void EventTarget::visitJSEventListeners(JSC::SlotVisitor& visitor) 171 { 172 EventListenerIterator iterator(this); 173 while (EventListener* listener = iterator.nextListener()) 174 listener->visitJSFunction(visitor); 175 } 176 177 inline bool EventTarget::isFiringEventListeners() 178 { 179 EventTargetData* d = eventTargetData(); 180 if (!d) 181 return false; 182 return d->firingEventIterators && !d->firingEventIterators->isEmpty(); 183 } 184 185 inline bool EventTarget::hasEventListeners() const 186 { 187 EventTargetData* d = const_cast<EventTarget*>(this)->eventTargetData(); 188 if (!d) 189 return false; 190 return !d->eventListenerMap.isEmpty(); 191 } 192 193 inline bool EventTarget::hasEventListeners(const AtomicString& eventType) 194 { 195 EventTargetData* d = eventTargetData(); 196 if (!d) 197 return false; 198 return d->eventListenerMap.contains(eventType); 199 } 200 201 inline bool EventTarget::hasCapturingEventListeners(const AtomicString& eventType) 202 { 203 EventTargetData* d = eventTargetData(); 204 if (!d) 205 return false; 206 return d->eventListenerMap.containsCapturing(eventType); 207 } 149 virtual EventTargetData* eventTargetData() = 0; 150 virtual EventTargetData& ensureEventTargetData() = 0; 151 152 private: 153 virtual void refEventTarget() = 0; 154 virtual void derefEventTarget() = 0; 155 156 void fireEventListeners(Event*, EventTargetData*, EventListenerVector&); 157 158 friend class EventListenerIterator; 159 }; 160 161 class EventTargetWithInlineData : public EventTarget { 162 protected: 163 virtual EventTargetData* eventTargetData() override final { return &m_eventTargetData; } 164 virtual EventTargetData& ensureEventTargetData() override final { return m_eventTargetData; } 165 private: 166 EventTargetData m_eventTargetData; 167 }; 168 169 inline void EventTarget::visitJSEventListeners(JSC::SlotVisitor& visitor) 170 { 171 EventListenerIterator iterator(this); 172 while (EventListener* listener = iterator.nextListener()) 173 listener->visitJSFunction(visitor); 174 } 175 176 inline bool EventTarget::isFiringEventListeners() 177 { 178 EventTargetData* d = eventTargetData(); 179 if (!d) 180 return false; 181 return d->firingEventIterators && !d->firingEventIterators->isEmpty(); 182 } 183 184 inline bool EventTarget::hasEventListeners() const 185 { 186 EventTargetData* d = const_cast<EventTarget*>(this)->eventTargetData(); 187 if (!d) 188 return false; 189 return !d->eventListenerMap.isEmpty(); 190 } 191 192 inline bool EventTarget::hasEventListeners(const AtomicString& eventType) 193 { 194 EventTargetData* d = eventTargetData(); 195 if (!d) 196 return false; 197 return d->eventListenerMap.contains(eventType); 198 } 199 200 inline bool EventTarget::hasCapturingEventListeners(const AtomicString& eventType) 201 { 202 EventTargetData* d = eventTargetData(); 203 if (!d) 204 return false; 205 return d->eventListenerMap.containsCapturing(eventType); 206 } 208 207 209 208 } // namespace WebCore
Note: See TracChangeset
for help on using the changeset viewer.