2 * Copyright (C) 2001 Peter Kelly (pmk@post.com)
3 * Copyright (C) 2003, 2008 Apple Inc. All rights reserved.
5 * This library is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU Lesser General Public
7 * License as published by the Free Software Foundation; either
8 * version 2 of the License, or (at your option) any later version.
10 * This library is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * Lesser General Public License for more details.
15 * You should have received a copy of the GNU Lesser General Public
16 * License along with this library; if not, write to the Free Software
17 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
20 #ifndef JSEventListener_h
21 #define JSEventListener_h
23 #include "EventListener.h"
24 #include "PlatformString.h"
25 #include <runtime/Protect.h>
30 class JSDOMGlobalObject;
33 class JSAbstractEventListener : public EventListener {
35 virtual void handleEvent(Event*, bool isWindowEvent);
36 virtual bool isInline() const;
37 virtual JSC::JSObject* listenerObj() const = 0;
38 virtual JSDOMGlobalObject* globalObject() const = 0;
41 JSAbstractEventListener(bool isInline)
42 : m_isInline(isInline)
50 class JSEventListener : public JSAbstractEventListener {
52 static PassRefPtr<JSEventListener> create(JSC::JSObject* listener, JSDOMGlobalObject* globalObject, bool isInline)
54 return adoptRef(new JSEventListener(listener, globalObject, isInline));
56 virtual ~JSEventListener();
58 virtual JSC::JSObject* listenerObj() const;
59 virtual JSDOMGlobalObject* globalObject() const;
60 void clearGlobalObject();
64 JSEventListener(JSC::JSObject* listener, JSDOMGlobalObject*, bool isInline);
66 JSC::JSObject* m_listener;
67 JSDOMGlobalObject* m_globalObject;
70 class JSProtectedEventListener : public JSAbstractEventListener {
72 static PassRefPtr<JSProtectedEventListener> create(JSC::JSObject* listener, JSDOMGlobalObject* globalObject, bool isInline)
74 return adoptRef(new JSProtectedEventListener(listener, globalObject, isInline));
76 virtual ~JSProtectedEventListener();
78 virtual JSC::JSObject* listenerObj() const;
79 virtual JSDOMGlobalObject* globalObject() const;
80 void clearGlobalObject();
83 JSProtectedEventListener(JSC::JSObject* listener, JSDOMGlobalObject*, bool isInline);
85 mutable JSC::ProtectedPtr<JSC::JSObject> m_listener;
88 JSC::ProtectedPtr<JSDOMGlobalObject> m_globalObject;
91 class JSLazyEventListener : public JSProtectedEventListener {
93 enum LazyEventListenerType {
96 , SVGLazyEventListener
100 virtual bool wasCreatedFromMarkup() const { return true; }
102 static PassRefPtr<JSLazyEventListener> create(LazyEventListenerType type, const String& functionName, const String& code, JSDOMGlobalObject* globalObject, Node* node, int lineNumber)
104 return adoptRef(new JSLazyEventListener(type, functionName, code, globalObject, node, lineNumber));
106 virtual JSC::JSObject* listenerObj() const;
109 JSLazyEventListener(LazyEventListenerType type, const String& functionName, const String& code, JSDOMGlobalObject*, Node*, int lineNumber);
112 void parseCode() const;
114 mutable String m_functionName;
115 mutable String m_code;
116 mutable bool m_parsed;
118 Node* m_originalNode;
120 LazyEventListenerType m_type;
123 } // namespace WebCore
125 #endif // JSEventListener_h