khtml Library API Documentation

kjs_window.h

00001 // -*- c-basic-offset: 2 -*-
00002 /*
00003  *  This file is part of the KDE libraries
00004  *  Copyright (C) 2000 Harri Porten (porten@kde.org)
00005  *  Copyright (C) 2003 Apple Computer, Inc.
00006  *
00007  *  This library is free software; you can redistribute it and/or
00008  *  modify it under the terms of the GNU Library General Public
00009  *  License as published by the Free Software Foundation; either
00010  *  version 2 of the License, or (at your option) any later version.
00011  *
00012  *  This library is distributed in the hope that it will be useful,
00013  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
00014  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00015  *  Library General Public License for more details.
00016  *
00017  *  You should have received a copy of the GNU Library General Public
00018  *  License along with this library; if not, write to the Free Software
00019  *  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
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 KJS {
00038 
00039   class WindowFunc;
00040   class WindowQObject;
00041   class Location;
00042   class History;
00043   class External;
00044   class FrameArray;
00045   class JSEventListener;
00046 
00047   class Screen : public ObjectImp {
00048   public:
00049     Screen(ExecState *exec);
00050     enum {
00051       Height, Width, ColorDepth, PixelDepth, AvailLeft, AvailTop, AvailHeight,
00052       AvailWidth
00053     };
00054     virtual Value get(ExecState *exec, const Identifier &propertyName) const;
00055     Value getValueProperty(ExecState *exec, int token) const;
00056   private:
00057     KHTMLView *view;
00058     virtual const ClassInfo* classInfo() const { return &info; }
00059     static const ClassInfo info;
00060   };
00061 
00062   class Window : public ObjectImp {
00063     friend QGuardedPtr<KHTMLPart> getInstance();
00064     friend class Location;
00065     friend class WindowFunc;
00066     friend class WindowQObject;
00067     friend class ScheduledAction;
00068   public:
00069     Window(KHTMLPart *p);
00070   public:
00071     ~Window();
00077     static Value retrieve(KHTMLPart *p);
00081     static Window *retrieveWindow(KHTMLPart *p);
00086     static Window *retrieveActive(ExecState *exec);
00087     QGuardedPtr<KHTMLPart> part() const { return m_part; }
00088     virtual void mark();
00089     virtual bool hasProperty(ExecState *exec, const Identifier &p) const;
00090     virtual Value get(ExecState *exec, const Identifier &propertyName) const;
00091     virtual void put(ExecState *exec, const Identifier &propertyName, const Value &value, int attr = None);
00092     virtual bool toBoolean(ExecState *exec) const;
00093     void scheduleClose();
00094     void closeNow();
00095     void delayedGoHistory(int steps);
00096     void goHistory(int steps);
00097     void goURL(ExecState* exec, const QString& url, bool lockHistory);
00098     Value openWindow(ExecState *exec, const List &args);
00099     void resizeTo(QWidget* tl, int width, int height);
00100     void afterScriptExecution();
00101     bool isSafeScript(ExecState *exec) const {
00102       KHTMLPart *activePart = static_cast<KJS::ScriptInterpreter *>(  exec->interpreter() )->part();
00103       if ( activePart == m_part ) return true;
00104       return checkIsSafeScript( activePart );
00105     }
00106     Location *location() const;
00107     ObjectImp* frames( ExecState* exec ) const;
00108     JSEventListener *getJSEventListener(const Value &val, bool html = false);
00109     void clear( ExecState *exec );
00110     virtual UString toString(ExecState *exec) const;
00111 
00112     // Set the current "event" object
00113     void setCurrentEvent( DOM::Event *evt );
00114 
00115     QPtrDict<JSEventListener> jsEventListeners;
00116     virtual const ClassInfo* classInfo() const { return &info; }
00117     static const ClassInfo info;
00118     enum { Closed, Crypto, DefaultStatus, Status, Document, Node, EventCtor, Range,
00119            NodeFilter, DOMException, CSSRule, Frames, _History, _External, Event, InnerHeight,
00120            InnerWidth, Length, _Location, Navigate, Name, _Navigator, _Konqueror, ClientInformation,
00121            OffscreenBuffering, Opener, OuterHeight, OuterWidth, PageXOffset, PageYOffset,
00122            Parent, Personalbar, ScreenX, ScreenY, Scrollbars, Scroll, ScrollBy,
00123            ScreenTop, ScreenLeft,
00124            ScrollTo, ScrollX, ScrollY, MoveBy, MoveTo, ResizeBy, ResizeTo, Self, _Window, Top, _Screen,
00125            Image, Option, Alert, Confirm, Prompt, Open, SetTimeout, ClearTimeout,
00126            Focus, Blur, Close, SetInterval, ClearInterval, CaptureEvents, ReleaseEvents,
00127            Print, AddEventListener, RemoveEventListener, SideBar,
00128            Onabort, Onblur,
00129            Onchange, Onclick, Ondblclick, Ondragdrop, Onerror, Onfocus,
00130            Onkeydown, Onkeypress, Onkeyup, Onload, Onmousedown, Onmousemove,
00131            Onmouseout, Onmouseover, Onmouseup, Onmove, Onreset, Onresize,
00132            Onselect, Onsubmit, Onunload };
00133     WindowQObject *winq;
00134   protected:
00135     enum DelayedActionId { NullAction, DelayedClose, DelayedGoHistory };
00136 
00137     Value getListener(ExecState *exec, int eventId) const;
00138     void setListener(ExecState *exec, int eventId, Value func);
00139   private:
00140     struct DelayedAction;
00141     friend struct DelayedAction;
00142 
00143     bool checkIsSafeScript( KHTMLPart* activePart ) const;
00144 
00145     QGuardedPtr<KHTMLPart> m_part;
00146     Screen *screen;
00147     History *history;
00148     External *external;
00149     FrameArray *m_frames;
00150     Location *loc;
00151     DOM::Event *m_evt;
00152 
00153     struct DelayedAction {
00154       DelayedAction() : actionId(NullAction) {} // for QValueList
00155       DelayedAction( DelayedActionId id, QVariant p = QVariant() ) : actionId(id), param(p) {}
00156       DelayedActionId actionId;
00157       QVariant param; // just in case
00158     };
00159     QValueList<DelayedAction> m_delayed;
00160   };
00161 
00167   class ScheduledAction {
00168   public:
00169     ScheduledAction(Object _func, List _args, QTime _nextTime, int _interval, bool _singleShot, int _timerId);
00170     ScheduledAction(QString _code, QTime _nextTime, int _interval, bool _singleShot, int _timerId);
00171     ~ScheduledAction();
00172     void execute(Window *window);
00173     void mark();
00174 
00175     ObjectImp *func;
00176     List args;
00177     QString code;
00178     bool isFunction;
00179     bool singleShot;
00180 
00181     QTime nextTime;
00182     int interval;
00183     bool executing;
00184     int timerId;
00185   };
00186 
00187   class WindowQObject : public QObject {
00188     Q_OBJECT
00189   public:
00190     WindowQObject(Window *w);
00191     ~WindowQObject();
00192     int installTimeout(const Identifier &handler, int t, bool singleShot);
00193     int installTimeout(const Value &func, List args, int t, bool singleShot);
00194     void clearTimeout(int timerId);
00195     void mark();
00196   public slots:
00197     void timeoutClose();
00198   protected slots:
00199     void parentDestroyed();
00200   protected:
00201     void timerEvent(QTimerEvent *e);
00202     void setNextTimer();
00203   private:
00204     Window *parent;
00205     KHTMLPart *part;        // not guarded, may be dangling
00206     QPtrList<ScheduledAction> scheduledActions;
00207     int pausedTime;
00208     int lastTimerId;
00209   };
00210 
00211   class Location : public ObjectImp {
00212   public:
00213     ~Location();
00214     virtual Value get(ExecState *exec, const Identifier &propertyName) const;
00215     virtual void put(ExecState *exec, const Identifier &propertyName, const Value &value, int attr = None);
00216     virtual Value toPrimitive(ExecState *exec, Type preferred) const;
00217     virtual UString toString(ExecState *exec) const;
00218     enum { Hash, Href, Hostname, Host, Pathname, Port, Protocol, Search, EqualEqual,
00219            Assign, Replace, Reload, ToString };
00220     KHTMLPart *part() const { return m_part; }
00221     virtual const ClassInfo* classInfo() const { return &info; }
00222     static const ClassInfo info;
00223   private:
00224     friend class Window;
00225     Location(KHTMLPart *p);
00226     QGuardedPtr<KHTMLPart> m_part;
00227   };
00228 
00229 #ifdef Q_WS_QWS
00230   class Konqueror : public ObjectImp {
00231     friend class KonquerorFunc;
00232   public:
00233     Konqueror(KHTMLPart *p) : part(p) { }
00234     virtual Value get(ExecState *exec, const Identifier &propertyName) const;
00235     virtual bool hasProperty(ExecState *exec, const Identifier &p) const;
00236     virtual UString toString(ExecState *exec) const;
00237     virtual const ClassInfo* classInfo() const { return &info; }
00238     static const ClassInfo info;
00239   private:
00240     KHTMLPart *part;
00241   };
00242 #endif
00243 
00244 } // namespace
00245 
00246 #endif
KDE Logo
This file is part of the documentation for khtml Library Version 3.2.0.
Documentation copyright © 1996-2004 the KDE developers.
Generated on Wed Feb 4 12:37:22 2004 by doxygen 1.2.18 written by Dimitri van Heesch, © 1997-2003