Subject: [kdelibs/KDE/4.8] /: Added a new interface, HtmlSettingsInterface, to HtmlExtension to allow
Git commit a43057985ce95d043608a5a74555fbb7e6f5ed20 by Dawit Alemayehu.
Committed on 21/02/2012 at 18:55.
Pushed by adawit into branch 'KDE/4.8'.

Added a new interface, HtmlSettingsInterface, to HtmlExtension to allow
generic access to HTML settings.

REVIEW: 103973

M +72 -2 khtml/khtml_ext.cpp
M +7 -1 khtml/khtml_ext.h
M +57 -0 kparts/htmlextension.h

http://commits.kde.org/kdelibs/a43057985ce95d043608a5a74555fbb7e6f5ed20

diff --git a/khtml/khtml_ext.cpp b/khtml/khtml_ext.cpp
index 6e8a846..3a1da4a 100644
--- a/khtml/khtml_ext.cpp
+++ b/khtml/khtml_ext.cpp
@@ -1147,13 +1147,13 @@ KParts::SelectorInterface::Element
KHTMLHtmlExtension::querySelector(const QStri
WTF::RefPtr<DOM::ElementImpl> domElem =
part()->document().handle()->querySelector(query, ec);
element = convertDomElement(domElem.get());
break;
- }
+ }
case KParts::SelectorInterface::SelectedContent:
if (part()->hasSelection()) {
DOM::Element domElem =
part()->selection().cloneContents().querySelector(query);
element =
convertDomElement(static_cast<DOM::ElementImpl*>(domElem.handle()));
}
- break;
+ break;
default:
break;
}
@@ -1206,6 +1206,76 @@ QList<KParts::SelectorInterface::Element>
KHTMLHtmlExtension::querySelectorAll(c
return elements;
}

+QVariant
KHTMLHtmlExtension::htmlSettingsProperty(HtmlSettingsInterface::HtmlSettingsType
type) const
+{
+ if (part()) {
+ switch (type) {
+ case KParts::HtmlSettingsInterface::AutoLoadImages:
+ return part()->autoloadImages();
+ case KParts::HtmlSettingsInterface::DnsPrefetchEnabled:
+ return (part()->dnsPrefetch() == KHTMLPart::DNSPrefetchEnabled);
+ case KParts::HtmlSettingsInterface::JavaEnabled:
+ return part()->javaEnabled();
+ case KParts::HtmlSettingsInterface::JavascriptEnabled:
+ return part()->jScriptEnabled();
+ case KParts::HtmlSettingsInterface::MetaRefreshEnabled:
+ return part()->metaRefreshEnabled();
+ case KParts::HtmlSettingsInterface::PluginsEnabled:
+ return part()->pluginsEnabled();
+ default:
+ break;
+ }
+ }
+ return QVariant();
+}
+
+bool
KHTMLHtmlExtension::setHtmlSettingsProperty(HtmlSettingsInterface::HtmlSettingsType
type, const QVariant& value)
+{
+ KHTMLPart* p = part();
+
+ if (p) {
+ switch (type) {
+ case KParts::HtmlSettingsInterface::AutoLoadImages:
+ p->setAutoloadImages(value.toBool());
+ return true;
+ case KParts::HtmlSettingsInterface::DnsPrefetchEnabled:
+ p->setDNSPrefetch((value.toBool() ? KHTMLPart::DNSPrefetchEnabled
: KHTMLPart::DNSPrefetchDisabled));
+ return true;
+ case KParts::HtmlSettingsInterface::JavaEnabled:
+ p->setJavaEnabled(value.toBool());
+ return true;
+ case KParts::HtmlSettingsInterface::JavascriptEnabled:
+ p->setJScriptEnabled(value.toBool());
+ return true;
+ case KParts::HtmlSettingsInterface::MetaRefreshEnabled:
+ p->setMetaRefreshEnabled(value.toBool());
+ return true;
+ case KParts::HtmlSettingsInterface::PluginsEnabled:
+ p->setPluginsEnabled(value.toBool());
+ return true;
+ case KParts::HtmlSettingsInterface::UserDefinedStyleSheetURL: {
+ const KUrl url (value.toUrl());
+ if (url.protocol() == QLatin1String("data")) {
+ const QByteArray data (url.encodedPath());
+ if (!data.isEmpty()) {
+ const int index = data.indexOf(',');
+ const QByteArray decodedData ((index > -1 ?
QByteArray::fromBase64(data.mid(index)) : QByteArray()));
+
part()->setUserStyleSheet(QString::fromUtf8(decodedData.constData(),
decodedData.size()));
+ }
+ } else {
+ part()->setUserStyleSheet(url);
+ }
+ return true;
+ }
+ default:
+ break; // Unsupported property...
+ }
+ }
+
+ return false;
+}
+
+
KHTMLPart* KHTMLHtmlExtension::part() const
{
return static_cast<KHTMLPart*>(parent());
diff --git a/khtml/khtml_ext.h b/khtml/khtml_ext.h
index ced53a3..571a629 100644
--- a/khtml/khtml_ext.h
+++ b/khtml/khtml_ext.h
@@ -196,10 +196,12 @@ public:
* Implements the HtmlExtension interface
*/
class KHTMLHtmlExtension : public KParts::HtmlExtension,
- public KParts::SelectorInterface
+ public KParts::SelectorInterface,
+ public KParts::HtmlSettingsInterface
{
Q_OBJECT
Q_INTERFACES(KParts::SelectorInterface)
+ Q_INTERFACES(KParts::HtmlSettingsInterface)

public:
KHTMLHtmlExtension(KHTMLPart* part);
@@ -213,6 +215,10 @@ public:
virtual Element querySelector(const QString& query, QueryMethod method)
const;
virtual QList<Element> querySelectorAll(const QString& query, QueryMethod
method) const;

+ // SettingsInterface
+ virtual QVariant htmlSettingsProperty(HtmlSettingsType type) const;
+ virtual bool setHtmlSettingsProperty(HtmlSettingsType type, const
QVariant& value);
+
KHTMLPart* part() const;
};

diff --git a/kparts/htmlextension.h b/kparts/htmlextension.h
index 9833d9a..b91f203 100644
--- a/kparts/htmlextension.h
+++ b/kparts/htmlextension.h
@@ -224,6 +224,60 @@ public:
};
};

