khtml Library API Documentation

khtml_part.h

00001 // -*- c-basic-offset: 2 -*-
00002 /* This file is part of the KDE project
00003  *
00004  * Copyright (C) 1998, 1999 Torben Weis <weis@kde.org>
00005  *                     1999-2001 Lars Knoll <knoll@kde.org>
00006  *                     1999-2001 Antti Koivisto <koivisto@kde.org>
00007  *                     2000-2001 Simon Hausmann <hausmann@kde.org>
00008  *                     2000-2001 Dirk Mueller <mueller@kde.org>
00009  *                     2000 Stefan Schimanski <1Stein@gmx.de>
00010  *
00011  * This library is free software; you can redistribute it and/or
00012  * modify it under the terms of the GNU Library General Public
00013  * License as published by the Free Software Foundation; either
00014  * version 2 of the License, or (at your option) any later version.
00015  *
00016  * This library is distributed in the hope that it will be useful,
00017  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00018  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00019  * Library General Public License for more details.
00020  *
00021  * You should have received a copy of the GNU Library General Public License
00022  * along with this library; see the file COPYING.LIB.  If not, write to
00023  * the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
00024  * Boston, MA 02111-1307, USA.
00025  */
00026 #ifndef __khtml_part_h__
00027 #define __khtml_part_h__
00028 
00029 #include "dom/html_document.h"
00030 #include "dom/dom2_range.h"
00031 
00032 #include <kparts/part.h>
00033 #include <kparts/browserextension.h>
00034 
00035 #include <qregexp.h>
00036 
00037 class KHTMLPartPrivate;
00038 class KHTMLPartBrowserExtension;
00039 class KJSProxy;
00040 class KHTMLView;
00041 class KHTMLSettings;
00042 class KJavaAppletContext;
00043 
00044 namespace DOM
00045 {
00046   class HTMLDocument;
00047   class HTMLDocumentImpl;
00048   class DocumentImpl;
00049   class HTMLTitleElementImpl;
00050   class HTMLElementImpl;
00051   class HTMLFrameElementImpl;
00052   class HTMLIFrameElementImpl;
00053   class HTMLObjectElementImpl;
00054   class HTMLFormElementImpl;
00055   class HTMLAnchorElementImpl;
00056   class HTMLMetaElementImpl;
00057   class NodeImpl;
00058   class Node;
00059   class HTMLEventListener;
00060   class EventListener;
00061 };
00062 
00063 namespace khtml
00064 {
00065   class DocLoader;
00066   class RenderPart;
00067   class RenderPartObject;
00068   struct ChildFrame;
00069   class MouseEvent;
00070   class MousePressEvent;
00071   class MouseDoubleClickEvent;
00072   class MouseMoveEvent;
00073   class MouseReleaseEvent;
00074   class DrawContentsEvent;
00075   class CachedObject;
00076   class RenderWidget;
00077   class CSSStyleSelector;
00078   class HTMLTokenizer;
00079 };
00080 
00081 namespace KJS {
00082     class Window;
00083     class WindowFunc;
00084     class JSEventListener;
00085     class DOMDocument;
00086 };
00087 
00088 namespace KParts
00089 {
00090   class PartManager;
00091   class LiveConnectExtension;
00092 };
00093 
00145 class KHTMLPart : public KParts::ReadOnlyPart
00146 {
00147   Q_OBJECT
00148   friend class KHTMLView;
00149   friend class DOM::HTMLTitleElementImpl;
00150   friend class DOM::HTMLFrameElementImpl;
00151   friend class DOM::HTMLIFrameElementImpl;
00152   friend class DOM::HTMLObjectElementImpl;
00153   friend class DOM::HTMLAnchorElementImpl;
00154   friend class DOM::HTMLMetaElementImpl;
00155   friend class DOM::NodeImpl;
00156   friend class KHTMLRun;
00157   friend class DOM::HTMLFormElementImpl;
00158   friend class khtml::RenderPartObject;
00159   friend class KJS::Window;
00160   friend class KJS::WindowFunc;
00161   friend class KJS::JSEventListener;
00162   friend class KJS::DOMDocument;
00163   friend class KJSProxy;
00164   friend class KHTMLPartBrowserExtension;
00165   friend class DOM::DocumentImpl;
00166   friend class DOM::HTMLDocumentImpl;
00167   friend class KHTMLPartBrowserHostExtension;
00168   friend class khtml::HTMLTokenizer;
00169   friend class XMLTokenizer;
00170   friend class khtml::RenderWidget;
00171   friend class khtml::CSSStyleSelector;
00172   friend class KHTMLPartIface;
00173 
00174   Q_PROPERTY( bool javaScriptEnabled READ jScriptEnabled WRITE setJScriptEnabled )
00175   Q_PROPERTY( bool javaEnabled READ javaEnabled WRITE setJavaEnabled )
00176   Q_PROPERTY( bool autoloadImages READ autoloadImages WRITE setAutoloadImages )
00177   Q_PROPERTY( bool dndEnabled READ dndEnabled WRITE setDNDEnabled )
00178   Q_PROPERTY( bool pluginsEnabled READ pluginsEnabled WRITE setPluginsEnabled )
00179   Q_PROPERTY( bool onlyLocalReferences READ onlyLocalReferences WRITE setOnlyLocalReferences )
00180   Q_PROPERTY( QCString dcopObjectId READ dcopObjectId )
00181 
00182 public:
00183   enum GUIProfile { DefaultGUI, BrowserViewGUI /* ... */ };
00184 
00197   KHTMLPart( QWidget *parentWidget = 0, const char *widgetname = 0,
00198              QObject *parent = 0, const char *name = 0, GUIProfile prof = DefaultGUI );
00199 
00200   KHTMLPart( KHTMLView *view, QObject *parent = 0, const char *name = 0, GUIProfile prof = DefaultGUI );
00201 
00205   virtual ~KHTMLPart();
00206 
00212   virtual bool openURL( const KURL &url );
00213 
00217   virtual bool closeURL();
00218 
00225   virtual void showError(KIO::Job* job);
00226 
00230   DOM::HTMLDocument htmlDocument() const;
00231 
00235   DOM::Document document() const;
00236 
00240   DOM::Node activeNode() const;
00241 
00245   KParts::BrowserExtension *browserExtension() const;
00246   KParts::LiveConnectExtension *liveConnectExtension( const khtml::RenderPart *) const;
00250   KHTMLView *view() const;
00251 
00258   void setJScriptEnabled( bool enable );
00259 
00264   bool jScriptEnabled() const;
00265 
00269   void setMetaRefreshEnabled( bool enable );
00270 
00274   bool metaRefreshEnabled() const;
00275 
00283   QVariant executeScript( const QString &script );
00287   QVariant executeScript( const DOM::Node &n, const QString &script );
00288 
00293   void setDNDEnabled( bool b );
00297   bool dndEnabled() const;
00298 
00305   void setJavaEnabled( bool enable );
00306 
00310   bool javaEnabled() const;
00311 
00315   KJavaAppletContext *javaContext();
00316 
00321   KJavaAppletContext *createJavaContext();
00322 
00326   void setPluginsEnabled( bool enable );
00327 
00331   bool pluginsEnabled() const;
00332 
00339   void setAutoloadImages( bool enable );
00346   bool autoloadImages() const;
00347 
00355   void setOnlyLocalReferences(bool enable);
00356 
00360   bool onlyLocalReferences() const;
00361 
00362 #ifndef KDE_NO_COMPAT
00363   void enableJScript(bool e) { setJScriptEnabled(e); }
00364   void enableJava(bool e) { setJavaEnabled(e); }
00365   void enablePlugins(bool e) { setPluginsEnabled(e); }
00366   void autoloadImages(bool e) { setAutoloadImages(e); }
00367   void enableMetaRefresh(bool e) { setMetaRefreshEnabled(e); }
00368   bool setCharset( const QString &, bool ) { return true; }
00369 
00370   KURL baseURL() const;
00371   QString baseTarget() const;
00372 #endif
00373 
00377   KURL backgroundURL() const;
00378 
00382   void scheduleRedirection( int delay, const QString &url, bool lockHistory = true );
00383 
00406   virtual void begin( const KURL &url = KURL(), int xOffset = 0, int yOffset = 0 );
00407 
00428   virtual void write( const char *str, int len = -1 );
00429 
00437   virtual void write( const QString &str );
00438 
00442   virtual void end();
00443 
00444   /*
00445    * Prints the current HTML page layed out for the printer.
00446    *
00447    * (not implemented at the moment)
00448    */
00449   //    void print(QPainter *, int pageHeight, int pageWidth);
00450 
00454   void paint(QPainter *, const QRect &, int = 0, bool * = 0);
00455 
00462   bool setEncoding( const QString &name, bool override = false );
00463 
00469   QString encoding() const;
00470 
00478   void setUserStyleSheet(const KURL &url);
00479 
00487   void setUserStyleSheet(const QString &styleSheet);
00488 
00489 public:
00490 
00496   void setStandardFont( const QString &name );
00497 
00504   void setFixedFont( const QString &name );
00505 
00513   bool gotoAnchor( const QString &name );
00514 
00518   void setURLCursor( const QCursor &c );
00519 
00523   QCursor urlCursor() const;
00524 
00528   void findTextBegin();
00529 
00534   bool findTextNext( const QString &str, bool forward, bool caseSensitive, bool isRegExp );
00535 
00546   void setZoomFactor(int percent);
00547 
00551   int zoomFactor() const;
00552 
00556   virtual QString selectedText() const;
00557 
00561   DOM::Range selection() const;
00562 
00566   void setSelection( const DOM::Range & );
00567 
00576   bool hasSelection() const;
00577 
00581   void selectAll();
00582 
00588   void show();
00589 
00595   void hide();
00596 
00601   KParts::PartManager *partManager();
00602 
00610   virtual void saveState( QDataStream &stream );
00620   virtual void restoreState( QDataStream &stream );
00621 
00625   DOM::Node nodeUnderMouse() const;
00626 
00630   const KHTMLSettings *settings() const;
00631 
00638   KHTMLPart *parentPart();
00639 
00645   QStringList frameNames() const;
00646 
00647   QPtrList<KParts::ReadOnlyPart> frames() const;
00648 
00652   KHTMLPart *findFrame( const QString &f );
00653 
00659   KParts::ReadOnlyPart *currentFrame() const;
00660 
00667   bool frameExists( const QString &frameName );
00668 
00669 
00675   void setJSStatusBarText( const QString &text );
00676 
00682   void setJSDefaultStatusBarText( const QString &text );
00683 
00689   QString jsStatusBarText() const;
00690 
00696   QString jsDefaultStatusBarText() const;
00697 
00701   QString referrer() const;
00702 
00706   QString pageReferrer() const;
00707 
00711   QString lastModified() const;
00712 
00716   void preloadStyleSheet(const QString &url, const QString &stylesheet);
00717 
00721   void preloadScript(const QString &url, const QString &script);
00722 
00726   bool restored() const;
00727 
00728 signals:
00732   void onURL( const QString &url );
00733 
00737   void popupMenu(const QString &url, const QPoint &point);
00738 
00742   void selectionChanged();
00743 
00751   void nodeActivated(const DOM::Node &);
00752 
00755   void docCreated();
00756 
00757 protected:
00758 
00763   KURL completeURL( const QString &url );
00764 
00771   void htmlError(int errorCode, const QString& text, const KURL& reqUrl);
00772 
00773   virtual void customEvent( QCustomEvent *event );
00774 
00778   virtual void khtmlMousePressEvent( khtml::MousePressEvent *event );
00782   virtual void khtmlMouseDoubleClickEvent( khtml::MouseDoubleClickEvent * );
00786   virtual void khtmlMouseMoveEvent( khtml::MouseMoveEvent *event );
00790   virtual void khtmlMouseReleaseEvent( khtml::MouseReleaseEvent *event );
00794   virtual void khtmlDrawContentsEvent( khtml::DrawContentsEvent * );
00795 
00799   virtual void guiActivateEvent( KParts::GUIActivateEvent *event );
00800 
00804   virtual bool openFile();
00805 
00806   virtual void urlSelected( const QString &url, int button, int state,
00807                             const QString &_target, KParts::URLArgs args = KParts::URLArgs());
00808 
00817   virtual KParts::ReadOnlyPart *createPart( QWidget *parentWidget, const char *widgetName,
00818                                             QObject *parent, const char *name,
00819                                             const QString &mimetype, QString &serviceName,
00820                                             QStringList &serviceTypes, const QStringList &params);
00821 
00822   // This is for RenderPartObject. We want to ask the 'download plugin?'
00823   // question only once per mimetype
00824   bool pluginPageQuestionAsked(const QString& mimetype) const;
00825   void setPluginPageQuestionAsked(const QString& mimetype);
00826 
00827 public slots:
00828 
00838   void setActiveNode(const DOM::Node &node);
00839 
00843   void stopAnimations();
00844 
00845   QCString dcopObjectId() const;
00846 
00847 private slots:
00848 
00852   void reparseConfiguration();
00853 
00857   void slotData( KIO::Job*, const QByteArray &data );
00861   void slotInfoMessage( KIO::Job*, const QString& msg );
00865   void slotRestoreData( const QByteArray &data );
00869   void slotFinished( KIO::Job* );
00873   void slotFinishedParsing();
00877   void slotRedirect();
00881   void slotRedirection(KIO::Job*, const KURL&);
00885   void slotDebugDOMTree();
00889   void slotDebugRenderTree();
00893   virtual void slotViewDocumentSource();
00897   virtual void slotViewFrameSource();
00901   void slotViewPageInfo();
00905   virtual void slotSaveBackground();
00909   virtual void slotSaveDocument();
00913   virtual void slotSaveFrame();
00917   virtual void slotSecurity();
00921   virtual void slotSetEncoding();
00922 
00926   virtual void slotUseStylesheet();
00927 
00928   virtual void slotFind();
00929   virtual void slotFindDone(); // ### remove me
00930   virtual void slotFindDialogDestroyed();
00931   void slotFindNext();
00932 
00933   void slotIncZoom();
00934   void slotDecZoom();
00935 
00936   void slotLoadImages();
00937 
00941   void submitFormAgain();
00942 
00946   void updateActions();
00950   void slotPartRemoved( KParts::Part *part );
00954   void slotActiveFrameChanged( KParts::Part *part );
00958   void slotChildStarted( KIO::Job *job );
00962   void slotChildCompleted();
00966   void slotChildCompleted( bool );
00970   void slotParentCompleted();
00974   void slotChildURLRequest( const KURL &url, const KParts::URLArgs &args );
00978   void slotChildDocCreated();
00979 
00980   void slotLoaderRequestStarted( khtml::DocLoader*, khtml::CachedObject* obj);
00981   void slotLoaderRequestDone( khtml::DocLoader*, khtml::CachedObject *obj );
00982   void checkCompleted();
00983 
00987   void slotShowDocument( const QString &url, const QString &target );
00988 
00992   void slotAutoScroll();
00993 
00994   void slotPrintFrame();
00995 
00996   void slotSelectAll();
00997 
01001   void slotProgressUpdate();
01002 
01003   /*
01004    * @internal
01005    */
01006   void slotJobPercent(KIO::Job*, unsigned long);
01007 
01008   /*
01009    * @internal
01010    */
01011   void slotJobDone(KIO::Job*);
01012 
01013   /*
01014    * @internal
01015    */
01016   void slotJobSpeed(KIO::Job*, unsigned long);
01017 
01021   void slotClearSelection();
01022 
01026   void slotZoomView( int );
01027 
01031   void slotHighlight( const QString &, int index, int length );
01032 
01033 private:
01034 
01035   enum StatusBarPriority { BarDefaultText, BarHoverText, BarOverrideText };
01036   void setStatusBarText( const QString& text, StatusBarPriority p);
01037 
01041   bool restoreURL( const KURL &url );
01042 
01046   void emitSelectionChanged();
01047 
01051   bool openURLInFrame( const KURL &url, const KParts::URLArgs &urlArgs );
01052 
01053   void startAutoScroll();
01054   void stopAutoScroll();
01055   void overURL( const QString &url, const QString &target, bool shiftPressed = false );
01056 
01060   bool processObjectRequest( khtml::ChildFrame *child, const KURL &url, const QString &mimetype );
01061 
01065   void submitForm( const char *action, const QString &url, const QByteArray &formData,
01066                    const QString &target, const QString& contentType = QString::null,
01067                    const QString& boundary = QString::null );
01068 
01072   void popupMenu( const QString &url );
01073 
01074   void init( KHTMLView *view, GUIProfile prof );
01075 
01076   void clear();
01077 
01078   bool scheduleScript( const DOM::Node &n, const QString& script);
01079 
01080   QVariant executeScheduledScript();
01081 
01082   bool requestFrame( khtml::RenderPart *frame, const QString &url, const QString &frameName,
01083                      const QStringList &args = QStringList(), bool isIFrame = false );
01084 
01092   QString requestFrameName();
01093 
01094   bool requestObject( khtml::RenderPart *frame, const QString &url, const QString &serviceType,
01095                       const QStringList &args = QStringList() );
01096 
01097   bool requestObject( khtml::ChildFrame *child, const KURL &url, const KParts::URLArgs &args = KParts::URLArgs() );
01098 
01099   DOM::EventListener *createHTMLEventListener( QString code );
01100 
01101   DOM::HTMLDocumentImpl *docImpl() const;
01102   DOM::DocumentImpl *xmlDocImpl() const;
01103   khtml::ChildFrame *frame( const QObject *obj );
01104 
01105   khtml::ChildFrame *recursiveFrameRequest( const KURL &url, const KParts::URLArgs &args, bool callParent = true );
01106 
01107   bool checkLinkSecurity(const KURL &linkURL,const QString &message = QString::null, const QString &button = QString::null);
01108   QVariant executeScript(QString filename, int baseLine, const DOM::Node &n, const QString &script);
01109 
01110   KJSProxy *jScript();
01111 
01112   KHTMLPart *opener();
01113   long cacheId() const;
01114   void setOpener(KHTMLPart *_opener);
01115   bool openedByJS();
01116   void setOpenedByJS(bool _openedByJS);
01117 
01118   void checkEmitLoadEvent();
01119   void emitLoadEvent();
01120 
01121   bool initFindNode( bool selection, bool reverse );
01122   void findText();
01123   void findTextNext();
01124   void extendSelection( DOM::NodeImpl* node, long offset, DOM::Node& selectionNode, long& selectionOffset, bool right, bool paragraph );
01125 
01126   KHTMLPartPrivate *d;
01127   friend class KHTMLPartPrivate;
01128 };
01129 
01130 
01131 #endif
KDE Logo
This file is part of the documentation for kdelibs Version 3.1.0.
Documentation copyright © 1996-2002 the KDE developers.
Generated on Wed Oct 8 12:22:39 2003 by doxygen 1.2.18 written by Dimitri van Heesch, © 1997-2001