1 // -*- c-basic-offset: 2 -*-
3 * This file is part of the KDE libraries
4 * Copyright (C) 2000 Harri Porten (porten@kde.org)
5 * Copyright (C) 2003 Apple Computer, Inc.
7 * This library is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU Lesser General Public
9 * License as published by the Free Software Foundation; either
10 * version 2 of the License, or (at your option) any later version.
12 * This library is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * Lesser General Public License for more details.
17 * You should have received a copy of the GNU Lesser General Public
18 * License along with this library; if not, write to the Free Software
19 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
22 #ifndef _KJS_WINDOW_H_
23 #define _KJS_WINDOW_H_
26 #include <qguardedptr.h>
30 #include "kjs_binding.h"
45 class JSEventListener;
46 class JSLazyEventListener;
48 class Screen : public ObjectImp {
50 Screen(ExecState *exec);
52 Height, Width, ColorDepth, PixelDepth, AvailLeft, AvailTop, AvailHeight,
55 virtual Value get(ExecState *exec, const Identifier &propertyName) const;
56 Value getValueProperty(ExecState *exec, int token) const;
59 virtual const ClassInfo* classInfo() const { return &info; }
60 static const ClassInfo info;
63 class Window : public ObjectImp {
64 friend QGuardedPtr<KHTMLPart> getInstance();
65 friend class Location;
66 friend class WindowFunc;
67 friend class WindowQObject;
68 friend class ScheduledAction;
74 * Returns and registers a window object. In case there's already a Window
75 * for the specified part p this will be returned in order to have unique
78 static Value retrieve(KHTMLPart *p);
80 * Returns the Window object for a given HTML part
82 static Window *retrieveWindow(KHTMLPart *p);
84 * returns a pointer to the Window object this javascript interpreting instance
87 static Window *retrieveActive(ExecState *exec);
88 QGuardedPtr<KHTMLPart> part() const { return m_part; }
90 virtual Value get(ExecState *exec, const Identifier &propertyName) const;
91 virtual bool hasProperty(ExecState *exec, const Identifier &propertyName) const;
92 virtual void put(ExecState *exec, const Identifier &propertyName, const Value &value, int attr = None);
93 virtual bool toBoolean(ExecState *exec) const;
94 int installTimeout(const UString &handler, int t, bool singleShot);
95 int installTimeout(const Value &function, List &args, int t, bool singleShot);
96 void clearTimeout(int timerId);
99 QMap<int, ScheduledAction*> *pauseTimeouts(const void *key);
100 void resumeTimeouts(QMap<int, ScheduledAction*>*sa, const void *key);
102 KJS::Interpreter *interpreter() const;
104 static bool isSafeScript (const KJS::ScriptInterpreter *origin, const KJS::ScriptInterpreter *target);
106 void scheduleClose();
108 bool isSafeScript(ExecState *exec) const;
109 Location *location() const;
110 Selection *selection() const;
111 BarInfo *locationbar(ExecState *exec) const;
112 BarInfo *menubar(ExecState *exec) const;
113 BarInfo *personalbar(ExecState *exec) const;
114 BarInfo *scrollbars(ExecState *exec) const;
115 BarInfo *statusbar(ExecState *exec) const;
116 BarInfo *toolbar(ExecState *exec) const;
117 JSEventListener *getJSEventListener(const Value &val, bool html = false);
118 JSLazyEventListener *getJSLazyEventListener(const QString &code, DOM::NodeImpl *node, int lineno = 0);
119 void clear( ExecState *exec );
120 virtual UString toString(ExecState *exec) const;
122 // Set the current "event" object
123 void setCurrentEvent( DOM::Event *evt );
125 QPtrDict<JSEventListener> jsEventListeners;
126 virtual const ClassInfo* classInfo() const { return &info; }
127 static const ClassInfo info;
128 enum { Closed, Crypto, DefaultStatus, Status, Document, Node, EventCtor, Range,
129 NodeFilter, DOMException, CSSRule, Frames, _History, Event, InnerHeight,
130 InnerWidth, Length, _Location, Locationbar, Name, _Navigator, _Konqueror, ClientInformation,
131 Menubar, OffscreenBuffering, Opener, OuterHeight, OuterWidth, PageXOffset, PageYOffset,
132 Parent, Personalbar, ScreenX, ScreenY, Scrollbars, Scroll, ScrollBy,
133 ScreenTop, ScreenLeft,
134 ScrollTo, ScrollX, ScrollY, MoveBy, MoveTo, ResizeBy, ResizeTo, Self, _Window, Top, _Screen,
135 Image, Option, Alert, Confirm, Prompt, Open, Print, SetTimeout, ClearTimeout,
136 Focus, GetSelection, Blur, Close, SetInterval, ClearInterval, CaptureEvents,
137 ReleaseEvents, AddEventListener, RemoveEventListener, XMLHttpRequest, XMLSerializer,
138 Onabort, Onblur, Onchange, Onclick, Ondblclick, Ondragdrop, Onerror,
139 Onfocus, Onkeydown, Onkeypress, Onkeyup, Onload, Onmousedown, Onmousemove,
140 Onmouseout, Onmouseover, Onmouseup, Onmove, Onreset, Onresize, Onscroll, Onsearch,
141 Onselect, Onsubmit, Onunload,
142 Statusbar, Toolbar };
144 Value getListener(ExecState *exec, int eventId) const;
145 void setListener(ExecState *exec, int eventId, Value func);
147 void updateLayout() const;
149 QGuardedPtr<KHTMLPart> m_part;
154 Selection *m_selection;
155 BarInfo *m_locationbar;
157 BarInfo *m_personalbar;
158 BarInfo *m_scrollbars;
159 BarInfo *m_statusbar;
166 * An action (either function or string) to be executed after a specified
167 * time interval, either once or repeatedly. Used for window.setTimeout()
168 * and window.setInterval()
170 class ScheduledAction {
172 ScheduledAction(Object _func, List _args, bool _singleShot);
173 ScheduledAction(const QString &_code, bool _singleShot);
175 void execute(Window *window);
177 ProtectedObject func;
184 class WindowQObject : public QObject {
187 WindowQObject(Window *w);
189 int installTimeout(const UString &handler, int t, bool singleShot);
190 int installTimeout(const Value &func, List args, int t, bool singleShot);
191 void clearTimeout(int timerId, bool delAction = true);
194 QMap<int, ScheduledAction*> *WindowQObject::pauseTimeouts(const void *key);
195 void WindowQObject::resumeTimeouts(QMap<int, ScheduledAction*> *sa, const void *key);
201 void parentDestroyed();
203 void timerEvent(QTimerEvent *e);
206 KHTMLPart *part; // not guarded, may be dangling
207 QMap<int, ScheduledAction*> scheduledActions;
210 class Location : public ObjectImp {
213 virtual Value get(ExecState *exec, const Identifier &propertyName) const;
214 virtual void put(ExecState *exec, const Identifier &propertyName, const Value &value, int attr = None);
215 virtual Value toPrimitive(ExecState *exec, Type preferred) const;
216 virtual UString toString(ExecState *exec) const;
217 enum { Hash, Href, Hostname, Host, Pathname, Port, Protocol, Search, EqualEqual,
218 Replace, Reload, ToString };
219 KHTMLPart *part() const { return m_part; }
220 virtual const ClassInfo* classInfo() const { return &info; }
221 static const ClassInfo info;
224 Location(KHTMLPart *p);
225 QGuardedPtr<KHTMLPart> m_part;
228 class Selection : public ObjectImp {
231 virtual Value get(ExecState *exec, const Identifier &propertyName) const;
232 virtual void put(ExecState *exec, const Identifier &propertyName, const Value &value, int attr = None);
233 virtual Value toPrimitive(ExecState *exec, Type preferred) const;
234 virtual UString toString(ExecState *exec) const;
235 enum { AnchorNode, AnchorOffset, FocusNode, FocusOffset, BaseNode, BaseOffset, ExtentNode, ExtentOffset,
236 IsCollapsed, _Type, EqualEqual, Collapse, CollapseToEnd, CollapseToStart, Empty, ToString,
237 SetBaseAndExtent, SetPosition, Modify };
238 KHTMLPart *part() const { return m_part; }
239 virtual const ClassInfo* classInfo() const { return &info; }
240 static const ClassInfo info;
243 Selection(KHTMLPart *p);
244 QGuardedPtr<KHTMLPart> m_part;
247 class BarInfo : public ObjectImp {
250 virtual Value get(ExecState *exec, const Identifier &propertyName) const;
251 virtual void put(ExecState *exec, const Identifier &propertyName, const Value &value, int attr = None);
253 enum Type { Locationbar, Menubar, Personalbar, Scrollbars, Statusbar, Toolbar };
254 KHTMLPart *part() const { return m_part; }
255 virtual const ClassInfo* classInfo() const { return &info; }
256 static const ClassInfo info;
259 BarInfo(ExecState *exec, KHTMLPart *p, Type barType);
260 QGuardedPtr<KHTMLPart> m_part;
265 class Konqueror : public ObjectImp {
266 friend class KonquerorFunc;
268 Konqueror(KHTMLPart *p) : part(p) { }
269 virtual Value get(ExecState *exec, const Identifier &propertyName) const;
270 virtual bool hasProperty(ExecState *exec, const Identifier &p) const;
271 virtual UString toString(ExecState *exec) const;
272 virtual const ClassInfo* classInfo() const { return &info; }
273 static const ClassInfo info;