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
00287 QString documentSource() const;
00288
00292 DOM::Node activeNode() const;
00293
00297 KParts::BrowserExtension *browserExtension() const;
00298 KParts::LiveConnectExtension *liveConnectExtension( const khtml::RenderPart *) const;
00299 KParts::BrowserHostExtension *browserHostExtension() const;
00300
00304 KHTMLView *view() const;
00305
00312 void setJScriptEnabled( bool enable );
00313
00318 bool jScriptEnabled() const;
00319
00337 KJS::Interpreter *jScriptInterpreter();
00338
00342 void setStatusMessagesEnabled( bool enable );
00343
00347 bool statusMessagesEnabled() const;
00348
00352 void setMetaRefreshEnabled( bool enable );
00353
00357 bool metaRefreshEnabled() const;
00358
00363 QVariant executeScript( const DOM::Node &n, const QString &script );
00364
00369 void setDNDEnabled( bool b );
00370
00374 bool dndEnabled() const;
00375
00382 void setJavaEnabled( bool enable );
00383
00387 bool javaEnabled() const;
00388
00392 KJavaAppletContext *javaContext();
00393
00398 KJavaAppletContext *createJavaContext();
00399
00403 void setPluginsEnabled( bool enable );
00404
00408 bool pluginsEnabled() const;
00409
00416 void setAutoloadImages( bool enable );
00423 bool autoloadImages() const;
00424
00441 void setOnlyLocalReferences( bool enable );
00442
00447 bool onlyLocalReferences() const;
00448
00452 bool isCaretMode() const;
00453
00458 bool isEditable() const;
00459
00473 void setCaretPosition(DOM::Node node, long offset, bool extendSelection = false);
00474
00482 enum CaretDisplayPolicy {
00483 CaretVisible, CaretInvisible, CaretBlink
00484 };
00485
00490 CaretDisplayPolicy caretDisplayPolicyNonFocused() const;
00491
00502 void setCaretDisplayPolicyNonFocused(CaretDisplayPolicy policy);
00503
00504 #ifndef KDE_NO_COMPAT
00505 void enableJScript( bool e ) { setJScriptEnabled(e); }
00506 void enableJava( bool e ) { setJavaEnabled(e); }
00507 void enablePlugins( bool e ) { setPluginsEnabled(e); }
00508 void autoloadImages( bool e ) { setAutoloadImages(e); }
00509 void enableMetaRefresh( bool e ) { setMetaRefreshEnabled(e); }
00510 bool setCharset( const QString &, bool ) { return true; }
00511
00512 KURL baseURL() const;
00513 QString baseTarget() const;
00514 #endif
00515
00519 KURL backgroundURL() const;
00520
00524 void scheduleRedirection( int delay, const QString &url, bool lockHistory = true );
00525
00548 virtual void begin( const KURL &url = KURL(), int xOffset = 0, int yOffset = 0 );
00549
00570 virtual void write( const char *str, int len = -1 );
00571
00579 virtual void write( const QString &str );
00580
00584 virtual void end();
00585
00586
00587
00588
00589
00590
00591
00592
00596 void paint( QPainter *, const QRect &, int = 0, bool * = 0 );
00597
00604 bool setEncoding( const QString &name, bool override = false );
00605
00611 QString encoding() const;
00612
00620 void setUserStyleSheet( const KURL &url );
00621
00629 void setUserStyleSheet( const QString &styleSheet );
00630
00631 public:
00632
00638 void setStandardFont( const QString &name );
00639
00646 void setFixedFont( const QString &name );
00647
00655 bool gotoAnchor( const QString &name );
00656
00663 bool nextAnchor();
00664
00669 bool prevAnchor();
00670
00674 void setURLCursor( const QCursor &c );
00675
00679 QCursor urlCursor() const;
00680
00685 enum FindOptions
00686 {
00687 FindLinksOnly = 1 * KFindDialog::MinimumUserOption,
00688 FindNoPopups = 2 * KFindDialog::MinimumUserOption
00689
00690 };
00691
00697 void findText();
00698
00707 void findText( const QString &str, long options, QWidget *parent = 0,
00708 KFindDialog *findDialog = 0 );
00709
00713 void findTextBegin();
00714
00720 bool findTextNext( const QString &str, bool forward, bool caseSensitive, bool isRegExp );
00721
00727 bool findTextNext();
00728
00739 void setZoomFactor(int percent);
00740
00744 int zoomFactor() const;
00745
00749 virtual QString selectedText() const;
00750
00759 QString selectedTextAsHTML() const;
00760
00764 DOM::Range selection() const;
00765
00777 void selection(DOM::Node &startNode, long &startOffset,
00778 DOM::Node &endNode, long &endOffset) const;
00779
00783 void setSelection( const DOM::Range & );
00784
00793 bool hasSelection() const;
00794
00798 void selectAll();
00799
00805 void show();
00806
00812 void hide();
00813
00818 KParts::PartManager *partManager();
00819
00827 virtual void saveState( QDataStream &stream );
00837 virtual void restoreState( QDataStream &stream );
00838
00845 DOM::Node nodeUnderMouse() const;
00846
00855 DOM::Node nonSharedNodeUnderMouse() const;
00856
00860 const KHTMLSettings *settings() const;
00861
00868 KHTMLPart *parentPart();
00869
00875 QStringList frameNames() const;
00876
00877 QPtrList<KParts::ReadOnlyPart> frames() const;
00878
00882 KHTMLPart *findFrame( const QString &f );
00883
00892 KHTMLPart *findFrameParent( KParts::ReadOnlyPart *callingPart, const QString &f, khtml::ChildFrame **childFrame=0 );
00893
00899 KParts::ReadOnlyPart *currentFrame() const;
00900
00907 bool frameExists( const QString &frameName );
00908
00912 KJSProxy *framejScript(KParts::ReadOnlyPart *framePart);
00913
00917 KParts::ReadOnlyPart *findFramePart( const QString &f );
00923 void setJSStatusBarText( const QString &text );
00924
00930 void setJSDefaultStatusBarText( const QString &text );
00931
00937 QString jsStatusBarText() const;
00938
00944 QString jsDefaultStatusBarText() const;
00945
00949 QString referrer() const;
00950
00954 QString pageReferrer() const;
00955
00959 QString lastModified() const;
00960
00964 void preloadStyleSheet( const QString &url, const QString &stylesheet );
00965
00969 void preloadScript( const QString &url, const QString &script );
00970
00974 bool restored() const;
00975
00976
00977 enum FormNotification { NoNotification = 0, Before, Only, Unused=255 };
00984 void setFormNotification(FormNotification fn);
00985
00992 FormNotification formNotification() const;
00993
01001 KURL toplevelURL();
01002
01009 bool isModified() const;
01010
01015 void setSuppressedPopupIndicator( bool enable );
01016
01017 signals:
01021 void onURL( const QString &url );
01022
01026 void popupMenu( const QString &url, const QPoint &point );
01027
01031 void selectionChanged();
01032
01040 void nodeActivated( const DOM::Node & );
01041
01044 void docCreated();
01045
01057 void caretPositionChanged(const DOM::Node &node, long offset);
01058
01059
01066 void formSubmitNotification(const char *action, const QString& url,
01067 const QByteArray& formData, const QString& target,
01068 const QString& contentType, const QString& boundary);
01069
01070
01071 protected:
01072
01077 KURL completeURL( const QString &url );
01078
01085 void htmlError( int errorCode, const QString& text, const KURL& reqUrl );
01086
01087 virtual void customEvent( QCustomEvent *event );
01088
01092 virtual void khtmlMousePressEvent( khtml::MousePressEvent *event );
01096 virtual void khtmlMouseDoubleClickEvent( khtml::MouseDoubleClickEvent * );
01100 virtual void khtmlMouseMoveEvent( khtml::MouseMoveEvent *event );
01104 virtual void khtmlMouseReleaseEvent( khtml::MouseReleaseEvent *event );
01108 virtual void khtmlDrawContentsEvent( khtml::DrawContentsEvent * );
01109
01113 virtual void guiActivateEvent( KParts::GUIActivateEvent *event );
01114
01118 virtual bool openFile();
01119
01120 virtual void urlSelected( const QString &url, int button, int state,
01121 const QString &_target, KParts::URLArgs args = KParts::URLArgs());
01122
01131 virtual KParts::ReadOnlyPart *createPart( QWidget *parentWidget, const char *widgetName,
01132 QObject *parent, const char *name,
01133 const QString &mimetype, QString &serviceName,
01134 QStringList &serviceTypes, const QStringList ¶ms);
01135
01136
01137
01138 bool pluginPageQuestionAsked( const QString& mimetype ) const;
01139 void setPluginPageQuestionAsked( const QString& mimetype );
01140
01141 enum PageSecurity { NotCrypted, Encrypted, Mixed };
01142 void setPageSecurity( PageSecurity sec );
01143
01147 virtual bool doOpenStream( const QString& mimeType );
01148
01152 virtual bool doWriteStream( const QByteArray& data );
01153
01157 virtual bool doCloseStream();
01158
01159 public slots:
01160
01170 void setActiveNode( const DOM::Node &node );
01171
01175 void stopAnimations();
01176
01177 QCString dcopObjectId() const;
01178
01186 QVariant executeScript( const QString &script );
01187
01198 void setCaretMode(bool enable);
01199
01211 void setEditable(bool enable);
01212
01229 void setCaretVisible(bool show);
01230
01231
01232
01233
01234
01235 void submitFormProxy( const char *action, const QString &url,
01236 const QByteArray &formData,
01237 const QString &target,
01238 const QString& contentType = QString::null,
01239 const QString& boundary = QString::null );
01240
01241 private slots:
01242
01246 void reparseConfiguration();
01247
01251 void slotData( KIO::Job*, const QByteArray &data );
01255 void slotInfoMessage( KIO::Job*, const QString& msg );
01259 void slotRestoreData( const QByteArray &data );
01263 void slotFinished( KIO::Job* );
01267 void slotFinishedParsing();
01271 void slotRedirect();
01275 void slotRedirection( KIO::Job*, const KURL& );
01279 void slotDebugScript();
01283 void slotDebugDOMTree();
01287 void slotDebugRenderTree();
01291 void slotStopAnimations();
01295 virtual void slotViewDocumentSource();
01299 virtual void slotViewFrameSource();
01303 void slotViewPageInfo();
01307 virtual void slotSaveBackground();
01311 virtual void slotSaveDocument();
01315 virtual void slotSaveFrame();
01319 virtual void slotSecurity();
01323 virtual void slotSetEncoding();
01324
01328 virtual void slotUseStylesheet();
01329
01330 virtual void slotFind();
01331 virtual void slotFindDone();
01332 virtual void slotFindDialogDestroyed();
01333 void slotFindNext();
01334
01335 void slotIncZoom();
01336 void slotDecZoom();
01337 void slotIncZoomFast();
01338 void slotDecZoomFast();
01339
01340 void slotLoadImages();
01341 void slotWalletClosed();
01342 void launchWalletManager();
01343 void walletMenu();
01344
01348 void submitFormAgain();
01349
01353 void updateActions();
01357 void slotPartRemoved( KParts::Part *part );
01361 void slotActiveFrameChanged( KParts::Part *part );
01365 void slotChildStarted( KIO::Job *job );
01369 void slotChildCompleted();
01373 void slotChildCompleted( bool );
01377 void slotParentCompleted();
01381 void slotChildURLRequest( const KURL &url, const KParts::URLArgs &args );
01385 void slotChildDocCreated();
01389 void slotRequestFocus( KParts::ReadOnlyPart * );
01390 void slotLoaderRequestStarted( khtml::DocLoader*, khtml::CachedObject* obj);
01391 void slotLoaderRequestDone( khtml::DocLoader*, khtml::CachedObject *obj );
01392 void checkCompleted();
01393
01397 void slotAutoScroll();
01398
01399 void slotPrintFrame();
01400
01401 void slotSelectAll();
01402
01406 void slotProgressUpdate();
01407
01408
01409
01410
01411 void slotJobPercent( KIO::Job*, unsigned long );
01412
01413
01414
01415
01416 void slotJobDone( KIO::Job* );
01417
01418
01419
01420
01421 void slotUserSheetStatDone( KIO::Job* );
01422
01423
01424
01425
01426 void slotJobSpeed( KIO::Job*, unsigned long );
01427
01431 void slotClearSelection();
01432
01436 void slotZoomView( int );
01437
01441 void slotHighlight( const QString &, int index, int length );
01442
01446 void slotAutomaticDetectionLanguage( int _id );
01447
01451 void slotToggleCaretMode();
01452
01456 void launchJSErrorDialog();
01457
01461 void removeJSErrorExtension();
01462
01466 void disableJSErrorExtension();
01467
01471 void jsErrorDialogContextMenu();
01472
01478 void restoreScrollPosition();
01479
01480 void walletOpened(KWallet::Wallet*);
01481
01482 private:
01483
01484 KJSErrorDlg *jsErrorExtension();
01485
01486 enum StatusBarPriority { BarDefaultText, BarHoverText, BarOverrideText };
01487 void setStatusBarText( const QString& text, StatusBarPriority p);
01488
01489 bool restoreURL( const KURL &url );
01490 void resetFromScript();
01491 void emitSelectionChanged();
01492
01493 bool checkFrameAccess(KHTMLPart *callingHtmlPart);
01494 bool openURLInFrame( const KURL &url, const KParts::URLArgs &urlArgs );
01495 void startAutoScroll();
01496 void stopAutoScroll();
01497 void overURL( const QString &url, const QString &target, bool shiftPressed = false );
01498 void resetHoverText();
01499
01500 bool processObjectRequest( khtml::ChildFrame *child, const KURL &url, const QString &mimetype );
01501
01502 KWallet::Wallet* wallet();
01503
01504 void openWallet(DOM::HTMLFormElementImpl*);
01505 void saveToWallet(const QString& key, const QMap<QString,QString>& data);
01506 void dequeueWallet(DOM::HTMLFormElementImpl*);
01507
01511
01512
01513
01514
01515
01516
01517
01518 void submitForm( const char *action, const QString &url, const QByteArray &formData,
01519 const QString &target, const QString& contentType = QString::null,
01520 const QString& boundary = QString::null );
01521
01522 void popupMenu( const QString &url );
01523
01524 void init( KHTMLView *view, GUIProfile prof );
01525
01526
01527 void clear();
01528
01529 bool scheduleScript( const DOM::Node &n, const QString& script);
01530
01531 QVariant crossFrameExecuteScript(const QString& target, const QString& script);
01532 QVariant executeScheduledScript();
01533
01534 bool requestFrame( khtml::RenderPart *frame, const QString &url, const QString &frameName,
01535 const QStringList &args = QStringList(), bool isIFrame = false );
01536
01544 QString requestFrameName();
01545
01546 bool requestObject( khtml::RenderPart *frame, const QString &url, const QString &serviceType,
01547 const QStringList &args = QStringList() );
01548
01549 bool requestObject( khtml::ChildFrame *child, const KURL &url, const KParts::URLArgs &args = KParts::URLArgs() );
01550
01551 DOM::EventListener *createHTMLEventListener( QString code, QString name );
01552
01553 DOM::HTMLDocumentImpl *docImpl() const;
01554 DOM::DocumentImpl *xmlDocImpl() const;
01555 khtml::ChildFrame *frame( const QObject *obj );
01556
01557 khtml::ChildFrame *recursiveFrameRequest( KHTMLPart *callingHtmlPart, const KURL &url, const KParts::URLArgs &args, bool callParent = true );
01558
01559 bool checkLinkSecurity( const KURL &linkURL,const QString &message = QString::null, const QString &button = QString::null );
01560 QVariant executeScript( const QString& filename, int baseLine, const DOM::Node &n, const QString& script );
01561
01562 KJSProxy *jScript();
01563
01564 KHTMLPart *opener();
01565 long cacheId() const;
01566 void setOpener( KHTMLPart *_opener );
01567 bool openedByJS();
01568 void setOpenedByJS( bool _openedByJS );
01569
01570 void checkEmitLoadEvent();
01571 void emitLoadEvent();
01572
01573 bool initFindNode( bool selection, bool reverse, bool fromCursor );
01574
01575 void extendSelection( DOM::NodeImpl* node, long offset, DOM::Node& selectionNode, long& selectionOffset, bool right, bool paragraph );
01585 void extendSelectionTo(int x, int y, int absX, int absY, const DOM::Node &innerNode);
01589 bool isExtendingSelection() const;
01590 khtml::Decoder *createDecoder();
01591 QString defaultEncoding() const;
01592
01596 void zoomIn(const int stepping[], int count);
01600 void zoomOut(const int stepping[], int count);
01601
01602 void emitCaretPositionChanged(const DOM::Node &node, long offset);
01603
01604 void setDebugScript( bool enable );
01605
01606 KHTMLPartPrivate *d;
01607 friend class KHTMLPartPrivate;
01608 };
01609
01610
01611 #endif