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 class 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 friend class KHTMLPopupGUIClient;
00219
00220 Q_PROPERTY( bool javaScriptEnabled READ jScriptEnabled WRITE setJScriptEnabled )
00221 Q_PROPERTY( bool javaEnabled READ javaEnabled WRITE setJavaEnabled )
00222 Q_PROPERTY( bool autoloadImages READ autoloadImages WRITE setAutoloadImages )
00223 Q_PROPERTY( bool dndEnabled READ dndEnabled WRITE setDNDEnabled )
00224 Q_PROPERTY( bool pluginsEnabled READ pluginsEnabled WRITE setPluginsEnabled )
00225 Q_PROPERTY( bool onlyLocalReferences READ onlyLocalReferences WRITE setOnlyLocalReferences )
00226 Q_PROPERTY( QCString dcopObjectId READ dcopObjectId )
00227 Q_PROPERTY( bool modified READ isModified )
00228
00229 public:
00230 enum GUIProfile { DefaultGUI, BrowserViewGUI };
00231
00244 KHTMLPart( QWidget *parentWidget = 0, const char *widgetname = 0,
00245 QObject *parent = 0, const char *name = 0, GUIProfile prof = DefaultGUI );
00246
00247 KHTMLPart( KHTMLView *view, QObject *parent = 0, const char *name = 0, GUIProfile prof = DefaultGUI );
00248
00252 virtual ~KHTMLPart();
00253
00259 virtual bool openURL( const KURL &url );
00260
00264 virtual bool closeURL();
00265
00272 virtual void showError( KIO::Job* job );
00273
00277 DOM::HTMLDocument htmlDocument() const;
00278
00282 DOM::Document document() const;
00283
00288 QString documentSource() const;
00289
00293 DOM::Node activeNode() const;
00294
00298 KParts::BrowserExtension *browserExtension() const;
00299 KParts::LiveConnectExtension *liveConnectExtension( const khtml::RenderPart *) const;
00300 KParts::BrowserHostExtension *browserHostExtension() const;
00301
00305 KHTMLView *view() const;
00306
00313 void setJScriptEnabled( bool enable );
00314
00319 bool jScriptEnabled() const;
00320
00338 KJS::Interpreter *jScriptInterpreter();
00339
00351 void setStatusMessagesEnabled( bool enable );
00352
00356 bool statusMessagesEnabled() const;
00357
00361 void setMetaRefreshEnabled( bool enable );
00362
00366 bool metaRefreshEnabled() const;
00367
00372 QVariant executeScript( const DOM::Node &n, const QString &script );
00373
00378 void setDNDEnabled( bool b );
00379
00383 bool dndEnabled() const;
00384
00391 void setJavaEnabled( bool enable );
00392
00396 bool javaEnabled() const;
00397
00401 KJavaAppletContext *javaContext();
00402
00407 KJavaAppletContext *createJavaContext();
00408
00412 void setPluginsEnabled( bool enable );
00413
00417 bool pluginsEnabled() const;
00418
00425 void setAutoloadImages( bool enable );
00432 bool autoloadImages() const;
00433
00450 void setOnlyLocalReferences( bool enable );
00451
00456 bool onlyLocalReferences() const;
00457
00461 bool isCaretMode() const;
00462
00467 bool isEditable() const;
00468
00482 void setCaretPosition(DOM::Node node, long offset, bool extendSelection = false);
00483
00491 enum CaretDisplayPolicy {
00492 CaretVisible, CaretInvisible, CaretBlink
00493 };
00494
00499 CaretDisplayPolicy caretDisplayPolicyNonFocused() const;
00500
00511 void setCaretDisplayPolicyNonFocused(CaretDisplayPolicy policy);
00512
00513 #ifndef KDE_NO_COMPAT
00514 void enableJScript( bool e ) { setJScriptEnabled(e); }
00515 void enableJava( bool e ) { setJavaEnabled(e); }
00516 void enablePlugins( bool e ) { setPluginsEnabled(e); }
00517 void autoloadImages( bool e ) { setAutoloadImages(e); }
00518 void enableMetaRefresh( bool e ) { setMetaRefreshEnabled(e); }
00519 bool setCharset( const QString &, bool ) { return true; }
00520
00521 KURL baseURL() const;
00522 QString baseTarget() const;
00523 #endif
00524
00528 KURL backgroundURL() const;
00529
00533 void scheduleRedirection( int delay, const QString &url, bool lockHistory = true );
00534
00557 virtual void begin( const KURL &url = KURL(), int xOffset = 0, int yOffset = 0 );
00558
00579 virtual void write( const char *str, int len = -1 );
00580
00588 virtual void write( const QString &str );
00589
00593 virtual void end();
00594
00595
00596
00597
00598
00599
00600
00601
00605 void paint( QPainter *, const QRect &, int = 0, bool * = 0 );
00606
00613 bool setEncoding( const QString &name, bool override = false );
00614
00620 QString encoding() const;
00621
00631 void setUserStyleSheet( const KURL &url );
00632
00642 void setUserStyleSheet( const QString &styleSheet );
00643
00644 public:
00645
00651 void setStandardFont( const QString &name );
00652
00659 void setFixedFont( const QString &name );
00660
00668 bool gotoAnchor( const QString &name );
00669
00676 bool nextAnchor();
00677
00682 bool prevAnchor();
00683
00687 void setURLCursor( const QCursor &c );
00688
00692 QCursor urlCursor() const;
00693
00698 enum FindOptions
00699 {
00700 FindLinksOnly = 1 * KFindDialog::MinimumUserOption,
00701 FindNoPopups = 2 * KFindDialog::MinimumUserOption
00702
00703 };
00704
00710 void findText();
00711
00720 void findText( const QString &str, long options, QWidget *parent = 0,
00721 KFindDialog *findDialog = 0 );
00722
00726 void findTextBegin();
00727
00733 bool findTextNext( const QString &str, bool forward, bool caseSensitive, bool isRegExp );
00734
00740 bool findTextNext();
00741
00748
00749 bool findTextNext( bool reverse );
00750
00761 void setZoomFactor(int percent);
00762
00766 int zoomFactor() const;
00767
00771 virtual QString selectedText() const;
00772
00781 QString selectedTextAsHTML() const;
00782
00786 DOM::Range selection() const;
00787
00799 void selection(DOM::Node &startNode, long &startOffset,
00800 DOM::Node &endNode, long &endOffset) const;
00801
00805 void setSelection( const DOM::Range & );
00806
00815 bool hasSelection() const;
00816
00820 void selectAll();
00821
00827 void show();
00828
00834 void hide();
00835
00840 KParts::PartManager *partManager();
00841
00849 virtual void saveState( QDataStream &stream );
00859 virtual void restoreState( QDataStream &stream );
00860
00867 DOM::Node nodeUnderMouse() const;
00868
00877 DOM::Node nonSharedNodeUnderMouse() const;
00878
00882 const KHTMLSettings *settings() const;
00883
00890 KHTMLPart *parentPart();
00891
00897 QStringList frameNames() const;
00898
00899 QPtrList<KParts::ReadOnlyPart> frames() const;
00900
00904 KHTMLPart *findFrame( const QString &f );
00905
00914 KHTMLPart *findFrameParent( KParts::ReadOnlyPart *callingPart, const QString &f, khtml::ChildFrame **childFrame=0 );
00915
00921 KParts::ReadOnlyPart *currentFrame() const;
00922
00929 bool frameExists( const QString &frameName );
00930
00934 KJSProxy *framejScript(KParts::ReadOnlyPart *framePart);
00935
00939 KParts::ReadOnlyPart *findFramePart( const QString &f );
00945 void setJSStatusBarText( const QString &text );
00946
00952 void setJSDefaultStatusBarText( const QString &text );
00953
00959 QString jsStatusBarText() const;
00960
00966 QString jsDefaultStatusBarText() const;
00967
00971 QString referrer() const;
00972
00976 QString pageReferrer() const;
00977
00981 QString lastModified() const;
00982
00986 void preloadStyleSheet( const QString &url, const QString &stylesheet );
00987
00991 void preloadScript( const QString &url, const QString &script );
00992
00996 bool restored() const;
00997
00998
00999 enum FormNotification { NoNotification = 0, Before, Only, Unused=255 };
01006 void setFormNotification(FormNotification fn);
01007
01014 FormNotification formNotification() const;
01015
01023 KURL toplevelURL();
01024
01031 bool isModified() const;
01032
01038 void setSuppressedPopupIndicator( bool enable );
01039
01044 void setSuppressedPopupIndicator( bool enable, KHTMLPart *originPart );
01045
01050 bool inProgress() const;
01051
01052 signals:
01056 void onURL( const QString &url );
01057
01061 void popupMenu( const QString &url, const QPoint &point );
01062
01066 void selectionChanged();
01067
01075 void nodeActivated( const DOM::Node & );
01076
01079 void docCreated();
01080
01092 void caretPositionChanged(const DOM::Node &node, long offset);
01093
01094
01101 void formSubmitNotification(const char *action, const QString& url,
01102 const QByteArray& formData, const QString& target,
01103 const QString& contentType, const QString& boundary);
01104
01105
01106 protected:
01107
01112 KURL completeURL( const QString &url );
01113
01120 void htmlError( int errorCode, const QString& text, const KURL& reqUrl );
01121
01122 virtual void customEvent( QCustomEvent *event );
01123
01127 virtual void khtmlMousePressEvent( khtml::MousePressEvent *event );
01131 virtual void khtmlMouseDoubleClickEvent( khtml::MouseDoubleClickEvent * );
01135 virtual void khtmlMouseMoveEvent( khtml::MouseMoveEvent *event );
01139 virtual void khtmlMouseReleaseEvent( khtml::MouseReleaseEvent *event );
01143 virtual void khtmlDrawContentsEvent( khtml::DrawContentsEvent * );
01144
01148 virtual void guiActivateEvent( KParts::GUIActivateEvent *event );
01149
01153 virtual bool openFile();
01154
01155 virtual void urlSelected( const QString &url, int button, int state,
01156 const QString &_target, KParts::URLArgs args = KParts::URLArgs());
01157
01166 virtual KParts::ReadOnlyPart *createPart( QWidget *parentWidget, const char *widgetName,
01167 QObject *parent, const char *name,
01168 const QString &mimetype, QString &serviceName,
01169 QStringList &serviceTypes, const QStringList ¶ms);
01170
01171
01172
01173 bool pluginPageQuestionAsked( const QString& mimetype ) const;
01174 void setPluginPageQuestionAsked( const QString& mimetype );
01175
01176 enum PageSecurity { NotCrypted, Encrypted, Mixed };
01177 void setPageSecurity( PageSecurity sec );
01178
01182 virtual bool doOpenStream( const QString& mimeType );
01183
01187 virtual bool doWriteStream( const QByteArray& data );
01188
01192 virtual bool doCloseStream();
01193
01194 public slots:
01195
01205 void setActiveNode( const DOM::Node &node );
01206
01210 void stopAnimations();
01211
01212 QCString dcopObjectId() const;
01213
01221 QVariant executeScript( const QString &script );
01222
01233 void setCaretMode(bool enable);
01234
01246 void setEditable(bool enable);
01247
01264 void setCaretVisible(bool show);
01265
01266
01267
01268
01269
01270 void submitFormProxy( const char *action, const QString &url,
01271 const QByteArray &formData,
01272 const QString &target,
01273 const QString& contentType = QString::null,
01274 const QString& boundary = QString::null );
01275
01276 private slots:
01277
01281 void reparseConfiguration();
01282
01286 void slotData( KIO::Job*, const QByteArray &data );
01290 void slotInfoMessage( KIO::Job*, const QString& msg );
01294 void slotRestoreData( const QByteArray &data );
01298 void slotFinished( KIO::Job* );
01302 void slotFinishedParsing();
01306 void slotRedirect();
01310 void slotRedirection( KIO::Job*, const KURL& );
01314 void slotDebugScript();
01318 void slotDebugDOMTree();
01322 void slotDebugRenderTree();
01326 void slotStopAnimations();
01330 virtual void slotViewDocumentSource();
01334 virtual void slotViewFrameSource();
01338 void slotViewPageInfo();
01342 virtual void slotSaveBackground();
01346 virtual void slotSaveDocument();
01350 virtual void slotSaveFrame();
01354 virtual void slotSecurity();
01358 virtual void slotSetEncoding();
01359
01363 virtual void slotUseStylesheet();
01364
01365 virtual void slotFind();
01366 virtual void slotFindDone();
01367 virtual void slotFindDialogDestroyed();
01368 void slotFindNext();
01369 void slotFindPrev();
01370 void slotFindAheadText();
01371 void slotFindAheadLink();
01372
01373 void slotIncZoom();
01374 void slotDecZoom();
01375 void slotIncZoomFast();
01376 void slotDecZoomFast();
01377
01378 void slotLoadImages();
01379 void slotWalletClosed();
01380 void launchWalletManager();
01381 void walletMenu();
01382
01386 void submitFormAgain();
01387
01391 void updateActions();
01395 void slotPartRemoved( KParts::Part *part );
01399 void slotActiveFrameChanged( KParts::Part *part );
01403 void slotChildStarted( KIO::Job *job );
01407 void slotChildCompleted();
01411 void slotChildCompleted( bool );
01415 void slotParentCompleted();
01419 void slotChildURLRequest( const KURL &url, const KParts::URLArgs &args );
01423 void slotChildDocCreated();
01427 void slotRequestFocus( KParts::ReadOnlyPart * );
01428 void slotLoaderRequestStarted( khtml::DocLoader*, khtml::CachedObject* obj);
01429 void slotLoaderRequestDone( khtml::DocLoader*, khtml::CachedObject *obj );
01430 void checkCompleted();
01431
01435 void slotAutoScroll();
01436
01437 void slotPrintFrame();
01438
01439 void slotSelectAll();
01440
01444 void slotProgressUpdate();
01445
01446
01447
01448
01449 void slotJobPercent( KIO::Job*, unsigned long );
01450
01451
01452
01453
01454 void slotJobDone( KIO::Job* );
01455
01456
01457
01458
01459 void slotUserSheetStatDone( KIO::Job* );
01460
01461
01462
01463
01464 void slotJobSpeed( KIO::Job*, unsigned long );
01465
01469 void slotClearSelection();
01470
01474 void slotZoomView( int );
01475
01479 void slotHighlight( const QString &, int index, int length );
01480
01484 void slotAutomaticDetectionLanguage( int _id );
01485
01489 void slotToggleCaretMode();
01490
01494 void suppressedPopupMenu();
01495
01499 void togglePopupPassivePopup();
01500
01504 void showSuppressedPopups();
01505
01509 void launchJSConfigDialog();
01510
01514 void launchJSErrorDialog();
01515
01519 void removeJSErrorExtension();
01520
01524 void disableJSErrorExtension();
01525
01529 void jsErrorDialogContextMenu();
01530
01536 void restoreScrollPosition();
01537
01538 void walletOpened(KWallet::Wallet*);
01539
01540 private:
01541
01542 KJSErrorDlg *jsErrorExtension();
01543
01544 enum StatusBarPriority { BarDefaultText, BarHoverText, BarOverrideText };
01545 void setStatusBarText( const QString& text, StatusBarPriority p);
01546
01547 bool restoreURL( const KURL &url );
01548 void resetFromScript();
01549 void emitSelectionChanged();
01550
01551 bool checkFrameAccess(KHTMLPart *callingHtmlPart);
01552 bool openURLInFrame( const KURL &url, const KParts::URLArgs &urlArgs );
01553 bool urlSelectedIntern( const QString &url, int button, int state,
01554 const QString &_target, KParts::URLArgs args = KParts::URLArgs());
01555 void startAutoScroll();
01556 void stopAutoScroll();
01557 void overURL( const QString &url, const QString &target, bool shiftPressed = false );
01558 void resetHoverText();
01559
01560 bool processObjectRequest( khtml::ChildFrame *child, const KURL &url, const QString &mimetype );
01561
01562 KWallet::Wallet* wallet();
01563
01564 void openWallet(DOM::HTMLFormElementImpl*);
01565 void saveToWallet(const QString& key, const QMap<QString,QString>& data);
01566 void dequeueWallet(DOM::HTMLFormElementImpl*);
01567
01568 void enableFindAheadActions(bool);
01569
01573
01574
01575
01576
01577
01578
01579
01580 void submitForm( const char *action, const QString &url, const QByteArray &formData,
01581 const QString &target, const QString& contentType = QString::null,
01582 const QString& boundary = QString::null );
01583
01584 void popupMenu( const QString &url );
01585
01586 void init( KHTMLView *view, GUIProfile prof );
01587
01588
01589 void clear();
01590
01591 bool scheduleScript( const DOM::Node &n, const QString& script);
01592
01593 QVariant crossFrameExecuteScript(const QString& target, const QString& script);
01594 QVariant executeScheduledScript();
01595
01596 bool requestFrame( khtml::RenderPart *frame, const QString &url, const QString &frameName,
01597 const QStringList &args = QStringList(), bool isIFrame = false );
01598
01606 QString requestFrameName();
01607
01608 bool requestObject( khtml::RenderPart *frame, const QString &url, const QString &serviceType,
01609 const QStringList &args = QStringList() );
01610
01611 bool requestObject( khtml::ChildFrame *child, const KURL &url, const KParts::URLArgs &args = KParts::URLArgs() );
01612
01613 DOM::EventListener *createHTMLEventListener( QString code, QString name, DOM::NodeImpl *node );
01614
01615 DOM::HTMLDocumentImpl *docImpl() const;
01616 DOM::DocumentImpl *xmlDocImpl() const;
01617 khtml::ChildFrame *frame( const QObject *obj );
01618
01619 khtml::ChildFrame *recursiveFrameRequest( KHTMLPart *callingHtmlPart, const KURL &url, const KParts::URLArgs &args, bool callParent = true );
01620
01621 bool checkLinkSecurity( const KURL &linkURL,const QString &message = QString::null, const QString &button = QString::null );
01622 QVariant executeScript( const QString& filename, int baseLine, const DOM::Node &n, const QString& script );
01623
01624 KJSProxy *jScript();
01625
01626 KHTMLPart *opener();
01627 long cacheId() const;
01628 void setOpener( KHTMLPart *_opener );
01629 bool openedByJS();
01630 void setOpenedByJS( bool _openedByJS );
01631
01632 void checkEmitLoadEvent();
01633 void emitLoadEvent();
01634
01635 bool initFindNode( bool selection, bool reverse, bool fromCursor );
01636
01637 void extendSelection( DOM::NodeImpl* node, long offset, DOM::Node& selectionNode, long& selectionOffset, bool right, bool paragraph );
01647 void extendSelectionTo(int x, int y, int absX, int absY, const DOM::Node &innerNode);
01651 bool isExtendingSelection() const;
01652 khtml::Decoder *createDecoder();
01653 QString defaultEncoding() const;
01654
01656 QString defaultExtension() const;
01657
01661 void zoomIn(const int stepping[], int count);
01665 void zoomOut(const int stepping[], int count);
01666
01667 void emitCaretPositionChanged(const DOM::Node &node, long offset);
01668
01669 void setDebugScript( bool enable );
01670
01671 void runAdFilter();
01672
01673 KHTMLPartPrivate *d;
01674 friend class KHTMLPartPrivate;
01675 };
01676
01677
01678 #endif