[prev in list] [next in list] [prev in thread] [next in thread]
List: kde-commits
Subject: KDE/kdelibs
From: David Faure <faure () kde ! org>
Date: 2010-10-09 1:46:38
Message-ID: 20101009014638.E53BAAC892 () svn ! kde ! org
[Download RAW message or body]
SVN commit 1184006 by dfaure:
New KParts extension: HtmlExtension. This one is ready for more virtual stuff in the \
future by the use of Q_INTERFACES. Currently supports one interface, \
SelectorInterface, which allows to call querySelector/querySelectorAll to find html \
elements. Extension and interface implemented in KHTML (reviewed by Maksim).
This will be used by the searchbar and akregator konq plugins (already ported \
akregator plugin locally, works).
M +1 -0 includes/CMakeLists.txt
A includes/KParts/HtmlExtension
M +57 -2 khtml/khtml_ext.cpp
M +23 -0 khtml/khtml_ext.h
M +2 -1 khtml/khtml_part.cpp
M +2 -1 kparts/CMakeLists.txt
A kparts/htmlextension.cpp [License: LGPL (v2+)]
A kparts/htmlextension.h [License: LGPL (v2+)]
--- trunk/KDE/kdelibs/includes/CMakeLists.txt #1184005:1184006
@@ -799,6 +799,7 @@
KParts/GenericFactory
KParts/GenericFactoryBase
KParts/HistoryProvider
+ KParts/HtmlExtension
KParts/LiveConnectExtension
KParts/MainWindow
KParts/OpenUrlEvent
--- trunk/KDE/kdelibs/khtml/khtml_ext.cpp #1184005:1184006
@@ -35,6 +35,8 @@
#include "dom/html_image.h"
#include "dom/dom_string.h"
#include "dom/html_document.h"
+#include "dom/dom_element.h"
+#include "xml/dom_elementimpl.h"
#include <QtGui/QClipboard>
#include <QtCore/QFileInfo>
#include <QtGui/QMenu>
@@ -66,8 +68,6 @@
#include <kactioncollection.h>
#include <kactionmenu.h>
-#include "dom/dom_element.h"
-
#include "khtmlpart_p.h"
KHTMLPartBrowserExtension::KHTMLPartBrowserExtension( KHTMLPart *parent )
@@ -1092,4 +1092,59 @@
return QString();
}
+////
+
+KHTMLHtmlExtension::KHTMLHtmlExtension(KHTMLPart* part)
+ : KParts::HtmlExtension(part)
+{
+}
+
+KHTMLPart* KHTMLHtmlExtension::part() const
+{
+ return static_cast<KHTMLPart*>(parent());
+}
+
+static KParts::SelectorInterface::Element convertDomElement(const DOM::ElementImpl* \
domElem) +{
+ KParts::SelectorInterface::Element elem;
+ elem.setTagName(domElem->tagName().string());
+ const DOM::NamedAttrMapImpl* attrMap = domElem->attributes(true /*readonly*/);
+ if (attrMap) {
+ for (unsigned i = 0; i < attrMap->length(); ++i) {
+ const DOM::AttributeImpl& attr = attrMap->attributeAt(i);
+ elem.setAttribute(attr.localName().string(), attr.value().string());
+ // we could have a setAttributeNS too.
+ }
+ }
+ return elem;
+}
+
+KParts::SelectorInterface::Element KHTMLHtmlExtension::querySelector(const QString& \
query) const +{
+ int ec = 0; // exceptions are ignored
+ WTF::RefPtr<DOM::ElementImpl> element = \
part()->document().handle()->querySelector(query, ec); + return \
convertDomElement(element.get()); +}
+
+QList<KParts::SelectorInterface::Element> KHTMLHtmlExtension::querySelectorAll(const \
QString& query) const +{
+ int ec = 0; // exceptions are ignored
+ WTF::RefPtr<DOM::NodeListImpl> nodes = \
part()->document().handle()->querySelectorAll(query, ec); + QList<Element> result;
+ const unsigned long len = nodes->length();
+ result.reserve(len);
+ for (unsigned long i = 0; i < len; ++i) {
+ DOM::NodeImpl* node = nodes->item(i);
+ if (node->isElementNode()) { // should be always true
+ result.append(convertDomElement(static_cast<DOM::ElementImpl*>(node)));
+ }
+ }
+ return result;
+}
+
+KUrl KHTMLHtmlExtension::baseUrl() const
+{
+ return part()->baseURL();
+}
+
#include "khtml_ext.moc"
--- trunk/KDE/kdelibs/khtml/khtml_ext.h #1184005:1184006
@@ -33,6 +33,7 @@
#include <kselectaction.h>
#include <kparts/textextension.h>
+#include <kparts/htmlextension.h>
#include <kio/global.h>
/**
@@ -190,4 +191,26 @@
KHTMLPart* part() const;
};
+/**
+ * @internal
+ * Implements the HtmlExtension interface
+ */
+class KHTMLHtmlExtension : public KParts::HtmlExtension,
+ public KParts::SelectorInterface
+{
+ Q_OBJECT
+ Q_INTERFACES(KParts::SelectorInterface)
+
+public:
+ KHTMLHtmlExtension(KHTMLPart* part);
+
+ virtual KUrl baseUrl() const;
+
+ // SelectorInterface
+ virtual Element querySelector(const QString& query) const;
+ virtual QList<Element> querySelectorAll(const QString& query) const;
+
+ KHTMLPart* part() const;
+};
+
#endif
--- trunk/KDE/kdelibs/khtml/khtml_part.cpp #1184005:1184006
@@ -237,6 +237,7 @@
d->m_statusBarExtension = new KParts::StatusBarExtension( this );
d->m_scriptableExtension = new KJS::KHTMLPartScriptable( this );
new KHTMLTextExtension( this );
+ new KHTMLHtmlExtension( this );
d->m_statusBarPopupLabel = 0L;
d->m_openableSuppressedPopups = 0;
@@ -2486,7 +2487,7 @@
return d->m_settings;
}
-#ifndef KDE_NO_COMPAT
+#ifndef KDE_NO_COMPAT // KDE5: remove this ifndef, keep the method (renamed to \
baseUrl) KUrl KHTMLPart::baseURL() const
{
if ( !d->m_doc ) return KUrl();
--- trunk/KDE/kdelibs/kparts/CMakeLists.txt #1184005:1184006
@@ -25,6 +25,7 @@
statusbarextension.cpp
scriptableextension.cpp
textextension.cpp
+ htmlextension.cpp
)
kde4_add_library(kparts ${LIBRARY_TYPE} ${kparts_LIB_SRCS})
@@ -49,6 +50,6 @@
install( FILES kparts_export.h part.h plugin.h partmanager.h mainwindow.h event.h
browserextension.h factory.h historyprovider.h browserinterface.h \
genericfactory.h
componentfactory.h browserrun.h statusbarextension.h \
browseropenorsavequestion.h
- scriptableextension.h textextension.h
+ scriptableextension.h textextension.h htmlextension.h
DESTINATION ${INCLUDE_INSTALL_DIR}/kparts COMPONENT Devel )
[prev in list] [next in list] [prev in thread] [next in thread]
Configure |
About |
News |
Add a list |
Sponsored by KoreLogic