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;
00247   KParts::BrowserHostExtension *browserHostExtension() const;
00248   
00252   KHTMLView *view() const;
00253 
00260   void setJScriptEnabled( bool enable );
00261 
00266   bool jScriptEnabled() const;
00267 
00271   void setMetaRefreshEnabled( bool enable );
00272 
00276   bool metaRefreshEnabled() const;
00277 
00285   QVariant executeScript( const QString &script );
00289   QVariant executeScript( const DOM::Node &n, const QString &script );
00290 
00295   void setDNDEnabled( bool b );
00299   bool dndEnabled() const;
00300 
00307   void setJavaEnabled( bool enable );
00308 
00312   bool javaEnabled() const;
00313 
00317   KJavaAppletContext *javaContext();
00318 
00323   KJavaAppletContext *createJavaContext();
00324 
00328   void setPluginsEnabled( bool enable );
00329 
00333   bool pluginsEnabled() const;
00334 
00341   void setAutoloadImages( bool enable );
00348   bool autoloadImages() const;
00349 
00357   void setOnlyLocalReferences(bool enable);
00358 
00362   bool onlyLocalReferences() const;
00363 
00364 #ifndef KDE_NO_COMPAT
00365   void enableJScript(bool e) { setJScriptEnabled(e); }
00366   void enableJava(bool e) { setJavaEnabled(e); }
00367   void enablePlugins(bool e) { setPluginsEnabled(e); }
00368   void autoloadImages(bool e) { setAutoloadImages(e); }
00369   void enableMetaRefresh(bool e) { setMetaRefreshEnabled(e); }
00370   bool setCharset( const QString &, bool ) { return true; }
00371 
00372   KURL baseURL() const;
00373   QString baseTarget() const;
00374 #endif
00375 
00379   KURL backgroundURL() const;
00380 
00384   void scheduleRedirection( int delay, const QString &url, bool lockHistory = true );
00385 
00408   virtual void begin( const KURL &url = KURL(), int xOffset = 0, int yOffset = 0 );
00409 
00430   virtual void write( const char *str, int len = -1 );
00431 
00439   virtual void write( const QString &str );
00440 
00444   virtual void end();
00445 
00446   /*
00447    * Prints the current HTML page layed out for the printer.
00448    *
00449    * (not implemented at the moment)
00450    */
00451   //    void print(QPainter *, int pageHeight, int pageWidth);
00452 
00456   void paint(QPainter *, const QRect &, int = 0, bool * = 0);
00457 
00464   bool setEncoding( const QString &name, bool override = false );
00465 
00471   QString encoding() const;
00472 
00480   void setUserStyleSheet(const KURL &url);
00481 
00489   void setUserStyleSheet(const QString &styleSheet);
00490 
00491 public:
00492 
00498   void setStandardFont( const QString &name );
00499 
00506   void setFixedFont( const QString &name );
00507 
00515   bool gotoAnchor( const QString &name );
00516 
00520   void setURLCursor( const QCursor &c );
00521 
00525   QCursor urlCursor() const;
00526 
00530   void findTextBegin();
00531 
00536   bool findTextNext( const QString &str, bool forward, bool caseSensitive, bool isRegExp );
00537 
00548   void setZoomFactor(int percent);
00549 
00553   int zoomFactor() const;
00554 
00558   virtual QString selectedText() const;
00559 
00563   DOM::Range selection() const;
00564 
00568   void setSelection( const DOM::Range & );
00569 
00578   bool hasSelection() const;
00579 
00583   void selectAll();
00584 
00590   void show();
00591 
00597   void hide();
00598 
00603   KParts::PartManager *partManager();
00604 
00612   virtual void saveState( QDataStream &stream );
00622   virtual void restoreState( QDataStream &stream );
00623 
00627   DOM::Node nodeUnderMouse() const;
00628 
00632   const KHTMLSettings *settings() const;
00633 
00640   KHTMLPart *parentPart();
00641 
00647   QStringList frameNames() const;
00648 
00649   QPtrList<KParts::ReadOnlyPart> frames() const;
00650 
00654   KHTMLPart *findFrame( const QString &f );
00655 
00664   KHTMLPart *findFrameParent( KParts::ReadOnlyPart *callingPart, const QString &f, khtml::ChildFrame **childFrame=0 );
00665 
00671   KParts::ReadOnlyPart *currentFrame() const;
00672 
00679   bool frameExists( const QString &frameName );
00680 
00681 
00687   void setJSStatusBarText( const QString &text );
00688 
00694   void setJSDefaultStatusBarText( const QString &text );
00695 
00701   QString jsStatusBarText() const;
00702 
00708   QString jsDefaultStatusBarText() const;
00709 
00713   QString referrer() const;
00714 
00718   QString pageReferrer() const;
00719 
00723   QString lastModified() const;
00724 
00728   void preloadStyleSheet(const QString &url, const QString &stylesheet);
00729 
00733   void preloadScript(const QString &url, const QString &script);
00734 
00738   bool restored() const;
00739 
00740 signals:
00744   void onURL( const QString &url );
00745 
00749   void popupMenu(const QString &url, const QPoint &point);
00750 
00754   void selectionChanged();
00755 
00763   void nodeActivated(const DOM::Node &);
00764 
00767   void docCreated();
00768 
00769 protected:
00770 
00775   KURL completeURL( const QString &url );
00776 
00783   void htmlError(int errorCode, const QString& text, const KURL& reqUrl);
00784 
00785   virtual void customEvent( QCustomEvent *event );
00786 
00790   virtual void khtmlMousePressEvent( khtml::MousePressEvent *event );
00794   virtual void khtmlMouseDoubleClickEvent( khtml::MouseDoubleClickEvent * );
00798   virtual void khtmlMouseMoveEvent( khtml::MouseMoveEvent *event );
00802   virtual void khtmlMouseReleaseEvent( khtml::MouseReleaseEvent *event );
00806   virtual void khtmlDrawContentsEvent( khtml::DrawContentsEvent * );
00807 
00811   virtual void guiActivateEvent( KParts::GUIActivateEvent *event );
00812 
00816   virtual bool openFile();
00817 
00818   virtual void urlSelected( const QString &url, int button, int state,
00819                             const QString &_target, KParts::URLArgs args = KParts::URLArgs());
00820 
00829   virtual KParts::ReadOnlyPart *createPart( QWidget *parentWidget, const char *widgetName,
00830                                             QObject *parent, const char *name,
00831                                             const QString &mimetype, QString &serviceName,
00832                                             QStringList &serviceTypes, const QStringList &params);
00833 
00834   // This is for RenderPartObject. We want to ask the 'download plugin?'
00835   // question only once per mimetype
00836   bool pluginPageQuestionAsked(const QString& mimetype) const;
00837   void setPluginPageQuestionAsked(const QString& mimetype);
00838 
00839 public slots:
00840 
00850   void setActiveNode(const DOM::Node &node);
00851 
00855   void stopAnimations();
00856 
00857   QCString dcopObjectId() const;
00858 
00859 private slots:
00860 
00864   void reparseConfiguration();
00865 
00869   void slotData( KIO::Job*, const QByteArray &data );
00873   void slotInfoMessage( KIO::Job*, const QString& msg );
00877   void slotRestoreData( const QByteArray &data );
00881   void slotFinished( KIO::Job* );
00885   void slotFinishedParsing();
00889   void slotRedirect();
00893   void slotRedirection(KIO::Job*, const KURL&);
00897   void slotDebugDOMTree();
00901   void slotDebugRenderTree();
00905   virtual void slotViewDocumentSource();
00909   virtual void slotViewFrameSource();
00913   void slotViewPageInfo();
00917   virtual void slotSaveBackground();
00921   virtual void slotSaveDocument();
00925   virtual void slotSaveFrame();
00929   virtual void slotSecurity();
00933   virtual void slotSetEncoding();
00934 
00938   virtual void slotUseStylesheet();
00939 
00940   virtual void slotFind();
00941   virtual void slotFindDone(); // ### remove me
00942   virtual void slotFindDialogDestroyed();
00943   void slotFindNext();
00944 
00945   void slotIncZoom();
00946   void slotDecZoom();
00947 
00948   void slotLoadImages();
00949 
00953   void submitFormAgain();
00954 
00958   void updateActions();
00962   void slotPartRemoved( KParts::Part *part );
00966   void slotActiveFrameChanged( KParts::Part *part );
00970   void slotChildStarted( KIO::Job *job );
00974   void slotChildCompleted();
00978   void slotChildCompleted( bool );
00982   void slotParentCompleted();
00986   void slotChildURLRequest( const KURL &url, const KParts::URLArgs &args );
00990   void slotChildDocCreated();
00991 
00992   void slotLoaderRequestStarted( khtml::DocLoader*, khtml::CachedObject* obj);
00993   void slotLoaderRequestDone( khtml::DocLoader*, khtml::CachedObject *obj );
00994   void checkCompleted();
00995 
00999   void slotShowDocument( const QString &url, const QString &target );
01000 
01004   void slotAutoScroll();
01005 
01006   void slotPrintFrame();
01007 
01008   void slotSelectAll();
01009 
01013   void slotProgressUpdate();
01014 
01015   /*
01016    * @internal
01017    */
01018   void slotJobPercent(KIO::Job*, unsigned long);
01019 
01020   /*
01021    * @internal
01022    */
01023   void slotJobDone(KIO::Job*);
01024 
01025   /*
01026    * @internal
01027    */
01028   void slotJobSpeed(KIO::Job*, unsigned long);
01029 
01033   void slotClearSelection();
01034 
01038   void slotZoomView( int );
01039 
01043   void slotHighlight( const QString &, int index, int length );
01044 
01045 private:
01046 
01047   enum StatusBarPriority { BarDefaultText, BarHoverText, BarOverrideText };
01048   void setStatusBarText( const QString& text, StatusBarPriority p);
01049 
01053   bool restoreURL( const KURL &url );
01054 
01058   void emitSelectionChanged();
01059 
01063   bool openURLInFrame( const KURL &url, const KParts::URLArgs &urlArgs );
01064   
01069   bool checkFrameAccess(KHTMLPart *callingHtmlPart);
01070 
01071   void startAutoScroll();
01072   void stopAutoScroll();
01073   void overURL( const QString &url, const QString &target, bool shiftPressed = false );
01074 
01078   bool processObjectRequest( khtml::ChildFrame *child, const KURL &url, const QString &mimetype );
01079 
01083   void submitForm( const char *action, const QString &url, const QByteArray &formData,
01084                    const QString &target, const QString& contentType = QString::null,
01085                    const QString& boundary = QString::null );
01086 
01090   void popupMenu( const QString &url );
01091 
01092   void init( KHTMLView *view, GUIProfile prof );
01093 
01094   void clear();
01095 
01096   bool scheduleScript( const DOM::Node &n, const QString& script);
01097 
01098   QVariant executeScheduledScript();
01099 
01100   bool requestFrame( khtml::RenderPart *frame, const QString &url, const QString &frameName,
01101                      const QStringList &args = QStringList(), bool isIFrame = false );
01102 
01110   QString requestFrameName();
01111 
01112   bool requestObject( khtml::RenderPart *frame, const QString &url, const QString &serviceType,
01113                       const QStringList &args = QStringList() );
01114 
01115   bool requestObject( khtml::ChildFrame *child, const KURL &url, const KParts::URLArgs &args = KParts::URLArgs() );
01116 
01117   DOM::EventListener *createHTMLEventListener( QString code );
01118 
01119   DOM::HTMLDocumentImpl *docImpl() const;
01120   DOM::DocumentImpl *xmlDocImpl() const;
01121   khtml::ChildFrame *frame( const QObject *obj );
01122 
01123   khtml::ChildFrame *recursiveFrameRequest( KHTMLPart *callingHtmlPart, const KURL &url, const KParts::URLArgs &args, bool callParent = true );
01124 
01125   bool checkLinkSecurity(const KURL &linkURL,const QString &message = QString::null, const QString &button = QString::null);
01126   QVariant executeScript(QString filename, int baseLine, const DOM::Node &n, const QString &script);
01127 
01128   KJSProxy *jScript();
01129 
01130   KHTMLPart *opener();
01131   long cacheId() const;
01132   void setOpener(KHTMLPart *_opener);
01133   bool openedByJS();
01134   void setOpenedByJS(bool _openedByJS);
01135 
01136   void checkEmitLoadEvent();
01137   void emitLoadEvent();
01138 
01139   bool initFindNode( bool selection, bool reverse );
01140   void findText();
01141   void findTextNext();
01142   void extendSelection( DOM::NodeImpl* node, long offset, DOM::Node& selectionNode, long& selectionOffset, bool right, bool paragraph );
01143 
01144   KHTMLPartPrivate *d;
01145   friend class KHTMLPartPrivate;
01146 };
01147 
01148 
01149 #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 Sun Feb 27 15:40:49 2005 by doxygen 1.2.18 written by Dimitri van Heesch, © 1997-2001