class KHTMLPart |
|
|
This class is khtml's main class. It features an almost complete web browser, and html renderer. The easiest way to use this class (if you just want to display an HTML page at some URL) is the following:
KUrl url = "http://www.kde.org"; KHTMLPart *w = new KHTMLPart(); w->openUrl(url); w->view()->resize(500, 400); w->show(); Java and JavaScript are enabled by default depending on the user's settings. If you do not need them, and especially if you display unfiltered data from untrusted sources, it is strongly recommended to turn them off. In that case, you should also turn off the automatic redirect and plugins:
w->setJScriptEnabled(false); w->setJavaEnabled(false); w->setMetaRefreshEnabled(false); w->setPluginsEnabled(false); You may also wish to disable external references. This will prevent KHTML from loading images, frames, etc, or redirecting to external sites.
w->setOnlyLocalReferences(true); Some apps want to write their HTML code directly into the widget instead of opening an url. You can do this in the following way:
QString myHTMLCode = ...; KHTMLPart *w = new KHTMLPart(); w->begin(); w->write(myHTMLCode); ... w->end(); You can do as many calls to write() as you wish. There are two write() methods, one accepting a QString and one accepting a char * argument. You should use one or the other (but not both) since the method using the char * argument does an additional decoding step to convert the written data to Unicode. It is also possible to write content to the HTML part using the standard streaming API from KParts.ReadOnlyPart. The usage of the API is similar to that of the begin(), write(), end() process described above as the following example shows:
KHTMLPart *doc = new KHTMLPart(); doc->openStream( "text/html", KUrl() ); doc->writeStream( QCString( " HTML Browser Widget Author Lars Knoll (knoll@kde.org)
|
|
Constructs a new KHTMLPart. KHTML basically consists of two objects: The KHTMLPart itself, holding the document data (DOM document), and the KHTMLView, derived from QScrollView, in which the document content is rendered in. You can specify two different parent objects for a KHTMLPart, one parent for the KHTMLPart document and on parent for the KHTMLView. If the second parent argument is 0L, then parentWidget is used as parent for both objects, the part and the view. |
|
|
Returns the node that has the keyboard focus. |
|
Returns whether images contained in the document are loaded automatically or not. that the returned information is unrelieable as long as no begin() was called. |
|
|
Returns the URL for the background Image (used by save background) |
|
|
|
Clears the widget and prepares it for new content. If you want url() to return for example "file:/tmp/test.html", you can use the following code: view->begin( KUrl("file:/tmp/test.html" ) );
url - is the url of the document to be displayed. Even if you are generating the HTML on the fly, it may be useful to specify a directory so that any pixmaps are found.
xOffset - is the initial horizontal scrollbar value. Usually you don't want to use this.
yOffset - is the initial vertical scrollbar value. Usually you don't want to use this. All child frames and the old document are removed if you call this method. |
|
Returns a pointer to the KParts.BrowserExtension. |
|
|
Returns the current caret policy when the view is not focused. |
|
This signal is emitted whenever the caret position has been changed. The signal transmits the position the DOM.Range way, the node and the zero-based offset within this node. node - node which the caret is in. This can be null if the caret has been deactivated. offset - offset within the node. If the node is null, the offset is meaningless. |
|
Stops loading the document and kills all data requests (for images, etc.) |
|
returns a KUrl object for the given url. Use when you know what you're doing. |
|
Emitted whenever the configuration has changed |
|
Returns the java context of the applets. If no context exists yet, a new one is created. |
|
This method is called when a new embedded object (include html frames) is to be created. Reimplement it if you want to add support for certain embeddable objects without registering them in the KDE wide registry system (KSyCoCa) . Another reason for re-implementing this method could be if you want to derive from KTHMLPart and also want all html frame objects to be a object of your derived type, in which case you should return a new instance for the mimetype 'text/html' . |
|
Return the current frame (the one that has focus) Not necessarily a direct child of ours, framesets can be nested. Returns "this" if this part isn't a frameset. |
|
|
Returns whether Dragn'n'Drop support is enabled or not. |
|
Implements the streaming API of KParts.ReadOnlyPart. |
|
Implements the streaming API of KParts.ReadOnlyPart. |
|
Implements the streaming API of KParts.ReadOnlyPart. |
|
Internal |
|
Returns a reference to the DOM document. |
|
Returns the content of the source document. |
|
|
|
|
|
Returns the encoding the page currently uses. Note that the encoding might be different from the charset. |
|
Call this after your last call to write(). |
|
Same as executeScript( const QString & ) except with the Node parameter specifying the 'this' value. |
|
Execute the specified snippet of JavaScript code. Returns true if JavaScript was enabled, no error occurred and the code returned true itself or false otherwise. @deprecated, use executeString( DOM.Node(), script) |
|
Finds a frame by name. Returns 0L if frame can't be found. |
|
Recursively finds the part containing the frame with name f and checks if it is accessible by callingPart Returns 0L if no suitable frame can't be found. Returns parent part if a suitable frame was found and frame info in *childFrame |
|
Finds a frame by name. Returns 0L if frame can't be found. |
|
Starts a new search by popping up a dialog asking the user what he wants to search for. |
|
Starts a new search, but bypasses the user dialog. str - The string to search for. options - Find options. parent - Parent used for centering popups like "string not found". findDialog - Optionally, you can supply your own dialog. |
|
Initiates a text search. |
|
Finds the next occurrence of the string or expression. If isRegExp is true then str is converted to a QRegExp, and caseSensitive is ignored. @deprecated, use findText( str, options, parent, findDialog ) |
|
Finds the next occurrence of a string set by findText() reverse - if true, revert seach direction (only if no find dialog is used) Returns true if a new match was found. |
|
Returns the current font scale factor. |
|
Determine if signal should be emitted before, instead or never when a submitForm() happens. ###KDE4 remove me |
|
If form notification is on, this will be emitted either for a form submit or before the form submit according to the setting. ###KDE4 remove me |
|
Returns whether a frame with the specified name is exists or not. In contrary to the findFrame method this one also returns true if the frame is defined but no displaying component has been found/loaded, yet. |
|
Returns a list of names of all frame (including iframe) objects of the current document. Note that this method is not working recursively for sub-frames. |
|
Returns child frame framePart its script interpreter |
|
|
Finds the anchor named name. If the anchor is found, the widget scrolls to the closest position. Returns if the anchor has been found. |
|
Internal reimplementation of KParts.Part.guiActivateEvent . |
|
Has the user selected anything? Call selectedText() to retrieve the selected text. Returns true if there is text selected. |
|
Convenience method to hide the document's view. Equivalent to widget()->hide() or view()->hide(). |
|
Returns a reference to the DOM HTML document (for non-HTML documents, returns null) |
|
presents a detailed error message to the user. errorCode kio error code, eg KIO.ERR_SERVER_TIMEOUT. text kio additional information text. url the url that triggered the error. |
|
Internal |
|
Returns whether caret mode is on/off. |
|
Returns true if the document is editable, false otherwise. |
|
Checks whether the page contains unsubmitted form changes. Returns true if form changes exist |
|
Returns true if Javascript support is enabled or false otherwise. |
|
Returns the JavaScript interpreter the part is using. This method is mainly intended for applications which embed and extend the part and provides a mechanism for adding additional native objects to the interpreter (or removing the built-ins). One thing people using this method to add things to the interpreter must consider, is that when you start writing new content to the part, the interpreter is cleared. This includes both use of the begin( const KUrl &, int, int ) method, and the openUrl( const KUrl & ) method. If you want your objects to have a longer lifespan, then you must retain a KJS.Object yourself to ensure that the reference count of your custom objects never reaches 0. You will also need to re-add your bindings every time this happens - one way to detect the need for this is to connect to the docCreated() signal, another is to reimplement the begin() method. |
|
Returns the java context of the applets. If no applet exists, 0 is returned. |
|
Return true if Java applet support is enabled, false if disabled |
|
Called by KJS. Returns the DefaultStatusBarText assigned via window.defaultStatus |
|
Called by KJS. Returns the StatusBarText assigned via window.status |
|
Eventhandler for the khtml.DrawContentsEvent. |
|
Eventhandler for the khtml.MouseDoubleClickEvent. |
|
Eventhandler for the khtml.MouseMouseMoveEvent. |
|
Eventhandler of the khtml.MousePressEvent. |
|
Eventhandler for the khtml.MouseMouseReleaseEvent. |
|
Last-modified date (in raw string format), if received in the [HTTP] headers. |
|
|
Returns true if automatic forwarding is enabled. |
|
Go to the next anchor This is useful to navigate from outside the navigator |
|
This signal is emitted when an element retrieves the keyboard focus. Note that the signal argument can be a null node if no element is active, meaning a node has explicitly been deactivated without a new one becoming active. |
|
Returns the Node currently under the mouse. The returned node may be a shared node (e. g. an \ node if the mouse is hovering over an image map). |
|
Returns the Node currently under the mouse that is not shared. The returned node is always the node that is physically under the mouse pointer (irrespective of logically overlying elements like, e. g., \ on image maps). |
|
Emitted if the cursor is moved over an URL. |
|
Returns whether only file:/ or data:/ references are allowed to be loaded ( default false ). See setOnlyLocalReferences.
|
|
Internal empty reimplementation of KParts.ReadOnlyPart.openFile . |
|
Opens the specified URL url. Reimplemented from KParts.ReadOnlyPart.openUrl . |
|
Referrer used to obtain this page. |
|
Paints the HTML page to a QPainter. See KHTMLView.paint for details |
|
Returns a pointer to the parent KHTMLPart if the part is a frame in an HTML frameset. Returns 0L otherwise. |
|
Returns a reference to the partmanager instance which manages html frame objects. |
|
|
Returns true if plugins are enabled, false if disabled. |
|
Emitted when the user clicks the right mouse button on the document. |
|
Loads a script into the script cache. |
|
Loads a style sheet into the stylesheet cache. |
|
Go to previous anchor |
|
Referrer used for links in this page. |
|
Restores the KHTMLPart's previously saved state (including child frame objects) from the provided QDataStream. See also saveState() This is called from the restoreState() method of the browserExtension() .
|
|
Internal |
|
Saves the KHTMLPart's complete state (including child frame objects) to the provided QDataStream. This is called from the saveState() method of the browserExtension(). |
|
Schedules a redirection after delay seconds. |
|
Marks all text in the document as selected. |
|
Returns the text the user has marked. |
|
Return the text the user has marked. This is guaranteed to be valid xml, and to contain the \ and \ tags.FIXME probably should make virtual for 4.0 ? |
|
Returns the selected part of the HTML. |
|
Returns the selected part of the HTML by returning the starting and end position. If there is no selection, both nodes and offsets are equal. startNode - returns node selection starts in startOffset - returns offset within starting node endNode - returns node selection ends in endOffset - returns offset within end node. |
|
This signal is emitted when the selection changes. |
|
Sets the focused node of the document to the specified node. If the node is a form control, the control will receive focus in the same way that it would if the user had clicked on it or tabbed to it with the keyboard. For most other types of elements, there is no visual indication of whether or not they are focused. See activeNode
node - The node to focus |
|
Specifies whether images contained in the document should be loaded automatically or not. Request will be ignored if called before begin(). |
|
Sets the caret display policy when the view is not focused. Whenever the caret is in use, this property determines how the caret should be displayed when the document view is not focused. The default policy is CaretInvisible. policy - new display policy |
|
Enables/disables caret mode. Enabling caret mode displays a caret which can be used to navigate the document using the keyboard only. Caret mode is switched off by default.
enable - true to enable, false to disable caret mode. |
|
Sets the caret to the given position. If the given location is invalid, it will snap to the nearest valid location. Immediately afterwards a caretPositionChanged signal containing the effective position is emitted node - node to set to offset - zero-based offset within the node extendSelection - If true, a selection will be spanned from the last caret position to the given one. Otherwise, any existing selection will be deselected. |
|
Sets the visibility of the caret. This methods displays or hides the caret regardless of the current caret display policy (see setCaretDisplayNonFocused), and regardless of focus. The caret will be shown/hidden only under at least one of the following conditions:
show - true to make visible, false to hide. |
|
|
Enables or disables Drag'n'Drop support. A drag operation is started if the users drags a link. |
|
Makes the document editable. Setting this property to true makes the document, and its subdocuments (such as frames, iframes, objects) editable as a whole. FIXME: insert more information about navigation, features etc. as seen fit
enable - true to set document editable, false to set it read-only. |
|
Sets the encoding the page uses. This can be different from the charset. The widget will try to reload the current page in the new encoding, if url() is not empty. |
|
Sets the fixed font style.
name - The font name to use for fixed text, e.g. the <pre> tag. |
|
Sets the scale factor to be applied to fonts. The value is given in percent, larger values mean generally larger fonts. The given value should be in the range of 20..300, values outside that range are not guaranteed to work. A value of 100 will disable all scaling of font sizes and show the page with the sizes determined via the given lengths in the stylesheets. |
|
Determine if signal should be emitted before, instead or never when a submitForm() happens. ###KDE4 remove me |
|
Called by KJS. Sets the DefaultStatusBarText assigned via window.defaultStatus |
|
Called by KJS. Sets the StatusBarText assigned via window.status |
|
Enable/disable Javascript support. Note that this will in either case permanently override the default usersetting. If you want to have the default UserSettings, don't call this method. |
|
Enables/disables Java applet support. Note that calling this function will permanently override the User settings about Java applet support. Not calling this function is the only way to let the default settings apply. |
|
Enable/disable automatic forwarding by <meta http-equiv="refresh" ....> |
|
Security option. Specify whether only file:/ or data:/ urls are allowed to be loaded without user confirmation by KHTML. ( for example referenced by stylesheets, images, scripts, subdocuments, embedded elements ). This option is mainly intended for enabling the "mail reader mode", where you load untrusted content with a file:/ url. Please note that enabling this option currently automatically disables Javascript, Java and Plugins support. This might change in the future if the security model is becoming more sophisticated, so don't rely on this behaviour. ( default false - everything is loaded unless forbidden by KApplication.authorizeURLAction). |
|
|
|
Enables or disables plugins, default is enabled |
|
Sets the current selection. |
|
Sets the standard font style.
name - The font name to use for standard text. |
|
|
Enable/disable statusbar messages.
When this class wants to set the statusbar text, it emits
setStatusBarText(const QString & text)
If you want to catch this for your own statusbar, note that it returns
back a rich text string, starting with " See also KParts.Part.setStatusBarText( const QString & text ) |
|
Shows or hides the suppressed popup indicator Deprecated |
|
Shows or hides the suppressed popup indicator |
|
Sets the cursor to use when the cursor is on a link. |
|
Sets a user defined style sheet to be used on top of the HTML 4 default style sheet. This gives a wide range of possibilities to change the layout of the page. To have an effect this function has to be called after calling begin(). |
|
Sets a user defined style sheet to be used on top of the HTML 4 default style sheet. This gives a wide range of possibilities to change the layout of the page. To have an effect this function has to be called after calling begin(). |
|
Sets the Zoom factor. The value is given in percent, larger values mean a generally larger font and larger page contents. The given value should be in the range of 20..300, values outside that range are not guaranteed to work. A value of 100 will disable all zooming and show the page with the sizes determined via the given lengths in the stylesheets. |
|
Internal |
|
Convenience method to show the document's view. Equivalent to widget()->show() or view()->show() . |
|
Called when a certain error situation (i.e. connection timed out) occurred. The default implementation either shows a KIO error dialog or loads a more verbose error description a as page, depending on the users configuration. job is the job that signaled the error situation |
|
Called when the job downloading the page is finished. Can be reimplemented, for instance to get metadata out of the job, but make sure to call KHTMLPart.slotFinished() too. |
|
Hook for adding code before a job is started. This can be used to add metadata, like job->addMetaData("PropagateHttpHeader", "true") to get the HTTP headers. |
|
Returns true if status messages are enabled. |
|
Stops all animated images on the current and child pages |
|
|
Returns the toplevel (origin) URL of this document, even if this part is a frame or an iframe. Returns the actual original url. |
|
Returns the cursor which is used when the cursor is on a link. |
|
|
Returns a pointer to the HTML document's view. |
|
Writes another part of the HTML code to the widget. You may call this function many times in sequence. But remember: The fewer calls you make, the faster the widget will be. The HTML code is send through a decoder which decodes the stream to Unicode. The len parameter is needed for streams encoded in utf-16, since these can have \\0 chars in them. In case the encoding you're using isn't utf-16, you can safely leave out the length parameter. Attention: Don't mix calls to write( const char *) with calls to write( const QString & ). The result might not be what you want. |
|
Writes another part of the HTML code to the widget. You may call this function many times in sequence. But remember: The fewer calls you make, the faster the widget will be. |
|
Returns the current zoom factor. |
CaretVisible | - | CaretVisible, < caret is displayed | |
CaretInvisible | - | CaretInvisible, < caret is not displayed | |
CaretBlink | - | CaretBlink < caret toggles between visible and invisible |
FindLinksOnly | - | ||
FindNoPopups | - |
NoNotification | - | ||
Before | - | ||
Only | - | ||
Unused | - |
DefaultGUI | - | ||
BrowserViewGUI | - |
NotCrypted | - | ||
Encrypted | - | ||
Mixed | - |