00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022 #ifndef _KJS_WINDOW_H_
00023 #define _KJS_WINDOW_H_
00024
00025 #include <qobject.h>
00026 #include <qguardedptr.h>
00027 #include <qmap.h>
00028 #include <qptrlist.h>
00029 #include <qdatetime.h>
00030
00031 #include "kjs_binding.h"
00032 #include "kjs_views.h"
00033
00034 class QTimer;
00035 class KHTMLView;
00036 class KHTMLPart;
00037
00038 namespace KParts {
00039 class ReadOnlyPart;
00040 }
00041
00042 namespace khtml {
00043 class ChildFrame;
00044 }
00045
00046 namespace KJS {
00047
00048 class WindowFunc;
00049 class WindowQObject;
00050 class Location;
00051 class History;
00052 class External;
00053 class FrameArray;
00054 class JSEventListener;
00055 class JSLazyEventListener;
00056
00057 class Screen : public ObjectImp {
00058 public:
00059 Screen(ExecState *exec);
00060 enum {
00061 Height, Width, ColorDepth, PixelDepth, AvailLeft, AvailTop, AvailHeight,
00062 AvailWidth
00063 };
00064 virtual Value get(ExecState *exec, const Identifier &propertyName) const;
00065 Value getValueProperty(ExecState *exec, int token) const;
00066 private:
00067 KHTMLView *view;
00068 virtual const ClassInfo* classInfo() const { return &info; }
00069 static const ClassInfo info;
00070 };
00071
00072 class KDE_EXPORT Window : public ObjectImp {
00073 friend QGuardedPtr<KHTMLPart> getInstance();
00074 friend class Location;
00075 friend class WindowFunc;
00076 friend class WindowQObject;
00077 friend class ScheduledAction;
00078 public:
00079 Window(khtml::ChildFrame *p);
00080 public:
00081 ~Window();
00087 static Value retrieve(KParts::ReadOnlyPart *p);
00091 static Window *retrieveWindow(KParts::ReadOnlyPart *p);
00096 static Window *retrieveActive(ExecState *exec);
00097 KParts::ReadOnlyPart *part() const;
00098 virtual void mark();
00099 virtual bool hasProperty(ExecState *exec, const Identifier &p) const;
00100 virtual Value get(ExecState *exec, const Identifier &propertyName) const;
00101 virtual void put(ExecState *exec, const Identifier &propertyName, const Value &value, int attr = None);
00102 virtual bool toBoolean(ExecState *exec) const;
00103 virtual DOM::AbstractView toAbstractView() const;
00104 void scheduleClose();
00105 void closeNow();
00106 void delayedGoHistory(int steps);
00107 void goHistory(int steps);
00108 void goURL(ExecState* exec, const QString& url, bool lockHistory);
00109 Value openWindow(ExecState *exec, const List &args);
00110 Value executeOpenWindow(ExecState *exec, const KURL& url, const QString& frameName, const QString& features);
00111 void resizeTo(QWidget* tl, int width, int height);
00112 void afterScriptExecution();
00113 bool isSafeScript(ExecState *exec) const {
00114 KParts::ReadOnlyPart *activePart = static_cast<KJS::ScriptInterpreter *>( exec->interpreter() )->part();
00115 if ( activePart == part() ) return true;
00116 return checkIsSafeScript( activePart );
00117 }
00118 Location *location() const;
00119 ObjectImp* frames( ExecState* exec ) const;
00120 JSEventListener *getJSEventListener(const Value &val, bool html = false);
00121 JSLazyEventListener *getJSLazyEventListener(const QString &code, const QString &name, DOM::NodeImpl* node);
00122 void clear( ExecState *exec );
00123 virtual UString toString(ExecState *exec) const;
00124
00125
00126 void setCurrentEvent( DOM::Event *evt );
00127
00128 QPtrDict<JSEventListener> jsEventListeners;
00129 virtual const ClassInfo* classInfo() const { return &info; }
00130 static const ClassInfo info;
00131 enum { Closed, Crypto, DefaultStatus, Status, Document, Node, EventCtor, Range,
00132 NodeFilter, DOMException, CSSRule, Frames, _History, _External, Event, InnerHeight,
00133 InnerWidth, Length, _Location, Navigate, Name, _Navigator, _Konqueror, ClientInformation,
00134 OffscreenBuffering, Opener, OuterHeight, OuterWidth, PageXOffset, PageYOffset,
00135 Parent, Personalbar, ScreenX, ScreenY, Scrollbars, Scroll, ScrollBy,
00136 ScreenTop, ScreenLeft, AToB, BToA, FrameElement, GetComputedStyle,
00137 ScrollTo, ScrollX, ScrollY, MoveBy, MoveTo, ResizeBy, ResizeTo, Self, _Window, Top, _Screen,
00138 Image, Option, Alert, Confirm, Prompt, Open, SetTimeout, ClearTimeout,
00139 XMLHttpRequest, XMLSerializer, DOMParser,
00140 Focus, Blur, Close, SetInterval, ClearInterval, CaptureEvents, ReleaseEvents,
00141 Print, AddEventListener, RemoveEventListener, SideBar,
00142 Onabort, Onblur,
00143 Onchange, Onclick, Ondblclick, Ondragdrop, Onerror, Onfocus,
00144 Onkeydown, Onkeypress, Onkeyup, Onload, Onmousedown, Onmousemove,
00145 Onmouseout, Onmouseover, Onmouseup, Onmove, Onreset, Onresize,
00146 Onselect, Onsubmit, Onunload,
00147 MutationEventCtor, KeyboardEventCtor, EventExceptionCtor };
00148 WindowQObject *winq;
00149
00150 void forgetSuppressedWindows();
00151 void showSuppressedWindows();
00152
00153 protected:
00154 enum DelayedActionId { NullAction, DelayedClose, DelayedGoHistory };
00155
00156 Value getListener(ExecState *exec, int eventId) const;
00157 void setListener(ExecState *exec, int eventId, Value func);
00158 private:
00159 struct DelayedAction;
00160 friend struct DelayedAction;
00161
00162 bool checkIsSafeScript( KParts::ReadOnlyPart* activePart ) const;
00163
00164 QGuardedPtr<khtml::ChildFrame> m_frame;
00165 Screen *screen;
00166 History *history;
00167 External *external;
00168 FrameArray *m_frames;
00169 Location *loc;
00170 DOM::Event *m_evt;
00171
00172 struct DelayedAction {
00173 DelayedAction() : actionId(NullAction) {}
00174 DelayedAction( DelayedActionId id, QVariant p = QVariant() ) : actionId(id), param(p) {}
00175 DelayedActionId actionId;
00176 QVariant param;
00177 };
00178 QValueList<DelayedAction> m_delayed;
00179
00180 struct SuppressedWindowInfo {
00181 SuppressedWindowInfo() {}
00182 SuppressedWindowInfo( KURL u, QString fr, QString fe ) : url(u), frameName(fr), features(fe) {}
00183 KURL url;
00184 QString frameName;
00185 QString features;
00186 };
00187 QValueList<SuppressedWindowInfo> m_suppressedWindowInfo;
00188 };
00189
00193 class DateTimeMS
00194 {
00195 QDate mDate;
00196 QTime mTime;
00197 public:
00198 DateTimeMS addMSecs(int s) const;
00199 bool operator >(const DateTimeMS &other) const;
00200 bool operator >=(const DateTimeMS &other) const;
00201
00202 int msecsTo(const DateTimeMS &other) const;
00203
00204 static DateTimeMS now();
00205 };
00206
00212 class ScheduledAction {
00213 public:
00214 ScheduledAction(Object _func, List _args, DateTimeMS _nextTime, int _interval, bool _singleShot, int _timerId);
00215 ScheduledAction(QString _code, DateTimeMS _nextTime, int _interval, bool _singleShot, int _timerId);
00216 ~ScheduledAction();
00217 bool execute(Window *window);
00218 void mark();
00219
00220 ObjectImp *func;
00221 List args;
00222 QString code;
00223 bool isFunction;
00224 bool singleShot;
00225
00226 DateTimeMS nextTime;
00227 int interval;
00228 bool executing;
00229 int timerId;
00230 };
00231
00232 class KDE_EXPORT WindowQObject : public QObject {
00233 Q_OBJECT
00234 public:
00235 WindowQObject(Window *w);
00236 ~WindowQObject();
00237 int installTimeout(const Identifier &handler, int t, bool singleShot);
00238 int installTimeout(const Value &func, List args, int t, bool singleShot);
00239 void clearTimeout(int timerId);
00240 void mark();
00241 bool hasTimers() const;
00242 public slots:
00243 void timeoutClose();
00244 protected slots:
00245 void parentDestroyed();
00246 protected:
00247 void timerEvent(QTimerEvent *e);
00248 void setNextTimer();
00249 private:
00250 Window *parent;
00251 QPtrList<ScheduledAction> scheduledActions;
00252 int pausedTime;
00253 int lastTimerId;
00254 bool currentlyDispatching;
00255 };
00256
00257 class Location : public ObjectImp {
00258 public:
00259 ~Location();
00260 virtual Value get(ExecState *exec, const Identifier &propertyName) const;
00261 virtual void put(ExecState *exec, const Identifier &propertyName, const Value &value, int attr = None);
00262 virtual Value toPrimitive(ExecState *exec, Type preferred) const;
00263 virtual UString toString(ExecState *exec) const;
00264 enum { Hash, Href, Hostname, Host, Pathname, Port, Protocol, Search, EqualEqual,
00265 Assign, Replace, Reload, ToString };
00266 KParts::ReadOnlyPart *part() const;
00267 virtual const ClassInfo* classInfo() const { return &info; }
00268 static const ClassInfo info;
00269 private:
00270 friend class Window;
00271 Location(khtml::ChildFrame *f);
00272 QGuardedPtr<khtml::ChildFrame> m_frame;
00273 };
00274
00275 #ifdef Q_WS_QWS
00276 class Konqueror : public ObjectImp {
00277 friend class KonquerorFunc;
00278 public:
00279 Konqueror(KHTMLPart *p) : part(p) { }
00280 virtual Value get(ExecState *exec, const Identifier &propertyName) const;
00281 virtual bool hasProperty(ExecState *exec, const Identifier &p) const;
00282 virtual UString toString(ExecState *exec) const;
00283 virtual const ClassInfo* classInfo() const { return &info; }
00284 static const ClassInfo info;
00285 private:
00286 KHTMLPart *part;
00287 };
00288 #endif
00289
00290 }
00291
00292 #endif