summaryrefslogtreecommitdiffstats
path: root/WebCore/bindings/js/JSEventListener.h
blob: 859d5d4d4eb06a40a74010a59623717e65a5a3b5 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
/*
 *  Copyright (C) 2001 Peter Kelly (pmk@post.com)
 *  Copyright (C) 2003, 2008 Apple Inc. All rights reserved.
 *
 *  This library is free software; you can redistribute it and/or
 *  modify it under the terms of the GNU Lesser General Public
 *  License as published by the Free Software Foundation; either
 *  version 2 of the License, or (at your option) any later version.
 *
 *  This library is distributed in the hope that it will be useful,
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 *  Lesser General Public License for more details.
 *
 *  You should have received a copy of the GNU Lesser General Public
 *  License along with this library; if not, write to the Free Software
 *  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
 */

#ifndef JSEventListener_h
#define JSEventListener_h

#include "EventListener.h"
#include "PlatformString.h"
#include <runtime/Protect.h>

namespace WebCore {

    class Event;
    class JSDOMGlobalObject;
    class Node;

    class JSAbstractEventListener : public EventListener {
    public:
        virtual void handleEvent(Event*, bool isWindowEvent);
        virtual bool isInline() const;
        virtual JSC::JSObject* listenerObj() const = 0;
        virtual JSDOMGlobalObject* globalObject() const = 0;

    protected:
        JSAbstractEventListener(bool isInline)
            : m_isInline(isInline)
        {
        }

    private:
        bool m_isInline;
    };

    class JSUnprotectedEventListener : public JSAbstractEventListener {
    public:
        static PassRefPtr<JSUnprotectedEventListener> create(JSC::JSObject* listener, JSDOMGlobalObject* globalObject, bool isInline)
        {
            return adoptRef(new JSUnprotectedEventListener(listener, globalObject, isInline));
        }
        virtual ~JSUnprotectedEventListener();

        virtual JSC::JSObject* listenerObj() const;
        virtual JSDOMGlobalObject* globalObject() const;
        void clearGlobalObject();
        void mark();

    private:
        JSUnprotectedEventListener(JSC::JSObject* listener, JSDOMGlobalObject*, bool isInline);

        JSC::JSObject* m_listener;
        JSDOMGlobalObject* m_globalObject;
    };

    class JSEventListener : public JSAbstractEventListener {
    public:
        static PassRefPtr<JSEventListener> create(JSC::JSObject* listener, JSDOMGlobalObject* globalObject, bool isInline)
        {
            return adoptRef(new JSEventListener(listener, globalObject, isInline));
        }
        virtual ~JSEventListener();

        virtual JSC::JSObject* listenerObj() const;
        virtual JSDOMGlobalObject* globalObject() const;
        void clearGlobalObject();

    protected:
        JSEventListener(JSC::JSObject* listener, JSDOMGlobalObject*, bool isInline);

        mutable JSC::ProtectedPtr<JSC::JSObject> m_listener;

    private:
        JSC::ProtectedPtr<JSDOMGlobalObject> m_globalObject;
    };

    class JSLazyEventListener : public JSEventListener {
    public:
        enum LazyEventListenerType {
            HTMLLazyEventListener
#if ENABLE(SVG)
            , SVGLazyEventListener
#endif
        };

        virtual bool wasCreatedFromMarkup() const { return true; }

        static PassRefPtr<JSLazyEventListener> create(LazyEventListenerType type, const String& functionName, const String& code, JSDOMGlobalObject* globalObject, Node* node, int lineNumber)
        {
            return adoptRef(new JSLazyEventListener(type, functionName, code, globalObject, node, lineNumber));
        }
        virtual JSC::JSObject* listenerObj() const;

    protected:
        JSLazyEventListener(LazyEventListenerType type, const String& functionName, const String& code, JSDOMGlobalObject*, Node*, int lineNumber);

    private:
        void parseCode() const;

        mutable String m_functionName;
        mutable String m_code;
        mutable bool m_parsed;
        int m_lineNumber;
        Node* m_originalNode;

        LazyEventListenerType m_type;
    };

} // namespace WebCore

#endif // JSEventListener_h