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
00226
00227
00228
00229
00230
00231 Q_PROPERTY( QCString dcopObjectId READ dcopObjectId )
00232 Q_PROPERTY( bool modified READ isModified )
00233
00234 public:
00235 enum GUIProfile { DefaultGUI, BrowserViewGUI };
00236
00249 KHTMLPart( QWidget *parentWidget = 0, const char *widgetname = 0,
00250 QObject *parent = 0, const char *name = 0, GUIProfile prof = DefaultGUI );
00251
00252 KHTMLPart( KHTMLView *view, QObject *parent = 0, const char *name = 0, GUIProfile prof = DefaultGUI );
00253
00257 virtual ~KHTMLPart();
00258
00264 virtual bool openURL( const KURL &url );
00265
00269 virtual bool closeURL();
00270
00277 virtual void showError( KIO::Job* job );
00278
00282 DOM::HTMLDocument htmlDocument() const;
00283
00287 DOM::Document document() const;
00288
00293 QString documentSource() const;
00294
00298 DOM::Node activeNode() const;
00299
00303 KParts::BrowserExtension *browserExtension() const;
00304 KParts::LiveConnectExtension *liveConnectExtension( const khtml::RenderPart *) const;
00305 KParts::BrowserHostExtension *browserHostExtension() const;
00306
00310 KHTMLView *view() const;
00311
00318 void setJScriptEnabled( bool enable );
00319
00324 bool jScriptEnabled() const;
00325
00343 KJS::Interpreter *jScriptInterpreter();
00344
00356 void setStatusMessagesEnabled( bool enable );
00357
00361 bool statusMessagesEnabled() const;
00362
00366 void setMetaRefreshEnabled( bool enable );
00367
00371 bool metaRefreshEnabled() const;
00372
00377 QVariant executeScript( const DOM::Node &n, const QString &script );
00378
00383 void setDNDEnabled( bool b );
00384
00388 bool dndEnabled() const;
00389
00396 void setJavaEnabled( bool enable );
00397
00401 bool javaEnabled() const;
00402
00406 KJavaAppletContext *javaContext();
00407
00412 KJavaAppletContext *createJavaContext();
00413
00417 void setPluginsEnabled( bool enable );
00418
00422 bool pluginsEnabled() const;
00423
00430 void setAutoloadImages( bool enable );
00437 bool autoloadImages() const;
00438
00455 void setOnlyLocalReferences( bool enable );
00456
00461 bool onlyLocalReferences() const;
00462
00466 bool isCaretMode() const;
00467
00472 bool isEditable() const;
00473
00487 void setCaretPosition(DOM::Node node, long offset, bool extendSelection = false);
00488
00496 enum CaretDisplayPolicy {
00497 CaretVisible, CaretInvisible, CaretBlink
00498 };
00499
00504 CaretDisplayPolicy caretDisplayPolicyNonFocused() const;
00505
00516 void setCaretDisplayPolicyNonFocused(CaretDisplayPolicy policy);
00517
00518 #ifndef KDE_NO_COMPAT
00519 void enableJScript( bool e ) { setJScriptEnabled(e); }
00520 void enableJava( bool e ) { setJavaEnabled(e); }
00521 void enablePlugins( bool e ) { setPluginsEnabled(e); }
00522 void autoloadImages( bool e ) { setAutoloadImages(e); }
00523 void enableMetaRefresh( bool e ) { setMetaRefreshEnabled(e); }
00524 bool setCharset( const QString &, bool ) { return true; }
00525
00526 KURL baseURL() const;
00527 QString baseTarget() const;
00528 #endif
00529
00533 KURL backgroundURL() const;
00534
00538 void scheduleRedirection( int delay, const QString &url, bool lockHistory = true );
00539
00562 virtual void begin( const KURL &url = KURL(), int xOffset = 0, int yOffset = 0 );
00563
00584 virtual void write( const char *str, int len = -1 );
00585
00593 virtual void write( const QString &str );
00594
00598 virtual void end();
00599
00600
00601
00602
00603
00604
00605
00606
00610 void paint( QPainter *, const QRect &, int = 0, bool * = 0 );
00611
00618 bool setEncoding( const QString &name, bool override = false );
00619
00625 QString encoding() const;
00626
00636 void setUserStyleSheet( const KURL &url );
00637
00647 void setUserStyleSheet( const QString &styleSheet );
00648
00649 public:
00650
00656 void setStandardFont( const QString &name );
00657
00664 void setFixedFont( const QString &name );
00665
00673 bool gotoAnchor( const QString &name );
00674
00681 bool nextAnchor();
00682
00687 bool prevAnchor();
00688
00692 void setURLCursor( const QCursor &c );
00693
00697 QCursor urlCursor() const;
00698
00703 enum FindOptions
00704 {
00705 FindLinksOnly = 1 * KFindDialog::MinimumUserOption,
00706 FindNoPopups = 2 * KFindDialog::MinimumUserOption
00707
00708 };
00709
00715 void findText();
00716
00725 void findText( const QString &str, long options, QWidget *parent = 0,
00726 KFindDialog *findDialog = 0 );
00727
00731 void findTextBegin();
00732
00738 bool findTextNext( const QString &str, bool forward, bool caseSensitive, bool isRegExp );
00739
00745 bool findTextNext();
00746
00753
00754 bool findTextNext( bool reverse );
00755
00766 void setZoomFactor(int percent);
00767
00771 int zoomFactor() const;
00772
00776 virtual QString selectedText() const;
00777
00786 QString selectedTextAsHTML() const;
00787
00791 DOM::Range selection() const;
00792
00804 void selection(DOM::Node &startNode, long &startOffset,
00805 DOM::Node &endNode, long &endOffset) const;
00806
00810 void setSelection( const DOM::Range & );
00811
00820 bool hasSelection() const;
00821
00825 void selectAll();
00826
00832 void show();
00833
00839 void hide();
00840
00845 KParts::PartManager *partManager();
00846
00854 virtual void saveState( QDataStream &stream );
00864 virtual void restoreState( QDataStream &stream );
00865
00872 DOM::Node nodeUnderMouse() const;
00873
00882 DOM::Node nonSharedNodeUnderMouse() const;
00883
00887 const KHTMLSettings *settings() const;
00888
00895 KHTMLPart *parentPart();
00896
00902 QStringList frameNames() const;
00903
00904 QPtrList<KParts::ReadOnlyPart> frames() const;
00905
00909 KHTMLPart *findFrame( const QString &f );
00910
00919 KHTMLPart *findFrameParent( KParts::ReadOnlyPart *callingPart, const QString &f, khtml::ChildFrame **childFrame=0 );
00920
00926 KParts::ReadOnlyPart *currentFrame() const;
00927
00934 bool frameExists( const QString &frameName );
00935
00939 KJSProxy *framejScript(KParts::ReadOnlyPart *framePart);
00940
00944 KParts::ReadOnlyPart *findFramePart( const QString &f );
00950 void setJSStatusBarText( const QString &text );
00951
00957 void setJSDefaultStatusBarText( const QString &text );
00958
00964 QString jsStatusBarText() const;
00965
00971 QString jsDefaultStatusBarText() const;
00972
00976 QString referrer() const;
00977
00981 QString pageReferrer() const;
00982
00986 QString lastModified() const;
00987
00991 void preloadStyleSheet( const QString &url, const QString &stylesheet );
00992
00996 void preloadScript( const QString &url, const QString &script );
00997
01001 bool restored() const;
01002
01003
01004 enum FormNotification { NoNotification = 0, Before, Only, Unused=255 };
01011 void setFormNotification(FormNotification fn);
01012
01019 FormNotification formNotification() const;
01020
01028 KURL toplevelURL();
01029
01036 bool isModified() const;
01037
01043 void setSuppressedPopupIndicator( bool enable );
01044
01049 void setSuppressedPopupIndicator( bool enable, KHTMLPart *originPart );
01050
01055 bool inProgress() const;
01056
01057 signals:
01061 void onURL( const QString &url );
01062
01066 void popupMenu( const QString &url, const QPoint &point );
01067
01071 void selectionChanged();
01072
01080 void nodeActivated( const DOM::Node & );
01081
01084 void docCreated();
01085
01097 void caretPositionChanged(const DOM::Node &node, long offset);
01098
01099
01106 void formSubmitNotification(const char *action, const QString& url,
01107 const QByteArray& formData, const QString& target,
01108 const QString& contentType, const QString& boundary);
01109
01110
01111 protected:
01112
01117 KURL completeURL( const QString &url );
01118
01125 void htmlError( int errorCode, const QString& text, const KURL& reqUrl );
01126
01127 virtual void customEvent( QCustomEvent *event );
01128
01132 virtual void khtmlMousePressEvent( khtml::MousePressEvent *event );
01136 virtual void khtmlMouseDoubleClickEvent( khtml::MouseDoubleClickEvent * );
01140 virtual void khtmlMouseMoveEvent( khtml::MouseMoveEvent *event );
01144 virtual void khtmlMouseReleaseEvent( khtml::MouseReleaseEvent *event );
01148 virtual void khtmlDrawContentsEvent( khtml::DrawContentsEvent * );
01149
01153 virtual void guiActivateEvent( KParts::GUIActivateEvent *event );
01154
01158 virtual bool openFile();
01159
01160 virtual void urlSelected( const QString &url, int button, int state,
01161 const QString &_target, KParts::URLArgs args = KParts::URLArgs());
01162
01171 virtual KParts::ReadOnlyPart *createPart( QWidget *parentWidget, const char *widgetName,
01172 QObject *parent, const char *name,
01173 const QString &mimetype, QString &serviceName,
01174 QStringList &serviceTypes, const QStringList ¶ms);
01175
01176
01177
01178 bool pluginPageQuestionAsked( const QString& mimetype ) const;
01179 void setPluginPageQuestionAsked( const QString& mimetype );
01180
01181 enum PageSecurity { NotCrypted, Encrypted, Mixed };
01182 void setPageSecurity( PageSecurity sec );
01183
01187 virtual bool doOpenStream( const QString& mimeType );
01188
01192 virtual bool doWriteStream( const QByteArray& data );
01193
01197 virtual bool doCloseStream();
01198
01199 public slots:
01200
01210 void setActiveNode( const DOM::Node &node );
01211
01215 void stopAnimations();
01216
01217 QCString dcopObjectId() const;
01218
01226 QVariant executeScript( const QString &script );
01227
01238 void setCaretMode(bool enable);
01239
01251 void setEditable(bool enable);
01252
01269 void setCaretVisible(bool show);
01270
01271
01272
01273
01274
01275 void submitFormProxy( const char *action, const QString &url,
01276 const QByteArray &formData,
01277 const QString &target,
01278 const QString& contentType = QString::null,
01279 const QString& boundary = QString::null );
01280
01281 private slots:
01282
01286 void reparseConfiguration();
01287
01291 void slotData( KIO::Job*, const QByteArray &data );
01295 void slotInfoMessage( KIO::Job*, const QString& msg );
01299 void slotRestoreData( const QByteArray &data );
01303 void slotFinished( KIO::Job* );
01307 void slotFinishedParsing();
01311 void slotRedirect();
01315 void slotRedirection( KIO::Job*, const KURL& );
01319 void slotDebugScript();
01323 void slotDebugDOMTree();
01327 void slotDebugRenderTree();
01331 void slotStopAnimations();
01335 virtual void slotViewDocumentSource();
01339 virtual void slotViewFrameSource();
01343 void slotViewPageInfo();
01347 virtual void slotSaveBackground();
01351 virtual void slotSaveDocument();
01355 virtual void slotSaveFrame();
01359 virtual void slotSecurity();
01363 virtual void slotSetEncoding();
01364
01368 virtual void slotUseStylesheet();
01369
01370 virtual void slotFind();
01371 virtual void slotFindDone();
01372 virtual void slotFindDialogDestroyed();
01373 void slotFindNext();
01374 void slotFindPrev();
01375 void slotFindAheadText();
01376 void slotFindAheadLink();
01377
01378 void slotIncZoom();
01379 void slotDecZoom();
01380 void slotIncZoomFast();
01381 void slotDecZoomFast();
01382
01383 void slotLoadImages();
01384 void slotWalletClosed();
01385 void launchWalletManager();
01386 void walletMenu();
01387
01391 void submitFormAgain();
01392
01396 void updateActions();
01400 void slotPartRemoved( KParts::Part *part );
01404 void slotActiveFrameChanged( KParts::Part *part );
01408 void slotChildStarted( KIO::Job *job );
01412 void slotChildCompleted();
01416 void slotChildCompleted( bool );
01420 void slotParentCompleted();
01424 void slotChildURLRequest( const KURL &url, const KParts::URLArgs &args );
01428 void slotChildDocCreated();
01432 void slotRequestFocus( KParts::ReadOnlyPart * );
01433 void slotLoaderRequestStarted( khtml::DocLoader*, khtml::CachedObject* obj);
01434 void slotLoaderRequestDone( khtml::DocLoader*, khtml::CachedObject *obj );
01435 void checkCompleted();
01436
01440 void slotAutoScroll();
01441
01442 void slotPrintFrame();
01443
01444 void slotSelectAll();
01445
01449 void slotProgressUpdate();
01450
01451
01452
01453
01454 void slotJobPercent( KIO::Job*, unsigned long );
01455
01456
01457
01458
01459 void slotJobDone( KIO::Job* );
01460
01461
01462
01463
01464 void slotUserSheetStatDone( KIO::Job* );
01465
01466
01467
01468
01469 void slotJobSpeed( KIO::Job*, unsigned long );
01470
01474 void slotClearSelection();
01475
01479 void slotZoomView( int );
01480
01484 void slotHighlight( const QString &, int index, int length );
01485
01489 void slotAutomaticDetectionLanguage( int _id );
01490
01494 void slotToggleCaretMode();
01495
01499 void suppressedPopupMenu();
01500
01504 void togglePopupPassivePopup();
01505
01509 void showSuppressedPopups();
01510
01514 void launchJSConfigDialog();
01515
01519 void launchJSErrorDialog();
01520
01524 void removeJSErrorExtension();
01525
01529 void disableJSErrorExtension();
01530
01534 void jsErrorDialogContextMenu();
01535
01541 void restoreScrollPosition();
01542
01543 void walletOpened(KWallet::Wallet*);
01544
01545 private:
01546
01547 KJSErrorDlg *jsErrorExtension();
01548
01549 enum StatusBarPriority { BarDefaultText, BarHoverText, BarOverrideText };
01550 void setStatusBarText( const QString& text, StatusBarPriority p);
01551
01552 bool restoreURL( const KURL &url );
01553 void resetFromScript();
01554 void emitSelectionChanged();
01555
01556 bool checkFrameAccess(KHTMLPart *callingHtmlPart);
01557 bool openURLInFrame( const KURL &url, const KParts::URLArgs &urlArgs );
01558 bool urlSelectedIntern( const QString &url, int button, int state,
01559 const QString &_target, KParts::URLArgs args = KParts::URLArgs());
01560 void startAutoScroll();
01561 void stopAutoScroll();
01562 void overURL( const QString &url, const QString &target, bool shiftPressed = false );
01563 void resetHoverText();
01564
01565 bool processObjectRequest( khtml::ChildFrame *child, const KURL &url, const QString &mimetype );
01566
01567 KWallet::Wallet* wallet();
01568
01569 void openWallet(DOM::HTMLFormElementImpl*);
01570 void saveToWallet(const QString& key, const QMap<QString,QString>& data);
01571 void dequeueWallet(DOM::HTMLFormElementImpl*);
01572
01573 void enableFindAheadActions(bool);
01574
01578
01579
01580
01581
01582
01583
01584
01585 void submitForm( const char *action, const QString &url, const QByteArray &formData,
01586 const QString &target, const QString& contentType = QString::null,
01587 const QString& boundary = QString::null );
01588
01589 void popupMenu( const QString &url );
01590
01591 void init( KHTMLView *view, GUIProfile prof );
01592
01593
01594 void clear();
01595
01596 bool scheduleScript( const DOM::Node &n, const QString& script);
01597
01598 QVariant crossFrameExecuteScript(const QString& target, const QString& script);
01599 QVariant executeScheduledScript();
01600
01601 bool requestFrame( khtml::RenderPart *frame, const QString &url, const QString &frameName,
01602 const QStringList &args = QStringList(), bool isIFrame = false );
01603
01611 QString requestFrameName();
01612
01613 bool requestObject( khtml::RenderPart *frame, const QString &url, const QString &serviceType,
01614 const QStringList &args = QStringList() );
01615
01616 bool requestObject( khtml::ChildFrame *child, const KURL &url, const KParts::URLArgs &args = KParts::URLArgs() );
01617
01618 DOM::EventListener *createHTMLEventListener( QString code, QString name, DOM::NodeImpl *node );
01619
01620 DOM::HTMLDocumentImpl *docImpl() const;
01621 DOM::DocumentImpl *xmlDocImpl() const;
01622 khtml::ChildFrame *frame( const QObject *obj );
01623
01624 khtml::ChildFrame *recursiveFrameRequest( KHTMLPart *callingHtmlPart, const KURL &url, const KParts::URLArgs &args, bool callParent = true );
01625
01626 bool checkLinkSecurity( const KURL &linkURL,const QString &message = QString::null, const QString &button = QString::null );
01627 QVariant executeScript( const QString& filename, int baseLine, const DOM::Node &n, const QString& script );
01628
01629 KJSProxy *jScript();
01630
01631 KHTMLPart *opener();
01632 long cacheId() const;
01633 void setOpener( KHTMLPart *_opener );
01634 bool openedByJS();
01635 void setOpenedByJS( bool _openedByJS );
01636
01637 void checkEmitLoadEvent();
01638 void emitLoadEvent();
01639
01640 bool initFindNode( bool selection, bool reverse, bool fromCursor );
01641
01642 void extendSelection( DOM::NodeImpl* node, long offset, DOM::Node& selectionNode, long& selectionOffset, bool right, bool paragraph );
01652 void extendSelectionTo(int x, int y, int absX, int absY, const DOM::Node &innerNode);
01656 bool isExtendingSelection() const;
01657 khtml::Decoder *createDecoder();
01658 QString defaultEncoding() const;
01659
01661 QString defaultExtension() const;
01662
01666 void zoomIn(const int stepping[], int count);
01670 void zoomOut(const int stepping[], int count);
01671
01672 void emitCaretPositionChanged(const DOM::Node &node, long offset);
01673
01674 void setDebugScript( bool enable );
01675
01676 void runAdFilter();
01677
01678 KHTMLPartPrivate *d;
01679 friend class KHTMLPartPrivate;
01680 };
01681
01682
01683 #endif