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 DEFINE_PSEUDO_CONSTRUCTOR(EventConstructor)
00088
00089 class DOMEvent : public DOMObject {
00090 public:
00091
00092 DOMEvent(ExecState *exec, DOM::Event e);
00093
00094 DOMEvent(const Object &proto, DOM::Event e);
00095 ~DOMEvent();
00096 virtual Value tryGet(ExecState *exec,const Identifier &p) const;
00097 Value getValueProperty(ExecState *, int token) const;
00098 virtual void tryPut(ExecState *exec, const Identifier &propertyName,
00099 const Value& value, int attr = None);
00100 virtual Value defaultValue(ExecState *exec, KJS::Type hint) const;
00101 void putValueProperty(ExecState *exec, int token, const Value& value, int);
00102 virtual const ClassInfo* classInfo() const { return &info; }
00103 static const ClassInfo info;
00104 enum { Type, Target, CurrentTarget, EventPhase, Bubbles,
00105 Cancelable, TimeStamp, StopPropagation, PreventDefault, InitEvent,
00106
00107 SrcElement, ReturnValue, CancelBubble };
00108 DOM::Event toEvent() const { return event; }
00109 protected:
00110 DOM::Event event;
00111 };
00112
00113 Value getDOMEvent(ExecState *exec, DOM::Event e);
00114
00118 DOM::Event toEvent(const Value&);
00119
00120
00121 class EventExceptionConstructor : public DOMObject {
00122 public:
00123 EventExceptionConstructor(ExecState *);
00124 virtual Value tryGet(ExecState *exec,const Identifier &p) const;
00125 Value getValueProperty(ExecState *, int token) const;
00126
00127 virtual const ClassInfo* classInfo() const { return &info; }
00128 static const ClassInfo info;
00129 };
00130
00131 Value getEventExceptionConstructor(ExecState *exec);
00132
00133 class DOMUIEvent : public DOMEvent {
00134 public:
00135
00136 DOMUIEvent(ExecState *exec, DOM::UIEvent ue);
00137
00138 DOMUIEvent(const Object &proto, DOM::UIEvent ue);
00139 ~DOMUIEvent();
00140 virtual Value tryGet(ExecState *exec,const Identifier &p) const;
00141 Value getValueProperty(ExecState *, int token) const;
00142
00143 virtual const ClassInfo* classInfo() const { return &info; }
00144 static const ClassInfo info;
00145 enum { View, Detail, KeyCode, CharCode, LayerX, LayerY, PageX, PageY, Which, InitUIEvent };
00146 DOM::UIEvent toUIEvent() const { return static_cast<DOM::UIEvent>(event); }
00147 };
00148
00149 class DOMMouseEvent : public DOMUIEvent {
00150 public:
00151 DOMMouseEvent(ExecState *exec, DOM::MouseEvent me);
00152 ~DOMMouseEvent();
00153 virtual Value tryGet(ExecState *exec,const Identifier &p) const;
00154 Value getValueProperty(ExecState *, int token) const;
00155
00156 virtual const ClassInfo* classInfo() const { return &info; }
00157 static const ClassInfo info;
00158 enum { ScreenX, ScreenY, ClientX, X, ClientY, Y, OffsetX, OffsetY,
00159 CtrlKey, ShiftKey, AltKey,
00160 MetaKey, Button, RelatedTarget, FromElement, ToElement,
00161 InitMouseEvent
00162 };
00163 DOM::MouseEvent toMouseEvent() const { return static_cast<DOM::MouseEvent>(event); }
00164 };
00165
00166 class DOMKeyEventBase : public DOMUIEvent {
00167 public:
00168 DOMKeyEventBase(const Object &proto, DOM::TextEvent ke);
00169 ~DOMKeyEventBase();
00170
00171 virtual Value tryGet(ExecState *exec,const Identifier &p) const;
00172 Value getValueProperty(ExecState *, int token) const;
00173
00174 virtual const ClassInfo* classInfo() const { return &info; }
00175 static const ClassInfo info;
00176 enum { Key, VirtKey, CtrlKey, ShiftKey, AltKey, MetaKey };
00177 DOM::KeyEventBaseImpl* impl() const { return static_cast<DOM::KeyEventBaseImpl*>(event.handle()); }
00178 };
00179
00180 class DOMTextEvent : public DOMKeyEventBase {
00181 public:
00182 DOMTextEvent(ExecState *exec, DOM::TextEvent ke);
00183 ~DOMTextEvent();
00184 virtual Value tryGet(ExecState *exec,const Identifier &p) const;
00185 Value getValueProperty(ExecState *, int token) const;
00186
00187 virtual const ClassInfo* classInfo() const { return &info; }
00188 static const ClassInfo info;
00189 enum {Data, InitTextEvent};
00190 DOM::TextEventImpl* impl() const { return static_cast<DOM::TextEventImpl*>(event.handle()); }
00191 };
00192
00193 class DOMKeyboardEvent : public DOMKeyEventBase {
00194 public:
00195 DOMKeyboardEvent(ExecState *exec, DOM::TextEvent ke);
00196 ~DOMKeyboardEvent();
00197 virtual Value tryGet(ExecState *exec,const Identifier &p) const;
00198 Value getValueProperty(ExecState *, int token) const;
00199
00200 virtual const ClassInfo* classInfo() const { return &info; }
00201 static const ClassInfo info;
00202 enum {KeyIdentifier, KeyLocation, GetModifierState, InitKeyboardEvent};
00203 DOM::KeyboardEventImpl* impl() const { return static_cast<DOM::KeyboardEventImpl*>(event.handle()); }
00204 };
00205
00206
00207 class KeyboardEventConstructor : public DOMObject {
00208 public:
00209 KeyboardEventConstructor(ExecState *);
00210 virtual Value tryGet(ExecState *exec,const Identifier &p) const;
00211 Value getValueProperty(ExecState *, int token) const;
00212
00213 virtual const ClassInfo* classInfo() const { return &info; }
00214 static const ClassInfo info;
00215 };
00216
00217 Value getKeyboardEventConstructor(ExecState *exec);
00218
00219
00220 class MutationEventConstructor : public DOMObject {
00221 public:
00222 MutationEventConstructor(ExecState *);
00223 virtual Value tryGet(ExecState *exec,const Identifier &p) const;
00224 Value getValueProperty(ExecState *, int token) const;
00225
00226 virtual const ClassInfo* classInfo() const { return &info; }
00227 static const ClassInfo info;
00228 };
00229
00230 Value getMutationEventConstructor(ExecState *exec);
00231
00232 class DOMMutationEvent : public DOMEvent {
00233 public:
00234 DOMMutationEvent(ExecState *exec, DOM::MutationEvent me);
00235 ~DOMMutationEvent();
00236 virtual Value tryGet(ExecState *exec,const Identifier &p) const;
00237 Value getValueProperty(ExecState *, int token) const;
00238
00239 virtual const ClassInfo* classInfo() const { return &info; }
00240 static const ClassInfo info;
00241 enum { AttrChange, RelatedNode, AttrName, PrevValue, NewValue,
00242 InitMutationEvent };
00243 DOM::MutationEvent toMutationEvent() const { return static_cast<DOM::MutationEvent>(event); }
00244 };
00245
00246 }
00247
00248 #endif