summaryrefslogtreecommitdiffstats
path: root/WebCore/bindings/js/kjs_events.h
blob: b488cc4724d9bf68f4bec474a62d2ef65ed7bb84 (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
126
127
128
129
130
131
132
/*
 *  This file is part of the KDE libraries
 *  Copyright (C) 2001 Peter Kelly (pmk@post.com)
 *  Copyright (C) 2003 Apple Computer, Inc.
 *
 *  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 kjs_events_h
#define kjs_events_h

#include "EventListener.h"
#include "PlatformString.h"
#include "kjs_dom.h"
#include "kjs_html.h"
#include <kjs/protect.h>

namespace KJS {
    class Window;
}

namespace WebCore {

    class Clipboard;
    class Event;

    class JSAbstractEventListener : public EventListener {
    public:
        JSAbstractEventListener(bool html = false);

        virtual void handleEvent(Event*, bool isWindowEvent);
        virtual bool isHTMLEventListener() const;
        virtual KJS::JSObject* listenerObj() const = 0;
        virtual KJS::Window* windowObj() const = 0;

    private:
        bool m_html;
    };

    class JSUnprotectedEventListener : public JSAbstractEventListener {
    public:
        JSUnprotectedEventListener(KJS::JSObject* listener, KJS::Window*, bool html = false);
        virtual ~JSUnprotectedEventListener();

        virtual KJS::JSObject* listenerObj() const;
        virtual KJS::Window* windowObj() const;
        void clearWindowObj();
        void mark();
    private:
        KJS::JSObject* m_listener;
        KJS::Window* m_win;
    };

    class JSEventListener : public JSAbstractEventListener {
    public:
        JSEventListener(KJS::JSObject* listener, KJS::Window*, bool html = false);
        virtual ~JSEventListener();

        virtual KJS::JSObject* listenerObj() const;
        virtual KJS::Window* windowObj() const;
        void clearWindowObj();

    protected:
        mutable KJS::ProtectedPtr<KJS::JSObject> m_listener;

    private:
        KJS::ProtectedPtr<KJS::Window> m_win;
    };

    class JSLazyEventListener : public JSEventListener {
    public:
        JSLazyEventListener(const String& functionName, const String& code, KJS::Window*, Node*, int lineNumber = 0);
        virtual KJS::JSObject* listenerObj() const;

    private:
        virtual KJS::JSValue* eventParameterName() const;
        void parseCode() const;

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

    KJS::JSValue* getNodeEventListener(Node*, const AtomicString& eventType);

    class JSClipboard : public DOMObject {
    public:
        JSClipboard(KJS::JSObject* prototype, Clipboard*);
        virtual ~JSClipboard();

        virtual bool getOwnPropertySlot(KJS::ExecState*, const KJS::Identifier&, KJS::PropertySlot&);
        KJS::JSValue* getValueProperty(KJS::ExecState*, int token) const;
        virtual void put(KJS::ExecState*, const KJS::Identifier&, KJS::JSValue*);
        void putValueProperty(KJS::ExecState*, int token, KJS::JSValue*);

        virtual const KJS::ClassInfo* classInfo() const { return &info; }
        static const KJS::ClassInfo info;

        enum { ClearData, GetData, SetData, Types, SetDragImage, DropEffect, EffectAllowed };

        Clipboard* impl() const { return m_impl.get(); }

    private:
        RefPtr<Clipboard> m_impl;
    };

    KJS::JSValue* toJS(KJS::ExecState*, Clipboard*);
    Clipboard* toClipboard(KJS::JSValue*);

    // Functions
    KJS::JSValue* jsClipboardPrototypeFunctionClearData(KJS::ExecState*, KJS::JSObject*, const KJS::List&);
    KJS::JSValue* jsClipboardPrototypeFunctionGetData(KJS::ExecState*, KJS::JSObject*, const KJS::List&);
    KJS::JSValue* jsClipboardPrototypeFunctionSetData(KJS::ExecState*, KJS::JSObject*, const KJS::List&);
    KJS::JSValue* jsClipboardPrototypeFunctionSetDragImage(KJS::ExecState*, KJS::JSObject*, const KJS::List&);

} // namespace WebCore

#endif // kjs_events_h