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 lastModified() const;
00707 
00711   void preloadStyleSheet(const QString &url, const QString &stylesheet);
00712 
00716   void preloadScript(const QString &url, const QString &script);
00717 
00721   bool restored() const;
00722 
00723 signals:
00727   void onURL( const QString &url );
00728 
00732   void popupMenu(const QString &url, const QPoint &point);
00733 
00737   void selectionChanged();
00738 
00746   void nodeActivated(const DOM::Node &);
00747 
00750   void docCreated();
00751 
00752 protected:
00753 
00758   KURL completeURL( const QString &url );
00759 
00766   void htmlError(int errorCode, const QString& text, const KURL& reqUrl);
00767 
00768   virtual void customEvent( QCustomEvent *event );
00769 
00773   virtual void khtmlMousePressEvent( khtml::MousePressEvent *event );
00777   virtual void khtmlMouseDoubleClickEvent( khtml::MouseDoubleClickEvent * );
00781   virtual void khtmlMouseMoveEvent( khtml::MouseMoveEvent *event );
00785   virtual void khtmlMouseReleaseEvent( khtml::MouseReleaseEvent *event );
00789   virtual void khtmlDrawContentsEvent( khtml::DrawContentsEvent * );
00790 
00794   virtual void guiActivateEvent( KParts::GUIActivateEvent *event );
00795 
00799   virtual bool openFile();
00800 
00801   virtual void urlSelected( const QString &url, int button, int state,
00802                             const QString &_target, KParts::URLArgs args = KParts::URLArgs());
00803 
00812   virtual KParts::ReadOnlyPart *createPart( QWidget *parentWidget, const char *widgetName,
00813                                             QObject *parent, const char *name,
00814                                             const QString &mimetype, QString &serviceName,
00815                                             QStringList &serviceTypes, const QStringList &params);
00816 
00817   // This is for RenderPartObject. We want to ask the 'download plugin?'
00818   // question only once per mimetype
00819   bool pluginPageQuestionAsked(const QString& mimetype) const;
00820   void setPluginPageQuestionAsked(const QString& mimetype);
00821 
00822 public slots:
00823 
00833   void setActiveNode(const DOM::Node &node);
00834 
00838   void stopAnimations();
00839 
00840   QCString dcopObjectId() const;
00841 
00842 private slots:
00843 
00847   void reparseConfiguration();
00848 
00852   void slotData( KIO::Job*, const QByteArray &data );
00856   void slotInfoMessage( KIO::Job*, const QString& msg );
00860   void slotRestoreData( const QByteArray &data );
00864   void slotFinished( KIO::Job* );
00868   void slotFinishedParsing();
00872   void slotRedirect();
00876   void slotRedirection(KIO::Job*, const KURL&);
00880   void slotDebugDOMTree();
00884   void slotDebugRenderTree();
00888   virtual void slotViewDocumentSource();
00892   virtual void slotViewFrameSource();
00896   void slotViewPageInfo();
00900   virtual void slotSaveBackground();
00904   virtual void slotSaveDocument();
00908   virtual void slotSaveFrame();
00912   virtual void slotSecurity();
00916   virtual void slotSetEncoding();
00917 
00921   virtual void slotUseStylesheet();
00922 
00923   virtual void slotFind();
00924   virtual void slotFindDone(); // ### remove me
00925   virtual void slotFindDialogDestroyed();
00926   void slotFindNext();
00927 
00928   void slotIncZoom();
00929   void slotDecZoom();
00930 
00931   void slotLoadImages();
00932 
00936   void submitFormAgain();
00937 
00941   void updateActions();
00945   void slotPartRemoved( KParts::Part *part );
00949   void slotActiveFrameChanged( KParts::Part *part );
00953   void slotChildStarted( KIO::Job *job );
00957   void slotChildCompleted();
00961   void slotChildCompleted( bool );
00965   void slotParentCompleted();
00969   void slotChildURLRequest( const KURL &url, const KParts::URLArgs &args );
00973   void slotChildDocCreated();
00974 
00975   void slotLoaderRequestStarted( khtml::DocLoader*, khtml::CachedObject* obj);
00976   void slotLoaderRequestDone( khtml::DocLoader*, khtml::CachedObject *obj );
00977   void checkCompleted();
00978 
00982   void slotShowDocument( const QString &url, const QString &target );
00983 
00987   void slotAutoScroll();
00988 
00989   void slotPrintFrame();
00990 
00991   void slotSelectAll();
00992 
00996   void slotProgressUpdate();
00997 
00998   /*
00999    * @internal
01000    */
01001   void slotJobPercent(KIO::Job*, unsigned long);
01002 
01003   /*
01004    * @internal
01005    */
01006   void slotJobDone(KIO::Job*);
01007 
01008   /*
01009    * @internal
01010    */
01011   void slotJobSpeed(KIO::Job*, unsigned long);
01012 
01016   void slotClearSelection();
01017 
01021   void slotZoomView( int );
01022 
01026   void slotHighlight( const QString &, int index, int length );
01027 
01028 private:
01029 
01030   enum StatusBarPriority { BarDefaultText, BarHoverText, BarOverrideText };
01031   void setStatusBarText( const QString& text, StatusBarPriority p);
01032 
01036   bool restoreURL( const KURL &url );
01037 
01041   void emitSelectionChanged();
01042 
01046   bool openURLInFrame( const KURL &url, const KParts::URLArgs &urlArgs );
01047 
01048   void startAutoScroll();
01049   void stopAutoScroll();
01050   void overURL( const QString &url, const QString &target, bool shiftPressed = false );
01051 
01055   bool processObjectRequest( khtml::ChildFrame *child, const KURL &url, const QString &mimetype );
01056 
01060   void submitForm( const char *action, const QString &url, const QByteArray &formData,
01061                    const QString &target, const QString& contentType = QString::null,
01062                    const QString& boundary = QString::null );
01063 
01067   void popupMenu( const QString &url );
01068 
01069   void init( KHTMLView *view, GUIProfile prof );
01070 
01071   void clear();
01072 
01073   bool scheduleScript( const DOM::Node &n, const QString& script);
01074 
01075   QVariant executeScheduledScript();
01076 
01077   bool requestFrame( khtml::RenderPart *frame, const QString &url, const QString &frameName,
01078                      const QStringList &args = QStringList(), bool isIFrame = false );
01079 
01087   QString requestFrameName();
01088 
01089   bool requestObject( khtml::RenderPart *frame, const QString &url, const QString &serviceType,
01090                       const QStringList &args = QStringList() );
01091 
01092   bool requestObject( khtml::ChildFrame *child, const KURL &url, const KParts::URLArgs &args = KParts::URLArgs() );
01093 
01094   DOM::EventListener *createHTMLEventListener( QString code );
01095 
01096   DOM::HTMLDocumentImpl *docImpl() const;
01097   DOM::DocumentImpl *xmlDocImpl() const;
01098   khtml::ChildFrame *frame( const QObject *obj );
01099 
01100   khtml::ChildFrame *recursiveFrameRequest( const KURL &url, const KParts::URLArgs &args, bool callParent = true );
01101 
01102   bool checkLinkSecurity(const KURL &linkURL,const QString &message = QString::null, const QString &button = QString::null);
01103   QVariant executeScript(QString filename, int baseLine, const DOM::Node &n, const QString &script);
01104 
01105   KJSProxy *jScript();
01106 
01107   KHTMLPart *opener();
01108   long cacheId() const;
01109   void setOpener(KHTMLPart *_opener);
01110   bool openedByJS();
01111   void setOpenedByJS(bool _openedByJS);
01112 
01113   void checkEmitLoadEvent();
01114   void emitLoadEvent();
01115 
01116   bool initFindNode( bool selection, bool reverse );
01117   void findText();
01118   void findTextNext();
01119   void extendSelection( DOM::NodeImpl* node, long offset, DOM::Node& selectionNode, long& selectionOffset, bool right, bool paragraph );
01120 
01121   KHTMLPartPrivate *d;
01122   friend class KHTMLPartPrivate;
01123 };
01124 
01125 
01126 #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 Mon Feb 24 15:07:57 2003 by doxygen 1.2.18 written by Dimitri van Heesch, © 1997-2001