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 }
00088 
00089 namespace KJS {
00090     class Window;
00091     class WindowFunc;
00092     class ExternalFunc;
00093     class JSEventListener;
00094     class DOMDocument;
00095     class SourceFile;
00096 }
00097 
00098 namespace KParts
00099 {
00100   class PartManager;
00101   class LiveConnectExtension;
00102 }
00103 
00104 namespace KWallet
00105 {
00106   class Wallet;
00107 }
00108 
00180 class KHTMLPart : public KParts::ReadOnlyPart
00181 {
00182   Q_OBJECT
00183   friend class KHTMLView;
00184   friend class DOM::HTMLTitleElementImpl;
00185   friend class DOM::HTMLFrameElementImpl;
00186   friend class DOM::HTMLIFrameElementImpl;
00187   friend class DOM::HTMLObjectElementImpl;
00188   friend class DOM::HTMLAnchorElementImpl;
00189   friend class DOM::HTMLMetaElementImpl;
00190   friend class DOM::NodeImpl;
00191   friend class KHTMLRun;
00192   friend class DOM::HTMLFormElementImpl;
00193   friend class khtml::RenderPartObject;
00194   friend class KJS::Window;
00195   friend class KJS::WindowFunc;
00196   friend class KJS::ExternalFunc;
00197   friend class KJS::JSEventListener;
00198   friend class KJS::DOMDocument;
00199   friend class KJS::SourceFile;
00200   friend class KJSProxy;
00201   friend class KHTMLPartBrowserExtension;
00202   friend class DOM::DocumentImpl;
00203   friend class DOM::HTMLDocumentImpl;
00204   friend class KHTMLPartBrowserHostExtension;
00205   friend class khtml::HTMLTokenizer;
00206   friend class XMLTokenizer;
00207   friend class khtml::RenderWidget;
00208   friend class khtml::CSSStyleSelector;
00209   friend class KHTMLPartIface;
00210   friend class KHTMLPartFunction;
00211 
00212   Q_PROPERTY( bool javaScriptEnabled READ jScriptEnabled WRITE setJScriptEnabled )
00213   Q_PROPERTY( bool javaEnabled READ javaEnabled WRITE setJavaEnabled )
00214   Q_PROPERTY( bool autoloadImages READ autoloadImages WRITE setAutoloadImages )
00215   Q_PROPERTY( bool dndEnabled READ dndEnabled WRITE setDNDEnabled )
00216   Q_PROPERTY( bool pluginsEnabled READ pluginsEnabled WRITE setPluginsEnabled )
00217   Q_PROPERTY( bool onlyLocalReferences READ onlyLocalReferences WRITE setOnlyLocalReferences )
00218   Q_PROPERTY( QCString dcopObjectId READ dcopObjectId )
00219 
00220 public:
00221   enum GUIProfile { DefaultGUI, BrowserViewGUI /* ... */ };
00222 
00235   KHTMLPart( QWidget *parentWidget = 0, const char *widgetname = 0,
00236              QObject *parent = 0, const char *name = 0, GUIProfile prof = DefaultGUI );
00237 
00238   KHTMLPart( KHTMLView *view, QObject *parent = 0, const char *name = 0, GUIProfile prof = DefaultGUI );
00239 
00243   virtual ~KHTMLPart();
00244 
00250   virtual bool openURL( const KURL &url );
00251 
00255   virtual bool closeURL();
00256 
00263   virtual void showError( KIO::Job* job );
00264 
00268   DOM::HTMLDocument htmlDocument() const;
00269 
00273   DOM::Document document() const;
00274 
00278   DOM::Node activeNode() const;
00279 
00283   KParts::BrowserExtension *browserExtension() const;
00284   KParts::LiveConnectExtension *liveConnectExtension( const khtml::RenderPart *) const;
00285 
00289   KHTMLView *view() const;
00290 
00297   void setJScriptEnabled( bool enable );
00298 
00303   bool jScriptEnabled() const;
00304 
00322   KJS::Interpreter *jScriptInterpreter();
00323 
00327   void setStatusMessagesEnabled( bool enable );
00328 
00332   bool statusMessagesEnabled() const;
00333 
00337   void setMetaRefreshEnabled( bool enable );
00338 
00342   bool metaRefreshEnabled() const;
00343 
00348   QVariant executeScript( const DOM::Node &n, const QString &script );
00349 
00354   void setDNDEnabled( bool b );
00355 
00359   bool dndEnabled() const;
00360 
00367   void setJavaEnabled( bool enable );
00368 
00372   bool javaEnabled() const;
00373 
00377   KJavaAppletContext *javaContext();
00378 
00383   KJavaAppletContext *createJavaContext();
00384 
00388   void setPluginsEnabled( bool enable );
00389 
00393   bool pluginsEnabled() const;
00394 
00401   void setAutoloadImages( bool enable );
00408   bool autoloadImages() const;
00409 
00417   void setOnlyLocalReferences( bool enable );
00418 
00422   bool onlyLocalReferences() const;
00423 
00427   bool isCaretMode() const;
00428 
00433   bool isEditable() const;
00434 
00448   void setCaretPosition(DOM::Node node, long offset, bool extendSelection = false);
00449 
00457   enum CaretDisplayPolicy {
00458     CaretVisible, CaretInvisible, CaretBlink
00459   };
00460 
00465   CaretDisplayPolicy caretDisplayPolicyNonFocused() const;
00466 
00477   void setCaretDisplayPolicyNonFocused(CaretDisplayPolicy policy);
00478 
00479 #ifndef KDE_NO_COMPAT
00480   void enableJScript( bool e ) { setJScriptEnabled(e); }
00481   void enableJava( bool e ) { setJavaEnabled(e); }
00482   void enablePlugins( bool e ) { setPluginsEnabled(e); }
00483   void autoloadImages( bool e ) { setAutoloadImages(e); }
00484   void enableMetaRefresh( bool e ) { setMetaRefreshEnabled(e); }
00485   bool setCharset( const QString &, bool ) { return true; }
00486 
00487   KURL baseURL() const;
00488   QString baseTarget() const;
00489 #endif
00490 
00494   KURL backgroundURL() const;
00495 
00499   void scheduleRedirection( int delay, const QString &url, bool lockHistory = true );
00500 
00523   virtual void begin( const KURL &url = KURL(), int xOffset = 0, int yOffset = 0 );
00524 
00545   virtual void write( const char *str, int len = -1 );
00546 
00554   virtual void write( const QString &str );
00555 
00559   virtual void end();
00560 
00561   /*
00562    * Prints the current HTML page laid out for the printer.
00563    *
00564    * (not implemented at the moment)
00565    */
00566   //    void print(QPainter *, int pageHeight, int pageWidth);
00567 
00571   void paint( QPainter *, const QRect &, int = 0, bool * = 0 );
00572 
00579   bool setEncoding( const QString &name, bool override = false );
00580 
00586   QString encoding() const;
00587 
00595   void setUserStyleSheet( const KURL &url );
00596 
00604   void setUserStyleSheet( const QString &styleSheet );
00605 
00606 public:
00607 
00613   void setStandardFont( const QString &name );
00614 
00621   void setFixedFont( const QString &name );
00622 
00630   bool gotoAnchor( const QString &name );
00631 
00638   bool nextAnchor();
00639 
00644   bool prevAnchor();
00645 
00649   void setURLCursor( const QCursor &c );
00650 
00654   QCursor urlCursor() const;
00655 
00659   void findTextBegin();
00660 
00665   bool findTextNext( const QString &str, bool forward, bool caseSensitive, bool isRegExp );
00666 
00677   void setZoomFactor(int percent);
00678 
00682   int zoomFactor() const;
00683 
00687   virtual QString selectedText() const;
00688 
00692   DOM::Range selection() const;
00693 
00705   void selection(DOM::Node &startNode, long &startOffset,
00706         DOM::Node &endNode, long &endOffset) const;
00707 
00711   void setSelection( const DOM::Range & );
00712 
00721   bool hasSelection() const;
00722 
00726   void selectAll();
00727 
00733   void show();
00734 
00740   void hide();
00741 
00746   KParts::PartManager *partManager();
00747 
00755   virtual void saveState( QDataStream &stream );
00765   virtual void restoreState( QDataStream &stream );
00766 
00770   DOM::Node nodeUnderMouse() const;
00771 
00775   const KHTMLSettings *settings() const;
00776 
00783   KHTMLPart *parentPart();
00784 
00790   QStringList frameNames() const;
00791 
00792   QPtrList<KParts::ReadOnlyPart> frames() const;
00793 
00797   KHTMLPart *findFrame( const QString &f );
00798 
00804   KParts::ReadOnlyPart *currentFrame() const;
00805 
00812   bool frameExists( const QString &frameName );
00813 
00814 
00820   void setJSStatusBarText( const QString &text );
00821 
00827   void setJSDefaultStatusBarText( const QString &text );
00828 
00834   QString jsStatusBarText() const;
00835 
00841   QString jsDefaultStatusBarText() const;
00842 
00846   QString referrer() const;
00847 
00851   QString pageReferrer() const;
00852 
00856   QString lastModified() const;
00857 
00861   void preloadStyleSheet( const QString &url, const QString &stylesheet );
00862 
00866   void preloadScript( const QString &url, const QString &script );
00867 
00871   bool restored() const;
00872 
00873   // ### KDE4 remove me
00874   enum FormNotification { NoNotification = 0, Before, Only, Unused=255 };
00881   void setFormNotification(FormNotification fn);
00882 
00889   FormNotification formNotification() const;
00890 
00898   KURL toplevelURL();
00899 
00900 
00901 signals:
00905   void onURL( const QString &url );
00906 
00910   void popupMenu( const QString &url, const QPoint &point );
00911 
00915   void selectionChanged();
00916 
00924   void nodeActivated( const DOM::Node & );
00925 
00928   void docCreated();
00929 
00941   void caretPositionChanged(const DOM::Node &node, long offset);
00942 
00943 
00950   void formSubmitNotification(const char *action, const QString& url,
00951                   const QByteArray& formData, const QString& target,
00952                   const QString& contentType, const QString& boundary);
00953 
00954 
00955 protected:
00956 
00961   KURL completeURL( const QString &url );
00962 
00969   void htmlError( int errorCode, const QString& text, const KURL& reqUrl );
00970 
00971   virtual void customEvent( QCustomEvent *event );
00972 
00976   virtual void khtmlMousePressEvent( khtml::MousePressEvent *event );
00980   virtual void khtmlMouseDoubleClickEvent( khtml::MouseDoubleClickEvent * );
00984   virtual void khtmlMouseMoveEvent( khtml::MouseMoveEvent *event );
00988   virtual void khtmlMouseReleaseEvent( khtml::MouseReleaseEvent *event );
00992   virtual void khtmlDrawContentsEvent( khtml::DrawContentsEvent * );
00993 
00997   virtual void guiActivateEvent( KParts::GUIActivateEvent *event );
00998 
01002   virtual bool openFile();
01003 
01004   virtual void urlSelected( const QString &url, int button, int state,
01005                             const QString &_target, KParts::URLArgs args = KParts::URLArgs());
01006 
01015   virtual KParts::ReadOnlyPart *createPart( QWidget *parentWidget, const char *widgetName,
01016                                             QObject *parent, const char *name,
01017                                             const QString &mimetype, QString &serviceName,
01018                                             QStringList &serviceTypes, const QStringList &params);
01019 
01020   // This is for RenderPartObject. We want to ask the 'download plugin?'
01021   // question only once per mimetype
01022   bool pluginPageQuestionAsked( const QString& mimetype ) const;
01023   void setPluginPageQuestionAsked( const QString& mimetype );
01024 
01025   enum PageSecurity { NotCrypted, Encrypted, Mixed };
01026   void setPageSecurity( PageSecurity sec );
01027 
01031   virtual bool doOpenStream( const QString& mimeType );
01032 
01036   virtual bool doWriteStream( const QByteArray& data );
01037 
01041   virtual bool doCloseStream();
01042 
01043 public slots:
01044 
01054   void setActiveNode( const DOM::Node &node );
01055 
01059   void stopAnimations();
01060 
01061   QCString dcopObjectId() const;
01062 
01070   QVariant executeScript( const QString &script );
01071 
01082   void setCaretMode(bool enable);
01083 
01088   void setEditable(bool enable);
01089 
01106   void setCaretVisible(bool show);
01107 
01108   // ### KDE4 FIXME:
01109   //          Remove this and make the one below protected+virtual slot.
01110   //          Warning: this is effectively "internal".  Be careful.
01111   // @since 3.2
01112   void submitFormProxy( const char *action, const QString &url,
01113                         const QByteArray &formData,
01114                         const QString &target,
01115                         const QString& contentType = QString::null,
01116                         const QString& boundary = QString::null );
01117 
01118 private slots:
01119 
01123   void reparseConfiguration();
01124 
01128   void slotData( KIO::Job*, const QByteArray &data );
01132   void slotInfoMessage( KIO::Job*, const QString& msg );
01136   void slotRestoreData( const QByteArray &data );
01140   void slotFinished( KIO::Job* );
01144   void slotFinishedParsing();
01148   void slotRedirect();
01152   void slotRedirection( KIO::Job*, const KURL& );
01156   void slotDebugScript();
01160   void slotDebugDOMTree();
01164   void slotDebugRenderTree();
01168   void slotStopAnimations();
01172   virtual void slotViewDocumentSource();
01176   virtual void slotViewFrameSource();
01180   void slotViewPageInfo();
01184   virtual void slotSaveBackground();
01188   virtual void slotSaveDocument();
01192   virtual void slotSaveFrame();
01196   virtual void slotSecurity();
01200   virtual void slotSetEncoding();
01201 
01205   virtual void slotUseStylesheet();
01206 
01207   virtual void slotFind();
01208   virtual void slotFindDone(); // ### remove me
01209   virtual void slotFindDialogDestroyed();
01210   void slotFindNext();
01211 
01212   void slotIncZoom();
01213   void slotDecZoom();
01214 
01215   void slotLoadImages();
01216   void slotWalletClosed();
01217   void launchWalletManager();
01218   void walletMenu();
01219 
01223   void submitFormAgain();
01224 
01228   void updateActions();
01232   void slotPartRemoved( KParts::Part *part );
01236   void slotActiveFrameChanged( KParts::Part *part );
01240   void slotChildStarted( KIO::Job *job );
01244   void slotChildCompleted();
01248   void slotChildCompleted( bool );
01252   void slotParentCompleted();
01256   void slotChildURLRequest( const KURL &url, const KParts::URLArgs &args );
01260   void slotChildDocCreated();
01261 
01262   void slotLoaderRequestStarted( khtml::DocLoader*, khtml::CachedObject* obj);
01263   void slotLoaderRequestDone( khtml::DocLoader*, khtml::CachedObject *obj );
01264   void checkCompleted();
01265 
01269   void slotAutoScroll();
01270 
01271   void slotPrintFrame();
01272 
01273   void slotSelectAll();
01274 
01278   void slotProgressUpdate();
01279 
01280   /*
01281    * @internal
01282    */
01283   void slotJobPercent( KIO::Job*, unsigned long );
01284 
01285   /*
01286    * @internal
01287    */
01288   void slotJobDone( KIO::Job* );
01289 
01290   /*
01291    * @internal
01292    */
01293   void slotJobSpeed( KIO::Job*, unsigned long );
01294 
01298   void slotClearSelection();
01299 
01303   void slotZoomView( int );
01304 
01308   void slotHighlight( const QString &, int index, int length );
01309 
01313   void slotAutomaticDetectionLanguage( int _id );
01314 
01318   void slotToggleCaretMode();
01319 
01323   void launchJSErrorDialog();
01324 
01328   void removeJSErrorExtension();
01329 
01333   void disableJSErrorExtension();
01334 
01338   void jsErrorDialogContextMenu();
01339 
01340 
01341 
01342 private:
01343 
01344   KJSErrorDlg *jsErrorExtension();
01345 
01346   enum StatusBarPriority { BarDefaultText, BarHoverText, BarOverrideText };
01347   void setStatusBarText( const QString& text, StatusBarPriority p);
01348 
01349   bool restoreURL( const KURL &url );
01350   void emitSelectionChanged();
01351   bool openURLInFrame( const KURL &url, const KParts::URLArgs &urlArgs );
01352   void startAutoScroll();
01353   void stopAutoScroll();
01354   void overURL( const QString &url, const QString &target, bool shiftPressed = false );
01355 
01356   bool processObjectRequest( khtml::ChildFrame *child, const KURL &url, const QString &mimetype );
01357 
01358   KWallet::Wallet* wallet();
01359 
01363   // ### KDE4 FIXME:
01364   //          It is desirable to be able to filter form submissions as well.
01365   //          For instance, forms can have a target and an inheriting class
01366   //          might want to filter based on the target.  Make this protected
01367   //          and virtual, or provide a better solution.
01368   //          See the web_module for the sidebar for an example where this is
01369   //          necessary.
01370   void submitForm( const char *action, const QString &url, const QByteArray &formData,
01371                    const QString &target, const QString& contentType = QString::null,
01372                    const QString& boundary = QString::null );
01373 
01374   void popupMenu( const QString &url );
01375 
01376   void init( KHTMLView *view, GUIProfile prof );
01377 
01378 
01379   void clear();
01380 
01381   bool scheduleScript( const DOM::Node &n, const QString& script);
01382 
01383   QVariant crossFrameExecuteScript(const QString& target, const QString& script);
01384   QVariant executeScheduledScript();
01385 
01386   bool requestFrame( khtml::RenderPart *frame, const QString &url, const QString &frameName,
01387                      const QStringList &args = QStringList(), bool isIFrame = false );
01388 
01396   QString requestFrameName();
01397 
01398   bool requestObject( khtml::RenderPart *frame, const QString &url, const QString &serviceType,
01399                       const QStringList &args = QStringList() );
01400 
01401   bool requestObject( khtml::ChildFrame *child, const KURL &url, const KParts::URLArgs &args = KParts::URLArgs() );
01402 
01403   DOM::EventListener *createHTMLEventListener( QString code, QString name );
01404 
01405   DOM::HTMLDocumentImpl *docImpl() const;
01406   DOM::DocumentImpl *xmlDocImpl() const;
01407   khtml::ChildFrame *frame( const QObject *obj );
01408 
01409   khtml::ChildFrame *recursiveFrameRequest( const KURL &url, const KParts::URLArgs &args, bool callParent = true );
01410 
01411   bool checkLinkSecurity( const KURL &linkURL,const QString &message = QString::null, const QString &button = QString::null );
01412   QVariant executeScript( const QString& filename, int baseLine, const DOM::Node &n, const QString& script );
01413 
01414   KJSProxy *jScript();
01415 
01416   KHTMLPart *opener();
01417   long cacheId() const;
01418   void setOpener( KHTMLPart *_opener );
01419   bool openedByJS();
01420   void setOpenedByJS( bool _openedByJS );
01421 
01422   void checkEmitLoadEvent();
01423   void emitLoadEvent();
01424 
01425   bool initFindNode( bool selection, bool reverse, bool fromCursor );
01426   void findText();
01427   void findTextNext();
01428   void extendSelection( DOM::NodeImpl* node, long offset, DOM::Node& selectionNode, long& selectionOffset, bool right, bool paragraph );
01438   void extendSelectionTo(int x, int y, int absX, int absY, const DOM::Node &innerNode);
01442   bool isExtendingSelection() const;
01443   khtml::Decoder *createDecoder();
01444 
01448   void zoomIn(const int stepping[], int count);
01452   void zoomOut(const int stepping[], int count);
01453 
01454   void emitCaretPositionChanged(const DOM::Node &node, long offset);
01455 
01456   KHTMLPartPrivate *d;
01457   friend class KHTMLPartPrivate;
01458 };
01459 
01460 
01461 #endif
KDE Logo
This file is part of the documentation for khtml Library Version 3.2.0.
Documentation copyright © 1996-2004 the KDE developers.
Generated on Wed Feb 4 12:37:20 2004 by doxygen 1.2.18 written by Dimitri van Heesch, © 1997-2003