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 JSUnprotectedEventListener;
47 class JSLazyEventListener;
49 class Screen : public ObjectImp {
51 Screen(ExecState *exec);
53 Height, Width, ColorDepth, PixelDepth, AvailLeft, AvailTop, AvailHeight,
56 virtual Value get(ExecState *exec, const Identifier &propertyName) const;
57 Value getValueProperty(ExecState *exec, int token) const;
60 virtual const ClassInfo* classInfo() const { return &info; }
61 static const ClassInfo info;
64 class Window : public ObjectImp {
65 friend QGuardedPtr<KHTMLPart> getInstance();
66 friend class Location;
67 friend class WindowFunc;
68 friend class WindowQObject;
69 friend class ScheduledAction;
75 * Returns and registers a window object. In case there's already a Window
76 * for the specified part p this will be returned in order to have unique
79 static Value retrieve(KHTMLPart *p);
81 * Returns the Window object for a given HTML part
83 static Window *retrieveWindow(KHTMLPart *p);
85 * returns a pointer to the Window object this javascript interpreting instance
88 static Window *retrieveActive(ExecState *exec);
89 QGuardedPtr<KHTMLPart> part() const { return m_part; }
91 virtual Value get(ExecState *exec, const Identifier &propertyName) const;
92 virtual bool hasProperty(ExecState *exec, const Identifier &propertyName) const;
93 virtual void put(ExecState *exec, const Identifier &propertyName, const Value &value, int attr = None);
94 virtual bool toBoolean(ExecState *exec) const;
95 int installTimeout(const UString &handler, int t, bool singleShot);
96 int installTimeout(const Value &function, List &args, int t, bool singleShot);
97 void clearTimeout(int timerId);
100 QMap<int, ScheduledAction*> *pauseTimeouts(const void *key);
101 void resumeTimeouts(QMap<int, ScheduledAction*>*sa, const void *key);
103 KJS::Interpreter *interpreter() const;
105 static bool isSafeScript (const KJS::ScriptInterpreter *origin, const KJS::ScriptInterpreter *target);
107 void scheduleClose();
109 bool isSafeScript(ExecState *exec) const;
110 Location *location() const;
111 Selection *selection() const;
112 BarInfo *locationbar(ExecState *exec) const;
113 BarInfo *menubar(ExecState *exec) const;
114 BarInfo *personalbar(ExecState *exec) const;
115 BarInfo *scrollbars(ExecState *exec) const;
116 BarInfo *statusbar(ExecState *exec) const;
117 BarInfo *toolbar(ExecState *exec) const;
118 JSEventListener *getJSEventListener(const Value &val, bool html = false);
119 JSUnprotectedEventListener *getJSUnprotectedEventListener(const Value &val, bool html = false);
120 JSLazyEventListener *getJSLazyEventListener(const QString &code, DOM::NodeImpl *node, int lineno = 0);
121 void clear( ExecState *exec );
122 virtual UString toString(ExecState *exec) const;
124 // Set the current "event" object
125 void setCurrentEvent( DOM::Event *evt );
127 QPtrDict<JSEventListener> jsEventListeners;
128 QPtrDict<JSUnprotectedEventListener> jsUnprotectedEventListeners;
129 virtual const ClassInfo* classInfo() const { return &info; }
130 static const ClassInfo info;
131 enum { Closed, Crypto, DefaultStatus, Status, Document, Node, EventCtor, Range,
132 NodeFilter, DOMException, CSSRule, Frames, _History, Event, InnerHeight,
133 InnerWidth, Length, _Location, Locationbar, Name, _Navigator, _Konqueror, ClientInformation,
134 Menubar, OffscreenBuffering, Opener, OuterHeight, OuterWidth, PageXOffset, PageYOffset,
135 Parent, Personalbar, ScreenX, ScreenY, Scrollbars, Scroll, ScrollBy,
136 ScreenTop, ScreenLeft,
137 ScrollTo, ScrollX, ScrollY, MoveBy, MoveTo, ResizeBy, ResizeTo, Self, _Window, Top, _Screen,
138 Image, Option, Alert, Confirm, Prompt, Open, Print, SetTimeout, ClearTimeout,
139 Focus, GetSelection, Blur, Close, SetInterval, ClearInterval, CaptureEvents,
140 ReleaseEvents, AddEventListener, RemoveEventListener, XMLHttpRequest, XMLSerializer,
141 Onabort, Onblur, Onchange, Onclick, Ondblclick, Ondragdrop, Onerror,
142 Onfocus, Onkeydown, Onkeypress, Onkeyup, Onload, Onmousedown, Onmousemove,
143 Onmouseout, Onmouseover, Onmouseup, OnWindowMouseWheel, Onmove, Onreset, Onresize, Onscroll, Onsearch,
144 Onselect, Onsubmit, Onunload,
145 Statusbar, Toolbar, FrameElement };
147 Value getListener(ExecState *exec, int eventId) const;
148 void setListener(ExecState *exec, int eventId, Value func);
150 void updateLayout(bool ignoreStylesheets = true) const;
152 QGuardedPtr<KHTMLPart> m_part;
157 Selection *m_selection;
158 BarInfo *m_locationbar;
160 BarInfo *m_personalbar;
161 BarInfo *m_scrollbars;
162 BarInfo *m_statusbar;
169 * An action (either function or string) to be executed after a specified
170 * time interval, either once or repeatedly. Used for window.setTimeout()
171 * and window.setInterval()
173 class ScheduledAction {
175 ScheduledAction(Object _func, List _args, bool _singleShot);
176 ScheduledAction(const QString &_code, bool _singleShot);
178 void execute(Window *window);
180 ProtectedObject func;
187 class WindowQObject : public QObject {
190 WindowQObject(Window *w);
192 int installTimeout(const UString &handler, int t, bool singleShot);
193 int installTimeout(const Value &func, List args, int t, bool singleShot);
194 void clearTimeout(int timerId, bool delAction = true);
197 QMap<int, ScheduledAction*> *WindowQObject::pauseTimeouts(const void *key);
198 void WindowQObject::resumeTimeouts(QMap<int, ScheduledAction*> *sa, const void *key);
204 void parentDestroyed();
206 void timerEvent(QTimerEvent *e);
209 KHTMLPart *part; // not guarded, may be dangling
210 QMap<int, ScheduledAction*> scheduledActions;
213 class Location : public ObjectImp {
216 virtual Value get(ExecState *exec, const Identifier &propertyName) const;
217 virtual void put(ExecState *exec, const Identifier &propertyName, const Value &value, int attr = None);
218 virtual Value toPrimitive(ExecState *exec, Type preferred) const;
219 virtual UString toString(ExecState *exec) const;
220 enum { Hash, Href, Hostname, Host, Pathname, Port, Protocol, Search, EqualEqual,
221 Replace, Reload, ToString };
222 KHTMLPart *part() const { return m_part; }
223 virtual const ClassInfo* classInfo() const { return &info; }
224 static const ClassInfo info;
227 Location(KHTMLPart *p);
228 QGuardedPtr<KHTMLPart> m_part;
231 class Selection : public ObjectImp {
234 virtual Value get(ExecState *exec, const Identifier &propertyName) const;
235 virtual void put(ExecState *exec, const Identifier &propertyName, const Value &value, int attr = None);
236 virtual Value toPrimitive(ExecState *exec, Type preferred) const;
237 virtual UString toString(ExecState *exec) const;
238 enum { AnchorNode, AnchorOffset, FocusNode, FocusOffset, BaseNode, BaseOffset, ExtentNode, ExtentOffset,
239 IsCollapsed, _Type, EqualEqual, Collapse, CollapseToEnd, CollapseToStart, Empty, ToString,
240 SetBaseAndExtent, SetPosition, Modify };
241 KHTMLPart *part() const { return m_part; }
242 virtual const ClassInfo* classInfo() const { return &info; }
243 static const ClassInfo info;
246 Selection(KHTMLPart *p);
247 QGuardedPtr<KHTMLPart> m_part;
250 class BarInfo : public ObjectImp {
253 virtual Value get(ExecState *exec, const Identifier &propertyName) const;
254 virtual void put(ExecState *exec, const Identifier &propertyName, const Value &value, int attr = None);
256 enum Type { Locationbar, Menubar, Personalbar, Scrollbars, Statusbar, Toolbar };
257 KHTMLPart *part() const { return m_part; }
258 virtual const ClassInfo* classInfo() const { return &info; }
259 static const ClassInfo info;
262 BarInfo(ExecState *exec, KHTMLPart *p, Type barType);
263 QGuardedPtr<KHTMLPart> m_part;
268 class Konqueror : public ObjectImp {
269 friend class KonquerorFunc;
271 Konqueror(KHTMLPart *p) : part(p) { }
272 virtual Value get(ExecState *exec, const Identifier &propertyName) const;
273 virtual bool hasProperty(ExecState *exec, const Identifier &p) const;
274 virtual UString toString(ExecState *exec) const;
275 virtual const ClassInfo* classInfo() const { return &info; }
276 static const ClassInfo info;