00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022 #ifndef _KJS_EVENTS_H_
00023 #define _KJS_EVENTS_H_
00024
00025 #include "ecma/kjs_dom.h"
00026 #include "dom/dom2_events.h"
00027 #include "dom/dom_misc.h"
00028
00029 namespace KJS {
00030
00031 class Window;
00032
00033 class JSEventListener : public DOM::EventListener {
00034 public:
00040 JSEventListener(Object _listener, ObjectImp *_compareListenerImp, const Object &_win, bool _html = false);
00041 virtual ~JSEventListener();
00042 virtual void handleEvent(DOM::Event &evt);
00043 virtual DOM::DOMString eventListenerType();
00044
00045 virtual Object listenerObj() const;
00046 ObjectImp *listenerObjImp() const { return listenerObj().imp(); }
00047
00048
00049
00050 void clear() { listener = Object(); }
00051 bool isHTMLEventListener() const { return html; }
00052
00053 protected:
00054 mutable Object listener;
00055
00056
00057
00058
00059
00060
00061
00062
00063
00064
00065 mutable ObjectImp *compareListenerImp;
00066 bool html;
00067 Object win;
00068 };
00069
00070 class JSLazyEventListener : public JSEventListener {
00071 public:
00072 JSLazyEventListener(const QString &_code, const QString &_name, const Object &_win, DOM::NodeImpl* node);
00073 ~JSLazyEventListener();
00074 virtual void handleEvent(DOM::Event &evt);
00075 Object listenerObj() const;
00076 private:
00077 void parseCode() const;
00078
00079 mutable QString code;
00080 mutable QString name;
00081 mutable bool parsed;
00082 DOM::NodeImpl *originalNode;
00083 };
00084
00085
00086 class EventConstructor : public DOMObject {
00087 public:
00088 EventConstructor(ExecState *);
00089 virtual Value tryGet(ExecState *exec,const Identifier &p) const;
00090 Value getValueProperty(ExecState *, int token) const;
00091
00092 virtual const ClassInfo* classInfo() const { return &info; }
00093 static const ClassInfo info;
00094 };
00095
00096 Value getEventConstructor(ExecState *exec);
00097
00098 class DOMEvent : public DOMObject {
00099 public:
00100
00101 DOMEvent(ExecState *exec, DOM::Event e);
00102
00103 DOMEvent(const Object &proto, DOM::Event e);
00104 ~DOMEvent();
00105 virtual Value tryGet(ExecState *exec,const Identifier &p) const;
00106 Value getValueProperty(ExecState *, int token) const;
00107 virtual void tryPut(ExecState *exec, const Identifier &propertyName,
00108 const Value& value, int attr = None);
00109 virtual Value defaultValue(ExecState *exec, KJS::Type hint) const;
00110 void putValueProperty(ExecState *exec, int token, const Value& value, int);
00111 virtual const ClassInfo* classInfo() const { return &info; }
00112 static const ClassInfo info;
00113 enum { Type, Target, CurrentTarget, EventPhase, Bubbles,
00114 Cancelable, TimeStamp, StopPropagation, PreventDefault, InitEvent,
00115
00116 SrcElement, ReturnValue, CancelBubble };
00117 DOM::Event toEvent() const { return event; }
00118 protected:
00119 DOM::Event event;
00120 };
00121
00122 Value getDOMEvent(ExecState *exec, DOM::Event e);
00123
00127 DOM::Event toEvent(const Value&);
00128
00129
00130 class EventExceptionConstructor : public DOMObject {
00131 public:
00132 EventExceptionConstructor(ExecState *);
00133 virtual Value tryGet(ExecState *exec,const Identifier &p) const;
00134 Value getValueProperty(ExecState *, int token) const;
00135
00136 virtual const ClassInfo* classInfo() const { return &info; }
00137 static const ClassInfo info;
00138 };
00139
00140 Value getEventExceptionConstructor(ExecState *exec);
00141
00142 class DOMUIEvent : public DOMEvent {
00143 public:
00144
00145 DOMUIEvent(ExecState *exec, DOM::UIEvent ue);
00146
00147 DOMUIEvent(const Object &proto, DOM::UIEvent ue);
00148 ~DOMUIEvent();
00149 virtual Value tryGet(ExecState *exec,const Identifier &p) const;
00150 Value getValueProperty(ExecState *, int token) const;
00151
00152 virtual const ClassInfo* classInfo() const { return &info; }
00153 static const ClassInfo info;
00154 enum { View, Detail, KeyCode, CharCode, LayerX, LayerY, PageX, PageY, Which, InitUIEvent };
00155 DOM::UIEvent toUIEvent() const { return static_cast<DOM::UIEvent>(event); }
00156 };
00157
00158 class DOMMouseEvent : public DOMUIEvent {
00159 public:
00160 DOMMouseEvent(ExecState *exec, DOM::MouseEvent me);
00161 ~DOMMouseEvent();
00162 virtual Value tryGet(ExecState *exec,const Identifier &p) const;
00163 Value getValueProperty(ExecState *, int token) const;
00164
00165 virtual const ClassInfo* classInfo() const { return &info; }
00166 static const ClassInfo info;
00167 enum { ScreenX, ScreenY, ClientX, X, ClientY, Y, OffsetX, OffsetY,
00168 CtrlKey, ShiftKey, AltKey,
00169 MetaKey, Button, RelatedTarget, FromElement, ToElement,
00170 InitMouseEvent
00171 };
00172 DOM::MouseEvent toMouseEvent() const { return static_cast<DOM::MouseEvent>(event); }
00173 };
00174
00175 class DOMTextEvent : public DOMUIEvent {
00176 public:
00177 DOMTextEvent(ExecState *exec, DOM::TextEvent ke);
00178 ~DOMTextEvent();
00179 virtual Value tryGet(ExecState *exec,const Identifier &p) const;
00180 Value getValueProperty(ExecState *, int token) const;
00181
00182 virtual const ClassInfo* classInfo() const { return &info; }
00183 static const ClassInfo info;
00184 enum { Key, VirtKey, OutputString, InitTextEvent, InputGenerated, NumPad,
00185 CtrlKey, ShiftKey, AltKey, MetaKey };
00186 DOM::TextEvent toTextEvent() const { return static_cast<DOM::TextEvent>(event); }
00187 };
00188
00189
00190 class MutationEventConstructor : public DOMObject {
00191 public:
00192 MutationEventConstructor(ExecState *);
00193 virtual Value tryGet(ExecState *exec,const Identifier &p) const;
00194 Value getValueProperty(ExecState *, int token) const;
00195
00196 virtual const ClassInfo* classInfo() const { return &info; }
00197 static const ClassInfo info;
00198 };
00199
00200 Value getMutationEventConstructor(ExecState *exec);
00201
00202 class DOMMutationEvent : public DOMEvent {
00203 public:
00204 DOMMutationEvent(ExecState *exec, DOM::MutationEvent me);
00205 ~DOMMutationEvent();
00206 virtual Value tryGet(ExecState *exec,const Identifier &p) const;
00207 Value getValueProperty(ExecState *, int token) const;
00208
00209 virtual const ClassInfo* classInfo() const { return &info; }
00210 static const ClassInfo info;
00211 enum { AttrChange, RelatedNode, AttrName, PrevValue, NewValue,
00212 InitMutationEvent };
00213 DOM::MutationEvent toMutationEvent() const { return static_cast<DOM::MutationEvent>(event); }
00214 };
00215
00216 }
00217
00218 #endif