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