Development/Architecture/KDE3/KHTML/pt-br

From KDE TechBase
Revision as of 15:00, 29 August 2014 by Camilaraw (talk | contribs) (Created page with "<tt>KHTML</tt> tem muitas funcionalidades. Quase tudo o que você realmente precisa pode ser acessado através das funções de membro da classe KHTMLWidget.")


KHTML - Biblioteca de HTML do KDE

KHTML é uma biblioteca XML/HTML4 compatível com HTML4, com suporte para DOM, Java, JavaScript e Cascading Style Sheets (CSS).

Você pode obter uma visão geral dos atuais recursos do KHTML aqui.

Pequeno exemplo

Usar o KHTML no seu programa é bem fácil. O exemplo a seguir mostra para você uma completa aplicação com a qual você já pode navegar na web:

#include <khtml.h>
#include <kapp.h>

<span class="mw-translate-fuzzy">
int main(int argc, char *argv[])
{
    KApplication a(argc, argv, "testkhtml");
</span>

    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]);

    <span class="mw-translate-fuzzy">
QWidget::connect(html, SIGNAL(setTitle(const QString &)),
                     html, SLOT(setCaption(const QString &)));
    html->show();
    a.exec();
}

Este pequeno exemplo já oferece a você um navegador funcional, que permite que você navegue na web (você vai precisar do executável kio_http do KDE para acessar os arquivos não locais). Teste testkhtml http://www.kde.org e você vai ter um widget que mostra a página inicial do KDE.

KHTML tem muitas funcionalidades. Quase tudo o que você realmente precisa pode ser acessado através das funções de membro da classe 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