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   friend class KHTMLPartFunction;
00174 
00175   Q_PROPERTY( bool javaScriptEnabled READ jScriptEnabled WRITE setJScriptEnabled )
00176   Q_PROPERTY( bool javaEnabled READ javaEnabled WRITE setJavaEnabled )
00177   Q_PROPERTY( bool autoloadImages READ autoloadImages WRITE setAutoloadImages )
00178   Q_PROPERTY( bool dndEnabled READ dndEnabled WRITE setDNDEnabled )
00179   Q_PROPERTY( bool pluginsEnabled READ pluginsEnabled WRITE setPluginsEnabled )
00180   Q_PROPERTY( bool onlyLocalReferences READ onlyLocalReferences WRITE setOnlyLocalReferences )
00181   Q_PROPERTY( QCString dcopObjectId READ dcopObjectId )
00182 
00183 public:
00184   enum GUIProfile { DefaultGUI, BrowserViewGUI /* ... */ };
00185 
00198   KHTMLPart( QWidget *parentWidget = 0, const char *widgetname = 0,
00199              QObject *parent = 0, const char *name = 0, GUIProfile prof = DefaultGUI );
00200 
00201   KHTMLPart( KHTMLView *view, QObject *parent = 0, const char *name = 0, GUIProfile prof = DefaultGUI );
00202 
00206   virtual ~KHTMLPart();
00207 
00213   virtual bool openURL( const KURL &url );
00214 
00218   virtual bool closeURL();
00219 
00226   virtual void showError(KIO::Job* job);
00227 
00231   DOM::HTMLDocument htmlDocument() const;
00232 
00236   DOM::Document document() const;
00237 
00241   DOM::Node activeNode() const;
00242 
00246   KParts::BrowserExtension *browserExtension() const;
00247   KParts::LiveConnectExtension *liveConnectExtension( const khtml::RenderPart *) const;
00248   KParts::BrowserHostExtension *browserHostExtension() const;
00249   
00253   KHTMLView *view() const;
00254 
00261   void setJScriptEnabled( bool enable );
00262 
00267   bool jScriptEnabled() const;
00268 
00272   void setMetaRefreshEnabled( bool enable );
00273 
00277   bool metaRefreshEnabled() const;
00278 
00286   QVariant executeScript( const QString &script );
00290   QVariant executeScript( const DOM::Node &n, const QString &script );
00291 
00296   void setDNDEnabled( bool b );
00300   bool dndEnabled() const;
00301 
00308   void setJavaEnabled( bool enable );
00309 
00313   bool javaEnabled() const;
00314 
00318   KJavaAppletContext *javaContext();
00319 
00324   KJavaAppletContext *createJavaContext();
00325 
00329   void setPluginsEnabled( bool enable );
00330 
00334   bool pluginsEnabled() const;
00335 
00342   void setAutoloadImages( bool enable );
00349   bool autoloadImages() const;
00350 
00358   void setOnlyLocalReferences(bool enable);
00359 
00363   bool onlyLocalReferences() const;
00364 
00365 #ifndef KDE_NO_COMPAT
00366   void enableJScript(bool e) { setJScriptEnabled(e); }
00367   void enableJava(bool e) { setJavaEnabled(e); }
00368   void enablePlugins(bool e) { setPluginsEnabled(e); }
00369   void autoloadImages(bool e) { setAutoloadImages(e); }
00370   void enableMetaRefresh(bool e) { setMetaRefreshEnabled(e); }
00371   bool setCharset( const QString &, bool ) { return true; }
00372 
00373   KURL baseURL() const;
00374   QString baseTarget() const;
00375 #endif
00376 
00380   KURL backgroundURL() const;
00381 
00385   void scheduleRedirection( int delay, const QString &url, bool lockHistory = true );
00386 
00409   virtual void begin( const KURL &url = KURL(), int xOffset = 0, int yOffset = 0 );
00410 
00431   virtual void write( const char *str, int len = -1 );
00432 
00440   virtual void write( const QString &str );
00441 
00445   virtual void end();
00446 
00447   /*
00448    * Prints the current HTML page layed out for the printer.
00449    *
00450    * (not implemented at the moment)
00451    */
00452   //    void print(QPainter *, int pageHeight, int pageWidth);
00453 
00457   void paint(QPainter *, const QRect &, int = 0, bool * = 0);
00458 
00465   bool setEncoding( const QString &name, bool override = false );
00466 
00472   QString encoding() const;
00473 
00481   void setUserStyleSheet(const KURL &url);
00482 
00490   void setUserStyleSheet(const QString &styleSheet);
00491 
00492 public:
00493 
00499   void setStandardFont( const QString &name );
00500 
00507   void setFixedFont( const QString &name );
00508 
00516   bool gotoAnchor( const QString &name );
00517 
00521   void setURLCursor( const QCursor &c );
00522 
00526   QCursor urlCursor() const;
00527 
00531   void findTextBegin();
00532 
00537   bool findTextNext( const QString &str, bool forward, bool caseSensitive, bool isRegExp );
00538 
00549   void setZoomFactor(int percent);
00550 
00554   int zoomFactor() const;
00555 
00559   virtual QString selectedText() const;
00560 
00564   DOM::Range selection() const;
00565 
00569   void setSelection( const DOM::Range & );
00570 
00579   bool hasSelection() const;
00580 
00584   void selectAll();
00585 
00591   void show();
00592 
00598   void hide();
00599 
00604   KParts::PartManager *partManager();
00605 
00613   virtual void saveState( QDataStream &stream );
00623   virtual void restoreState( QDataStream &stream );
00624 
00628   DOM::Node nodeUnderMouse() const;
00629 
00633   const KHTMLSettings *settings() const;
00634 
00641   KHTMLPart *parentPart();
00642 
00648   QStringList frameNames() const;
00649 
00650   QPtrList<KParts::ReadOnlyPart> frames() const;
00651 
00655   KHTMLPart *findFrame( const QString &f );
00656 
00665   KHTMLPart *findFrameParent( KParts::ReadOnlyPart *callingPart, const QString &f, khtml::ChildFrame **childFrame=0 );
00666 
00672   KParts::ReadOnlyPart *currentFrame() const;
00673 
00680   bool frameExists( const QString &frameName );
00681 
00682 
00688   void setJSStatusBarText( const QString &text );
00689 
00695   void setJSDefaultStatusBarText( const QString &text );
00696 
00702   QString jsStatusBarText() const;
00703 
00709   QString jsDefaultStatusBarText() const;
00710 
00714   QString referrer() const;
00715 
00719   QString pageReferrer() const;
00720 
00724   QString lastModified() const;
00725 
00729   void preloadStyleSheet(const QString &url, const QString &stylesheet);
00730 
00734   void preloadScript(const QString &url, const QString &script);
00735 
00739   bool restored() const;
00740 
00741 signals:
00745   void onURL( const QString &url );
00746 
00750   void popupMenu(const QString &url, const QPoint &point);
00751 
00755   void selectionChanged();
00756 
00764   void nodeActivated(const DOM::Node &);
00765 
00768   void docCreated();
00769 
00770 protected:
00771 
00776   KURL completeURL( const QString &url );
00777 
00784   void htmlError(int errorCode, const QString& text, const KURL& reqUrl);
00785 
00786   virtual void customEvent( QCustomEvent *event );
00787 
00791   virtual void khtmlMousePressEvent( khtml::MousePressEvent *event );
00795   virtual void khtmlMouseDoubleClickEvent( khtml::MouseDoubleClickEvent * );
00799   virtual void khtmlMouseMoveEvent( khtml::MouseMoveEvent *event );
00803   virtual void khtmlMouseReleaseEvent( khtml::MouseReleaseEvent *event );
00807   virtual void khtmlDrawContentsEvent( khtml::DrawContentsEvent * );
00808 
00812   virtual void guiActivateEvent( KParts::GUIActivateEvent *event );
00813 
00817   virtual bool openFile();
00818 
00819   virtual void urlSelected( const QString &url, int button, int state,
00820                             const QString &_target, KParts::URLArgs args = KParts::URLArgs());
00821 
00830   virtual KParts::ReadOnlyPart *createPart( QWidget *parentWidget, const char *widgetName,
00831                                             QObject *parent, const char *name,
00832                                             const QString &mimetype, QString &serviceName,
00833                                             QStringList &serviceTypes, const QStringList &params);
00834 
00835   // This is for RenderPartObject. We want to ask the 'download plugin?'
00836   // question only once per mimetype
00837   bool pluginPageQuestionAsked(const QString& mimetype) const;
00838   void setPluginPageQuestionAsked(const QString& mimetype);
00839 
00840 public slots:
00841 
00851   void setActiveNode(const DOM::Node &node);
00852 
00856   void stopAnimations();
00857 
00858   QCString dcopObjectId() const;
00859 
00860 private slots:
00861 
00865   void reparseConfiguration();
00866 
00870   void slotData( KIO::Job*, const QByteArray &data );
00874   void slotInfoMessage( KIO::Job*, const QString& msg );
00878   void slotRestoreData( const QByteArray &data );
00882   void slotFinished( KIO::Job* );
00886   void slotFinishedParsing();
00890   void slotRedirect();
00894   void slotRedirection(KIO::Job*, const KURL&);
00898   void slotDebugDOMTree();
00902   void slotDebugRenderTree();
00906   virtual void slotViewDocumentSource();
00910   virtual void slotViewFrameSource();
00914   void slotViewPageInfo();
00918   virtual void slotSaveBackground();
00922   virtual void slotSaveDocument();
00926   virtual void slotSaveFrame();
00930   virtual void slotSecurity();
00934   virtual void slotSetEncoding();
00935 
00939   virtual void slotUseStylesheet();
00940 
00941   virtual void slotFind();
00942   virtual void slotFindDone(); // ### remove me
00943   virtual void slotFindDialogDestroyed();
00944   void slotFindNext();
00945 
00946   void slotIncZoom();
00947   void slotDecZoom();
00948 
00949   void slotLoadImages();
00950 
00954   void submitFormAgain();
00955 
00959   void updateActions();
00963   void slotPartRemoved( KParts::Part *part );
00967   void slotActiveFrameChanged( KParts::Part *part );
00971   void slotChildStarted( KIO::Job *job );
00975   void slotChildCompleted();
00979   void slotChildCompleted( bool );
00983   void slotParentCompleted();
00987   void slotChildURLRequest( const KURL &url, const KParts::URLArgs &args );
00991   void slotChildDocCreated();
00992 
00993   void slotLoaderRequestStarted( khtml::DocLoader*, khtml::CachedObject* obj);
00994   void slotLoaderRequestDone( khtml::DocLoader*, khtml::CachedObject *obj );
00995   void checkCompleted();
00996 
01000   void slotShowDocument( const QString &url, const QString &target );
01001 
01005   void slotAutoScroll();
01006 
01007   void slotPrintFrame();
01008 
01009   void slotSelectAll();
01010 
01014   void slotProgressUpdate();
01015 
01016   /*
01017    * @internal
01018    */
01019   void slotJobPercent(KIO::Job*, unsigned long);
01020 
01021   /*
01022    * @internal
01023    */
01024   void slotJobDone(KIO::Job*);
01025 
01026   /*
01027    * @internal
01028    */
01029   void slotJobSpeed(KIO::Job*, unsigned long);
01030 
01034   void slotClearSelection();
01035 
01039   void slotZoomView( int );
01040 
01044   void slotHighlight( const QString &, int index, int length );
01045 
01046 private:
01047 
01048   enum StatusBarPriority { BarDefaultText, BarHoverText, BarOverrideText };
01049   void setStatusBarText( const QString& text, StatusBarPriority p);
01050 
01054   bool restoreURL( const KURL &url );
01055 
01059   void emitSelectionChanged();
01060 
01064   bool openURLInFrame( const KURL &url, const KParts::URLArgs &urlArgs );
01065   
01070   bool checkFrameAccess(KHTMLPart *callingHtmlPart);
01071 
01072   void startAutoScroll();
01073   void stopAutoScroll();
01074   void overURL( const QString &url, const QString &target, bool shiftPressed = false );
01075 
01079   bool processObjectRequest( khtml::ChildFrame *child, const KURL &url, const QString &mimetype );
01080 
01084   void submitForm( const char *action, const QString &url, const QByteArray &formData,
01085                    const QString &target, const QString& contentType = QString::null,
01086                    const QString& boundary = QString::null );
01087 
01091   void popupMenu( const QString &url );
01092 
01093   void init( KHTMLView *view, GUIProfile prof );
01094 
01095   void clear();
01096 
01097   bool scheduleScript( const DOM::Node &n, const QString& script);
01098 
01099   QVariant executeScheduledScript();
01100 
01101   bool requestFrame( khtml::RenderPart *frame, const QString &url, const QString &frameName,
01102                      const QStringList &args = QStringList(), bool isIFrame = false );
01103 
01111   QString requestFrameName();
01112 
01113   bool requestObject( khtml::RenderPart *frame, const QString &url, const QString &serviceType,
01114                       const QStringList &args = QStringList() );
01115 
01116   bool requestObject( khtml::ChildFrame *child, const KURL &url, const KParts::URLArgs &args = KParts::URLArgs() );
01117 
01118   DOM::EventListener *createHTMLEventListener( QString code );
01119 
01120   DOM::HTMLDocumentImpl *docImpl() const;
01121   DOM::DocumentImpl *xmlDocImpl() const;
01122   khtml::ChildFrame *frame( const QObject *obj );
01123 
01124   khtml::ChildFrame *recursiveFrameRequest( KHTMLPart *callingHtmlPart, const KURL &url, const KParts::URLArgs &args, bool callParent = true );
01125 
01126   bool checkLinkSecurity(const KURL &linkURL,const QString &message = QString::null, const QString &button = QString::null);
01127   QVariant executeScript(QString filename, int baseLine, const DOM::Node &n, const QString &script);
01128 
01129   KJSProxy *jScript();
01130 
01131   KHTMLPart *opener();
01132   long cacheId() const;
01133   void setOpener(KHTMLPart *_opener);
01134   bool openedByJS();
01135   void setOpenedByJS(bool _openedByJS);
01136 
01137   void checkEmitLoadEvent();
01138   void emitLoadEvent();
01139 
01140   bool initFindNode( bool selection, bool reverse );
01141   void findText();
01142   void findTextNext();
01143   void extendSelection( DOM::NodeImpl* node, long offset, DOM::Node& selectionNode, long& selectionOffset, bool right, bool paragraph );
01144 
01145   KHTMLPartPrivate *d;
01146   friend class KHTMLPartPrivate;
01147 };
01148 
01149 
01150 #endif
KDE Logo
This file is part of the documentation for kdelibs Version 3.1.4.
Documentation copyright © 1996-2002 the KDE developers.
Generated on Sun Feb 27 22:16:37 2005 by doxygen 1.3.4 written by Dimitri van Heesch, © 1997-2001