#ifndef KJS_EVENTS_H
#define KJS_EVENTS_H
#include "EventListener.h"
#include "PlatformString.h"
#include "kjs_dom.h"
#include "kjs_html.h"
namespace WebCore {
class Clipboard;
class Event;
class KeyboardEvent;
class MouseEvent;
class MutationEvent;
class UIEvent;
}
namespace KJS {
class Window;
class Clipboard;
class JSAbstractEventListener : public WebCore::EventListener {
public:
JSAbstractEventListener(bool HTML = false);
virtual void handleEvent(WebCore::Event*, bool isWindowEvent);
virtual bool isHTMLEventListener() const;
virtual JSObject* listenerObj() const = 0;
virtual Window* windowObj() const = 0;
private:
bool html;
};
class JSUnprotectedEventListener : public JSAbstractEventListener {
public:
JSUnprotectedEventListener(JSObject* listener, Window*, bool HTML = false);
virtual ~JSUnprotectedEventListener();
virtual JSObject* listenerObj() const;
virtual Window* windowObj() const;
void clearWindowObj();
virtual void mark();
private:
JSObject* listener;
Window* win;
};
class JSEventListener : public JSAbstractEventListener {
public:
JSEventListener(JSObject* listener, Window*, bool HTML = false);
virtual ~JSEventListener();
virtual JSObject* listenerObj() const;
virtual Window* windowObj() const;
void clearWindowObj();
protected:
mutable ProtectedPtr<JSObject> listener;
private:
ProtectedPtr<Window> win;
};
class JSLazyEventListener : public JSEventListener {
public:
JSLazyEventListener(const WebCore::String& functionName, const WebCore::String& code, Window*, WebCore::Node*, int lineno = 0);
virtual JSObject* listenerObj() const;
private:
virtual JSValue* eventParameterName() const;
void parseCode() const;
mutable WebCore::String m_functionName;
mutable WebCore::String code;
mutable bool parsed;
int lineNumber;
WebCore::Node* originalNode;
};
JSValue* getNodeEventListener(WebCore::Node* n, const WebCore::AtomicString& eventType);
class DOMEvent : public DOMObject {
public:
DOMEvent(ExecState*, WebCore::Event*);
virtual ~DOMEvent();
virtual bool getOwnPropertySlot(ExecState*, const Identifier&, PropertySlot&);
JSValue* getValueProperty(ExecState*, int token) const;
virtual void put(ExecState*, const Identifier&, JSValue*, int attr = None);
void putValueProperty(ExecState*, int token, JSValue*, int);
virtual const ClassInfo* classInfo() const { return &info; }
static const ClassInfo info;
enum { Type, Target, CurrentTarget, EventPhase, Bubbles,
Cancelable, TimeStamp, StopPropagation, PreventDefault, InitEvent,
SrcElement, ReturnValue, CancelBubble, ClipboardData, DataTransfer };
WebCore::Event *impl() const { return m_impl.get(); }
virtual void mark();
protected:
RefPtr<WebCore::Event> m_impl;
mutable Clipboard* clipboard;
};
JSValue* toJS(ExecState*, WebCore::Event*);
WebCore::Event* toEvent(JSValue*);
KJS_DEFINE_PROTOTYPE(DOMEventProto)
class Clipboard : public DOMObject {
friend class ClipboardProtoFunc;
public:
Clipboard(ExecState*, WebCore::Clipboard *ds);
virtual bool getOwnPropertySlot(ExecState*, const Identifier&, PropertySlot&);
JSValue* getValueProperty(ExecState*, int token) const;
virtual void put(ExecState*, const Identifier&, JSValue*, int attr = None);
void putValueProperty(ExecState*, int token, JSValue*, int attr);
virtual bool toBoolean(ExecState*) const { return true; }
virtual const ClassInfo* classInfo() const { return &info; }
static const ClassInfo info;
enum { ClearData, GetData, SetData, Types, SetDragImage, DropEffect, EffectAllowed };
private:
RefPtr<WebCore::Clipboard> clipboard;
};
}
#endif