KHTML
KHTMLPart Class Reference
#include <khtml_part.h>

Detailed Description
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><body><p>KHTML Rocks!</p></body></html>" ) ); doc->closeStream();
HTML Browser Widget
Definition at line 195 of file khtml_part.h.
Member Enumeration Documentation
Enumeration for displaying the caret.
- Enumerator:
-
CaretVisible caret is displayed CaretInvisible caret is not displayed CaretBlink caret toggles between visible and invisible
Definition at line 512 of file khtml_part.h.
Extra Find options that can be used when calling the extended findText().
Definition at line 713 of file khtml_part.h.
enum KHTMLPart::PageSecurity [protected] |
Constructor & Destructor Documentation
| KHTMLPart::KHTMLPart | ( | QWidget * | parentWidget = 0, |
|
| QObject * | parent = 0, |
|||
| GUIProfile | prof = DefaultGUI | |||
| ) |
Constructs a new KHTMLPart.
KHTML basically consists of two objects: The KHTMLPart itself, holding the document data (DOM document), and the KHTMLView, derived from QScrollArea, 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 one 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.
Definition at line 213 of file khtml_part.cpp.
| KHTMLPart::KHTMLPart | ( | KHTMLView * | view, | |
| QObject * | parent = 0, |
|||
| GUIProfile | prof = DefaultGUI | |||
| ) |
Constructs a new KHTMLPart.
This constructor is useful if you wish to subclass KHTMLView. If the view passed as first argument to the constructor was built with a null KHTMLPart pointer, then the newly created KHTMLPart will be assigned as the view's part.
Therefore, you might either initialize the view as part of the initialization list of your derived KHTMLPart class constructor:
MyKHTMLPart() : KHTMLPart( new MyKHTMLView( this ), ...
KHTMLView * v = KHTMLView( 0L, parentWidget()); KHTMLPart * p = KHTMLPart( v ); // p will be assigned to v, so that v->part() == p
Definition at line 222 of file khtml_part.cpp.
| KHTMLPart::~KHTMLPart | ( | ) | [virtual] |
Member Function Documentation
| DOM::Node KHTMLPart::activeNode | ( | ) | const |
| bool KHTMLPart::autoloadImages | ( | ) | const |
Returns whether images contained in the document are loaded automatically or not.
- Note:
- that the returned information is unrelieable as long as no begin() was called.
Definition at line 1384 of file khtml_part.cpp.
| KUrl KHTMLPart::backgroundURL | ( | ) | const |
Returns the URL for the background Image (used by save background).
Definition at line 4162 of file khtml_part.cpp.
| KUrl KHTMLPart::baseURL | ( | ) | const |
Definition at line 2348 of file khtml_part.cpp.
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:
- Parameters:
-
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.
Definition at line 1849 of file khtml_part.cpp.
| KParts::BrowserExtension * KHTMLPart::browserExtension | ( | ) | const |
Returns a pointer to the KParts::BrowserExtension.
Reimplemented from KParts::ReadOnlyPart.
Definition at line 943 of file khtml_part.cpp.
| KParts::BrowserHostExtension * KHTMLPart::browserHostExtension | ( | ) | const |
Definition at line 948 of file khtml_part.cpp.
| KHTMLPart::CaretDisplayPolicy KHTMLPart::caretDisplayPolicyNonFocused | ( | ) | const |
Returns the current caret policy when the view is not focused.
Definition at line 2744 of file khtml_part.cpp.
| void KHTMLPart::caretPositionChanged | ( | const DOM::Node & | node, | |
| long | offset | |||
| ) | [signal] |
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.
- Parameters:
-
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.
| bool KHTMLPart::closeUrl | ( | ) | [virtual] |
Stops loading the document and kills all data requests (for images, etc.
)
Reimplemented from KParts::ReadOnlyPart.
Definition at line 816 of file khtml_part.cpp.
returns a KUrl object for the given url.
Use when you know what you're doing.
Definition at line 2356 of file khtml_part.cpp.
| void KHTMLPart::configurationChanged | ( | ) | [signal] |
Emitted whenever the configuration has changed.
| KParts::ReadOnlyPart * KHTMLPart::createPart | ( | QWidget * | parentWidget, | |
| QObject * | parent, | |||
| const QString & | mimetype, | |||
| QString & | serviceName, | |||
| QStringList & | serviceTypes, | |||
| const QStringList & | params | |||
| ) | [protected, virtual] |
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' .
Definition at line 4748 of file khtml_part.cpp.
| KParts::ReadOnlyPart * KHTMLPart::currentFrame | ( | ) | const |
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.
Definition at line 5379 of file khtml_part.cpp.
| void KHTMLPart::customEvent | ( | QEvent * | event | ) | [protected, virtual] |
| bool KHTMLPart::dndEnabled | ( | ) | const |
Returns whether Dragn'n'Drop support is enabled or not.
| void KHTMLPart::docCreated | ( | ) | [signal] |
| bool KHTMLPart::doCloseStream | ( | ) | [protected, virtual] |
Implements the streaming API of KParts::ReadOnlyPart.
Definition at line 2029 of file khtml_part.cpp.
| DOM::Document KHTMLPart::document | ( | ) | const |
| QString KHTMLPart::documentSource | ( | ) | const |
Implements the streaming API of KParts::ReadOnlyPart.
Definition at line 2012 of file khtml_part.cpp.
| bool KHTMLPart::doWriteStream | ( | const QByteArray & | data | ) | [protected, virtual] |
Implements the streaming API of KParts::ReadOnlyPart.
Definition at line 2023 of file khtml_part.cpp.
| DOM::Editor * KHTMLPart::editor | ( | ) | const |
Returns the instance of the attached html editor interface.
Definition at line 3750 of file khtml_part.cpp.
| QString KHTMLPart::encoding | ( | ) | const |
Returns the encoding the page currently uses.
Note that the encoding might be different from the charset.
| void KHTMLPart::end | ( | ) | [virtual] |
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)
Definition at line 1233 of file khtml_part.cpp.
Same as executeScript( const QString & ) except with the Node parameter specifying the 'this' value.
Definition at line 1238 of file khtml_part.cpp.
Finds a frame by name.
Returns 0L if frame can't be found.
Definition at line 5360 of file khtml_part.cpp.
| KHTMLPart * KHTMLPart::findFrameParent | ( | KParts::ReadOnlyPart * | callingPart, | |
| const QString & | f, | |||
| khtml::ChildFrame ** | childFrame = 0 | |||
| ) |
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
Definition at line 5319 of file khtml_part.cpp.
| KParts::ReadOnlyPart * KHTMLPart::findFramePart | ( | const QString & | f | ) |
Finds a frame by name.
Returns 0L if frame can't be found.
Definition at line 5373 of file khtml_part.cpp.
| void KHTMLPart::findText | ( | const QString & | str, | |
| long | options, | |||
| QWidget * | parent = 0, |
|||
| KFindDialog * | findDialog = 0 | |||
| ) |
Starts a new search, but bypasses the user dialog.
- Parameters:
-
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.
Definition at line 3001 of file khtml_part.cpp.
| void KHTMLPart::findText | ( | ) |
Starts a new search by popping up a dialog asking the user what he wants to search for.
Definition at line 2959 of file khtml_part.cpp.
| void KHTMLPart::findTextBegin | ( | ) |
KDE 4.1 API Reference