+/**
+ * @short An interface for modifying the settings of browser engines.
+ *
+ * This interface provides a generic means for querying or changing the
+ * settings of browser engines that implement it.
+ *
+ * To use this class simply cast an instance of the HTMLExtension object
+ * using qobject_cast<KParts::HtmlSettingsInterface>.
+ *
+ * Example:
+ * <code>
+ * KParts::HTMLExtension* extension =
KParts::HTMLExtension::childObject(part);
+ * KParts::HtmlSettingsInterface* settings =
qobject_cast&lt;KParts::HtmlSettingsInterface&gt;(extension);
+ * const bool autoLoadImages = settings->attribute(KParts::AutoLoadImages);
+ * </code>
+ *
+ * @since 4.9.0
+ */
+class KPARTS_EXPORT HtmlSettingsInterface
+{
+public:
+ /**
+ * Settings attribute types.
+ */
+ enum HtmlSettingsType {
+ AutoLoadImages,
+ DnsPrefetchEnabled,
+ JavaEnabled,
+ JavascriptEnabled,
+ MetaRefreshEnabled,
+ PluginsEnabled,
+ PrivateBrowsingEnabled,
+ OfflineStorageDatabaseEnabled,
+ OfflineWebApplicationCacheEnabled,
+ LocalStorageEnabled,
+ UserDefinedStyleSheetURL
+ };
+
+ /**
+ * Destructor
+ */
+ virtual ~HtmlSettingsInterface() {}
+
+ /**
+ * Returns the value of the browser engine's attribute @p type.
+ */
+ virtual QVariant htmlSettingsProperty(HtmlSettingsType type) const = 0;
+
+ /**
+ * Sets the value of the browser engine's attribute @p type to @p value.
+ */
+ virtual bool setHtmlSettingsProperty(HtmlSettingsType type, const
QVariant& value) = 0;
+};
+
} // namespace KParts

inline void qSwap( KParts::SelectorInterface::Element & lhs,
KParts::SelectorInterface::Element & rhs )
@@ -237,5 +291,8 @@ Q_DECLARE_TYPEINFO(KParts::SelectorInterface::Element,
Q_MOVABLE_TYPE);

Q_DECLARE_INTERFACE(KParts::SelectorInterface,
"org.kde.KParts.SelectorInterface")
+Q_DECLARE_INTERFACE(KParts::HtmlSettingsInterface,
+ "org.kde.KParts.HtmlSettingsInterface")
+

#endif /* KPARTS_HTMLEXTENSION_H */

(C)2011 mailinglist-archive.com