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 #include <kdemacros.h>
00035 
00036 #include <qregexp.h>
00037 
00038 class KHTMLPartPrivate;
00039 class KHTMLPartBrowserExtension;
00040 class KJSProxy;
00041 class KHTMLView;
00042 class KHTMLSettings;
00043 class KJavaAppletContext;
00044 class KJSErrorDlg;
00045 
00046 namespace DOM
00047 {
00048   class HTMLDocument;
00049   class HTMLDocumentImpl;
00050   class DocumentImpl;
00051   class HTMLTitleElementImpl;
00052   class HTMLElementImpl;
00053   class HTMLFrameElementImpl;
00054   class HTMLIFrameElementImpl;
00055   class HTMLObjectElementImpl;
00056   class HTMLFormElementImpl;
00057   class HTMLAnchorElementImpl;
00058   class HTMLMetaElementImpl;
00059   class NodeImpl;
00060   class Node;
00061   class HTMLEventListener;
00062   class EventListener;
00063 }
00064 
00065 namespace KJS
00066 {
00067   class Interpreter;
00068 }
00069 
00070 namespace khtml
00071 {
00072   class DocLoader;
00073   class RenderPart;
00074   class RenderPartObject;
00075   struct ChildFrame;
00076   class MouseEvent;
00077   class MousePressEvent;
00078   class MouseDoubleClickEvent;
00079   class MouseMoveEvent;
00080   class MouseReleaseEvent;
00081   class DrawContentsEvent;
00082   class CachedObject;
00083   class RenderWidget;
00084   class CSSStyleSelector;
00085   class HTMLTokenizer;
00086   class Decoder;
00087   class XMLTokenizer;
00088 }
00089 
00090 namespace KJS {
00091     class Window;
00092     class WindowFunc;
00093     class ExternalFunc;
00094     class JSEventListener;
00095     class JSNodeFilter;
00096     class DOMDocument;
00097     class SourceFile;
00098     class ScheduledAction;
00099 }
00100 
00101 namespace KParts
00102 {
00103   class PartManager;
00104   class LiveConnectExtension;
00105 }
00106 
00107 namespace KWallet
00108 {
00109   class Wallet;
00110 }
00111 
00183 class KHTMLPart : public KParts::ReadOnlyPart
00184 {
00185   Q_OBJECT
00186   friend class KHTMLView;
00187   friend class DOM::HTMLTitleElementImpl;
00188   friend class DOM::HTMLFrameElementImpl;
00189   friend class DOM::HTMLIFrameElementImpl;
00190   friend class DOM::HTMLObjectElementImpl;
00191   friend class DOM::HTMLAnchorElementImpl;
00192   friend class DOM::HTMLMetaElementImpl;
00193   friend class DOM::NodeImpl;
00194   friend class KHTMLRun;
00195   friend class DOM::HTMLFormElementImpl;
00196   friend class khtml::RenderPartObject;
00197   friend class KJS::Window;
00198   friend class KJS::ScheduledAction;
00199   friend class KJS::JSNodeFilter;
00200   friend class KJS::WindowFunc;
00201   friend class KJS::ExternalFunc;
00202   friend class KJS::JSEventListener;
00203   friend class KJS::DOMDocument;
00204   friend class KJS::SourceFile;
00205   friend class KJSProxy;
00206   friend class KHTMLPartBrowserExtension;
00207   friend class DOM::DocumentImpl;
00208   friend class DOM::HTMLDocumentImpl;
00209   friend class KHTMLPartBrowserHostExtension;
00210   friend class khtml::HTMLTokenizer;
00211   friend class khtml::XMLTokenizer;
00212   friend class khtml::RenderWidget;
00213   friend class khtml::CSSStyleSelector;
00214   friend class KHTMLPartIface;
00215   friend class KHTMLPartFunction;
00216 
00217   Q_PROPERTY( bool javaScriptEnabled READ jScriptEnabled WRITE setJScriptEnabled )
00218   Q_PROPERTY( bool javaEnabled READ javaEnabled WRITE setJavaEnabled )
00219   Q_PROPERTY( bool autoloadImages READ autoloadImages WRITE setAutoloadImages )
00220   Q_PROPERTY( bool dndEnabled READ dndEnabled WRITE setDNDEnabled )
00221   Q_PROPERTY( bool pluginsEnabled READ pluginsEnabled WRITE setPluginsEnabled )
00222   Q_PROPERTY( bool onlyLocalReferences READ onlyLocalReferences WRITE setOnlyLocalReferences )
00223   Q_PROPERTY( QCString dcopObjectId READ dcopObjectId )
00224 
00225 public:
00226   enum GUIProfile { DefaultGUI, BrowserViewGUI /* ... */ };
00227 
00240   KHTMLPart( QWidget *parentWidget = 0, const char *widgetname = 0,
00241              QObject *parent = 0, const char *name = 0, GUIProfile prof = DefaultGUI );
00242 
00243   KHTMLPart( KHTMLView *view, QObject *parent = 0, const char *name = 0, GUIProfile prof = DefaultGUI );
00244 
00248   virtual ~KHTMLPart();
00249 
00255   virtual bool openURL( const KURL &url );
00256 
00260   virtual bool closeURL();
00261 
00268   virtual void showError( KIO::Job* job );
00269 
00273   DOM::HTMLDocument htmlDocument() const;
00274 
00278   DOM::Document document() const;
00279 
00283   DOM::Node activeNode() const;
00284 
00288   KParts::BrowserExtension *browserExtension() const;
00289   KParts::LiveConnectExtension *liveConnectExtension( const khtml::RenderPart *) const;
00290   KParts::BrowserHostExtension *browserHostExtension() const;
00291 
00295   KHTMLView *view() const;
00296 
00303   void setJScriptEnabled( bool enable );
00304 
00309   bool jScriptEnabled() const;
00310 
00328   KJS::Interpreter *jScriptInterpreter();
00329 
00333   void setStatusMessagesEnabled( bool enable );
00334 
00338   bool statusMessagesEnabled() const;
00339 
00343   void setMetaRefreshEnabled( bool enable );
00344 
00348   bool metaRefreshEnabled() const;
00349 
00354   QVariant executeScript( const DOM::Node &n, const QString &script );
00355 
00360   void setDNDEnabled( bool b );
00361 
00365   bool dndEnabled() const;
00366 
00373   void setJavaEnabled( bool enable );
00374 
00378   bool javaEnabled() const;
00379 
00383   KJavaAppletContext *javaContext();
00384 
00389   KJavaAppletContext *createJavaContext();
00390 
00394   void setPluginsEnabled( bool enable );
00395 
00399   bool pluginsEnabled() const;
00400 
00407   void setAutoloadImages( bool enable );
00414   bool autoloadImages() const;
00415 
00432   void setOnlyLocalReferences( bool enable );
00433 
00438   bool onlyLocalReferences() const;
00439 
00443   bool isCaretMode() const;
00444 
00449   bool isEditable() const;
00450 
00464   void setCaretPosition(DOM::Node node, long offset, bool extendSelection = false);
00465 
00473   enum CaretDisplayPolicy {
00474     CaretVisible, CaretInvisible, CaretBlink
00475   };
00476 
00481   CaretDisplayPolicy caretDisplayPolicyNonFocused() const;
00482 
00493   void setCaretDisplayPolicyNonFocused(CaretDisplayPolicy policy);
00494 
00495 #ifndef KDE_NO_COMPAT
00496   void enableJScript( bool e ) { setJScriptEnabled(e); }
00497   void enableJava( bool e ) { setJavaEnabled(e); }
00498   void enablePlugins( bool e ) { setPluginsEnabled(e); }
00499   void autoloadImages( bool e ) { setAutoloadImages(e); }
00500   void enableMetaRefresh( bool e ) { setMetaRefreshEnabled(e); }
00501   bool setCharset( const QString &, bool ) { return true; }
00502 
00503   KURL baseURL() const;
00504   QString baseTarget() const;
00505 #endif
00506 
00510   KURL backgroundURL() const;
00511 
00515   void scheduleRedirection( int delay, const QString &url, bool lockHistory = true );
00516 
00539   virtual void begin( const KURL &url = KURL(), int xOffset = 0, int yOffset = 0 );
00540 
00561   virtual void write( const char *str, int len = -1 );
00562 
00570   virtual void write( const QString &str );
00571 
00575   virtual void end();
00576 
00577   /*
00578    * Prints the current HTML page laid out for the printer.
00579    *
00580    * (not implemented at the moment)
00581    */
00582   //    void print(QPainter *, int pageHeight, int pageWidth);
00583 
00587   void paint( QPainter *, const QRect &, int = 0, bool * = 0 );
00588 
00595   bool setEncoding( const QString &name, bool override = false );
00596 
00602   QString encoding() const;
00603 
00611   void setUserStyleSheet( const KURL &url );
00612 
00620   void setUserStyleSheet( const QString &styleSheet );
00621 
00622 public:
00623 
00629   void setStandardFont( const QString &name );
00630 
00637   void setFixedFont( const QString &name );
00638 
00646   bool gotoAnchor( const QString &name );
00647 
00654   bool nextAnchor();
00655 
00660   bool prevAnchor();
00661 
00665   void setURLCursor( const QCursor &c );
00666 
00670   QCursor urlCursor() const;
00671 
00675   void findTextBegin();
00676 
00681   bool findTextNext( const QString &str, bool forward, bool caseSensitive, bool isRegExp );
00682 
00693   void setZoomFactor(int percent);
00694 
00698   int zoomFactor() const;
00699 
00703   virtual QString selectedText() const;
00704 
00708   DOM::Range selection() const;
00709 
00721   void selection(DOM::Node &startNode, long &startOffset,
00722         DOM::Node &endNode, long &endOffset) const;
00723 
00727   void setSelection( const DOM::Range & );
00728 
00737   bool hasSelection() const;
00738 
00742   void selectAll();
00743 
00749   void show();
00750 
00756   void hide();
00757 
00762   KParts::PartManager *partManager();
00763 
00771   virtual void saveState( QDataStream &stream );
00781   virtual void restoreState( QDataStream &stream );
00782 
00786   DOM::Node nodeUnderMouse() const;
00787 
00791   const KHTMLSettings *settings() const;
00792 
00799   KHTMLPart *parentPart();
00800 
00806   QStringList frameNames() const;
00807 
00808   QPtrList<KParts::ReadOnlyPart> frames() const;
00809 
00813   KHTMLPart *findFrame( const QString &f );
00814 
00823   KHTMLPart *findFrameParent( KParts::ReadOnlyPart *callingPart, const QString &f, khtml::ChildFrame **childFrame=0 );
00824 
00830   KParts::ReadOnlyPart *currentFrame() const;
00831 
00838   bool frameExists( const QString &frameName );
00839 
00840 
00846   void setJSStatusBarText( const QString &text );
00847 
00853   void setJSDefaultStatusBarText( const QString &text );
00854 
00860   QString jsStatusBarText() const;
00861 
00867   QString jsDefaultStatusBarText() const;
00868 
00872   QString referrer() const;
00873 
00877   QString pageReferrer() const;
00878 
00882   QString lastModified() const;
00883 
00887   void preloadStyleSheet( const QString &url, const QString &stylesheet );
00888 
00892   void preloadScript( const QString &url, const QString &script );
00893 
00897   bool restored() const;
00898 
00899   // ### KDE4 remove me
00900   enum FormNotification { NoNotification = 0, Before, Only, Unused=255 };
00907   void setFormNotification(FormNotification fn);
00908 
00915   FormNotification formNotification() const;
00916 
00924   KURL toplevelURL();
00925 
00926 
00927 signals:
00931   void onURL( const QString &url );
00932 
00936   void popupMenu( const QString &url, const QPoint &point );
00937 
00941   void selectionChanged();
00942 
00950   void nodeActivated( const DOM::Node & );
00951 
00954   void docCreated();
00955 
00967   void caretPositionChanged(const DOM::Node &node, long offset);
00968 
00969 
00976   void formSubmitNotification(const char *action, const QString& url,
00977                   const QByteArray& formData, const QString& target,
00978                   const QString& contentType, const QString& boundary);
00979 
00980 
00981 protected:
00982 
00987   KURL completeURL( const QString &url );
00988 
00995   void htmlError( int errorCode, const QString& text, const KURL& reqUrl );
00996 
00997   virtual void customEvent( QCustomEvent *event );
00998 
01002   virtual void khtmlMousePressEvent( khtml::MousePressEvent *event );
01006   virtual void khtmlMouseDoubleClickEvent( khtml::MouseDoubleClickEvent * );
01010   virtual void khtmlMouseMoveEvent( khtml::MouseMoveEvent *event );
01014   virtual void khtmlMouseReleaseEvent( khtml::MouseReleaseEvent *event );
01018   virtual void khtmlDrawContentsEvent( khtml::DrawContentsEvent * );
01019 
01023   virtual void guiActivateEvent( KParts::GUIActivateEvent *event );
01024 
01028   virtual bool openFile();
01029 
01030   virtual void urlSelected( const QString &url, int button, int state,
01031                             const QString &_target, KParts::URLArgs args = KParts::URLArgs());
01032 
01041   virtual KParts::ReadOnlyPart *createPart( QWidget *parentWidget, const char *widgetName,
01042                                             QObject *parent, const char *name,
01043                                             const QString &mimetype, QString &serviceName,
01044                                             QStringList &serviceTypes, const QStringList &params);
01045 
01046   // This is for RenderPartObject. We want to ask the 'download plugin?'
01047   // question only once per mimetype
01048   bool pluginPageQuestionAsked( const QString& mimetype ) const;
01049   void setPluginPageQuestionAsked( const QString& mimetype );
01050 
01051   enum PageSecurity { NotCrypted, Encrypted, Mixed };
01052   void setPageSecurity( PageSecurity sec );
01053 
01057   virtual bool doOpenStream( const QString& mimeType );
01058 
01062   virtual bool doWriteStream( const QByteArray& data );
01063 
01067   virtual bool doCloseStream();
01068 
01069 public slots:
01070 
01080   void setActiveNode( const DOM::Node &node );
01081 
01085   void stopAnimations();
01086 
01087   QCString dcopObjectId() const;
01088 
01096   QVariant executeScript( const QString &script );
01097 
01108   void setCaretMode(bool enable);
01109 
01114   void setEditable(bool enable);
01115 
01132   void setCaretVisible(bool show);
01133 
01134   // ### KDE4 FIXME:
01135   //          Remove this and make the one below protected+virtual slot.
01136   //          Warning: this is effectively "internal".  Be careful.
01137   // @since 3.2
01138   void submitFormProxy( const char *action, const QString &url,
01139                         const QByteArray &formData,
01140                         const QString &target,
01141                         const QString& contentType = QString::null,
01142                         const QString& boundary = QString::null );
01143 
01144 private slots:
01145 
01149   void reparseConfiguration();
01150 
01154   void slotData( KIO::Job*, const QByteArray &data );
01158   void slotInfoMessage( KIO::Job*, const QString& msg );
01162   void slotRestoreData( const QByteArray &data );
01166   void slotFinished( KIO::Job* );
01170   void slotFinishedParsing();
01174   void slotRedirect();
01178   void slotRedirection( KIO::Job*, const KURL& );
01182   void slotDebugScript();
01186   void slotDebugDOMTree();
01190   void slotDebugRenderTree();
01194   void slotStopAnimations();
01198   virtual void slotViewDocumentSource();
01202   virtual void slotViewFrameSource();
01206   void slotViewPageInfo();
01210   virtual void slotSaveBackground();
01214   virtual void slotSaveDocument();
01218   virtual void slotSaveFrame();
01222   virtual void slotSecurity();
01226   virtual void slotSetEncoding();
01227 
01231   virtual void slotUseStylesheet();
01232 
01233   virtual void slotFind();
01234   virtual void slotFindDone(); // ### remove me
01235   virtual void slotFindDialogDestroyed();
01236   void slotFindNext();
01237 
01238   void slotIncZoom();
01239   void slotDecZoom();
01240 
01241   void slotLoadImages();
01242   void slotWalletClosed();
01243   void launchWalletManager();
01244   void walletMenu();
01245 
01249   void submitFormAgain();
01250 
01254   void updateActions();
01258   void slotPartRemoved( KParts::Part *part );
01262   void slotActiveFrameChanged( KParts::Part *part );
01266   void slotChildStarted( KIO::Job *job );
01270   void slotChildCompleted();
01274   void slotChildCompleted( bool );
01278   void slotParentCompleted();
01282   void slotChildURLRequest( const KURL &url, const KParts::URLArgs &args );
01286   void slotChildDocCreated();
01287 
01288   void slotLoaderRequestStarted( khtml::DocLoader*, khtml::CachedObject* obj);
01289   void slotLoaderRequestDone( khtml::DocLoader*, khtml::CachedObject *obj );
01290   void checkCompleted();
01291 
01295   void slotAutoScroll();
01296 
01297   void slotPrintFrame();
01298 
01299   void slotSelectAll();
01300 
01304   void slotProgressUpdate();
01305 
01306   /*
01307    * @internal
01308    */
01309   void slotJobPercent( KIO::Job*, unsigned long );
01310 
01311   /*
01312    * @internal
01313    */
01314   void slotJobDone( KIO::Job* );
01315 
01316   /*
01317    * @internal
01318    */
01319   void slotUserSheetStatDone( KIO::Job* );
01320 
01321   /*
01322    * @internal
01323    */
01324   void slotJobSpeed( KIO::Job*, unsigned long );
01325 
01329   void slotClearSelection();
01330 
01334   void slotZoomView( int );
01335 
01339   void slotHighlight( const QString &, int index, int length );
01340 
01344   void slotAutomaticDetectionLanguage( int _id );
01345 
01349   void slotToggleCaretMode();
01350 
01354   void launchJSErrorDialog();
01355 
01359   void removeJSErrorExtension();
01360 
01364   void disableJSErrorExtension();
01365 
01369   void jsErrorDialogContextMenu();
01370 
01371 
01372 
01373 private:
01374 
01375   KJSErrorDlg *jsErrorExtension();
01376 
01377   enum StatusBarPriority { BarDefaultText, BarHoverText, BarOverrideText };
01378   void setStatusBarText( const QString& text, StatusBarPriority p);
01379 
01380   bool restoreURL( const KURL &url );
01381   void emitSelectionChanged();
01382   // Returns whether callingHtmlPart may access this part
01383   bool checkFrameAccess(KHTMLPart *callingHtmlPart);
01384   bool openURLInFrame( const KURL &url, const KParts::URLArgs &urlArgs );
01385   void startAutoScroll();
01386   void stopAutoScroll();
01387   void overURL( const QString &url, const QString &target, bool shiftPressed = false );
01388 
01389   bool processObjectRequest( khtml::ChildFrame *child, const KURL &url, const QString &mimetype );
01390 
01391   KWallet::Wallet* wallet();
01392 
01396   // ### KDE4 FIXME:
01397   //          It is desirable to be able to filter form submissions as well.
01398   //          For instance, forms can have a target and an inheriting class
01399   //          might want to filter based on the target.  Make this protected
01400   //          and virtual, or provide a better solution.
01401   //          See the web_module for the sidebar for an example where this is
01402   //          necessary.
01403   void submitForm( const char *action, const QString &url, const QByteArray &formData,
01404                    const QString &target, const QString& contentType = QString::null,
01405                    const QString& boundary = QString::null );
01406 
01407   void popupMenu( const QString &url );
01408 
01409   void init( KHTMLView *view, GUIProfile prof );
01410 
01411 
01412   void clear();
01413 
01414   bool scheduleScript( const DOM::Node &n, const QString& script);
01415 
01416   QVariant crossFrameExecuteScript(const QString& target, const QString& script);
01417   QVariant executeScheduledScript();
01418 
01419   bool requestFrame( khtml::RenderPart *frame, const QString &url, const QString &frameName,
01420                      const QStringList &args = QStringList(), bool isIFrame = false );
01421 
01429   QString requestFrameName();
01430 
01431   bool requestObject( khtml::RenderPart *frame, const QString &url, const QString &serviceType,
01432                       const QStringList &args = QStringList() );
01433 
01434   bool requestObject( khtml::ChildFrame *child, const KURL &url, const KParts::URLArgs &args = KParts::URLArgs() );
01435 
01436   DOM::EventListener *createHTMLEventListener( QString code, QString name );
01437 
01438   DOM::HTMLDocumentImpl *docImpl() const;
01439   DOM::DocumentImpl *xmlDocImpl() const;
01440   khtml::ChildFrame *frame( const QObject *obj );
01441 
01442   khtml::ChildFrame *recursiveFrameRequest( KHTMLPart *callingHtmlPart, const KURL &url, const KParts::URLArgs &args, bool callParent = true );
01443 
01444   bool checkLinkSecurity( const KURL &linkURL,const QString &message = QString::null, const QString &button = QString::null );
01445   QVariant executeScript( const QString& filename, int baseLine, const DOM::Node &n, const QString& script );
01446 
01447   KJSProxy *jScript();
01448 
01449   KHTMLPart *opener();
01450   long cacheId() const;
01451   void setOpener( KHTMLPart *_opener );
01452   bool openedByJS();
01453   void setOpenedByJS( bool _openedByJS );
01454 
01455   void checkEmitLoadEvent();
01456   void emitLoadEvent();
01457 
01458   bool initFindNode( bool selection, bool reverse, bool fromCursor );
01459   void findText();
01460   void findTextNext();
01461   void extendSelection( DOM::NodeImpl* node, long offset, DOM::Node& selectionNode, long& selectionOffset, bool right, bool paragraph );
01471   void extendSelectionTo(int x, int y, int absX, int absY, const DOM::Node &innerNode);
01475   bool isExtendingSelection() const;
01476   khtml::Decoder *createDecoder();
01477 
01481   void zoomIn(const int stepping[], int count);
01485   void zoomOut(const int stepping[], int count);
01486 
01487   void emitCaretPositionChanged(const DOM::Node &node, long offset);
01488 
01489   void setDebugScript( bool enable );
01490   
01491   KHTMLPartPrivate *d;
01492   friend class KHTMLPartPrivate;
01493 };
01494 
01495 
01496 #endif
KDE Logo
This file is part of the documentation for khtml Library Version 3.2.2.
Documentation copyright © 1996-2004 the KDE developers.
Generated on Fri Jan 21 09:58:56 2005 by doxygen 1.3.6 written by Dimitri van Heesch, © 1997-2003