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 void hackSetThisObj( Object& thisObj ) { m_hackThisObj = thisObj; }
00043 void hackUnsetThisObj() { m_hackThisObj = Object(0L); }
00044 virtual void handleEvent(DOM::Event &evt);
00045 virtual DOM::DOMString eventListenerType();
00046
00047 virtual Object listenerObj() const;
00048 ObjectImp *listenerObjImp() const { return listenerObj().imp(); }
00049
00050
00051
00052 void clear() { listener = Object(); }
00053
00054 protected:
00055 mutable Object listener;
00056
00057
00058
00059
00060
00061
00062
00063
00064
00065
00066 mutable ObjectImp *compareListenerImp;
00067 bool html;
00068 Object win, m_hackThisObj;
00069 };
00070
00071 class JSLazyEventListener : public JSEventListener {
00072 public:
00073 JSLazyEventListener(const QString &_code, const QString &_name, const Object &_win, bool _html = false);
00074 ~JSLazyEventListener();
00075 virtual void handleEvent(DOM::Event &evt);
00076 Object listenerObj() const;
00077 private:
00078 void parseCode() const;
00079
00080 mutable QString code;
00081 mutable QString name;
00082 mutable bool parsed;
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, 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 DOM::TextEvent toTextEvent() const { return static_cast<DOM::TextEvent>(event); }
00186 };
00187
00188
00189 class MutationEventConstructor : public DOMObject {
00190 public:
00191 MutationEventConstructor(ExecState *);
00192 virtual Value tryGet(ExecState *exec,const Identifier &p) const;
00193 Value getValueProperty(ExecState *, int token) const;
00194
00195 virtual const ClassInfo* classInfo() const { return &info; }
00196 static const ClassInfo info;
00197 };
00198
00199 Value getMutationEventConstructor(ExecState *exec);
00200
00201 class DOMMutationEvent : public DOMEvent {
00202 public:
00203 DOMMutationEvent(ExecState *exec, DOM::MutationEvent me);
00204 ~DOMMutationEvent();
00205 virtual Value tryGet(ExecState *exec,const Identifier &p) const;
00206 Value getValueProperty(ExecState *, int token) const;
00207
00208 virtual const ClassInfo* classInfo() const { return &info; }
00209 static const ClassInfo info;
00210 enum { AttrChange, RelatedNode, AttrName, PrevValue, NewValue,
00211 InitMutationEvent };
00212 DOM::MutationEvent toMutationEvent() const { return static_cast<DOM::MutationEvent>(event); }
00213 };
00214
00215 }
00216
00217 #endif