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 #include "xml/dom2_eventsimpl.h"
00029
00030 namespace KJS {
00031
00032 class Window;
00033
00034 class JSEventListener : public DOM::EventListener {
00035 public:
00041 JSEventListener(Object _listener, ObjectImp *_compareListenerImp, const Object &_win, bool _html = false);
00042 virtual ~JSEventListener();
00043 virtual void handleEvent(DOM::Event &evt);
00044 virtual DOM::DOMString eventListenerType();
00045
00046 virtual Object listenerObj() const;
00047 ObjectImp *listenerObjImp() const { return listenerObj().imp(); }
00048
00049
00050
00051 void clear() { listener = Object(); }
00052 bool isHTMLEventListener() const { return html; }
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;
00069 };
00070
00071 class JSLazyEventListener : public JSEventListener {
00072 public:
00073 JSLazyEventListener(const QString &_code, const QString &_name, const Object &_win, DOM::NodeImpl* node);
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 DOM::NodeImpl *originalNode;
00084 };
00085
00086
00087 class EventConstructor : public DOMObject {
00088 public:
00089 EventConstructor(ExecState *);
00090 virtual Value tryGet(ExecState *exec,const Identifier &p) const;
00091 Value getValueProperty(ExecState *, int token) const;
00092
00093 virtual const ClassInfo* classInfo() const { return &info; }
00094 static const ClassInfo info;
00095 };
00096
00097 Value getEventConstructor(ExecState *exec);
00098
00099 class DOMEvent : public DOMObject {
00100 public:
00101
00102 DOMEvent(ExecState *exec, DOM::Event e);
00103
00104 DOMEvent(const Object &proto, DOM::Event e);
00105 ~DOMEvent();
00106 virtual Value tryGet(ExecState *exec,const Identifier &p) const;
00107 Value getValueProperty(ExecState *, int token) const;
00108 virtual void tryPut(ExecState *exec, const Identifier &propertyName,
00109 const Value& value, int attr = None);
00110 virtual Value defaultValue(ExecState *exec, KJS::Type hint) const;
00111 void putValueProperty(ExecState *exec, int token, const Value& value, int);
00112 virtual const ClassInfo* classInfo() const { return &info; }
00113 static const ClassInfo info;
00114 enum { Type, Target, CurrentTarget, EventPhase, Bubbles,
00115 Cancelable, TimeStamp, StopPropagation, PreventDefault, InitEvent,
00116
00117 SrcElement, ReturnValue, CancelBubble };
00118 DOM::Event toEvent() const { return event; }
00119 protected:
00120 DOM::Event event;
00121 };
00122
00123 Value getDOMEvent(ExecState *exec, DOM::Event e);
00124
00128 DOM::Event toEvent(const Value&);
00129
00130
00131 class EventExceptionConstructor : public DOMObject {
00132 public:
00133 EventExceptionConstructor(ExecState *);
00134 virtual Value tryGet(ExecState *exec,const Identifier &p) const;
00135 Value getValueProperty(ExecState *, int token) const;
00136
00137 virtual const ClassInfo* classInfo() const { return &info; }
00138 static const ClassInfo info;
00139 };
00140
00141 Value getEventExceptionConstructor(ExecState *exec);
00142
00143 class DOMUIEvent : public DOMEvent {
00144 public:
00145
00146 DOMUIEvent(ExecState *exec, DOM::UIEvent ue);
00147
00148 DOMUIEvent(const Object &proto, DOM::UIEvent ue);
00149 ~DOMUIEvent();
00150 virtual Value tryGet(ExecState *exec,const Identifier &p) const;
00151 Value getValueProperty(ExecState *, int token) const;
00152
00153 virtual const ClassInfo* classInfo() const { return &info; }
00154 static const ClassInfo info;
00155 enum { View, Detail, KeyCode, CharCode, LayerX, LayerY, PageX, PageY, Which, InitUIEvent };
00156 DOM::UIEvent toUIEvent() const { return static_cast<DOM::UIEvent>(event); }
00157 };
00158
00159 class DOMMouseEvent : public DOMUIEvent {
00160 public:
00161 DOMMouseEvent(ExecState *exec, DOM::MouseEvent me);
00162 ~DOMMouseEvent();
00163 virtual Value tryGet(ExecState *exec,const Identifier &p) const;
00164 Value getValueProperty(ExecState *, int token) const;
00165
00166 virtual const ClassInfo* classInfo() const { return &info; }
00167 static const ClassInfo info;
00168 enum { ScreenX, ScreenY, ClientX, X, ClientY, Y, OffsetX, OffsetY,
00169 CtrlKey, ShiftKey, AltKey,
00170 MetaKey, Button, RelatedTarget, FromElement, ToElement,
00171 InitMouseEvent
00172 };
00173 DOM::MouseEvent toMouseEvent() const { return static_cast<DOM::MouseEvent>(event); }
00174 };
00175
00176 class DOMKeyEventBase : public DOMUIEvent {
00177 public:
00178 DOMKeyEventBase(const Object &proto, DOM::TextEvent ke);
00179 ~DOMKeyEventBase();
00180
00181 virtual Value tryGet(ExecState *exec,const Identifier &p) const;
00182 Value getValueProperty(ExecState *, int token) const;
00183
00184 virtual const ClassInfo* classInfo() const { return &info; }
00185 static const ClassInfo info;
00186 enum { Key, VirtKey, CtrlKey, ShiftKey, AltKey, MetaKey };
00187 DOM::KeyEventBaseImpl* impl() const { return static_cast<DOM::KeyEventBaseImpl*>(event.handle()); }
00188 };
00189
00190 class DOMTextEvent : public DOMKeyEventBase {
00191 public:
00192 DOMTextEvent(ExecState *exec, DOM::TextEvent ke);
00193 ~DOMTextEvent();
00194 virtual Value tryGet(ExecState *exec,const Identifier &p) const;
00195 Value getValueProperty(ExecState *, int token) const;
00196
00197 virtual const ClassInfo* classInfo() const { return &info; }
00198 static const ClassInfo info;
00199 enum {Data, InitTextEvent};
00200 DOM::TextEventImpl* impl() const { return static_cast<DOM::TextEventImpl*>(event.handle()); }
00201 };
00202
00203 class DOMKeyboardEvent : public DOMKeyEventBase {
00204 public:
00205 DOMKeyboardEvent(ExecState *exec, DOM::TextEvent ke);
00206 ~DOMKeyboardEvent();
00207 virtual Value tryGet(ExecState *exec,const Identifier &p) const;
00208 Value getValueProperty(ExecState *, int token) const;
00209
00210 virtual const ClassInfo* classInfo() const { return &info; }
00211 static const ClassInfo info;
00212 enum {KeyIdentifier, KeyLocation, GetModifierState, InitKeyboardEvent};
00213 DOM::KeyboardEventImpl* impl() const { return static_cast<DOM::KeyboardEventImpl*>(event.handle()); }
00214 };
00215
00216
00217 class KeyboardEventConstructor : public DOMObject {
00218 public:
00219 KeyboardEventConstructor(ExecState *);
00220 virtual Value tryGet(ExecState *exec,const Identifier &p) const;
00221 Value getValueProperty(ExecState *, int token) const;
00222
00223 virtual const ClassInfo* classInfo() const { return &info; }
00224 static const ClassInfo info;
00225 };
00226
00227 Value getKeyboardEventConstructor(ExecState *exec);
00228
00229
00230 class MutationEventConstructor : public DOMObject {
00231 public:
00232 MutationEventConstructor(ExecState *);
00233 virtual Value tryGet(ExecState *exec,const Identifier &p) const;
00234 Value getValueProperty(ExecState *, int token) const;
00235
00236 virtual const ClassInfo* classInfo() const { return &info; }
00237 static const ClassInfo info;
00238 };
00239
00240 Value getMutationEventConstructor(ExecState *exec);
00241
00242 class DOMMutationEvent : public DOMEvent {
00243 public:
00244 DOMMutationEvent(ExecState *exec, DOM::MutationEvent me);
00245 ~DOMMutationEvent();
00246 virtual Value tryGet(ExecState *exec,const Identifier &p) const;
00247 Value getValueProperty(ExecState *, int token) const;
00248
00249 virtual const ClassInfo* classInfo() const { return &info; }
00250 static const ClassInfo info;
00251 enum { AttrChange, RelatedNode, AttrName, PrevValue, NewValue,
00252 InitMutationEvent };
00253 DOM::MutationEvent toMutationEvent() const { return static_cast<DOM::MutationEvent>(event); }
00254 };
00255
00256 }
00257
00258 #endif