Development/Architecture/KDE3/KHTML: Difference between revisions
mNo edit summary |
(Marked this version for translation) |
||
Line 2: | Line 2: | ||
<translate> | <translate> | ||
== KHTML - KDE's HTML library == | == KHTML - KDE's HTML library == <!--T:1--> | ||
<!--T:2--> | |||
<tt>KHTML</tt> is an [http://www.w3.org/TR/REC-xml/ XML]/[http://www.w3.org/TR/html401/ HTML4] compliant HTML library, with support for [http://www.w3.org/TR/REC-DOM-Level-1/ DOM], | <tt>KHTML</tt> is an [http://www.w3.org/TR/REC-xml/ XML]/[http://www.w3.org/TR/html401/ HTML4] compliant HTML library, with support for [http://www.w3.org/TR/REC-DOM-Level-1/ DOM], | ||
[http://java.sun.com/docs/books/tutorial/deployment/applet/index.html Java], [http://www.ecma-international.org/publications/files/ECMA-ST/ECMA-262.pdf JavaScript] and Cascading Style Sheets ([http://www.w3.org/TR/CSS2/ CSS]). | [http://java.sun.com/docs/books/tutorial/deployment/applet/index.html Java], [http://www.ecma-international.org/publications/files/ECMA-ST/ECMA-262.pdf JavaScript] and Cascading Style Sheets ([http://www.w3.org/TR/CSS2/ CSS]). | ||
<!--T:3--> | |||
You can get an overview of <tt>KHTML</tt>'s current capabilities [http://www.konqueror.org/konq-browser.html here.] | You can get an overview of <tt>KHTML</tt>'s current capabilities [http://www.konqueror.org/konq-browser.html here.] | ||
== Small example == | == Small example == <!--T:4--> | ||
<!--T:5--> | |||
Using <tt>KHTML</tt> in your program is quite easy. The following example shows | Using <tt>KHTML</tt> in your program is quite easy. The following example shows | ||
you a complete application with which you can already browse the web: | you a complete application with which you can already browse the web: | ||
<!--T:6--> | |||
<syntaxhighlight lang="cpp-qt"> | <syntaxhighlight lang="cpp-qt"> | ||
#include <khtml.h> | #include <khtml.h> | ||
#include <kapp.h> | #include <kapp.h> | ||
<!--T:7--> | |||
int main(int argc, char *argv[]) | int main(int argc, char *argv[]) | ||
{ | { | ||
KApplication a(argc, argv, "testkhtml"); | KApplication a(argc, argv, "testkhtml"); | ||
KHTMLWidget *html = new KHTMLWidget; | <!--T:8--> | ||
KHTMLWidget *html = new KHTMLWidget; | |||
html->resize(800,500); | html->resize(800,500); | ||
//html->setJScriptEnabled(true); | //html->setJScriptEnabled(true); | ||
Line 28: | Line 34: | ||
//html->setFollowsLinks(false); | //html->setFollowsLinks(false); | ||
a.setTopWidget(html); | <!--T:9--> | ||
a.setTopWidget(html); | |||
html->setURLCursor(QCursor(PointingHandCursor)); | html->setURLCursor(QCursor(PointingHandCursor)); | ||
html->openURL(argv[1]); | html->openURL(argv[1]); | ||
QWidget::connect(html, SIGNAL(setTitle(const QString &)), | <!--T:10--> | ||
QWidget::connect(html, SIGNAL(setTitle(const QString &)), | |||
html, SLOT(setCaption(const QString &))); | html, SLOT(setCaption(const QString &))); | ||
html->show(); | html->show(); | ||
Line 39: | Line 47: | ||
</syntaxhighlight> | </syntaxhighlight> | ||
<!--T:11--> | |||
This small example already gives you a functional browser, that lets you browse | This small example already gives you a functional browser, that lets you browse | ||
the web (you'll need the <tt>kio_http</tt> executable from KDE though to access | the web (you'll need the <tt>kio_http</tt> executable from KDE though to access | ||
Line 44: | Line 53: | ||
get a widget showing KDE's home page. | get a widget showing KDE's home page. | ||
<!--T:12--> | |||
<tt>KHTML</tt> has a lot of functionality. Almost everything you'll ever need | <tt>KHTML</tt> has a lot of functionality. Almost everything you'll ever need | ||
can be accessed through the member functions of the class KHTMLWidget. | can be accessed through the member functions of the class KHTMLWidget. | ||
== Document Object Model (DOM) == | == Document Object Model (DOM) == <!--T:13--> | ||
<!--T:14--> | |||
<tt>KHTML</tt> provides a mostly complete implementation of | <tt>KHTML</tt> provides a mostly complete implementation of | ||
[http://www.w3.org/DOM/ Dom Level 1 and 2]. | [http://www.w3.org/DOM/ Dom Level 1 and 2]. | ||
<!--T:15--> | |||
The DOM is an implementation using internal classes to hold the document's data. | The DOM is an implementation using internal classes to hold the document's data. | ||
The classes accessing the DOM are using a refcounting scheme to hold the data. | The classes accessing the DOM are using a refcounting scheme to hold the data. | ||
Line 58: | Line 70: | ||
don't use pointers, you will not get memory leaks. | don't use pointers, you will not get memory leaks. | ||
<!--T:16--> | |||
You can easily access the document being shown by the | You can easily access the document being shown by the | ||
<tt>KHTMLWidget::document()</tt> method, from where you can | <tt>KHTMLWidget::document()</tt> method, from where you can | ||
get access to every part of the document. | get access to every part of the document. | ||
== Java == | == Java == <!--T:17--> | ||
<!--T:18--> | |||
Thanks to the work of Richard Moore, <tt>KHTML</tt> can display Java applets. | Thanks to the work of Richard Moore, <tt>KHTML</tt> can display Java applets. | ||
Java is not enabled by default, but you can do so by using | Java is not enabled by default, but you can do so by using | ||
Line 69: | Line 83: | ||
<tt>CLASSPATH</tt> to: | <tt>CLASSPATH</tt> to: | ||
CLASSPATH=$KDEDIR/share/apps/kjava/kjava-classes.zip:$JDK_DIR/lib | <!--T:19--> | ||
CLASSPATH=$KDEDIR/share/apps/kjava/kjava-classes.zip:$JDK_DIR/lib | |||
<!--T:20--> | |||
You will need to have the java developers kit installed though. I tested it | You will need to have the java developers kit installed though. I tested it | ||
with JDK-1.1.7, and don't know if it'll run with other versions of JDK or with | with JDK-1.1.7, and don't know if it'll run with other versions of JDK or with | ||
Kaffe. | Kaffe. | ||
== JavaScript (ECMA-Script) == | == JavaScript (ECMA-Script) == <!--T:21--> | ||
<!--T:22--> | |||
The JavaScript support aims at compliance with the ECMAScript Language | The JavaScript support aims at compliance with the ECMAScript Language | ||
specification [http://www.ecma.ch/ecma1/STAND/ECMA-262.HTM ECMA-262] 3rd edition. | specification [http://www.ecma.ch/ecma1/STAND/ECMA-262.HTM ECMA-262] 3rd edition. | ||
This roughly equals JavaScript 1.5. | This roughly equals JavaScript 1.5. | ||
== Cascading Style Sheets (CSS) == | == Cascading Style Sheets (CSS) == <!--T:23--> | ||
<!--T:24--> | |||
Cascading style sheets 2.1 are mostly supported now. | Cascading style sheets 2.1 are mostly supported now. | ||
<!--T:25--> | |||
''Initial Author:'' [mailto:[email protected] Lars Knoll] | ''Initial Author:'' [mailto:[email protected] Lars Knoll] | ||
<!--T:26--> | |||
[[Category:KDE3]] | [[Category:KDE3]] | ||
[[Category:Architecture]] | [[Category:Architecture]] | ||
</translate> | </translate> |
Revision as of 18:58, 11 July 2012
KHTML - KDE's HTML library
KHTML is an XML/HTML4 compliant HTML library, with support for DOM, Java, JavaScript and Cascading Style Sheets (CSS).
You can get an overview of KHTML's current capabilities here.
Small example
Using KHTML in your program is quite easy. The following example shows you a complete application with which you can already browse the web:
#include <khtml.h>
#include <kapp.h>
int main(int argc, char *argv[])
{
KApplication a(argc, argv, "testkhtml");
KHTMLWidget *html = new KHTMLWidget;
html->resize(800,500);
//html->setJScriptEnabled(true);
html->setJavaEnabled(true);
//html->setFollowsLinks(false);
a.setTopWidget(html);
html->setURLCursor(QCursor(PointingHandCursor));
html->openURL(argv[1]);
QWidget::connect(html, SIGNAL(setTitle(const QString &)),
html, SLOT(setCaption(const QString &)));
html->show();
a.exec();
}
This small example already gives you a functional browser, that lets you browse the web (you'll need the kio_http executable from KDE though to access non local files). Just try testkhtml http://www.kde.org and you will get a widget showing KDE's home page.
KHTML has a lot of functionality. Almost everything you'll ever need can be accessed through the member functions of the class KHTMLWidget.
Document Object Model (DOM)
KHTML provides a mostly complete implementation of Dom Level 1 and 2.
The DOM is an implementation using internal classes to hold the document's data. The classes accessing the DOM are using a refcounting scheme to hold the data. Thus the DOM does the memory management for you. You can just use the classes defined in the DOM header files to access parts of the document. As long as you don't use pointers, you will not get memory leaks.
You can easily access the document being shown by the KHTMLWidget::document() method, from where you can get access to every part of the document.
Java
Thanks to the work of Richard Moore, KHTML can display Java applets. Java is not enabled by default, but you can do so by using KHTMLWidget::setEnableJava(true);, and setting the environment variable CLASSPATH to:
CLASSPATH=$KDEDIR/share/apps/kjava/kjava-classes.zip:$JDK_DIR/lib
You will need to have the java developers kit installed though. I tested it with JDK-1.1.7, and don't know if it'll run with other versions of JDK or with Kaffe.
JavaScript (ECMA-Script)
The JavaScript support aims at compliance with the ECMAScript Language specification ECMA-262 3rd edition. This roughly equals JavaScript 1.5.
Cascading Style Sheets (CSS)
Cascading style sheets 2.1 are mostly supported now.
Initial Author: Lars Knoll