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 WindowQObject *winq;
00148
00149 void forgetSuppressedWindows();
00150 void showSuppressedWindows();
00151
00152 protected:
00153 enum DelayedActionId { NullAction, DelayedClose, DelayedGoHistory };
00154
00155 Value getListener(ExecState *exec, int eventId) const;
00156 void setListener(ExecState *exec, int eventId, Value func);
00157 private:
00158 struct DelayedAction;
00159 friend struct DelayedAction;
00160
00161 bool checkIsSafeScript( KParts::ReadOnlyPart* activePart ) const;
00162
00163 QGuardedPtr<khtml::ChildFrame> m_frame;
00164 Screen *screen;
00165 History *history;
00166 External *external;
00167 FrameArray *m_frames;
00168 Location *loc;
00169 DOM::Event *m_evt;
00170
00171 struct DelayedAction {
00172 DelayedAction() : actionId(NullAction) {}
00173 DelayedAction( DelayedActionId id, QVariant p = QVariant() ) : actionId(id), param(p) {}
00174 DelayedActionId actionId;
00175 QVariant param;
00176 };
00177 QValueList<DelayedAction> m_delayed;
00178
00179 struct SuppressedWindowInfo {
00180 SuppressedWindowInfo() {}
00181 SuppressedWindowInfo( KURL u, QString fr, QString fe ) : url(u), frameName(fr), features(fe) {}
00182 KURL url;
00183 QString frameName;
00184 QString features;
00185 };
00186 QValueList<SuppressedWindowInfo> m_suppressedWindowInfo;
00187 };
00188
00194 class ScheduledAction {
00195 public:
00196 ScheduledAction(Object _func, List _args, QTime _nextTime, int _interval, bool _singleShot, int _timerId);
00197 ScheduledAction(QString _code, QTime _nextTime, int _interval, bool _singleShot, int _timerId);
00198 ~ScheduledAction();
00199 bool execute(Window *window);
00200 void mark();
00201
00202 ObjectImp *func;
00203 List args;
00204 QString code;
00205 bool isFunction;
00206 bool singleShot;
00207
00208 QTime nextTime;
00209 int interval;
00210 bool executing;
00211 int timerId;
00212 };
00213
00214 class KDE_EXPORT WindowQObject : public QObject {
00215 Q_OBJECT
00216 public:
00217 WindowQObject(Window *w);
00218 ~WindowQObject();
00219 int installTimeout(const Identifier &handler, int t, bool singleShot);
00220 int installTimeout(const Value &func, List args, int t, bool singleShot);
00221 void clearTimeout(int timerId);
00222 void mark();
00223 bool hasTimers() const;
00224 public slots:
00225 void timeoutClose();
00226 protected slots:
00227 void parentDestroyed();
00228 protected:
00229 void timerEvent(QTimerEvent *e);
00230 void setNextTimer();
00231 private:
00232 Window *parent;
00233 QPtrList<ScheduledAction> scheduledActions;
00234 int pausedTime;
00235 int lastTimerId;
00236 bool currentlyDispatching;
00237 };
00238
00239 class Location : public ObjectImp {
00240 public:
00241 ~Location();
00242 virtual Value get(ExecState *exec, const Identifier &propertyName) const;
00243 virtual void put(ExecState *exec, const Identifier &propertyName, const Value &value, int attr = None);
00244 virtual Value toPrimitive(ExecState *exec, Type preferred) const;
00245 virtual UString toString(ExecState *exec) const;
00246 enum { Hash, Href, Hostname, Host, Pathname, Port, Protocol, Search, EqualEqual,
00247 Assign, Replace, Reload, ToString };
00248 KParts::ReadOnlyPart *part() const;
00249 virtual const ClassInfo* classInfo() const { return &info; }
00250 static const ClassInfo info;
00251 private:
00252 friend class Window;
00253 Location(khtml::ChildFrame *f);
00254 QGuardedPtr<khtml::ChildFrame> m_frame;
00255 };
00256
00257 #ifdef Q_WS_QWS
00258 class Konqueror : public ObjectImp {
00259 friend class KonquerorFunc;
00260 public:
00261 Konqueror(KHTMLPart *p) : part(p) { }
00262 virtual Value get(ExecState *exec, const Identifier &propertyName) const;
00263 virtual bool hasProperty(ExecState *exec, const Identifier &p) const;
00264 virtual UString toString(ExecState *exec) const;
00265 virtual const ClassInfo* classInfo() const { return &info; }
00266 static const ClassInfo info;
00267 private:
00268 KHTMLPart *part;
00269 };
00270 #endif
00271
00272 }
00273
00274 #endif