00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
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 #include <kfinddialog.h>
00036
00037 #include <qregexp.h>
00038
00039 class KHTMLPartPrivate;
00040 class KHTMLPartBrowserExtension;
00041 class KJSProxy;
00042 class KHTMLView;
00043 class KHTMLSettings;
00044 class KJavaAppletContext;
00045 class KJSErrorDlg;
00046
00047 namespace DOM
00048 {
00049 class HTMLDocument;
00050 class HTMLDocumentImpl;
00051 class DocumentImpl;
00052 class HTMLTitleElementImpl;
00053 class HTMLElementImpl;
00054 class HTMLFrameElementImpl;
00055 class HTMLIFrameElementImpl;
00056 class HTMLObjectElementImpl;
00057 class HTMLFormElementImpl;
00058 class HTMLAnchorElementImpl;
00059 class HTMLMetaElementImpl;
00060 class NodeImpl;
00061 class Node;
00062 class HTMLEventListener;
00063 class EventListener;
00064 }
00065
00066 namespace KJS
00067 {
00068 class Interpreter;
00069 }
00070
00071 namespace khtml
00072 {
00073 class DocLoader;
00074 class RenderPart;
00075 class RenderPartObject;
00076 struct ChildFrame;
00077 class MouseEvent;
00078 class MousePressEvent;
00079 class MouseDoubleClickEvent;
00080 class MouseMoveEvent;
00081 class MouseReleaseEvent;
00082 class DrawContentsEvent;
00083 class CachedObject;
00084 class RenderWidget;
00085 class CSSStyleSelector;
00086 class HTMLTokenizer;
00087 class Decoder;
00088 class XMLTokenizer;
00089 }
00090
00091 namespace KJS {
00092 class Window;
00093 class WindowFunc;
00094 class ExternalFunc;
00095 class JSEventListener;
00096 class JSLazyEventListener;
00097 class JSNodeFilter;
00098 class DOMDocument;
00099 class SourceFile;
00100 class ScheduledAction;
00101 }
00102
00103 namespace KParts
00104 {
00105 class PartManager;
00106 class LiveConnectExtension;
00107 }
00108
00109 namespace KWallet
00110 {
00111 class Wallet;
00112 }
00113
00184 class KHTML_EXPORT KHTMLPart : public KParts::ReadOnlyPart
00185 {
00186 Q_OBJECT
00187 friend class KHTMLView;
00188 friend class DOM::HTMLTitleElementImpl;
00189 friend class DOM::HTMLFrameElementImpl;
00190 friend class DOM::HTMLIFrameElementImpl;
00191 friend class DOM::HTMLObjectElementImpl;
00192 friend class DOM::HTMLAnchorElementImpl;
00193 friend class DOM::HTMLMetaElementImpl;
00194 friend class DOM::NodeImpl;
00195 friend class KHTMLRun;
00196 friend class DOM::HTMLFormElementImpl;
00197 friend class khtml::RenderPartObject;
00198 friend class KJS::Window;
00199 friend class KJS::ScheduledAction;
00200 friend class KJS::JSNodeFilter;
00201 friend class KJS::WindowFunc;
00202 friend class KJS::ExternalFunc;
00203 friend class KJS::JSEventListener;
00204 friend class KJS::JSLazyEventListener;
00205 friend class KJS::DOMDocument;
00206 friend class KJS::SourceFile;
00207 friend class KJSProxy;
00208 friend class KHTMLPartBrowserExtension;
00209 friend class DOM::DocumentImpl;
00210 friend class DOM::HTMLDocumentImpl;
00211 friend class KHTMLPartBrowserHostExtension;
00212 friend class khtml::HTMLTokenizer;
00213 friend class khtml::XMLTokenizer;
00214 friend class khtml::RenderWidget;
00215 friend class khtml::CSSStyleSelector;
00216 friend class KHTMLPartIface;
00217 friend class KHTMLPartFunction;
00218
00219 Q_PROPERTY( bool javaScriptEnabled READ jScriptEnabled WRITE setJScriptEnabled )
00220 Q_PROPERTY( bool javaEnabled READ javaEnabled WRITE setJavaEnabled )
00221 Q_PROPERTY( bool autoloadImages READ autoloadImages WRITE setAutoloadImages )
00222 Q_PROPERTY( bool dndEnabled READ dndEnabled WRITE setDNDEnabled )
00223 Q_PROPERTY( bool pluginsEnabled READ pluginsEnabled WRITE setPluginsEnabled )
00224 Q_PROPERTY( bool onlyLocalReferences READ onlyLocalReferences WRITE setOnlyLocalReferences )
00225 Q_PROPERTY( QCString dcopObjectId READ dcopObjectId )
00226 Q_PROPERTY( bool modified READ isModified )
00227
00228 public:
00229 enum GUIProfile { DefaultGUI, BrowserViewGUI };
00230
00243 KHTMLPart( QWidget *parentWidget = 0, const char *widgetname = 0,
00244 QObject *parent = 0, const char *name = 0, GUIProfile prof = DefaultGUI );
00245
00246 KHTMLPart( KHTMLView *view, QObject *parent = 0, const char *name = 0, GUIProfile prof = DefaultGUI );
00247
00251 virtual ~KHTMLPart();
00252
00258 virtual bool openURL( const KURL &url );
00259
00263 virtual bool closeURL();
00264
00271 virtual void showError( KIO::Job* job );
00272
00276 DOM::HTMLDocument htmlDocument() const;
00277
00281 DOM::Document document() const;
00282
00286 DOM::Node activeNode() const;
00287
00291 KParts::BrowserExtension *browserExtension() const;
00292 KParts::LiveConnectExtension *liveConnectExtension( const khtml::RenderPart *) const;
00293 KParts::BrowserHostExtension *browserHostExtension() const;
00294
00298 KHTMLView *view() const;
00299
00306 void setJScriptEnabled( bool enable );
00307
00312 bool jScriptEnabled() const;
00313
00331 KJS::Interpreter *jScriptInterpreter();
00332
00336 void setStatusMessagesEnabled( bool enable );
00337
00341 bool statusMessagesEnabled() const;
00342
00346 void setMetaRefreshEnabled( bool enable );
00347
00351 bool metaRefreshEnabled() const;
00352
00357 QVariant executeScript( const DOM::Node &n, const QString &script );
00358
00363 void setDNDEnabled( bool b );
00364
00368 bool dndEnabled() const;
00369
00376 void setJavaEnabled( bool enable );
00377
00381 bool javaEnabled() const;
00382
00386 KJavaAppletContext *javaContext();
00387
00392 KJavaAppletContext *createJavaContext();
00393
00397 void setPluginsEnabled( bool enable );
00398
00402 bool pluginsEnabled() const;
00403
00410 void setAutoloadImages( bool enable );
00417 bool autoloadImages() const;
00418
00435 void setOnlyLocalReferences( bool enable );
00436
00441 bool onlyLocalReferences() const;
00442
00446 bool isCaretMode() const;
00447
00452 bool isEditable() const;
00453
00467 void setCaretPosition(DOM::Node node, long offset, bool extendSelection = false);
00468
00476 enum CaretDisplayPolicy {
00477 CaretVisible, CaretInvisible, CaretBlink
00478 };
00479
00484 CaretDisplayPolicy caretDisplayPolicyNonFocused() const;
00485
00496 void setCaretDisplayPolicyNonFocused(CaretDisplayPolicy policy);
00497
00498 #ifndef KDE_NO_COMPAT
00499 void enableJScript( bool e ) { setJScriptEnabled(e); }
00500 void enableJava( bool e ) { setJavaEnabled(e); }
00501 void enablePlugins( bool e ) { setPluginsEnabled(e); }
00502 void autoloadImages( bool e ) { setAutoloadImages(e); }
00503 void enableMetaRefresh( bool e ) { setMetaRefreshEnabled(e); }
00504 bool setCharset( const QString &, bool ) { return true; }
00505
00506 KURL baseURL() const;
00507 QString baseTarget() const;
00508 #endif
00509
00513 KURL backgroundURL() const;
00514
00518 void scheduleRedirection( int delay, const QString &url, bool lockHistory = true );
00519
00542 virtual void begin( const KURL &url = KURL(), int xOffset = 0, int yOffset = 0 );
00543
00564 virtual void write( const char *str, int len = -1 );
00565
00573 virtual void write( const QString &str );
00574
00578 virtual void end();
00579
00580
00581
00582
00583
00584
00585
00586
00590 void paint( QPainter *, const QRect &, int = 0, bool * = 0 );
00591
00598 bool setEncoding( const QString &name, bool override = false );
00599
00605 QString encoding() const;
00606
00614 void setUserStyleSheet( const KURL &url );
00615
00623 void setUserStyleSheet( const QString &styleSheet );
00624
00625 public:
00626
00632 void setStandardFont( const QString &name );
00633
00640 void setFixedFont( const QString &name );
00641
00649 bool gotoAnchor( const QString &name );
00650
00657 bool nextAnchor();
00658
00663 bool prevAnchor();
00664
00668 void setURLCursor( const QCursor &c );
00669
00673 QCursor urlCursor() const;
00674
00679 enum FindOptions
00680 {
00681 FindLinksOnly = 1 * KFindDialog::MinimumUserOption,
00682 FindNoPopups = 2 * KFindDialog::MinimumUserOption
00683
00684 };
00685
00691 void findText();
00692
00701 void findText( const QString &str, long options, QWidget *parent = 0,
00702 KFindDialog *findDialog = 0 );
00703
00707 void findTextBegin();
00708
00714 bool findTextNext( const QString &str, bool forward, bool caseSensitive, bool isRegExp );
00715
00721 bool findTextNext();
00722
00733 void setZoomFactor(int percent);
00734
00738 int zoomFactor() const;
00739
00743 virtual QString selectedText() const;
00744
00748 DOM::Range selection() const;
00749
00761 void selection(DOM::Node &startNode, long &startOffset,
00762 DOM::Node &endNode, long &endOffset) const;
00763
00767 void setSelection( const DOM::Range & );
00768
00777 bool hasSelection() const;
00778
00782 void selectAll();
00783
00789 void show();
00790
00796 void hide();
00797
00802 KParts::PartManager *partManager();
00803
00811 virtual void saveState( QDataStream &stream );
00821 virtual void restoreState( QDataStream &stream );
00822
00829 DOM::Node nodeUnderMouse() const;
00830
00839 DOM::Node nonSharedNodeUnderMouse() const;
00840
00844 const KHTMLSettings *settings() const;
00845
00852 KHTMLPart *parentPart();
00853
00859 QStringList frameNames() const;
00860
00861 QPtrList<KParts::ReadOnlyPart> frames() const;
00862
00866 KHTMLPart *findFrame( const QString &f );
00867
00876 KHTMLPart *findFrameParent( KParts::ReadOnlyPart *callingPart, const QString &f, khtml::ChildFrame **childFrame=0 );
00877
00883 KParts::ReadOnlyPart *currentFrame() const;
00884
00891 bool frameExists( const QString &frameName );
00892
00896 KJSProxy *framejScript(KParts::ReadOnlyPart *framePart);
00897
00901 KParts::ReadOnlyPart *findFramePart( const QString &f );
00907 void setJSStatusBarText( const QString &text );
00908
00914 void setJSDefaultStatusBarText( const QString &text );
00915
00921 QString jsStatusBarText() const;
00922
00928 QString jsDefaultStatusBarText() const;
00929
00933 QString referrer() const;
00934
00938 QString pageReferrer() const;
00939
00943 QString lastModified() const;
00944
00948 void preloadStyleSheet( const QString &url, const QString &stylesheet );
00949
00953 void preloadScript( const QString &url, const QString &script );
00954
00958 bool restored() const;
00959
00960
00961 enum FormNotification { NoNotification = 0, Before, Only, Unused=255 };
00968 void setFormNotification(FormNotification fn);
00969
00976 FormNotification formNotification() const;
00977
00985 KURL toplevelURL();
00986
00993 bool isModified() const;
00994
00995 signals:
00999 void onURL( const QString &url );
01000
01004 void popupMenu( const QString &url, const QPoint &point );
01005
01009 void selectionChanged();
01010
01018 void nodeActivated( const DOM::Node & );
01019
01022 void docCreated();
01023
01035 void caretPositionChanged(const DOM::Node &node, long offset);
01036
01037
01044 void formSubmitNotification(const char *action, const QString& url,
01045 const QByteArray& formData, const QString& target,
01046 const QString& contentType, const QString& boundary);
01047
01048
01049 protected:
01050
01055 KURL completeURL( const QString &url );
01056
01063 void htmlError( int errorCode, const QString& text, const KURL& reqUrl );
01064
01065 virtual void customEvent( QCustomEvent *event );
01066
01070 virtual void khtmlMousePressEvent( khtml::MousePressEvent *event );
01074 virtual void khtmlMouseDoubleClickEvent( khtml::MouseDoubleClickEvent * );
01078 virtual void khtmlMouseMoveEvent( khtml::MouseMoveEvent *event );
01082 virtual void khtmlMouseReleaseEvent( khtml::MouseReleaseEvent *event );
01086 virtual void khtmlDrawContentsEvent( khtml::DrawContentsEvent * );
01087
01091 virtual void guiActivateEvent( KParts::GUIActivateEvent *event );
01092
01096 virtual bool openFile();
01097
01098 virtual void urlSelected( const QString &url, int button, int state,
01099 const QString &_target, KParts::URLArgs args = KParts::URLArgs());
01100
01109 virtual KParts::ReadOnlyPart *createPart( QWidget *parentWidget, const char *widgetName,
01110 QObject *parent, const char *name,
01111 const QString &mimetype, QString &serviceName,
01112 QStringList &serviceTypes, const QStringList ¶ms);
01113
01114
01115
01116 bool pluginPageQuestionAsked( const QString& mimetype ) const;
01117 void setPluginPageQuestionAsked( const QString& mimetype );
01118
01119 enum PageSecurity { NotCrypted, Encrypted, Mixed };
01120 void setPageSecurity( PageSecurity sec );
01121
01125 virtual bool doOpenStream( const QString& mimeType );
01126
01130 virtual bool doWriteStream( const QByteArray& data );
01131
01135 virtual bool doCloseStream();
01136
01137 public slots:
01138
01148 void setActiveNode( const DOM::Node &node );
01149
01153 void stopAnimations();
01154
01155 QCString dcopObjectId() const;
01156
01164 QVariant executeScript( const QString &script );
01165
01176 void setCaretMode(bool enable);
01177
01189 void setEditable(bool enable);
01190
01207 void setCaretVisible(bool show);
01208
01209
01210
01211
01212
01213 void submitFormProxy( const char *action, const QString &url,
01214 const QByteArray &formData,
01215 const QString &target,
01216 const QString& contentType = QString::null,
01217 const QString& boundary = QString::null );
01218
01219 private slots:
01220
01224 void reparseConfiguration();
01225
01229 void slotData( KIO::Job*, const QByteArray &data );
01233 void slotInfoMessage( KIO::Job*, const QString& msg );
01237 void slotRestoreData( const QByteArray &data );
01241 void slotFinished( KIO::Job* );
01245 void slotFinishedParsing();
01249 void slotRedirect();
01253 void slotRedirection( KIO::Job*, const KURL& );
01257 void slotDebugScript();
01261 void slotDebugDOMTree();
01265 void slotDebugRenderTree();
01269 void slotStopAnimations();
01273 virtual void slotViewDocumentSource();
01277 virtual void slotViewFrameSource();
01281 void slotViewPageInfo();
01285 virtual void slotSaveBackground();
01289 virtual void slotSaveDocument();
01293 virtual void slotSaveFrame();
01297 virtual void slotSecurity();
01301 virtual void slotSetEncoding();
01302
01306 virtual void slotUseStylesheet();
01307
01308 virtual void slotFind();
01309 virtual void slotFindDone();
01310 virtual void slotFindDialogDestroyed();
01311 void slotFindNext();
01312
01313 void slotIncZoom();
01314 void slotDecZoom();
01315 void slotIncZoomFast();
01316 void slotDecZoomFast();
01317
01318 void slotLoadImages();
01319 void slotWalletClosed();
01320 void launchWalletManager();
01321 void walletMenu();
01322
01326 void submitFormAgain();
01327
01331 void updateActions();
01335 void slotPartRemoved( KParts::Part *part );
01339 void slotActiveFrameChanged( KParts::Part *part );
01343 void slotChildStarted( KIO::Job *job );
01347 void slotChildCompleted();
01351 void slotChildCompleted( bool );
01355 void slotParentCompleted();
01359 void slotChildURLRequest( const KURL &url, const KParts::URLArgs &args );
01363 void slotChildDocCreated();
01367 void slotRequestFocus( KParts::ReadOnlyPart * );
01368 void slotLoaderRequestStarted( khtml::DocLoader*, khtml::CachedObject* obj);
01369 void slotLoaderRequestDone( khtml::DocLoader*, khtml::CachedObject *obj );
01370 void checkCompleted();
01371
01375 void slotAutoScroll();
01376
01377 void slotPrintFrame();
01378
01379 void slotSelectAll();
01380
01384 void slotProgressUpdate();
01385
01386
01387
01388
01389 void slotJobPercent( KIO::Job*, unsigned long );
01390
01391
01392
01393
01394 void slotJobDone( KIO::Job* );
01395
01396
01397
01398
01399 void slotUserSheetStatDone( KIO::Job* );
01400
01401
01402
01403
01404 void slotJobSpeed( KIO::Job*, unsigned long );
01405
01409 void slotClearSelection();
01410
01414 void slotZoomView( int );
01415
01419 void slotHighlight( const QString &, int index, int length );
01420
01424 void slotAutomaticDetectionLanguage( int _id );
01425
01429 void slotToggleCaretMode();
01430
01434 void launchJSErrorDialog();
01435
01439 void removeJSErrorExtension();
01440
01444 void disableJSErrorExtension();
01445
01449 void jsErrorDialogContextMenu();
01450
01456 void restoreScrollPosition();
01457
01458 void walletOpened(KWallet::Wallet*);
01459
01460 private:
01461
01462 KJSErrorDlg *jsErrorExtension();
01463
01464 enum StatusBarPriority { BarDefaultText, BarHoverText, BarOverrideText };
01465 void setStatusBarText( const QString& text, StatusBarPriority p);
01466
01467 bool restoreURL( const KURL &url );
01468 void resetFromScript();
01469 void emitSelectionChanged();
01470
01471 bool checkFrameAccess(KHTMLPart *callingHtmlPart);
01472 bool openURLInFrame( const KURL &url, const KParts::URLArgs &urlArgs );
01473 void startAutoScroll();
01474 void stopAutoScroll();
01475 void overURL( const QString &url, const QString &target, bool shiftPressed = false );
01476
01477 void resetHoverText();
01478 bool processObjectRequest( khtml::ChildFrame *child, const KURL &url, const QString &mimetype );
01479
01480 KWallet::Wallet* wallet();
01481
01482 void openWallet(DOM::HTMLFormElementImpl*);
01483 void saveToWallet(const QString& key, const QMap<QString,QString>& data);
01484 void dequeueWallet(DOM::HTMLFormElementImpl*);
01485
01489
01490
01491
01492
01493
01494
01495
01496 void submitForm( const char *action, const QString &url, const QByteArray &formData,
01497 const QString &target, const QString& contentType = QString::null,
01498 const QString& boundary = QString::null );
01499
01500 void popupMenu( const QString &url );
01501
01502 void init( KHTMLView *view, GUIProfile prof );
01503
01504
01505 void clear();
01506
01507 bool scheduleScript( const DOM::Node &n, const QString& script);
01508
01509 QVariant crossFrameExecuteScript(const QString& target, const QString& script);
01510 QVariant executeScheduledScript();
01511
01512 bool requestFrame( khtml::RenderPart *frame, const QString &url, const QString &frameName,
01513 const QStringList &args = QStringList(), bool isIFrame = false );
01514
01522 QString requestFrameName();
01523
01524 bool requestObject( khtml::RenderPart *frame, const QString &url, const QString &serviceType,
01525 const QStringList &args = QStringList() );
01526
01527 bool requestObject( khtml::ChildFrame *child, const KURL &url, const KParts::URLArgs &args = KParts::URLArgs() );
01528
01529 DOM::EventListener *createHTMLEventListener( QString code, QString name );
01530
01531 DOM::HTMLDocumentImpl *docImpl() const;
01532 DOM::DocumentImpl *xmlDocImpl() const;
01533 khtml::ChildFrame *frame( const QObject *obj );
01534
01535 khtml::ChildFrame *recursiveFrameRequest( KHTMLPart *callingHtmlPart, const KURL &url, const KParts::URLArgs &args, bool callParent = true );
01536
01537 bool checkLinkSecurity( const KURL &linkURL,const QString &message = QString::null, const QString &button = QString::null );
01538 QVariant executeScript( const QString& filename, int baseLine, const DOM::Node &n, const QString& script );
01539
01540 KJSProxy *jScript();
01541
01542 KHTMLPart *opener();
01543 long cacheId() const;
01544 void setOpener( KHTMLPart *_opener );
01545 bool openedByJS();
01546 void setOpenedByJS( bool _openedByJS );
01547
01548 void checkEmitLoadEvent();
01549 void emitLoadEvent();
01550
01551 bool initFindNode( bool selection, bool reverse, bool fromCursor );
01552
01553 void extendSelection( DOM::NodeImpl* node, long offset, DOM::Node& selectionNode, long& selectionOffset, bool right, bool paragraph );
01563 void extendSelectionTo(int x, int y, int absX, int absY, const DOM::Node &innerNode);
01567 bool isExtendingSelection() const;
01568 khtml::Decoder *createDecoder();
01569 QString defaultEncoding() const;
01570
01574 void zoomIn(const int stepping[], int count);
01578 void zoomOut(const int stepping[], int count);
01579
01580 void emitCaretPositionChanged(const DOM::Node &node, long offset);
01581
01582 void setDebugScript( bool enable );
01583
01584 KHTMLPartPrivate *d;
01585 friend class KHTMLPartPrivate;
01586 };
01587
01588
01589 #endif