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 lastModified() const;
00719 
00723   void preloadStyleSheet(const QString &url, const QString &stylesheet);
00724 
00728   void preloadScript(const QString &url, const QString &script);
00729 
00733   bool restored() const;
00734 
00735 signals:
00739   void onURL( const QString &url );
00740 
00744   void popupMenu(const QString &url, const QPoint &point);
00745 
00749   void selectionChanged();
00750 
00758   void nodeActivated(const DOM::Node &);
00759 
00762   void docCreated();
00763 
00764 protected:
00765 
00770   KURL completeURL( const QString &url );
00771 
00778   void htmlError(int errorCode, const QString& text, const KURL& reqUrl);
00779 
00780   virtual void customEvent( QCustomEvent *event );
00781 
00785   virtual void khtmlMousePressEvent( khtml::MousePressEvent *event );
00789   virtual void khtmlMouseDoubleClickEvent( khtml::MouseDoubleClickEvent * );
00793   virtual void khtmlMouseMoveEvent( khtml::MouseMoveEvent *event );
00797   virtual void khtmlMouseReleaseEvent( khtml::MouseReleaseEvent *event );
00801   virtual void khtmlDrawContentsEvent( khtml::DrawContentsEvent * );
00802 
00806   virtual void guiActivateEvent( KParts::GUIActivateEvent *event );
00807 
00811   virtual bool openFile();
00812 
00813   virtual void urlSelected( const QString &url, int button, int state,
00814                             const QString &_target, KParts::URLArgs args = KParts::URLArgs());
00815 
00824   virtual KParts::ReadOnlyPart *createPart( QWidget *parentWidget, const char *widgetName,
00825                                             QObject *parent, const char *name,
00826                                             const QString &mimetype, QString &serviceName,
00827                                             QStringList &serviceTypes, const QStringList &params);
00828 
00829   // This is for RenderPartObject. We want to ask the 'download plugin?'
00830   // question only once per mimetype
00831   bool pluginPageQuestionAsked(const QString& mimetype) const;
00832   void setPluginPageQuestionAsked(const QString& mimetype);
00833 
00834 public slots:
00835 
00845   void setActiveNode(const DOM::Node &node);
00846 
00850   void stopAnimations();
00851 
00852   QCString dcopObjectId() const;
00853 
00854 private slots:
00855 
00859   void reparseConfiguration();
00860 
00864   void slotData( KIO::Job*, const QByteArray &data );
00868   void slotInfoMessage( KIO::Job*, const QString& msg );
00872   void slotRestoreData( const QByteArray &data );
00876   void slotFinished( KIO::Job* );
00880   void slotFinishedParsing();
00884   void slotRedirect();
00888   void slotRedirection(KIO::Job*, const KURL&);
00892   void slotDebugDOMTree();
00896   void slotDebugRenderTree();
00900   virtual void slotViewDocumentSource();
00904   virtual void slotViewFrameSource();
00908   void slotViewPageInfo();
00912   virtual void slotSaveBackground();
00916   virtual void slotSaveDocument();
00920   virtual void slotSaveFrame();
00924   virtual void slotSecurity();
00928   virtual void slotSetEncoding();
00929 
00933   virtual void slotUseStylesheet();
00934 
00935   virtual void slotFind();
00936   virtual void slotFindDone(); // ### remove me
00937   virtual void slotFindDialogDestroyed();
00938   void slotFindNext();
00939 
00940   void slotIncZoom();
00941   void slotDecZoom();
00942 
00943   void slotLoadImages();
00944 
00948   void submitFormAgain();
00949 
00953   void updateActions();
00957   void slotPartRemoved( KParts::Part *part );
00961   void slotActiveFrameChanged( KParts::Part *part );
00965   void slotChildStarted( KIO::Job *job );
00969   void slotChildCompleted();
00973   void slotChildCompleted( bool );
00977   void slotParentCompleted();
00981   void slotChildURLRequest( const KURL &url, const KParts::URLArgs &args );
00985   void slotChildDocCreated();
00986 
00987   void slotLoaderRequestStarted( khtml::DocLoader*, khtml::CachedObject* obj);
00988   void slotLoaderRequestDone( khtml::DocLoader*, khtml::CachedObject *obj );
00989   void checkCompleted();
00990 
00994   void slotShowDocument( const QString &url, const QString &target );
00995 
00999   void slotAutoScroll();
01000 
01001   void slotPrintFrame();
01002 
01003   void slotSelectAll();
01004 
01008   void slotProgressUpdate();
01009 
01010   /*
01011    * @internal
01012    */
01013   void slotJobPercent(KIO::Job*, unsigned long);
01014 
01015   /*
01016    * @internal
01017    */
01018   void slotJobDone(KIO::Job*);
01019 
01020   /*
01021    * @internal
01022    */
01023   void slotJobSpeed(KIO::Job*, unsigned long);
01024 
01028   void slotClearSelection();
01029 
01033   void slotZoomView( int );
01034 
01038   void slotHighlight( const QString &, int index, int length );
01039 
01040 private:
01041 
01042   enum StatusBarPriority { BarDefaultText, BarHoverText, BarOverrideText };
01043   void setStatusBarText( const QString& text, StatusBarPriority p);
01044 
01048   bool restoreURL( const KURL &url );
01049 
01053   void emitSelectionChanged();
01054 
01058   bool openURLInFrame( const KURL &url, const KParts::URLArgs &urlArgs );
01059   
01064   bool checkFrameAccess(KHTMLPart *callingHtmlPart);
01065 
01066   void startAutoScroll();
01067   void stopAutoScroll();
01068   void overURL( const QString &url, const QString &target, bool shiftPressed = false );
01069 
01073   bool processObjectRequest( khtml::ChildFrame *child, const KURL &url, const QString &mimetype );
01074 
01078   void submitForm( const char *action, const QString &url, const QByteArray &formData,
01079                    const QString &target, const QString& contentType = QString::null,
01080                    const QString& boundary = QString::null );
01081 
01085   void popupMenu( const QString &url );
01086 
01087   void init( KHTMLView *view, GUIProfile prof );
01088 
01089   void clear();
01090 
01091   bool scheduleScript( const DOM::Node &n, const QString& script);
01092 
01093   QVariant executeScheduledScript();
01094 
01095   bool requestFrame( khtml::RenderPart *frame, const QString &url, const QString &frameName,
01096                      const QStringList &args = QStringList(), bool isIFrame = false );
01097 
01105   QString requestFrameName();
01106 
01107   bool requestObject( khtml::RenderPart *frame, const QString &url, const QString &serviceType,
01108                       const QStringList &args = QStringList() );
01109 
01110   bool requestObject( khtml::ChildFrame *child, const KURL &url, const KParts::URLArgs &args = KParts::URLArgs() );
01111 
01112   DOM::EventListener *createHTMLEventListener( QString code );
01113 
01114   DOM::HTMLDocumentImpl *docImpl() const;
01115   DOM::DocumentImpl *xmlDocImpl() const;
01116   khtml::ChildFrame *frame( const QObject *obj );
01117 
01118   khtml::ChildFrame *recursiveFrameRequest( KHTMLPart *callingHtmlPart, const KURL &url, const KParts::URLArgs &args, bool callParent = true );
01119 
01120   bool checkLinkSecurity(const KURL &linkURL,const QString &message = QString::null, const QString &button = QString::null);
01121   QVariant executeScript(QString filename, int baseLine, const DOM::Node &n, const QString &script);
01122 
01123   KJSProxy *jScript();
01124 
01125   KHTMLPart *opener();
01126   long cacheId() const;
01127   void setOpener(KHTMLPart *_opener);
01128   bool openedByJS();
01129   void setOpenedByJS(bool _openedByJS);
01130 
01131   void checkEmitLoadEvent();
01132   void emitLoadEvent();
01133 
01134   bool initFindNode( bool selection, bool reverse );
01135   void findText();
01136   void findTextNext();
01137   void extendSelection( DOM::NodeImpl* node, long offset, DOM::Node& selectionNode, long& selectionOffset, bool right, bool paragraph );
01138 
01139   KHTMLPartPrivate *d;
01140   friend class KHTMLPartPrivate;
01141 };
01142 
01143 
01144 #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 Mon Oct 24 13:09:45 2011 by doxygen 1.3.5 written by Dimitri van Heesch, © 1997-2001