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
00033
class QTimer;
00034
class KHTMLView;
00035
class KHTMLPart;
00036
00037
namespace KParts {
00038
class ReadOnlyPart;
00039 }
00040
00041
namespace khtml {
00042
class ChildFrame;
00043 }
00044
00045
namespace KJS {
00046
00047
class WindowFunc;
00048
class WindowQObject;
00049
class Location;
00050
class History;
00051
class External;
00052
class FrameArray;
00053
class JSEventListener;
00054
class JSLazyEventListener;
00055
00056
class Screen :
public ObjectImp {
00057
public:
00058 Screen(ExecState *exec);
00059
enum {
00060 Height, Width, ColorDepth, PixelDepth, AvailLeft, AvailTop, AvailHeight,
00061 AvailWidth
00062 };
00063
virtual Value
get(ExecState *exec,
const Identifier &propertyName)
const;
00064 Value getValueProperty(ExecState *exec,
int token)
const;
00065
private:
00066
KHTMLView *view;
00067
virtual const ClassInfo* classInfo()
const {
return &info; }
00068
static const ClassInfo info;
00069 };
00070
00071
class Window :
public ObjectImp {
00072
friend QGuardedPtr<KHTMLPart> getInstance();
00073
friend class Location;
00074
friend class WindowFunc;
00075
friend class WindowQObject;
00076
friend class ScheduledAction;
00077
public:
00078 Window(khtml::ChildFrame *p);
00079
public:
00080 ~Window();
00086
static Value retrieve(
KParts::ReadOnlyPart *p);
00090
static Window *retrieveWindow(
KParts::ReadOnlyPart *p);
00095
static Window *retrieveActive(ExecState *exec);
00096
KParts::ReadOnlyPart *part() const;
00097 virtual
void mark();
00098 virtual
bool hasProperty(ExecState *exec, const Identifier &p) const;
00099 virtual Value get(ExecState *exec, const Identifier &propertyName) const;
00100 virtual
void put(ExecState *exec, const Identifier &propertyName, const Value &value,
int attr = None);
00101 virtual
bool toBoolean(ExecState *exec) const;
00102
void scheduleClose();
00103
void closeNow();
00104
void delayedGoHistory(
int steps);
00105
void goHistory(
int steps);
00106
void goURL(ExecState* exec, const
QString& url,
bool lockHistory);
00107 Value openWindow(ExecState *exec, const List &args);
00108
void resizeTo(
QWidget* tl,
int width,
int height);
00109
void afterScriptExecution();
00110
bool isSafeScript(ExecState *exec)
const {
00111
KParts::ReadOnlyPart *activePart = static_cast<KJS::ScriptInterpreter *>( exec->interpreter() )->part();
00112
if ( activePart == part() )
return true;
00113
return checkIsSafeScript( activePart );
00114 }
00115 Location *location() const;
00116 ObjectImp* frames( ExecState* exec ) const;
00117 JSEventListener *getJSEventListener(const Value &val,
bool html = false);
00118 JSLazyEventListener *getJSLazyEventListener(const
QString &code, const
QString &name,
bool html = false);
00119
void clear( ExecState *exec );
00120 virtual UString toString(ExecState *exec) const;
00121
00122
00123
void setCurrentEvent( DOM::
Event *evt );
00124
00125
QPtrDict<JSEventListener> jsEventListeners;
00126 virtual const ClassInfo* classInfo()
const {
return &info; }
00127
static const ClassInfo info;
00128
enum { Closed, Crypto, DefaultStatus, Status,
Document,
Node, EventCtor, Range,
00129
NodeFilter,
DOMException,
CSSRule, Frames, _History, _External,
Event, InnerHeight,
00130 InnerWidth, Length, _Location, Navigate, Name, _Navigator, _Konqueror, ClientInformation,
00131 OffscreenBuffering, Opener, OuterHeight, OuterWidth, PageXOffset, PageYOffset,
00132 Parent, Personalbar, ScreenX, ScreenY, Scrollbars, Scroll, ScrollBy,
00133 ScreenTop, ScreenLeft,
00134 ScrollTo, ScrollX, ScrollY, MoveBy, MoveTo, ResizeBy, ResizeTo, Self, _Window, Top, _Screen,
00135 Image, Option, Alert, Confirm, Prompt, Open, SetTimeout, ClearTimeout, XMLHttpRequest, XMLSerializer,
00136 Focus, Blur, Close, SetInterval, ClearInterval, CaptureEvents, ReleaseEvents,
00137 Print, AddEventListener, RemoveEventListener, SideBar,
00138 Onabort, Onblur,
00139 Onchange, Onclick, Ondblclick, Ondragdrop, Onerror, Onfocus,
00140 Onkeydown, Onkeypress, Onkeyup, Onload, Onmousedown, Onmousemove,
00141 Onmouseout, Onmouseover, Onmouseup, Onmove, Onreset, Onresize,
00142 Onselect, Onsubmit, Onunload };
00143 WindowQObject *winq;
00144
protected:
00145
enum DelayedActionId { NullAction, DelayedClose, DelayedGoHistory };
00146
00147 Value getListener(ExecState *exec,
int eventId)
const;
00148
void setListener(ExecState *exec,
int eventId, Value func);
00149
private:
00150
struct DelayedAction;
00151
friend struct DelayedAction;
00152
00153
bool checkIsSafeScript(
KParts::ReadOnlyPart* activePart )
const;
00154
00155
QGuardedPtr<khtml::ChildFrame> m_frame;
00156 Screen *screen;
00157 History *history;
00158 External *external;
00159 FrameArray *m_frames;
00160 Location *loc;
00161
DOM::Event *m_evt;
00162
00163
struct DelayedAction {
00164 DelayedAction() : actionId(NullAction) {}
00165 DelayedAction( DelayedActionId
id,
QVariant p =
QVariant() ) : actionId(id), param(p) {}
00166 DelayedActionId actionId;
00167
QVariant param;
00168 };
00169
QValueList<DelayedAction> m_delayed;
00170 };
00171
00177 class ScheduledAction {
00178
public:
00179
ScheduledAction(Object _func, List _args,
QTime _nextTime,
int _interval,
bool _singleShot,
int _timerId);
00180
ScheduledAction(
QString _code,
QTime _nextTime,
int _interval,
bool _singleShot,
int _timerId);
00181 ~
ScheduledAction();
00182
bool execute(Window *window);
00183
void mark();
00184
00185 ObjectImp *func;
00186 List args;
00187
QString code;
00188
bool isFunction;
00189
bool singleShot;
00190
00191
QTime nextTime;
00192
int interval;
00193
bool executing;
00194
int timerId;
00195 };
00196
00197
class WindowQObject :
public QObject {
00198 Q_OBJECT
00199
public:
00200 WindowQObject(Window *w);
00201 ~WindowQObject();
00202
int installTimeout(
const Identifier &handler,
int t,
bool singleShot);
00203
int installTimeout(
const Value &func, List args,
int t,
bool singleShot);
00204
void clearTimeout(
int timerId);
00205
void mark();
00206
bool hasTimers() const;
00207 public slots:
00208
void timeoutClose();
00209 protected slots:
00210
void parentDestroyed();
00211 protected:
00212
void timerEvent(
QTimerEvent *e);
00213
void setNextTimer();
00214 private:
00215 Window *parent;
00216
QPtrList<
ScheduledAction> scheduledActions;
00217
int pausedTime;
00218
int lastTimerId;
00219 };
00220
00221 class Location : public ObjectImp {
00222
public:
00223 ~Location();
00224
virtual Value get(ExecState *exec,
const Identifier &propertyName)
const;
00225
virtual void put(ExecState *exec,
const Identifier &propertyName,
const Value &value,
int attr = None);
00226
virtual Value toPrimitive(ExecState *exec, Type preferred)
const;
00227
virtual UString toString(ExecState *exec)
const;
00228
enum { Hash, Href, Hostname, Host, Pathname, Port, Protocol, Search, EqualEqual,
00229 Assign, Replace, Reload, ToString };
00230
KParts::ReadOnlyPart *part() const;
00231 virtual const ClassInfo* classInfo()
const {
return &info; }
00232
static const ClassInfo info;
00233
private:
00234
friend class Window;
00235 Location(khtml::ChildFrame *f);
00236
QGuardedPtr<khtml::ChildFrame> m_frame;
00237 };
00238
00239
#ifdef Q_WS_QWS
00240
class Konqueror :
public ObjectImp {
00241
friend class KonquerorFunc;
00242
public:
00243 Konqueror(
KHTMLPart *p) : part(p) { }
00244
virtual Value
get(ExecState *exec,
const Identifier &propertyName)
const;
00245
virtual bool hasProperty(ExecState *exec,
const Identifier &p)
const;
00246
virtual UString toString(ExecState *exec)
const;
00247
virtual const ClassInfo* classInfo()
const {
return &info; }
00248
static const ClassInfo info;
00249
private:
00250
KHTMLPart *part;
00251 };
00252
#endif
00253
00254 }
00255
00256
#endif