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            MutationEventCtor, KeyboardEventCtor, EventExceptionCtor,
00148            ElementCtor, DocumentCtor, HTMLElementCtor, HTMLDocumentCtor,
00149            CSSStyleDeclarationCtor};
00150     WindowQObject *winq;
00151 
00152     void forgetSuppressedWindows();
00153     void showSuppressedWindows();
00154 
00155   protected:
00156     enum DelayedActionId { NullAction, DelayedClose, DelayedGoHistory };
00157 
00158     Value getListener(ExecState *exec, int eventId) const;
00159     void setListener(ExecState *exec, int eventId, Value func);
00160   private:
00161     struct DelayedAction;
00162     friend struct DelayedAction;
00163 
00164     bool checkIsSafeScript( KParts::ReadOnlyPart* activePart ) const;
00165 
00166     QGuardedPtr<khtml::ChildFrame> m_frame;
00167     Screen *screen;
00168     History *history;
00169     External *external;
00170     FrameArray *m_frames;
00171     Location *loc;
00172     DOM::Event *m_evt;
00173 
00174     struct DelayedAction {
00175       DelayedAction() : actionId(NullAction) {} // for QValueList
00176       DelayedAction( DelayedActionId id, QVariant p = QVariant() ) : actionId(id), param(p) {}
00177       DelayedActionId actionId;
00178       QVariant param; // just in case
00179     };
00180     QValueList<DelayedAction> m_delayed;
00181 
00182     struct SuppressedWindowInfo {
00183       SuppressedWindowInfo() {}  // for QValueList
00184       SuppressedWindowInfo( KURL u, QString fr, QString fe ) : url(u), frameName(fr), features(fe) {}
00185       KURL url;
00186       QString frameName;
00187       QString features;
00188     };
00189     QValueList<SuppressedWindowInfo> m_suppressedWindowInfo;
00190   };
00191 
00195   class DateTimeMS
00196   {
00197     QDate mDate;
00198     QTime mTime;
00199   public:
00200     DateTimeMS addMSecs(int s) const;
00201     bool operator >(const DateTimeMS &other) const;
00202     bool operator >=(const DateTimeMS &other) const;
00203     
00204     int msecsTo(const DateTimeMS &other) const;
00205     
00206     static DateTimeMS now();
00207   };
00208 
00214   class ScheduledAction {
00215   public:
00216     ScheduledAction(Object _func, List _args, DateTimeMS _nextTime, int _interval, bool _singleShot, int _timerId);
00217     ScheduledAction(QString _code, DateTimeMS _nextTime, int _interval, bool _singleShot, int _timerId);
00218     ~ScheduledAction();
00219     bool execute(Window *window);
00220     void mark();
00221 
00222     ObjectImp *func;
00223     List args;
00224     QString code;
00225     bool isFunction;
00226     bool singleShot;
00227 
00228     DateTimeMS nextTime;
00229     int interval;
00230     bool executing;
00231     int timerId;
00232   };
00233 
00234   class KDE_EXPORT WindowQObject : public QObject {
00235     Q_OBJECT
00236   public:
00237     WindowQObject(Window *w);
00238     ~WindowQObject();
00239     int installTimeout(const Identifier &handler, int t, bool singleShot);
00240     int installTimeout(const Value &func, List args, int t, bool singleShot);
00241     void clearTimeout(int timerId);
00242     void mark();
00243     bool hasTimers() const;
00244   public slots:
00245     void timeoutClose();
00246   protected slots:
00247     void parentDestroyed();
00248   protected:
00249     void timerEvent(QTimerEvent *e);
00250     void setNextTimer();
00251   private:
00252     Window *parent;
00253     QPtrList<ScheduledAction> scheduledActions;
00254     int pausedTime;
00255     int lastTimerId;
00256     bool currentlyDispatching;
00257   };
00258 
00259   class Location : public ObjectImp {
00260   public:
00261     ~Location();
00262     virtual Value get(ExecState *exec, const Identifier &propertyName) const;
00263     virtual void put(ExecState *exec, const Identifier &propertyName, const Value &value, int attr = None);
00264     virtual Value toPrimitive(ExecState *exec, Type preferred) const;
00265     virtual UString toString(ExecState *exec) const;
00266     enum { Hash, Href, Hostname, Host, Pathname, Port, Protocol, Search, EqualEqual,
00267            Assign, Replace, Reload, ToString };
00268     KParts::ReadOnlyPart *part() const;
00269     virtual const ClassInfo* classInfo() const { return &info; }
00270     static const ClassInfo info;
00271   private:
00272     friend class Window;
00273     Location(khtml::ChildFrame *f);
00274     QGuardedPtr<khtml::ChildFrame> m_frame;
00275   };
00276 
00277 #ifdef Q_WS_QWS
00278   class Konqueror : public ObjectImp {
00279     friend class KonquerorFunc;
00280   public:
00281     Konqueror(KHTMLPart *p) : part(p) { }
00282     virtual Value get(ExecState *exec, const Identifier &propertyName) const;
00283     virtual bool hasProperty(ExecState *exec, const Identifier &p) const;
00284     virtual UString toString(ExecState *exec) const;
00285     virtual const ClassInfo* classInfo() const { return &info; }
00286     static const ClassInfo info;
00287   private:
00288     KHTMLPart *part;
00289   };
00290 #endif
00291 
00292 } // namespace
00293 
00294 #endif
KDE Home | KDE Accessibility Home | Description of Access Keys