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 
00294   KHTMLView *view() const;
00295 
00302   void setJScriptEnabled( bool enable );
00303 
00308   bool jScriptEnabled() const;
00309 
00327   KJS::Interpreter *jScriptInterpreter();
00328 
00332   void setStatusMessagesEnabled( bool enable );
00333 
00337   bool statusMessagesEnabled() const;
00338 
00342   void setMetaRefreshEnabled( bool enable );
00343 
00347   bool metaRefreshEnabled() const;
00348 
00353   QVariant executeScript( const DOM::Node &n, const QString &script );
00354 
00359   void setDNDEnabled( bool b );
00360 
00364   bool dndEnabled() const;
00365 
00372   void setJavaEnabled( bool enable );
00373 
00377   bool javaEnabled() const;
00378 
00382   KJavaAppletContext *javaContext();
00383 
00388   KJavaAppletContext *createJavaContext();
00389 
00393   void setPluginsEnabled( bool enable );
00394 
00398   bool pluginsEnabled() const;
00399 
00406   void setAutoloadImages( bool enable );
00413   bool autoloadImages() const;
00414 
00422   void setOnlyLocalReferences( bool enable );
00423 
00427   bool onlyLocalReferences() const;
00428 
00432   bool isCaretMode() const;
00433 
00438   bool isEditable() const;
00439 
00453   void setCaretPosition(DOM::Node node, long offset, bool extendSelection = false);
00454 
00462   enum CaretDisplayPolicy {
00463     CaretVisible, CaretInvisible, CaretBlink
00464   };
00465 
00470   CaretDisplayPolicy caretDisplayPolicyNonFocused() const;
00471 
00482   void setCaretDisplayPolicyNonFocused(CaretDisplayPolicy policy);
00483 
00484 #ifndef KDE_NO_COMPAT
00485   void enableJScript( bool e ) { setJScriptEnabled(e); }
00486   void enableJava( bool e ) { setJavaEnabled(e); }
00487   void enablePlugins( bool e ) { setPluginsEnabled(e); }
00488   void autoloadImages( bool e ) { setAutoloadImages(e); }
00489   void enableMetaRefresh( bool e ) { setMetaRefreshEnabled(e); }
00490   bool setCharset( const QString &, bool ) { return true; }
00491 
00492   KURL baseURL() const;
00493   QString baseTarget() const;
00494 #endif
00495 
00499   KURL backgroundURL() const;
00500 
00504   void scheduleRedirection( int delay, const QString &url, bool lockHistory = true );
00505 
00528   virtual void begin( const KURL &url = KURL(), int xOffset = 0, int yOffset = 0 );
00529 
00550   virtual void write( const char *str, int len = -1 );
00551 
00559   virtual void write( const QString &str );
00560 
00564   virtual void end();
00565 
00566   /*
00567    * Prints the current HTML page laid out for the printer.
00568    *
00569    * (not implemented at the moment)
00570    */
00571   //    void print(QPainter *, int pageHeight, int pageWidth);
00572 
00576   void paint( QPainter *, const QRect &, int = 0, bool * = 0 );
00577 
00584   bool setEncoding( const QString &name, bool override = false );
00585 
00591   QString encoding() const;
00592 
00600   void setUserStyleSheet( const KURL &url );
00601 
00609   void setUserStyleSheet( const QString &styleSheet );
00610 
00611 public:
00612 
00618   void setStandardFont( const QString &name );
00619 
00626   void setFixedFont( const QString &name );
00627 
00635   bool gotoAnchor( const QString &name );
00636 
00643   bool nextAnchor();
00644 
00649   bool prevAnchor();
00650 
00654   void setURLCursor( const QCursor &c );
00655 
00659   QCursor urlCursor() const;
00660 
00664   void findTextBegin();
00665 
00670   bool findTextNext( const QString &str, bool forward, bool caseSensitive, bool isRegExp );
00671 
00682   void setZoomFactor(int percent);
00683 
00687   int zoomFactor() const;
00688 
00692   virtual QString selectedText() const;
00693 
00697   DOM::Range selection() const;
00698 
00710   void selection(DOM::Node &startNode, long &startOffset,
00711         DOM::Node &endNode, long &endOffset) const;
00712 
00716   void setSelection( const DOM::Range & );
00717 
00726   bool hasSelection() const;
00727 
00731   void selectAll();
00732 
00738   void show();
00739 
00745   void hide();
00746 
00751   KParts::PartManager *partManager();
00752 
00760   virtual void saveState( QDataStream &stream );
00770   virtual void restoreState( QDataStream &stream );
00771 
00775   DOM::Node nodeUnderMouse() const;
00776 
00780   const KHTMLSettings *settings() const;
00781 
00788   KHTMLPart *parentPart();
00789 
00795   QStringList frameNames() const;
00796 
00797   QPtrList<KParts::ReadOnlyPart> frames() const;
00798 
00802   KHTMLPart *findFrame( const QString &f );
00803 
00809   KParts::ReadOnlyPart *currentFrame() const;
00810 
00817   bool frameExists( const QString &frameName );
00818 
00819 
00825   void setJSStatusBarText( const QString &text );
00826 
00832   void setJSDefaultStatusBarText( const QString &text );
00833 
00839   QString jsStatusBarText() const;
00840 
00846   QString jsDefaultStatusBarText() const;
00847 
00851   QString referrer() const;
00852 
00856   QString pageReferrer() const;
00857 
00861   QString lastModified() const;
00862 
00866   void preloadStyleSheet( const QString &url, const QString &stylesheet );
00867 
00871   void preloadScript( const QString &url, const QString &script );
00872 
00876   bool restored() const;
00877 
00878   // ### KDE4 remove me
00879   enum FormNotification { NoNotification = 0, Before, Only, Unused=255 };
00886   void setFormNotification(FormNotification fn);
00887 
00894   FormNotification formNotification() const;
00895 
00903   KURL toplevelURL();
00904 
00905 
00906 signals:
00910   void onURL( const QString &url );
00911 
00915   void popupMenu( const QString &url, const QPoint &point );
00916 
00920   void selectionChanged();
00921 
00929   void nodeActivated( const DOM::Node & );
00930 
00933   void docCreated();
00934 
00946   void caretPositionChanged(const DOM::Node &node, long offset);
00947 
00948 
00955   void formSubmitNotification(const char *action, const QString& url,
00956                   const QByteArray& formData, const QString& target,
00957                   const QString& contentType, const QString& boundary);
00958 
00959 
00960 protected:
00961 
00966   KURL completeURL( const QString &url );
00967 
00974   void htmlError( int errorCode, const QString& text, const KURL& reqUrl );
00975 
00976   virtual void customEvent( QCustomEvent *event );
00977 
00981   virtual void khtmlMousePressEvent( khtml::MousePressEvent *event );
00985   virtual void khtmlMouseDoubleClickEvent( khtml::MouseDoubleClickEvent * );
00989   virtual void khtmlMouseMoveEvent( khtml::MouseMoveEvent *event );
00993   virtual void khtmlMouseReleaseEvent( khtml::MouseReleaseEvent *event );
00997   virtual void khtmlDrawContentsEvent( khtml::DrawContentsEvent * );
00998 
01002   virtual void guiActivateEvent( KParts::GUIActivateEvent *event );
01003 
01007   virtual bool openFile();
01008 
01009   virtual void urlSelected( const QString &url, int button, int state,
01010                             const QString &_target, KParts::URLArgs args = KParts::URLArgs());
01011 
01020   virtual KParts::ReadOnlyPart *createPart( QWidget *parentWidget, const char *widgetName,
01021                                             QObject *parent, const char *name,
01022                                             const QString &mimetype, QString &serviceName,
01023                                             QStringList &serviceTypes, const QStringList &params);
01024 
01025   // This is for RenderPartObject. We want to ask the 'download plugin?'
01026   // question only once per mimetype
01027   bool pluginPageQuestionAsked( const QString& mimetype ) const;
01028   void setPluginPageQuestionAsked( const QString& mimetype );
01029 
01030   enum PageSecurity { NotCrypted, Encrypted, Mixed };
01031   void setPageSecurity( PageSecurity sec );
01032 
01036   virtual bool doOpenStream( const QString& mimeType );
01037 
01041   virtual bool doWriteStream( const QByteArray& data );
01042 
01046   virtual bool doCloseStream();
01047 
01048 public slots:
01049 
01059   void setActiveNode( const DOM::Node &node );
01060 
01064   void stopAnimations();
01065 
01066   QCString dcopObjectId() const;
01067 
01075   QVariant executeScript( const QString &script );
01076 
01087   void setCaretMode(bool enable);
01088 
01100   void setEditable(bool enable);
01101 
01118   void setCaretVisible(bool show);
01119 
01120   // ### KDE4 FIXME:
01121   //          Remove this and make the one below protected+virtual slot.
01122   //          Warning: this is effectively "internal".  Be careful.
01123   // @since 3.2
01124   void submitFormProxy( const char *action, const QString &url,
01125                         const QByteArray &formData,
01126                         const QString &target,
01127                         const QString& contentType = QString::null,
01128                         const QString& boundary = QString::null );
01129 
01130 private slots:
01131 
01135   void reparseConfiguration();
01136 
01140   void slotData( KIO::Job*, const QByteArray &data );
01144   void slotInfoMessage( KIO::Job*, const QString& msg );
01148   void slotRestoreData( const QByteArray &data );
01152   void slotFinished( KIO::Job* );
01156   void slotFinishedParsing();
01160   void slotRedirect();
01164   void slotRedirection( KIO::Job*, const KURL& );
01168   void slotDebugScript();
01172   void slotDebugDOMTree();
01176   void slotDebugRenderTree();
01180   void slotStopAnimations();
01184   virtual void slotViewDocumentSource();
01188   virtual void slotViewFrameSource();
01192   void slotViewPageInfo();
01196   virtual void slotSaveBackground();
01200   virtual void slotSaveDocument();
01204   virtual void slotSaveFrame();
01208   virtual void slotSecurity();
01212   virtual void slotSetEncoding();
01213 
01217   virtual void slotUseStylesheet();
01218 
01219   virtual void slotFind();
01220   virtual void slotFindDone(); // ### remove me
01221   virtual void slotFindDialogDestroyed();
01222   void slotFindNext();
01223 
01224   void slotIncZoom();
01225   void slotDecZoom();
01226 
01227   void slotLoadImages();
01228   void slotWalletClosed();
01229   void launchWalletManager();
01230   void walletMenu();
01231 
01235   void submitFormAgain();
01236 
01240   void updateActions();
01244   void slotPartRemoved( KParts::Part *part );
01248   void slotActiveFrameChanged( KParts::Part *part );
01252   void slotChildStarted( KIO::Job *job );
01256   void slotChildCompleted();
01260   void slotChildCompleted( bool );
01264   void slotParentCompleted();
01268   void slotChildURLRequest( const KURL &url, const KParts::URLArgs &args );
01272   void slotChildDocCreated();
01273 
01274   void slotLoaderRequestStarted( khtml::DocLoader*, khtml::CachedObject* obj);
01275   void slotLoaderRequestDone( khtml::DocLoader*, khtml::CachedObject *obj );
01276   void checkCompleted();
01277 
01281   void slotAutoScroll();
01282 
01283   void slotPrintFrame();
01284 
01285   void slotSelectAll();
01286 
01290   void slotProgressUpdate();
01291 
01292   /*
01293    * @internal
01294    */
01295   void slotJobPercent( KIO::Job*, unsigned long );
01296 
01297   /*
01298    * @internal
01299    */
01300   void slotJobDone( KIO::Job* );
01301 
01302   /*
01303    * @internal
01304    */
01305   void slotUserSheetStatDone( KIO::Job* );
01306 
01307   /*
01308    * @internal
01309    */
01310   void slotJobSpeed( KIO::Job*, unsigned long );
01311 
01315   void slotClearSelection();
01316 
01320   void slotZoomView( int );
01321 
01325   void slotHighlight( const QString &, int index, int length );
01326 
01330   void slotAutomaticDetectionLanguage( int _id );
01331 
01335   void slotToggleCaretMode();
01336 
01340   void launchJSErrorDialog();
01341 
01345   void removeJSErrorExtension();
01346 
01350   void disableJSErrorExtension();
01351 
01355   void jsErrorDialogContextMenu();
01356 
01357 
01358 
01359 private:
01360 
01361   KJSErrorDlg *jsErrorExtension();
01362 
01363   enum StatusBarPriority { BarDefaultText, BarHoverText, BarOverrideText };
01364   void setStatusBarText( const QString& text, StatusBarPriority p);
01365 
01366   bool restoreURL( const KURL &url );
01367   void emitSelectionChanged();
01368   bool openURLInFrame( const KURL &url, const KParts::URLArgs &urlArgs );
01369   void startAutoScroll();
01370   void stopAutoScroll();
01371   void overURL( const QString &url, const QString &target, bool shiftPressed = false );
01372 
01373   bool processObjectRequest( khtml::ChildFrame *child, const KURL &url, const QString &mimetype );
01374 
01375   KWallet::Wallet* wallet();
01376 
01380   // ### KDE4 FIXME:
01381   //          It is desirable to be able to filter form submissions as well.
01382   //          For instance, forms can have a target and an inheriting class
01383   //          might want to filter based on the target.  Make this protected
01384   //          and virtual, or provide a better solution.
01385   //          See the web_module for the sidebar for an example where this is
01386   //          necessary.
01387   void submitForm( const char *action, const QString &url, const QByteArray &formData,
01388                    const QString &target, const QString& contentType = QString::null,
01389                    const QString& boundary = QString::null );
01390 
01391   void popupMenu( const QString &url );
01392 
01393   void init( KHTMLView *view, GUIProfile prof );
01394 
01395 
01396   void clear();
01397 
01398   bool scheduleScript( const DOM::Node &n, const QString& script);
01399 
01400   QVariant crossFrameExecuteScript(const QString& target, const QString& script);
01401   QVariant executeScheduledScript();
01402 
01403   bool requestFrame( khtml::RenderPart *frame, const QString &url, const QString &frameName,
01404                      const QStringList &args = QStringList(), bool isIFrame = false );
01405 
01413   QString requestFrameName();
01414 
01415   bool requestObject( khtml::RenderPart *frame, const QString &url, const QString &serviceType,
01416                       const QStringList &args = QStringList() );
01417 
01418   bool requestObject( khtml::ChildFrame *child, const KURL &url, const KParts::URLArgs &args = KParts::URLArgs() );
01419 
01420   DOM::EventListener *createHTMLEventListener( QString code, QString name );
01421 
01422   DOM::HTMLDocumentImpl *docImpl() const;
01423   DOM::DocumentImpl *xmlDocImpl() const;
01424   khtml::ChildFrame *frame( const QObject *obj );
01425 
01426   khtml::ChildFrame *recursiveFrameRequest( const KURL &url, const KParts::URLArgs &args, bool callParent = true );
01427 
01428   bool checkLinkSecurity( const KURL &linkURL,const QString &message = QString::null, const QString &button = QString::null );
01429   QVariant executeScript( const QString& filename, int baseLine, const DOM::Node &n, const QString& script );
01430 
01431   KJSProxy *jScript();
01432 
01433   KHTMLPart *opener();
01434   long cacheId() const;
01435   void setOpener( KHTMLPart *_opener );
01436   bool openedByJS();
01437   void setOpenedByJS( bool _openedByJS );
01438 
01439   void checkEmitLoadEvent();
01440   void emitLoadEvent();
01441 
01442   bool initFindNode( bool selection, bool reverse, bool fromCursor );
01443   void findText();
01444   void findTextNext();
01445   void extendSelection( DOM::NodeImpl* node, long offset, DOM::Node& selectionNode, long& selectionOffset, bool right, bool paragraph );
01455   void extendSelectionTo(int x, int y, int absX, int absY, const DOM::Node &innerNode);
01459   bool isExtendingSelection() const;
01460   khtml::Decoder *createDecoder();
01461 
01465   void zoomIn(const int stepping[], int count);
01469   void zoomOut(const int stepping[], int count);
01470 
01471   void emitCaretPositionChanged(const DOM::Node &node, long offset);
01472 
01473   void setDebugScript( bool enable );
01474   
01475   KHTMLPartPrivate *d;
01476   friend class KHTMLPartPrivate;
01477 };
01478 
01479 
01480 #endif
KDE Logo
This file is part of the documentation for khtml Library Version 3.2.1.
Documentation copyright © 1996-2004 the KDE developers.
Generated on Thu Mar 4 22:45:42 2004 by doxygen 1.3.6-20040222 written by Dimitri van Heesch, © 1997-2003