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 bool hasProperty(ExecState *exec, const Identifier &p) const;
91 virtual Value get(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 void scheduleClose();
103 bool isSafeScript(ExecState *exec) const;
104 Location *location() const;
105 Selection *selection() const;
106 BarInfo *locationbar(ExecState *exec) const;
107 BarInfo *menubar(ExecState *exec) const;
108 BarInfo *personalbar(ExecState *exec) const;
109 BarInfo *scrollbars(ExecState *exec) const;
110 BarInfo *statusbar(ExecState *exec) const;
111 BarInfo *toolbar(ExecState *exec) const;
112 JSEventListener *getJSEventListener(const Value &val, bool html = false);
113 JSLazyEventListener *getJSLazyEventListener(const QString &code, bool html = false, int lineno = 0);
114 void clear( ExecState *exec );
115 virtual UString toString(ExecState *exec) const;
117 // Set the current "event" object
118 void setCurrentEvent( DOM::Event *evt );
120 QPtrDict<JSEventListener> jsEventListeners;
121 virtual const ClassInfo* classInfo() const { return &info; }
122 static const ClassInfo info;
123 enum { Closed, Crypto, DefaultStatus, Status, Document, Node, EventCtor, Range,
124 NodeFilter, DOMException, CSSRule, Frames, _History, Event, InnerHeight,
125 InnerWidth, Length, _Location, Locationbar, Name, _Navigator, _Konqueror, ClientInformation,
126 Menubar, OffscreenBuffering, Opener, OuterHeight, OuterWidth, PageXOffset, PageYOffset,
127 Parent, Personalbar, ScreenX, ScreenY, Scrollbars, Scroll, ScrollBy,
128 ScreenTop, ScreenLeft,
129 ScrollTo, ScrollX, ScrollY, MoveBy, MoveTo, ResizeBy, ResizeTo, Self, _Window, Top, _Screen,
130 Image, Option, Alert, Confirm, Prompt, Open, Print, SetTimeout, ClearTimeout,
131 Focus, GetSelection, Blur, Close, SetInterval, ClearInterval, CaptureEvents,
132 ReleaseEvents, AddEventListener, RemoveEventListener, XMLHttpRequest, XMLSerializer,
133 Onabort, Onblur, Onchange, Onclick, Ondblclick, Ondragdrop, Onerror,
134 Onfocus, Onkeydown, Onkeypress, Onkeyup, Onload, Onmousedown, Onmousemove,
135 Onmouseout, Onmouseover, Onmouseup, Onmove, Onreset, Onresize, Onscroll, Onsearch,
136 Onselect, Onsubmit, Onunload,
137 Statusbar, Toolbar };
139 Value getListener(ExecState *exec, int eventId) const;
140 void setListener(ExecState *exec, int eventId, Value func);
142 void updateLayout() const;
144 QGuardedPtr<KHTMLPart> m_part;
149 Selection *m_selection;
150 BarInfo *m_locationbar;
152 BarInfo *m_personalbar;
153 BarInfo *m_scrollbars;
154 BarInfo *m_statusbar;
161 * An action (either function or string) to be executed after a specified
162 * time interval, either once or repeatedly. Used for window.setTimeout()
163 * and window.setInterval()
165 class ScheduledAction {
167 ScheduledAction(Object _func, List _args, bool _singleShot);
168 ScheduledAction(const QString &_code, bool _singleShot);
170 void execute(Window *window);
172 ProtectedObject func;
179 class WindowQObject : public QObject {
182 WindowQObject(Window *w);
184 int installTimeout(const UString &handler, int t, bool singleShot);
185 int installTimeout(const Value &func, List args, int t, bool singleShot);
186 void clearTimeout(int timerId, bool delAction = true);
189 QMap<int, ScheduledAction*> *WindowQObject::pauseTimeouts(const void *key);
190 void WindowQObject::resumeTimeouts(QMap<int, ScheduledAction*> *sa, const void *key);
196 void parentDestroyed();
198 void timerEvent(QTimerEvent *e);
201 KHTMLPart *part; // not guarded, may be dangling
202 QMap<int, ScheduledAction*> scheduledActions;
205 class Location : public ObjectImp {
208 virtual Value get(ExecState *exec, const Identifier &propertyName) const;
209 virtual void put(ExecState *exec, const Identifier &propertyName, const Value &value, int attr = None);
210 virtual Value toPrimitive(ExecState *exec, Type preferred) const;
211 virtual UString toString(ExecState *exec) const;
212 enum { Hash, Href, Hostname, Host, Pathname, Port, Protocol, Search, EqualEqual,
213 Replace, Reload, ToString };
214 KHTMLPart *part() const { return m_part; }
215 virtual const ClassInfo* classInfo() const { return &info; }
216 static const ClassInfo info;
219 Location(KHTMLPart *p);
220 QGuardedPtr<KHTMLPart> m_part;
223 class Selection : public ObjectImp {
226 virtual Value get(ExecState *exec, const Identifier &propertyName) const;
227 virtual void put(ExecState *exec, const Identifier &propertyName, const Value &value, int attr = None);
228 virtual Value toPrimitive(ExecState *exec, Type preferred) const;
229 virtual UString toString(ExecState *exec) const;
230 enum { AnchorNode, AnchorOffset, FocusNode, FocusOffset, BaseNode, BaseOffset, ExtentNode, ExtentOffset,
231 IsCollapsed, _Type, EqualEqual, Collapse, CollapseToEnd, CollapseToStart, Empty, ToString,
232 SetBaseAndExtent, SetPosition, Modify };
233 KHTMLPart *part() const { return m_part; }
234 virtual const ClassInfo* classInfo() const { return &info; }
235 static const ClassInfo info;
238 Selection(KHTMLPart *p);
239 QGuardedPtr<KHTMLPart> m_part;
242 class BarInfo : public ObjectImp {
245 virtual Value get(ExecState *exec, const Identifier &propertyName) const;
246 virtual void put(ExecState *exec, const Identifier &propertyName, const Value &value, int attr = None);
248 enum Type { Locationbar, Menubar, Personalbar, Scrollbars, Statusbar, Toolbar };
249 KHTMLPart *part() const { return m_part; }
250 virtual const ClassInfo* classInfo() const { return &info; }
251 static const ClassInfo info;
254 BarInfo(ExecState *exec, KHTMLPart *p, Type barType);
255 QGuardedPtr<KHTMLPart> m_part;
260 class Konqueror : public ObjectImp {
261 friend class KonquerorFunc;
263 Konqueror(KHTMLPart *p) : part(p) { }
264 virtual Value get(ExecState *exec, const Identifier &propertyName) const;
265 virtual bool hasProperty(ExecState *exec, const Identifier &p) const;
266 virtual UString toString(ExecState *exec) const;
267 virtual const ClassInfo* classInfo() const { return &info; }
268 static const ClassInfo info;