summaryrefslogtreecommitdiffstats
path: root/WebKit/qt/Api
diff options
context:
space:
mode:
Diffstat (limited to 'WebKit/qt/Api')
-rw-r--r--WebKit/qt/Api/headers.pri7
-rw-r--r--WebKit/qt/Api/qcookiejar.cpp16
-rw-r--r--WebKit/qt/Api/qcookiejar.h9
-rw-r--r--WebKit/qt/Api/qwebdatabase.cpp61
-rw-r--r--WebKit/qt/Api/qwebdatabase.h6
-rw-r--r--WebKit/qt/Api/qwebdatabase_p.h7
-rw-r--r--WebKit/qt/Api/qwebelement.cpp1613
-rw-r--r--WebKit/qt/Api/qwebelement.h152
-rw-r--r--WebKit/qt/Api/qwebframe.cpp408
-rw-r--r--WebKit/qt/Api/qwebframe.h36
-rw-r--r--WebKit/qt/Api/qwebframe_p.h34
-rw-r--r--WebKit/qt/Api/qwebhistory.cpp156
-rw-r--r--WebKit/qt/Api/qwebhistory.h31
-rw-r--r--WebKit/qt/Api/qwebhistory_p.h31
-rw-r--r--WebKit/qt/Api/qwebhistoryinterface.cpp31
-rw-r--r--WebKit/qt/Api/qwebhistoryinterface.h3
-rw-r--r--WebKit/qt/Api/qwebkitglobal.h22
-rw-r--r--WebKit/qt/Api/qwebkitversion.cpp58
-rw-r--r--WebKit/qt/Api/qwebkitversion.h32
-rw-r--r--WebKit/qt/Api/qwebnetworkinterface.cpp214
-rw-r--r--WebKit/qt/Api/qwebnetworkinterface.h22
-rw-r--r--WebKit/qt/Api/qwebnetworkinterface_p.h33
-rw-r--r--WebKit/qt/Api/qwebpage.cpp446
-rw-r--r--WebKit/qt/Api/qwebpage.h40
-rw-r--r--WebKit/qt/Api/qwebpage_p.h16
-rw-r--r--WebKit/qt/Api/qwebplugindatabase.cpp382
-rw-r--r--WebKit/qt/Api/qwebplugindatabase.h94
-rw-r--r--WebKit/qt/Api/qwebplugindatabase_p.h46
-rw-r--r--WebKit/qt/Api/qwebpluginfactory.cpp7
-rw-r--r--WebKit/qt/Api/qwebpluginfactory.h21
-rw-r--r--WebKit/qt/Api/qwebsecurityorigin.cpp28
-rw-r--r--WebKit/qt/Api/qwebsecurityorigin.h3
-rw-r--r--WebKit/qt/Api/qwebsecurityorigin_p.h3
-rw-r--r--WebKit/qt/Api/qwebsettings.cpp224
-rw-r--r--WebKit/qt/Api/qwebsettings.h21
-rw-r--r--WebKit/qt/Api/qwebview.cpp184
-rw-r--r--WebKit/qt/Api/qwebview.h58
37 files changed, 3929 insertions, 626 deletions
diff --git a/WebKit/qt/Api/headers.pri b/WebKit/qt/Api/headers.pri
index 2b3c940..92a120d 100644
--- a/WebKit/qt/Api/headers.pri
+++ b/WebKit/qt/Api/headers.pri
@@ -5,4 +5,9 @@ WEBKIT_API_HEADERS = $$PWD/qwebframe.h \
$$PWD/qwebsettings.h \
$$PWD/qwebhistoryinterface.h \
$$PWD/qwebdatabase.h \
- $$PWD/qwebsecurityorigin.h
+ $$PWD/qwebsecurityorigin.h \
+ $$PWD/qwebelement.h \
+ $$PWD/qwebplugindatabase.h \
+ $$PWD/qwebpluginfactory.h \
+ $$PWD/qwebhistory.h \
+ $$PWD/qwebkitversion.h
diff --git a/WebKit/qt/Api/qcookiejar.cpp b/WebKit/qt/Api/qcookiejar.cpp
index a6cbdab..a02fe78 100644
--- a/WebKit/qt/Api/qcookiejar.cpp
+++ b/WebKit/qt/Api/qcookiejar.cpp
@@ -17,7 +17,7 @@
Boston, MA 02110-1301, USA.
*/
-
+#include "config.h"
#include "qcookiejar.h"
#include <QCoreApplication>
uint qHash(const QUrl&);
@@ -26,7 +26,8 @@ uint qHash(const QUrl&);
class QCookieJarPrivate {
public:
- QCookieJarPrivate() {
+ QCookieJarPrivate()
+ {
enabled = true;
}
bool enabled;
@@ -34,7 +35,8 @@ class QCookieJarPrivate {
};
-uint qHash(const QUrl& url) {
+uint qHash(const QUrl& url)
+{
return qHash(url.toString());
}
@@ -85,7 +87,7 @@ static void gCleanupJar()
}
-void QCookieJar::setCookieJar(QCookieJar *jar)
+void QCookieJar::setCookieJar(QCookieJar* jar)
{
if (!gRoutineAdded) {
qAddPostRoutine(gCleanupJar);
@@ -96,10 +98,10 @@ void QCookieJar::setCookieJar(QCookieJar *jar)
}
-QCookieJar *QCookieJar::cookieJar()
+QCookieJar* QCookieJar::cookieJar()
{
- if (!gJar) {
+ if (!gJar)
setCookieJar(new QCookieJar);
- }
+
return gJar;
}
diff --git a/WebKit/qt/Api/qcookiejar.h b/WebKit/qt/Api/qcookiejar.h
index 0ca00bd..7885cc1 100644
--- a/WebKit/qt/Api/qcookiejar.h
+++ b/WebKit/qt/Api/qcookiejar.h
@@ -26,8 +26,7 @@
class QCookieJarPrivate;
-class QWEBKIT_EXPORT QCookieJar : public QObject
-{
+class QWEBKIT_EXPORT QCookieJar : public QObject {
Q_OBJECT
Q_PROPERTY(bool enabled READ isEnabled WRITE setEnabled)
@@ -40,15 +39,15 @@ public:
bool isEnabled() const;
- static void setCookieJar(QCookieJar *jar);
- static QCookieJar *cookieJar();
+ static void setCookieJar(QCookieJar* jar);
+ static QCookieJar* cookieJar();
public slots:
virtual void setEnabled(bool enabled);
private:
friend class QCookieJarPrivate;
- QCookieJarPrivate *d;
+ QCookieJarPrivate* d;
};
diff --git a/WebKit/qt/Api/qwebdatabase.cpp b/WebKit/qt/Api/qwebdatabase.cpp
index 0203d72..d51e4e6 100644
--- a/WebKit/qt/Api/qwebdatabase.cpp
+++ b/WebKit/qt/Api/qwebdatabase.cpp
@@ -20,8 +20,6 @@
#include "config.h"
#include "qwebdatabase.h"
-#if ENABLE(DATABASE)
-
#include "qwebdatabase_p.h"
#include "qwebsecurityorigin.h"
#include "qwebsecurityorigin_p.h"
@@ -36,9 +34,20 @@ using namespace WebCore;
\brief The QWebDatabase class provides access to HTML 5 databases created with JavaScript.
The upcoming HTML 5 standard includes support for SQL databases that web sites can create and
- access on a local computer through JavaScript. QWebDatabase is the C++ interface to these databases.
+ access on a local computer through JavaScript. QWebDatabase is the C++ interface to these
+ databases.
+
+ To get access to all databases defined by a security origin, use QWebSecurityOrigin::databases().
+ Each database has an internal name(), as well as a user-friendly name, provided by displayName().
+
+ WebKit uses SQLite to create and access the local SQL databases. The location of the database
+ file in the local file system is returned by fileName(). You can access the database directly
+ through the QtSql database module.
- For more information refer to the \l{http://www.w3.org/html/wg/html5/#sql}{HTML 5 Draft Standard}.
+ For each database the web site can define an expectedSize(). The current size of the database
+ in bytes is returned by size().
+
+ For more information refer to the \l{http://dev.w3.org/html5/webdatabase/}{HTML 5 Draft Standard}.
\sa QWebSecurityOrigin
*/
@@ -46,7 +55,8 @@ using namespace WebCore;
/*!
Constructs a web database from \a other.
*/
-QWebDatabase::QWebDatabase(const QWebDatabase& other) : d(other.d)
+QWebDatabase::QWebDatabase(const QWebDatabase& other)
+ : d(other.d)
{
}
@@ -72,8 +82,12 @@ QString QWebDatabase::name() const
*/
QString QWebDatabase::displayName() const
{
+#if ENABLE(DATABASE)
DatabaseDetails details = DatabaseTracker::tracker().detailsForNameAndOrigin(d->name, d->origin.get());
return details.displayName();
+#else
+ return QString();
+#endif
}
/*!
@@ -81,8 +95,12 @@ QString QWebDatabase::displayName() const
*/
qint64 QWebDatabase::expectedSize() const
{
+#if ENABLE(DATABASE)
DatabaseDetails details = DatabaseTracker::tracker().detailsForNameAndOrigin(d->name, d->origin.get());
return details.expectedUsage();
+#else
+ return 0;
+#endif
}
/*!
@@ -90,8 +108,12 @@ qint64 QWebDatabase::expectedSize() const
*/
qint64 QWebDatabase::size() const
{
+#if ENABLE(DATABASE)
DatabaseDetails details = DatabaseTracker::tracker().detailsForNameAndOrigin(d->name, d->origin.get());
return details.currentUsage();
+#else
+ return 0;
+#endif
}
/*!
@@ -117,11 +139,15 @@ QWebDatabase::QWebDatabase(QWebDatabasePrivate* priv)
\endcode
\note Concurrent access to a database from multiple threads or processes
- is not very efficient because Sqlite is used as WebKit's database backend.
+ is not very efficient because SQLite is used as WebKit's database backend.
*/
QString QWebDatabase::fileName() const
{
+#if ENABLE(DATABASE)
return DatabaseTracker::tracker().fullPathForDatabase(d->origin.get(), d->name, false);
+#else
+ return QString();
+#endif
}
/*!
@@ -135,12 +161,28 @@ QWebSecurityOrigin QWebDatabase::origin() const
}
/*!
- Removes the database, \a db, from its security origin. All data stored in this database
- will be destroyed.
+ Removes the database \a db from its security origin. All data stored in the
+ database \a db will be destroyed.
*/
-void QWebDatabase::removeDatabase(const QWebDatabase &db)
+void QWebDatabase::removeDatabase(const QWebDatabase& db)
{
+#if ENABLE(DATABASE)
DatabaseTracker::tracker().deleteDatabase(db.d->origin.get(), db.d->name);
+#endif
+}
+
+/*!
+ \since 4.6
+
+ Deletes all web databases in the configured offline storage path.
+
+ \sa QWebSettings::setOfflineStoragePath()
+*/
+void QWebDatabase::removeAllDatabases()
+{
+#if ENABLE(DATABASE)
+ DatabaseTracker::tracker().deleteAllDatabases();
+#endif
}
/*!
@@ -150,4 +192,3 @@ QWebDatabase::~QWebDatabase()
{
}
-#endif
diff --git a/WebKit/qt/Api/qwebdatabase.h b/WebKit/qt/Api/qwebdatabase.h
index 4e832bb..875b2eb 100644
--- a/WebKit/qt/Api/qwebdatabase.h
+++ b/WebKit/qt/Api/qwebdatabase.h
@@ -31,8 +31,7 @@ namespace WebCore {
class QWebDatabasePrivate;
class QWebSecurityOrigin;
-class QWEBKIT_EXPORT QWebDatabase
-{
+class QWEBKIT_EXPORT QWebDatabase {
public:
QWebDatabase(const QWebDatabase& other);
QWebDatabase &operator=(const QWebDatabase& other);
@@ -45,7 +44,8 @@ public:
QString fileName() const;
QWebSecurityOrigin origin() const;
- static void removeDatabase(const QWebDatabase &db);
+ static void removeDatabase(const QWebDatabase&);
+ static void removeAllDatabases();
private:
QWebDatabase(QWebDatabasePrivate* priv);
diff --git a/WebKit/qt/Api/qwebdatabase_p.h b/WebKit/qt/Api/qwebdatabase_p.h
index 145115e..9ae8fc8 100644
--- a/WebKit/qt/Api/qwebdatabase_p.h
+++ b/WebKit/qt/Api/qwebdatabase_p.h
@@ -19,8 +19,6 @@
#ifndef _WEBDATABASE_P_H_
#define _WEBDATABASE_P_H_
-#if ENABLE(DATABASE)
-
#include <QString>
#include <QtCore/qshareddata.h>
@@ -29,8 +27,7 @@
#include "RefPtr.h"
-class QWebDatabasePrivate : public QSharedData
-{
+class QWebDatabasePrivate : public QSharedData {
public:
WebCore::String name;
WTF::RefPtr<WebCore::SecurityOrigin> origin;
@@ -38,5 +35,3 @@ public:
#endif
-#endif
-
diff --git a/WebKit/qt/Api/qwebelement.cpp b/WebKit/qt/Api/qwebelement.cpp
new file mode 100644
index 0000000..14b2811
--- /dev/null
+++ b/WebKit/qt/Api/qwebelement.cpp
@@ -0,0 +1,1613 @@
+/*
+ Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies)
+
+ This library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Library General Public
+ License as published by the Free Software Foundation; either
+ version 2 of the License, or (at your option) any later version.
+
+ This library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Library General Public License for more details.
+
+ You should have received a copy of the GNU Library General Public License
+ along with this library; see the file COPYING.LIB. If not, write to
+ the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+ Boston, MA 02110-1301, USA.
+*/
+
+#include "config.h"
+#include "qwebelement.h"
+
+#include "CSSComputedStyleDeclaration.h"
+#include "CSSMutableStyleDeclaration.h"
+#include "CSSParser.h"
+#include "CSSRuleList.h"
+#include "CSSRule.h"
+#include "CSSStyleRule.h"
+#include "CString.h"
+#include "Document.h"
+#include "DocumentFragment.h"
+#include "FrameView.h"
+#include "HTMLElement.h"
+#include "JSGlobalObject.h"
+#include "JSHTMLElement.h"
+#include "JSObject.h"
+#include "NodeList.h"
+#include "PropertyNameArray.h"
+#include "ScriptFunctionCall.h"
+#include "StaticNodeList.h"
+#include "qt_runtime.h"
+#include "qwebframe.h"
+#include "qwebframe_p.h"
+#include "runtime_root.h"
+#include <wtf/Vector.h>
+
+using namespace WebCore;
+
+class QWebElementPrivate {
+public:
+};
+
+/*!
+ \class QWebElement
+ \since 4.6
+ \brief The QWebElement class provides convenient access to DOM elements in a QWebFrame.
+
+ QWebElement is the main class to easily access to the document model.
+ The document model is represented by a tree-like structure of DOM elements.
+ The root of the tree is called the document element and can be accessed using QWebFrame::documentElement().
+
+ You can reach specific elements using findAll() and findFirst(); the elements
+ are identified through CSS selectors.
+
+ \snippet webkitsnippets/webelement/main.cpp FindAll
+
+ The first list contains all \c span elements in the document. The second list contains
+ \c span elements that are children of \c p, classified with \c intro.
+
+ Using findFirst() is more efficient than calling findAll() and extracting the first element
+ only in the returned list.
+
+ Alternatively you can manually traverse the document using firstChild() and nextSibling():
+
+ \snippet webkitsnippets/webelement/main.cpp Traversing with QWebElement
+
+ The underlying content of QWebElement is explicitly shared. Creating a copy of a QWebElement
+ does not create a copy of the content. Instead, both instances point to the same element.
+
+ The element's attributes can be read using attribute() and modified with setAttribute().
+
+ The contents of child elements can be converted to plain text with toPlainText() and to
+ XHTML using toInnerXml(). To also include the element's tag in the output, use toOuterXml().
+
+ It is possible to replace the contents using setPlainText() and setInnerXml(). To replace
+ the element itself and its contents, use setOuterXml().
+
+ In the JavaScript DOM interfaces, elements can have additional functions depending on their
+ type. For example an HTML form element can be triggered to submit the entire form to the
+ web server using the submit() function. A list of these special functions can be obtained
+ in QWebElement using functions(); they can be invoked using callFunction().
+
+ Similarly element specific properties can be obtained using scriptableProperties() and
+ read/written using scriptableProperty()/setScriptableProperty().
+*/
+
+/*!
+ Constructs a null web element.
+*/
+QWebElement::QWebElement()
+ : d(0)
+ , m_element(0)
+{
+}
+
+/*!
+ \internal
+*/
+QWebElement::QWebElement(WebCore::Element* domElement)
+ : d(0)
+ , m_element(domElement)
+{
+ if (m_element)
+ m_element->ref();
+}
+
+/*!
+ \internal
+*/
+QWebElement::QWebElement(WebCore::Node* node)
+ : d(0)
+ , m_element(0)
+{
+ if (node && node->isHTMLElement()) {
+ m_element = static_cast<HTMLElement*>(node);
+ m_element->ref();
+ }
+}
+
+/*!
+ Constructs a copy of \a other.
+*/
+QWebElement::QWebElement(const QWebElement &other)
+ : d(0)
+ , m_element(other.m_element)
+{
+ if (m_element)
+ m_element->ref();
+}
+
+/*!
+ Assigns \a other to this element and returns a reference to this element.
+*/
+QWebElement &QWebElement::operator=(const QWebElement &other)
+{
+ // ### handle "d" assignment
+ if (this != &other) {
+ Element *otherElement = other.m_element;
+ if (otherElement)
+ otherElement->ref();
+ if (m_element)
+ m_element->deref();
+ m_element = otherElement;
+ }
+ return *this;
+}
+
+/*!
+ Destroys the element. The underlying DOM element is not destroyed.
+*/
+QWebElement::~QWebElement()
+{
+ delete d;
+ if (m_element)
+ m_element->deref();
+}
+
+bool QWebElement::operator==(const QWebElement& o) const
+{
+ return m_element == o.m_element;
+}
+
+bool QWebElement::operator!=(const QWebElement& o) const
+{
+ return m_element != o.m_element;
+}
+
+/*!
+ Returns true if the element is a null element; false otherwise.
+*/
+bool QWebElement::isNull() const
+{
+ return !m_element;
+}
+
+/*!
+ Returns a new list of child elements matching the given CSS selector \a selectorQuery.
+ If there are no matching elements, an empty list is returned.
+
+ \l{http://www.w3.org/TR/REC-CSS2/selector.html#q1}{Standard CSS2 selector} syntax is
+ used for the query.
+
+ \note This search is performed recursively.
+*/
+QList<QWebElement> QWebElement::findAll(const QString &selectorQuery) const
+{
+ QList<QWebElement> elements;
+ if (!m_element)
+ return elements;
+
+ ExceptionCode exception = 0; // ###
+ RefPtr<NodeList> nodes = m_element->querySelectorAll(selectorQuery, exception);
+ if (!nodes)
+ return elements;
+
+ for (int i = 0; i < nodes->length(); ++i) {
+ WebCore::Node* n = nodes->item(i);
+ elements.append(QWebElement(static_cast<Element*>(n)));
+ }
+
+ return elements;
+}
+
+/*!
+ Returns the first child element that matches the given CSS selector \a selectorQuery.
+
+ \l{http://www.w3.org/TR/REC-CSS2/selector.html#q1}{Standard CSS2 selector} syntax is
+ used for the query.
+
+ \note This search is performed recursively.
+*/
+QWebElement QWebElement::findFirst(const QString &selectorQuery) const
+{
+ if (!m_element)
+ return QWebElement();
+ ExceptionCode exception = 0; // ###
+ return QWebElement(m_element->querySelector(selectorQuery, exception).get());
+}
+
+/*!
+ Replaces the existing content of this element with \a text.
+
+ This is equivalent to setting the HTML innerText property.
+*/
+void QWebElement::setPlainText(const QString &text)
+{
+ if (!m_element || !m_element->isHTMLElement())
+ return;
+ ExceptionCode exception = 0;
+ static_cast<HTMLElement*>(m_element)->setInnerText(text, exception);
+}
+
+/*!
+ Returns the text between the start and the end tag of this
+ element.
+
+ This is equivalent to reading the HTML innerText property.
+*/
+QString QWebElement::toPlainText() const
+{
+ if (!m_element || !m_element->isHTMLElement())
+ return QString();
+ return static_cast<HTMLElement*>(m_element)->innerText();
+}
+
+/*!
+ Replaces the contents of this element as well as its own tag with \a markup.
+ The string may contain HTML or XML tags, which is parsed and formatted
+ before insertion into the document.
+
+ \note This is currently only implemented for (X)HTML elements.
+*/
+void QWebElement::setOuterXml(const QString &markup)
+{
+ if (!m_element || !m_element->isHTMLElement())
+ return;
+
+ ExceptionCode exception = 0;
+
+ static_cast<HTMLElement*>(m_element)->setOuterHTML(markup, exception);
+}
+
+/*!
+ Returns this element converted to XML, including the start and the end
+ tag of this element and its attributes.
+
+ \note This is currently only implemented for (X)HTML elements.
+*/
+QString QWebElement::toOuterXml() const
+{
+ if (!m_element || !m_element->isHTMLElement())
+ return QString();
+
+ return static_cast<HTMLElement*>(m_element)->outerHTML();
+}
+
+/*!
+ Replaces the content of this element with \a markup.
+ The string may contain HTML or XML tags, which is parsed and formatted
+ before insertion into the document.
+
+ \note This is currently only implemented for (X)HTML elements.
+*/
+void QWebElement::setInnerXml(const QString &markup)
+{
+ if (!m_element || !m_element->isHTMLElement())
+ return;
+
+ ExceptionCode exception = 0;
+
+ static_cast<HTMLElement*>(m_element)->setInnerHTML(markup, exception);
+}
+
+/*!
+ Returns the XML between the start and the end tag of this
+ element.
+
+ \note This is currently only implemented for (X)HTML elements.
+*/
+QString QWebElement::toInnerXml() const
+{
+ if (!m_element || !m_element->isHTMLElement())
+ return QString();
+
+ return static_cast<HTMLElement*>(m_element)->innerHTML();
+}
+
+/*!
+ Adds an attribute called \a name with the value \a value. If an attribute
+ with the same name exists, its value is replaced by \a value.
+*/
+void QWebElement::setAttribute(const QString &name, const QString &value)
+{
+ if (!m_element)
+ return;
+ ExceptionCode exception = 0;
+ m_element->setAttribute(name, value, exception);
+}
+
+/*!
+ Adds an attribute called \a name in the namespace described with \a namespaceUri
+ with the value \a value. If an attribute with the same name exists, its value is
+ replaced by \a value.
+*/
+void QWebElement::setAttributeNS(const QString &namespaceUri, const QString &name, const QString &value)
+{
+ if (!m_element)
+ return;
+ WebCore::ExceptionCode exception = 0;
+ m_element->setAttributeNS(namespaceUri, name, value, exception);
+}
+
+/*!
+ Returns the attributed called \a name. If the attribute does not exist \a defaultValue is
+ returned.
+*/
+QString QWebElement::attribute(const QString &name, const QString &defaultValue) const
+{
+ if (!m_element)
+ return QString();
+ if (m_element->hasAttribute(name))
+ return m_element->getAttribute(name);
+ else
+ return defaultValue;
+}
+
+/*!
+ Returns the attributed called \a name in the namespace described with \a namespaceUri.
+ If the attribute does not exist \a defaultValue is returned.
+*/
+QString QWebElement::attributeNS(const QString &namespaceUri, const QString &name, const QString &defaultValue) const
+{
+ if (!m_element)
+ return QString();
+ if (m_element->hasAttributeNS(namespaceUri, name))
+ return m_element->getAttributeNS(namespaceUri, name);
+ else
+ return defaultValue;
+}
+
+/*!
+ Returns true if this element has an attribute called \a name; otherwise returns false.
+*/
+bool QWebElement::hasAttribute(const QString &name) const
+{
+ if (!m_element)
+ return false;
+ return m_element->hasAttribute(name);
+}
+
+/*!
+ Returns true if this element has an attribute called \a name in the namespace described
+ with \a namespaceUri; otherwise returns false.
+*/
+bool QWebElement::hasAttributeNS(const QString &namespaceUri, const QString &name) const
+{
+ if (!m_element)
+ return false;
+ return m_element->hasAttributeNS(namespaceUri, name);
+}
+
+/*!
+ Removes the attribute called \a name from this element.
+*/
+void QWebElement::removeAttribute(const QString &name)
+{
+ if (!m_element)
+ return;
+ ExceptionCode exception = 0;
+ m_element->removeAttribute(name, exception);
+}
+
+/*!
+ Removes the attribute called \a name in the namespace described with \a namespaceUri
+ from this element.
+*/
+void QWebElement::removeAttributeNS(const QString &namespaceUri, const QString &name)
+{
+ if (!m_element)
+ return;
+ WebCore::ExceptionCode exception = 0;
+ m_element->removeAttributeNS(namespaceUri, name, exception);
+}
+
+/*!
+ Returns true if the element has any attributes defined; otherwise returns false;
+*/
+bool QWebElement::hasAttributes() const
+{
+ if (!m_element)
+ return false;
+ return m_element->hasAttributes();
+}
+
+/*!
+ Returns the geometry of this element, relative to its containing frame.
+*/
+QRect QWebElement::geometry() const
+{
+ if (!m_element)
+ return QRect();
+ return m_element->getRect();
+}
+
+/*!
+ Returns the tag name of this element.
+*/
+QString QWebElement::tagName() const
+{
+ if (!m_element)
+ return QString();
+ return m_element->tagName();
+}
+
+/*!
+ Returns the namespace prefix of the element or an empty string if the element has no namespace prefix.
+*/
+QString QWebElement::prefix() const
+{
+ if (!m_element)
+ return QString();
+ return m_element->prefix();
+}
+
+/*!
+ If the element uses namespaces, this function returns the local name of the element;
+ otherwise it returns an empty string.
+*/
+QString QWebElement::localName() const
+{
+ if (!m_element)
+ return QString();
+ return m_element->localName();
+}
+
+/*!
+ Returns the namespace URI of this element or an empty string if the element has no namespace URI.
+*/
+QString QWebElement::namespaceUri() const
+{
+ if (!m_element)
+ return QString();
+ return m_element->namespaceURI();
+}
+
+/*!
+ Returns the parent element of this element or a null element if this element
+ is the root document element.
+*/
+QWebElement QWebElement::parent() const
+{
+ if (m_element)
+ return QWebElement(m_element->parentElement());
+ return QWebElement();
+}
+
+/*!
+ Returns the first child element of this element.
+
+ \sa lastChild() previousSibling() nextSibling()
+*/
+QWebElement QWebElement::firstChild() const
+{
+ if (!m_element)
+ return QWebElement();
+ for (Node* child = m_element->firstChild(); child; child = child->nextSibling()) {
+ if (!child->isElementNode())
+ continue;
+ Element* e = static_cast<Element*>(child);
+ return QWebElement(e);
+ }
+ return QWebElement();
+}
+
+/*!
+ Returns the last child element of this element.
+
+ \sa firstChild() previousSibling() nextSibling()
+*/
+QWebElement QWebElement::lastChild() const
+{
+ if (!m_element)
+ return QWebElement();
+ for (Node* child = m_element->lastChild(); child; child = child->previousSibling()) {
+ if (!child->isElementNode())
+ continue;
+ Element* e = static_cast<Element*>(child);
+ return QWebElement(e);
+ }
+ return QWebElement();
+}
+
+/*!
+ Returns the next sibling element of this element.
+
+ \sa firstChild() previousSibling() lastChild()
+*/
+QWebElement QWebElement::nextSibling() const
+{
+ if (!m_element)
+ return QWebElement();
+ for (Node* sib = m_element->nextSibling(); sib; sib = sib->nextSibling()) {
+ if (!sib->isElementNode())
+ continue;
+ Element* e = static_cast<Element*>(sib);
+ return QWebElement(e);
+ }
+ return QWebElement();
+}
+
+/*!
+ Returns the previous sibling element of this element.
+
+ \sa firstChild() nextSibling() lastChild()
+*/
+QWebElement QWebElement::previousSibling() const
+{
+ if (!m_element)
+ return QWebElement();
+ for (Node* sib = m_element->previousSibling(); sib; sib = sib->previousSibling()) {
+ if (!sib->isElementNode())
+ continue;
+ Element* e = static_cast<Element*>(sib);
+ return QWebElement(e);
+ }
+ return QWebElement();
+}
+
+/*!
+ Returns the document this element belongs to.
+*/
+QWebElement QWebElement::document() const
+{
+ if (!m_element)
+ return QWebElement();
+ Document* document = m_element->document();
+ if (!document)
+ return QWebElement();
+ return QWebElement(document->documentElement());
+}
+
+/*!
+ Returns the web frame this elements is a part of. If the element is
+ a null element null is returned.
+*/
+QWebFrame *QWebElement::webFrame() const
+{
+ if (!m_element)
+ return 0;
+
+ Document* document = m_element->document();
+ if (!document)
+ return 0;
+
+ Frame* frame = document->frame();
+ if (!frame)
+ return 0;
+ return QWebFramePrivate::kit(frame);
+}
+
+static bool setupScriptContext(WebCore::Element* element, JSC::JSValue& thisValue, ScriptState*& state, ScriptController*& scriptController)
+{
+ if (!element)
+ return false;
+
+ Document* document = element->document();
+ if (!document)
+ return false;
+
+ Frame* frame = document->frame();
+ if (!frame)
+ return false;
+
+ scriptController = frame->script();
+ if (!scriptController)
+ return false;
+
+ state = scriptController->globalObject()->globalExec();
+ if (!state)
+ return false;
+
+ thisValue = toJS(state, element);
+ if (!thisValue)
+ return false;
+
+ return true;
+}
+
+
+static bool setupScriptObject(WebCore::Element* element, ScriptObject& object, ScriptState*& state, ScriptController*& scriptController)
+{
+ if (!element)
+ return false;
+
+ Document* document = element->document();
+ if (!document)
+ return false;
+
+ Frame* frame = document->frame();
+ if (!frame)
+ return false;
+
+ scriptController = frame->script();
+
+ state = scriptController->globalObject()->globalExec();
+
+ JSC::JSValue thisValue = toJS(state, element);
+ if (!thisValue)
+ return false;
+
+ JSC::JSObject* thisObject = thisValue.toObject(state);
+ if (!thisObject)
+ return false;
+
+ object = ScriptObject(state, thisObject);
+ return true;
+}
+
+/*!
+ Executes the \a scriptSource with this element as the `this' object.
+
+ \sa callFunction()
+*/
+QVariant QWebElement::evaluateScript(const QString& scriptSource)
+{
+ if (scriptSource.isEmpty())
+ return QVariant();
+
+ ScriptState* state = 0;
+ JSC::JSValue thisValue;
+ ScriptController* scriptController = 0;
+
+ if (!setupScriptContext(m_element, thisValue, state, scriptController))
+ return QVariant();
+
+ JSC::ScopeChain& scopeChain = state->dynamicGlobalObject()->globalScopeChain();
+ JSC::UString script((const UChar*)scriptSource.data(), scriptSource.length());
+ JSC::Completion completion = JSC::evaluate(state, scopeChain, JSC::makeSource(script), thisValue);
+ if ((completion.complType() != JSC::ReturnValue) && (completion.complType() != JSC::Normal))
+ return QVariant();
+
+ JSC::JSValue result = completion.value();
+ if (!result)
+ return QVariant();
+
+ int distance = 0;
+ return JSC::Bindings::convertValueToQVariant(state, result, QMetaType::Void, &distance);
+}
+
+/*!
+ Calls the function with the given \a name and \a arguments.
+
+ The underlying DOM element that QWebElement wraps may have dedicated functions depending
+ on its type. For example a form element can have the "submit" function, that would submit
+ the form to the destination specified in the HTML.
+
+ \sa functions()
+*/
+QVariant QWebElement::callFunction(const QString &name, const QVariantList &arguments)
+{
+ ScriptState* state = 0;
+ ScriptObject thisObject;
+ ScriptController* scriptController = 0;
+
+ if (!setupScriptObject(m_element, thisObject, state, scriptController))
+ return QVariant();
+
+ ScriptFunctionCall functionCall(state, thisObject, name);
+
+ for (QVariantList::ConstIterator it = arguments.constBegin(), end = arguments.constEnd();
+ it != end; ++it)
+ functionCall.appendArgument(JSC::Bindings::convertQVariantToValue(state, scriptController->bindingRootObject(), *it));
+
+ bool hadException = false;
+ ScriptValue result = functionCall.call(hadException);
+ if (hadException)
+ return QVariant();
+
+ int distance = 0;
+ return JSC::Bindings::convertValueToQVariant(state, result.jsValue(), QMetaType::Void, &distance);
+}
+
+/*!
+ Returns a list of function names this element supports.
+
+ The function names returned are the same functions that are callable from the DOM
+ element's JavaScript binding.
+
+ \sa callFunction()
+*/
+QStringList QWebElement::functions() const
+{
+ ScriptState* state = 0;
+ ScriptObject thisObject;
+ ScriptController* scriptController = 0;
+
+ if (!setupScriptObject(m_element, thisObject, state, scriptController))
+ return QStringList();
+
+ JSC::JSObject* object = thisObject.jsObject();
+ if (!object)
+ return QStringList();
+
+ QStringList names;
+
+ // Enumerate the contents of the object
+ JSC::PropertyNameArray properties(state);
+ object->getPropertyNames(state, properties);
+ for (JSC::PropertyNameArray::const_iterator it = properties.begin();
+ it != properties.end(); ++it) {
+
+ JSC::JSValue property = object->get(state, *it);
+ if (!property)
+ continue;
+
+ JSC::JSObject* function = property.toObject(state);
+ if (!function)
+ continue;
+
+ JSC::CallData callData;
+ JSC::CallType callType = function->getCallData(callData);
+ if (callType == JSC::CallTypeNone)
+ continue;
+
+ JSC::UString ustring = (*it).ustring();
+ names << QString::fromUtf16((const ushort*)ustring.rep()->data(), ustring.size());
+ }
+
+ if (state->hadException())
+ state->clearException();
+
+ return names;
+}
+
+/*!
+ Returns the value of the element's \a name property.
+
+ If no such property exists, the returned variant is invalid.
+
+ The return property has the same value as the corresponding property
+ in the element's JavaScript binding with the same name.
+
+ Information about all available properties is provided through scriptProperties().
+
+ \sa setScriptableProperty(), scriptableProperties()
+*/
+QVariant QWebElement::scriptableProperty(const QString &name) const
+{
+ ScriptState* state = 0;
+ ScriptObject thisObject;
+ ScriptController *scriptController = 0;
+
+ if (!setupScriptObject(m_element, thisObject, state, scriptController))
+ return QVariant();
+
+ String wcName(name);
+ JSC::JSValue property = thisObject.jsObject()->get(state, JSC::Identifier(state, wcName));
+
+ // ###
+ if (state->hadException())
+ state->clearException();
+
+ int distance = 0;
+ return JSC::Bindings::convertValueToQVariant(state, property, QMetaType::Void, &distance);
+}
+
+/*!
+ Sets the value of the element's \a name property to \a value.
+
+ Information about all available properties is provided through scriptProperties().
+
+ Setting the property will affect the corresponding property
+ in the element's JavaScript binding with the same name.
+
+ \sa scriptableProperty(), scriptableProperties()
+*/
+void QWebElement::setScriptableProperty(const QString &name, const QVariant &value)
+{
+ ScriptState* state = 0;
+ ScriptObject thisObject;
+ ScriptController* scriptController = 0;
+
+ if (!setupScriptObject(m_element, thisObject, state, scriptController))
+ return;
+
+ JSC::JSValue jsValue = JSC::Bindings::convertQVariantToValue(state, scriptController->bindingRootObject(), value);
+ if (!jsValue)
+ return;
+
+ String wcName(name);
+ JSC::PutPropertySlot slot;
+ thisObject.jsObject()->put(state, JSC::Identifier(state, wcName), jsValue, slot);
+ if (state->hadException())
+ state->clearException();
+}
+
+/*!
+ Returns a list of property names this element supports.
+
+ The function names returned are the same properties that are accessible from the DOM
+ element's JavaScript binding.
+
+ \sa setScriptableProperty(), scriptableProperty()
+*/
+QStringList QWebElement::scriptableProperties() const
+{
+ if (!m_element)
+ return QStringList();
+
+ Document* document = m_element->document();
+ if (!document)
+ return QStringList();
+
+ Frame* frame = document->frame();
+ if (!frame)
+ return QStringList();
+
+ ScriptController* script = frame->script();
+ JSC::ExecState* exec = script->globalObject()->globalExec();
+
+ JSC::JSValue thisValue = toJS(exec, m_element);
+ if (!thisValue)
+ return QStringList();
+
+ JSC::JSObject* object = thisValue.toObject(exec);
+ if (!object)
+ return QStringList();
+
+ QStringList names;
+
+ // Enumerate the contents of the object
+ JSC::PropertyNameArray properties(exec);
+ object->getPropertyNames(exec, properties);
+ for (JSC::PropertyNameArray::const_iterator it = properties.begin();
+ it != properties.end(); ++it) {
+
+ JSC::JSValue property = object->get(exec, *it);
+ if (!property)
+ continue;
+
+ JSC::JSObject* function = property.toObject(exec);
+ if (!function)
+ continue;
+
+ JSC::CallData callData;
+ JSC::CallType callType = function->getCallData(callData);
+ if (callType != JSC::CallTypeNone)
+ continue;
+
+ JSC::UString ustring = (*it).ustring();
+ names << QString::fromUtf16((const ushort*)ustring.rep()->data(), ustring.size());
+ }
+
+ if (exec->hadException())
+ exec->clearException();
+
+ return names;
+}
+
+/*!
+ \enum QWebElement::ResolveRule
+ \since 4.6
+
+ This enum describes how QWebElement's styleProperty resolves the given
+ property name.
+
+ \value IgnoreCascadingStyles Return the property value as it is defined
+ in the element, without respecting style inheritance and other CSS rules.
+ \value RespectCascadingStyles The property's value is determined using
+ the inheritance and importance rules defined in the document's stylesheet.
+*/
+
+/*!
+ \enum QWebElement::StylePriority
+ \since 4.6
+
+ This enum describes the priority newly set CSS properties should have when
+ set using QWebElement::setStyleProperty().
+
+ \value NormalStylePriority Define the property without important
+ priority even if "!important" is explicitly set in \a value.
+ \value DeclaredStylePriority Define the property respecting the
+ priority specified in \a value.
+ \value ImportantStylePriority Define the property to have
+ an important priority, this is equal to appending "!important" to the value.
+*/
+
+/*!
+ Returns the value of the style named \a name or an empty string if such one
+ does not exist.
+
+ If \a rule is IgnoreCascadingStyles, the value defined inside the element
+ (inline in CSS terminology) is returned.
+
+ if \a rule is RespectCascadingStyles, the actual style applied to the
+ element is returned.
+
+ In CSS, the cascading part has to do with which CSS rule has priority and
+ is thus applied. Generally speaking, the last defined rule has priority,
+ thus an inline style rule has priority over an embedded block style rule,
+ which in return has priority over an external style rule.
+
+ If the !important declaration is set on one of those, the declaration gets
+ highest priority, unless other declarations also use the !important
+ declaration, in which the last !important declaration takes predecence.
+*/
+QString QWebElement::styleProperty(const QString &name, ResolveRule rule) const
+{
+ if (!m_element || !m_element->isStyledElement())
+ return QString();
+
+ int propID = cssPropertyID(name);
+
+ if (!propID)
+ return QString();
+
+ CSSStyleDeclaration* style = static_cast<StyledElement*>(m_element)->style();
+
+ if (rule == IgnoreCascadingStyles)
+ return style->getPropertyValue(propID);
+
+ if (rule == RespectCascadingStyles) {
+ if (style->getPropertyPriority(propID))
+ return style->getPropertyValue(propID);
+
+ // We are going to resolve the style property by walking through the
+ // list of non-inline matched CSS rules for the element, looking for
+ // the highest priority definition.
+
+ // Get an array of matched CSS rules for the given element sorted
+ // by importance and inheritance order. This include external CSS
+ // declarations, as well as embedded and inline style declarations.
+
+ DOMWindow* domWindow = m_element->document()->frame()->domWindow();
+ if (RefPtr<CSSRuleList> rules = domWindow->getMatchedCSSRules(m_element, "")) {
+ for (int i = rules->length(); i > 0; --i) {
+ CSSStyleRule* rule = static_cast<CSSStyleRule*>(rules->item(i - 1));
+
+ if (rule->style()->getPropertyPriority(propID))
+ return rule->style()->getPropertyValue(propID);
+
+ if (style->getPropertyValue(propID).isEmpty())
+ style = rule->style();
+ }
+ }
+
+ return style->getPropertyValue(propID);
+ }
+
+ return QString();
+}
+
+/*!
+ Sets the value of the style named \a name to \a value.
+
+ Setting a value, doesn't necessarily mean that it will become the applied
+ value, due to the fact that the style property's value might have been set
+ earlier with priority in external or embedded style declarations.
+
+ In order to ensure that the value will be applied, ImportantStylePriority
+ should be used as \a priority.
+
+ Following the CSS syntax for property values, this is equal to appending
+ "!important" to the value.
+
+ This syntax is supported when using DeclaredStylePriority as \a priority.
+
+ Using NormalStylePriority as \a priority, the property will have normal
+ priority, and any "!important" declaration will be ignored. On the other
+ hand, using ImportantStylePriority sets the important priority even when
+ not explicit passed in \a value.
+ By using DeclaredStylePriority as \a priority the property will respect the
+ priority specified in \a value.
+*/
+void QWebElement::setStyleProperty(const QString &name, const QString &value, StylePriority priority)
+{
+ if (!m_element || !m_element->isStyledElement())
+ return;
+
+ int propID = cssPropertyID(name);
+ CSSStyleDeclaration* style = static_cast<StyledElement*>(m_element)->style();
+ if (!propID || !style)
+ return;
+
+ ExceptionCode exception = 0;
+
+ const QRegExp hasImportantTest(QLatin1String("!\\s*important"));
+ int index = value.indexOf(hasImportantTest);
+
+ QString newValue = (index != -1) ? value.left(index - 1) : value;
+
+ switch (priority) {
+ case NormalStylePriority:
+ style->setProperty(name, newValue, "", exception);
+ break;
+ case DeclaredStylePriority:
+ style->setProperty(name, newValue, (index != -1) ? "important" : "", exception);
+ break;
+ case ImportantStylePriority:
+ style->setProperty(name, newValue, "important", exception);
+ break;
+ default:
+ break;
+ }
+}
+
+/*!
+ Returns the computed value for style named \a name or an empty string if the style has no such name.
+*/
+QString QWebElement::computedStyleProperty(const QString &name) const
+{
+ if (!m_element || !m_element->isStyledElement())
+ return QString();
+
+ int propID = cssPropertyID(name);
+
+ RefPtr<CSSComputedStyleDeclaration> style = computedStyle(m_element);
+ if (!propID || !style)
+ return QString();
+
+ return style->getPropertyValue(propID);
+}
+
+/*!
+ Returns the list of classes of this element.
+*/
+QStringList QWebElement::classes() const
+{
+ if (!hasAttribute(QLatin1String("class")))
+ return QStringList();
+
+ QStringList classes = attribute(QLatin1String("class")).simplified().split(QLatin1Char(' '), QString::SkipEmptyParts);
+#if QT_VERSION >= 0x040500
+ classes.removeDuplicates();
+#else
+ int n = classes.size();
+ int j = 0;
+ QSet<QString> seen;
+ seen.reserve(n);
+ for (int i = 0; i < n; ++i) {
+ const QString& s = classes.at(i);
+ if (seen.contains(s))
+ continue;
+ seen.insert(s);
+ if (j != i)
+ classes[j] = s;
+ ++j;
+ }
+ if (n != j)
+ classes.erase(classes.begin() + j, classes.end());
+#endif
+ return classes;
+}
+
+/*!
+ Returns true if this element has a class called \a name; otherwise returns false.
+*/
+bool QWebElement::hasClass(const QString &name) const
+{
+ QStringList list = classes();
+ return list.contains(name);
+}
+
+/*!
+ Adds the specified class \a name to the element.
+*/
+void QWebElement::addClass(const QString &name)
+{
+ QStringList list = classes();
+ if (!list.contains(name)) {
+ list.append(name);
+ QString value = list.join(QLatin1String(" "));
+ setAttribute(QLatin1String("class"), value);
+ }
+}
+
+/*!
+ Removes the specified class \a name from the element.
+*/
+void QWebElement::removeClass(const QString &name)
+{
+ QStringList list = classes();
+ if (list.contains(name)) {
+ list.removeAll(name);
+ QString value = list.join(QLatin1String(" "));
+ setAttribute(QLatin1String("class"), value);
+ }
+}
+
+/*!
+ Adds the specified class \a name if it is not present,
+ removes it if it is already present.
+*/
+void QWebElement::toggleClass(const QString &name)
+{
+ QStringList list = classes();
+ if (list.contains(name))
+ list.removeAll(name);
+ else
+ list.append(name);
+
+ QString value = list.join(QLatin1String(" "));
+ setAttribute(QLatin1String("class"), value);
+}
+
+/*!
+ Appends \a element as the element's last child.
+
+ If \a element is the child of another element, it is re-parented
+ to this element. If \a element is a child of this element, then
+ its position in the list of children is changed.
+
+ Calling this function on a null element does nothing.
+
+ \sa prependInside(), prependOutside(), appendOutside()
+*/
+void QWebElement::appendInside(const QWebElement &element)
+{
+ if (!m_element || element.isNull())
+ return;
+
+ ExceptionCode exception = 0;
+ m_element->appendChild(element.m_element, exception);
+}
+
+/*!
+ Appends the result of parsing \a markup as the element's last child.
+
+ Calling this function on a null element does nothing.
+
+ \sa prependInside(), prependOutside(), appendOutside()
+*/
+void QWebElement::appendInside(const QString &markup)
+{
+ if (!m_element)
+ return;
+
+ if (!m_element->isHTMLElement())
+ return;
+
+ HTMLElement* htmlElement = static_cast<HTMLElement*>(m_element);
+ RefPtr<DocumentFragment> fragment = htmlElement->createContextualFragment(markup);
+
+ ExceptionCode exception = 0;
+ m_element->appendChild(fragment, exception);
+}
+
+/*!
+ Prepends \a element as the element's first child.
+
+ If \a element is the child of another element, it is re-parented
+ to this element. If \a element is a child of this element, then
+ its position in the list of children is changed.
+
+ Calling this function on a null element does nothing.
+
+ \sa appendInside(), prependOutside(), appendOutside()
+*/
+void QWebElement::prependInside(const QWebElement &element)
+{
+ if (!m_element || element.isNull())
+ return;
+
+ ExceptionCode exception = 0;
+
+ if (m_element->hasChildNodes())
+ m_element->insertBefore(element.m_element, m_element->firstChild(), exception);
+ else
+ m_element->appendChild(element.m_element, exception);
+}
+
+/*!
+ Prepends the result of parsing \a markup as the element's first child.
+
+ Calling this function on a null element does nothing.
+
+ \sa appendInside(), prependOutside(), appendOutside()
+*/
+void QWebElement::prependInside(const QString &markup)
+{
+ if (!m_element)
+ return;
+
+ if (!m_element->isHTMLElement())
+ return;
+
+ HTMLElement* htmlElement = static_cast<HTMLElement*>(m_element);
+ RefPtr<DocumentFragment> fragment = htmlElement->createContextualFragment(markup);
+
+ ExceptionCode exception = 0;
+
+ if (m_element->hasChildNodes())
+ m_element->insertBefore(fragment, m_element->firstChild(), exception);
+ else
+ m_element->appendChild(fragment, exception);
+}
+
+
+/*!
+ Inserts \a element before this element.
+
+ If \a element is the child of another element, it is re-parented
+ to the parent of this element.
+
+ Calling this function on a null element does nothing.
+
+ \sa appendInside(), prependInside(), appendOutside()
+*/
+void QWebElement::prependOutside(const QWebElement &element)
+{
+ if (!m_element || element.isNull())
+ return;
+
+ if (!m_element->parent())
+ return;
+
+ ExceptionCode exception = 0;
+ m_element->parent()->insertBefore(element.m_element, m_element, exception);
+}
+
+/*!
+ Inserts the result of parsing \a markup before this element.
+
+ Calling this function on a null element does nothing.
+
+ \sa appendInside(), prependInside(), appendOutside()
+*/
+void QWebElement::prependOutside(const QString &markup)
+{
+ if (!m_element)
+ return;
+
+ if (!m_element->parent())
+ return;
+
+ if (!m_element->isHTMLElement())
+ return;
+
+ HTMLElement* htmlElement = static_cast<HTMLElement*>(m_element);
+ RefPtr<DocumentFragment> fragment = htmlElement->createContextualFragment(markup);
+
+ ExceptionCode exception = 0;
+ m_element->parent()->insertBefore(fragment, m_element, exception);
+}
+
+/*!
+ Inserts \a element after this element.
+
+ If \a element is the child of another element, it is re-parented
+ to the parent of this element.
+
+ Calling this function on a null element does nothing.
+
+ \sa appendInside(), prependInside(), prependOutside()
+*/
+void QWebElement::appendOutside(const QWebElement &element)
+{
+ if (!m_element || element.isNull())
+ return;
+
+ if (!m_element->parent())
+ return;
+
+ ExceptionCode exception = 0;
+ if (!m_element->nextSibling())
+ m_element->parent()->appendChild(element.m_element, exception);
+ else
+ m_element->parent()->insertBefore(element.m_element, m_element->nextSibling(), exception);
+}
+
+/*!
+ Inserts the result of parsing \a markup after this element.
+
+ Calling this function on a null element does nothing.
+
+ \sa appendInside(), prependInside(), prependOutside()
+*/
+void QWebElement::appendOutside(const QString &markup)
+{
+ if (!m_element)
+ return;
+
+ if (!m_element->parent())
+ return;
+
+ if (!m_element->isHTMLElement())
+ return;
+
+ HTMLElement* htmlElement = static_cast<HTMLElement*>(m_element);
+ RefPtr<DocumentFragment> fragment = htmlElement->createContextualFragment(markup);
+
+ ExceptionCode exception = 0;
+ if (!m_element->nextSibling())
+ m_element->parent()->appendChild(fragment, exception);
+ else
+ m_element->parent()->insertBefore(fragment, m_element->nextSibling(), exception);
+}
+
+/*!
+ Returns a clone of this element.
+
+ The clone may be inserted at any point in the document.
+
+ \sa appendInside(), prependInside(), prependOutside(), appendOutside()
+*/
+QWebElement QWebElement::clone() const
+{
+ if (!m_element)
+ return QWebElement();
+
+ return QWebElement(m_element->cloneElementWithChildren().get());
+}
+
+/*!
+ Removes this element from the document and returns a reference
+ to this.
+
+ The element is still valid after removal, and can be inserted into
+ other parts of the document.
+
+ \sa removeChildren(), removeFromDocument()
+*/
+QWebElement &QWebElement::takeFromDocument()
+{
+ if (!m_element)
+ return *this;
+
+ ExceptionCode exception = 0;
+ m_element->remove(exception);
+
+ return *this;
+}
+
+/*!
+ Removes this element from the document and makes this
+ a null element.
+
+ \sa removeChildren(), takeFromDocument()
+*/
+void QWebElement::removeFromDocument()
+{
+ if (!m_element)
+ return;
+
+ ExceptionCode exception = 0;
+ m_element->remove(exception);
+ m_element->deref();
+ m_element = 0;
+}
+
+/*!
+ Removes all children from this element.
+
+ \sa removeFromDocument(), takeFromDocument()
+*/
+void QWebElement::removeChildren()
+{
+ if (!m_element)
+ return;
+
+ m_element->removeAllChildren();
+}
+
+static RefPtr<Node> findInsertionPoint(PassRefPtr<Node> root)
+{
+ RefPtr<Node> node = root;
+
+ // Go as far down the tree as possible.
+ while (node->hasChildNodes() && node->firstChild()->isElementNode())
+ node = node->firstChild();
+
+ // TODO: Implement SVG support
+ if (node->isHTMLElement()) {
+ HTMLElement* element = static_cast<HTMLElement*>(node.get());
+
+ // The insert point could be a non-enclosable tag and it can thus
+ // never have children, so go one up. Get the parent element, and not
+ // note as a root note will always exist.
+ if (element->endTagRequirement() == TagStatusForbidden)
+ node = node->parentElement();
+ }
+
+ return node;
+}
+
+/*!
+ Enclose the contents of this element in \a element as the child
+ of the deepest descendant element within the structure of the
+ first element provided.
+
+ \sa encloseWith()
+*/
+void QWebElement::encloseContentsWith(const QWebElement &element)
+{
+ if (!m_element || element.isNull())
+ return;
+
+ RefPtr<Node> insertionPoint = findInsertionPoint(element.m_element);
+
+ if (!insertionPoint)
+ return;
+
+ ExceptionCode exception = 0;
+
+ // reparent children
+ for (RefPtr<Node> child = m_element->firstChild(); child;) {
+ RefPtr<Node> next = child->nextSibling();
+ insertionPoint->appendChild(child, exception);
+ child = next;
+ }
+
+ if (m_element->hasChildNodes())
+ m_element->insertBefore(element.m_element, m_element->firstChild(), exception);
+ else
+ m_element->appendChild(element.m_element, exception);
+}
+
+/*!
+ Enclose the contents of this element in the result of parsing
+ \a markup as the child of the deepest descendant element within
+ the structure of the first element provided.
+
+ \sa encloseWith()
+*/
+void QWebElement::encloseContentsWith(const QString &markup)
+{
+ if (!m_element)
+ return;
+
+ if (!m_element->parent())
+ return;
+
+ if (!m_element->isHTMLElement())
+ return;
+
+ HTMLElement* htmlElement = static_cast<HTMLElement*>(m_element);
+ RefPtr<DocumentFragment> fragment = htmlElement->createContextualFragment(markup);
+
+ if (!fragment || !fragment->firstChild())
+ return;
+
+ RefPtr<Node> insertionPoint = findInsertionPoint(fragment->firstChild());
+
+ if (!insertionPoint)
+ return;
+
+ ExceptionCode exception = 0;
+
+ // reparent children
+ for (RefPtr<Node> child = m_element->firstChild(); child;) {
+ RefPtr<Node> next = child->nextSibling();
+ insertionPoint->appendChild(child, exception);
+ child = next;
+ }
+
+ if (m_element->hasChildNodes())
+ m_element->insertBefore(fragment, m_element->firstChild(), exception);
+ else
+ m_element->appendChild(fragment, exception);
+}
+
+/*!
+ Enclose this element in \a element as the child of the deepest
+ descendant element within the structure of the first element
+ provided.
+
+ \sa replace()
+*/
+void QWebElement::encloseWith(const QWebElement &element)
+{
+ if (!m_element || element.isNull())
+ return;
+
+ RefPtr<Node> insertionPoint = findInsertionPoint(element.m_element);
+
+ if (!insertionPoint)
+ return;
+
+ // Keep reference to these two nodes before pulling out this element and
+ // wrapping it in the fragment. The reason for doing it in this order is
+ // that once the fragment has been added to the document it is empty, so
+ // we no longer have access to the nodes it contained.
+ Node* parentNode = m_element->parent();
+ Node* siblingNode = m_element->nextSibling();
+
+ ExceptionCode exception = 0;
+ insertionPoint->appendChild(m_element, exception);
+
+ if (!siblingNode)
+ parentNode->appendChild(element.m_element, exception);
+ else
+ parentNode->insertBefore(element.m_element, siblingNode, exception);
+}
+
+/*!
+ Enclose this element in the result of parsing \a markup,
+ as the last child.
+
+ \sa replace()
+*/
+void QWebElement::encloseWith(const QString &markup)
+{
+ if (!m_element)
+ return;
+
+ if (!m_element->parent())
+ return;
+
+ if (!m_element->isHTMLElement())
+ return;
+
+ HTMLElement* htmlElement = static_cast<HTMLElement*>(m_element);
+ RefPtr<DocumentFragment> fragment = htmlElement->createContextualFragment(markup);
+
+ if (!fragment || !fragment->firstChild())
+ return;
+
+ RefPtr<Node> insertionPoint = findInsertionPoint(fragment->firstChild());
+
+ if (!insertionPoint)
+ return;
+
+ // Keep reference to these two nodes before pulling out this element and
+ // wrapping it in the fragment. The reason for doing it in this order is
+ // that once the fragment has been added to the document it is empty, so
+ // we no longer have access to the nodes it contained.
+ Node* parentNode = m_element->parent();
+ Node* siblingNode = m_element->nextSibling();
+
+ ExceptionCode exception = 0;
+ insertionPoint->appendChild(m_element, exception);
+
+ if (!siblingNode)
+ parentNode->appendChild(fragment, exception);
+ else
+ parentNode->insertBefore(fragment, siblingNode, exception);
+}
+
+/*!
+ Replaces this element with \a element.
+
+ It is not possible to replace the <html>, <head>, or <body>
+ elements using this method.
+
+ \sa encloseWith()
+*/
+void QWebElement::replace(const QWebElement &element)
+{
+ if (!m_element || element.isNull())
+ return;
+
+ appendOutside(element);
+ takeFromDocument();
+}
+
+/*!
+ Replaces this element with the result of parsing \a markup.
+
+ It is not possible to replace the <html>, <head>, or <body>
+ elements using this method.
+
+ \sa encloseWith()
+*/
+void QWebElement::replace(const QString &markup)
+{
+ if (!m_element)
+ return;
+
+ appendOutside(markup);
+ takeFromDocument();
+}
+
+/*!
+ \fn inline bool QWebElement::operator==(const QWebElement& o) const;
+
+ Returns true if this element points to the same underlying DOM object than \a o; otherwise returns false.
+*/
+
+/*!
+ \fn inline bool QWebElement::operator!=(const QWebElement& o) const;
+
+ Returns true if this element points to a different underlying DOM object than \a o; otherwise returns false.
+*/
diff --git a/WebKit/qt/Api/qwebelement.h b/WebKit/qt/Api/qwebelement.h
new file mode 100644
index 0000000..bc6f8a9
--- /dev/null
+++ b/WebKit/qt/Api/qwebelement.h
@@ -0,0 +1,152 @@
+/*
+ Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies)
+
+ This library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Library General Public
+ License as published by the Free Software Foundation; either
+ version 2 of the License, or (at your option) any later version.
+
+ This library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Library General Public License for more details.
+
+ You should have received a copy of the GNU Library General Public License
+ along with this library; see the file COPYING.LIB. If not, write to
+ the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+ Boston, MA 02110-1301, USA.
+*/
+
+#ifndef QWEBELEMENT_H
+#define QWEBELEMENT_H
+
+#include <QString>
+#include <QRect>
+#include <QVariant>
+#include <QExplicitlySharedDataPointer>
+
+#include "qwebkitglobal.h"
+namespace WebCore {
+ class Element;
+ class Node;
+}
+
+class QWebFrame;
+class QWebElementPrivate;
+
+class QWEBKIT_EXPORT QWebElement {
+public:
+ QWebElement();
+ QWebElement(const QWebElement&);
+ QWebElement &operator=(const QWebElement&);
+ ~QWebElement();
+
+ bool operator==(const QWebElement& o) const;
+ bool operator!=(const QWebElement& o) const;
+
+ bool isNull() const;
+
+ QList<QWebElement> findAll(const QString& selectorQuery) const;
+ QWebElement findFirst(const QString& selectorQuery) const;
+
+ void setPlainText(const QString& text);
+ QString toPlainText() const;
+
+ void setOuterXml(const QString& markup);
+ QString toOuterXml() const;
+
+ void setInnerXml(const QString& markup);
+ QString toInnerXml() const;
+
+ void setAttribute(const QString& name, const QString& value);
+ void setAttributeNS(const QString& namespaceUri, const QString& name, const QString& value);
+ QString attribute(const QString& name, const QString& defaultValue = QString()) const;
+ QString attributeNS(const QString& namespaceUri, const QString& name, const QString& defaultValue = QString()) const;
+ bool hasAttribute(const QString& name) const;
+ bool hasAttributeNS(const QString& namespaceUri, const QString& name) const;
+ void removeAttribute(const QString& name);
+ void removeAttributeNS(const QString& namespaceUri, const QString& name);
+ bool hasAttributes() const;
+
+ QStringList classes() const;
+ bool hasClass(const QString& name) const;
+ void addClass(const QString& name);
+ void removeClass(const QString& name);
+ void toggleClass(const QString& name);
+
+ QRect geometry() const;
+
+ QString tagName() const;
+ QString prefix() const;
+ QString localName() const;
+ QString namespaceUri() const;
+
+ QWebElement parent() const;
+ QWebElement firstChild() const;
+ QWebElement lastChild() const;
+ QWebElement nextSibling() const;
+ QWebElement previousSibling() const;
+ QWebElement document() const;
+ QWebFrame *webFrame() const;
+
+ // TODO: Add QList<QWebElement> overloads
+ // docs need example snippet
+ void appendInside(const QString& markup);
+ void appendInside(const QWebElement& element);
+
+ // docs need example snippet
+ void prependInside(const QString& markup);
+ void prependInside(const QWebElement& element);
+
+ // docs need example snippet
+ void appendOutside(const QString& markup);
+ void appendOutside(const QWebElement& element);
+
+ // docs need example snippet
+ void prependOutside(const QString& markup);
+ void prependOutside(const QWebElement& element);
+
+ // docs need example snippet
+ void encloseContentsWith(const QWebElement& element);
+ void encloseContentsWith(const QString& markup);
+ void encloseWith(const QString& markup);
+ void encloseWith(const QWebElement& element);
+
+ void replace(const QString& markup);
+ void replace(const QWebElement& element);
+
+ QWebElement clone() const;
+ QWebElement& takeFromDocument();
+ void removeFromDocument();
+ void removeChildren();
+
+ QVariant evaluateScript(const QString& scriptSource);
+
+ QVariant callFunction(const QString& functionName, const QVariantList& arguments = QVariantList());
+ QStringList functions() const;
+
+ QVariant scriptableProperty(const QString& name) const;
+ void setScriptableProperty(const QString& name, const QVariant& value);
+ QStringList scriptableProperties() const;
+
+ enum ResolveRule { IgnoreCascadingStyles, RespectCascadingStyles };
+ QString styleProperty(const QString& name, ResolveRule = IgnoreCascadingStyles) const;
+
+ enum StylePriority { NormalStylePriority, DeclaredStylePriority, ImportantStylePriority };
+ void setStyleProperty(const QString& name, const QString& value, StylePriority = DeclaredStylePriority);
+
+ QString computedStyleProperty(const QString& name) const;
+
+private:
+ explicit QWebElement(WebCore::Element*);
+ explicit QWebElement(WebCore::Node*);
+
+ friend class QWebFrame;
+ friend class QWebHitTestResult;
+ friend class QWebHitTestResultPrivate;
+
+ QWebElementPrivate* d;
+ WebCore::Element* m_element;
+};
+
+#endif // QWEBELEMENT_H
diff --git a/WebKit/qt/Api/qwebframe.cpp b/WebKit/qt/Api/qwebframe.cpp
index 725a880..c857df2 100644
--- a/WebKit/qt/Api/qwebframe.cpp
+++ b/WebKit/qt/Api/qwebframe.cpp
@@ -20,72 +20,71 @@
#include "config.h"
#include "qwebframe.h"
-#include "qwebpage.h"
-#include "qwebpage_p.h"
-#include "qwebframe_p.h"
-#include "qwebsecurityorigin.h"
-#include "qwebsecurityorigin_p.h"
+#include "CallFrame.h"
+#include "Document.h"
#include "DocumentLoader.h"
+#include "DragData.h"
+#include "Element.h"
#include "FocusController.h"
-#include "FrameLoaderClientQt.h"
#include "Frame.h"
+#include "FrameLoaderClientQt.h"
#include "FrameTree.h"
#include "FrameView.h"
+#include "GCController.h"
+#include "GraphicsContext.h"
+#include "HTMLMetaElement.h"
+#include "HitTestResult.h"
#include "IconDatabase.h"
#include "InspectorController.h"
+#include "JSDOMBinding.h"
+#include "JSDOMWindowBase.h"
+#include "JSLock.h"
+#include "JSObject.h"
+#include "NodeList.h"
#include "Page.h"
+#include "PlatformMouseEvent.h"
+#include "PlatformWheelEvent.h"
+#include "PrintContext.h"
#include "PutPropertySlot.h"
-#include "ResourceRequest.h"
+#include "RenderTreeAsText.h"
#include "RenderView.h"
-#include "SelectionController.h"
+#include "ResourceRequest.h"
+#include "ScriptController.h"
+#include "ScriptSourceCode.h"
+#include "ScriptValue.h"
#include "Scrollbar.h"
-#include "PrintContext.h"
+#include "SelectionController.h"
#include "SubstituteData.h"
-
-#include "markup.h"
#include "htmlediting.h"
-#include "RenderTreeAsText.h"
-#include "Element.h"
-#include "Document.h"
-#include "DragData.h"
-#include "RenderView.h"
-#include "GraphicsContext.h"
-#include "PlatformMouseEvent.h"
-#include "PlatformWheelEvent.h"
-#include "GraphicsContext.h"
-#include "HitTestResult.h"
-
-#include "CallFrame.h"
-#include "JSDOMBinding.h"
-#include "JSDOMWindow.h"
-#include "JSLock.h"
-#include "JSObject.h"
+#include "markup.h"
#include "qt_instance.h"
#include "qt_runtime.h"
+#include "qwebelement.h"
+#include "qwebframe_p.h"
+#include "qwebpage.h"
+#include "qwebpage_p.h"
+#include "qwebsecurityorigin.h"
+#include "qwebsecurityorigin_p.h"
#include "runtime.h"
#include "runtime_object.h"
#include "runtime_root.h"
-#include "ScriptController.h"
-#include "ScriptSourceCode.h"
-#include "ScriptValue.h"
-
#include "wtf/HashMap.h"
-
+#include <QMultiMap>
#include <qdebug.h>
#include <qevent.h>
#include <qfileinfo.h>
#include <qpainter.h>
-#include <QMultiMap>
+#include <qprinter.h>
+#include <qregion.h>
+
+#if QT_VERSION < 0x040400
+#include "qwebnetworkinterface.h"
+#endif
+
#if QT_VERSION >= 0x040400
#include <qnetworkrequest.h>
-#else
-#include "qwebnetworkinterface.h"
#endif
-#include <qregion.h>
-#include <qprinter.h>
-#include "HTMLMetaElement.h"
-#include "NodeList.h"
using namespace WebCore;
@@ -96,6 +95,7 @@ QT_END_NAMESPACE
void QWEBKIT_EXPORT qt_drt_setJavaScriptProfilingEnabled(QWebFrame* qframe, bool enabled)
{
+#if ENABLE(JAVASCRIPT_DEBUGGER)
Frame* frame = QWebFramePrivate::core(qframe);
InspectorController* controller = frame->page()->inspectorController();
if (!controller)
@@ -104,6 +104,7 @@ void QWEBKIT_EXPORT qt_drt_setJavaScriptProfilingEnabled(QWebFrame* qframe, bool
controller->enableProfiler();
else
controller->disableProfiler();
+#endif
}
// Pause a given CSS animation or transition on the target node at a specific time.
@@ -163,27 +164,56 @@ int QWEBKIT_EXPORT qt_drt_numberOfActiveAnimations(QWebFrame *qframe)
return controller->numberOfActiveAnimations();
}
-void QWebFramePrivate::init(QWebFrame *qframe, WebCore::Page *webcorePage, QWebFrameData *frameData)
+void QWEBKIT_EXPORT qt_drt_clearFrameName(QWebFrame* qFrame)
{
- q = qframe;
+ Frame* frame = QWebFramePrivate::core(qFrame);
+ frame->tree()->clearName();
+}
- allowsScrolling = frameData->allowsScrolling;
- marginWidth = frameData->marginWidth;
- marginHeight = frameData->marginHeight;
+int QWEBKIT_EXPORT qt_drt_javaScriptObjectsCount()
+{
+ return JSDOMWindowBase::commonJSGlobalData()->heap.globalObjectCount();
+}
+void QWEBKIT_EXPORT qt_drt_garbageCollector_collect()
+{
+ gcController().garbageCollectNow();
+}
+
+void QWEBKIT_EXPORT qt_drt_garbageCollector_collectOnAlternateThread(bool waitUntilDone)
+{
+ gcController().garbageCollectOnAlternateThreadForDebugging(waitUntilDone);
+}
+
+QWebFrameData::QWebFrameData(WebCore::Page* parentPage, WebCore::Frame* parentFrame,
+ WebCore::HTMLFrameOwnerElement* ownerFrameElement,
+ const WebCore::String& frameName)
+ : name(frameName)
+ , ownerElement(ownerFrameElement)
+ , page(parentPage)
+ , allowsScrolling(true)
+ , marginWidth(0)
+ , marginHeight(0)
+{
frameLoaderClient = new FrameLoaderClientQt();
- RefPtr<Frame> newFrame = Frame::create(webcorePage, frameData->ownerElement, frameLoaderClient);
- frame = newFrame.get();
- frameLoaderClient->setFrame(qframe, frame);
+ frame = Frame::create(page, ownerElement, frameLoaderClient);
// FIXME: All of the below should probably be moved over into WebCore
- frame->tree()->setName(frameData->name);
- if (QWebFrame* _parentFrame = parentFrame())
- QWebFramePrivate::core(_parentFrame)->tree()->appendChild(frame);
+ frame->tree()->setName(name);
+ if (parentFrame)
+ parentFrame->tree()->appendChild(frame);
+}
+
+void QWebFramePrivate::init(QWebFrame *qframe, QWebFrameData *frameData)
+{
+ q = qframe;
- // balanced by adoptRef in FrameLoaderClientQt::createFrame
- if (frameData->ownerElement)
- frame->ref();
+ allowsScrolling = frameData->allowsScrolling;
+ marginWidth = frameData->marginWidth;
+ marginHeight = frameData->marginHeight;
+ frame = frameData->frame.get();
+ frameLoaderClient = frameData->frameLoaderClient;
+ frameLoaderClient->setFrame(qframe, frame);
frame->init();
}
@@ -202,7 +232,7 @@ WebCore::Scrollbar* QWebFramePrivate::verticalScrollBar() const
return frame->view()->verticalScrollbar();
}
-void QWebFramePrivate::renderPrivate(QPainter *painter, const QRegion &clip, bool contents)
+void QWebFramePrivate::renderPrivate(QPainter *painter, const QRegion &clip)
{
if (!frame->view() || !frame->contentRenderer())
return;
@@ -216,7 +246,7 @@ void QWebFramePrivate::renderPrivate(QPainter *painter, const QRegion &clip, boo
GraphicsContext context(painter);
- if (!contents)
+ if (clipRenderToViewport)
view->paint(&context, vector.first());
else
view->paintContents(&context, vector.first());
@@ -225,7 +255,7 @@ void QWebFramePrivate::renderPrivate(QPainter *painter, const QRegion &clip, boo
const QRect& clipRect = vector.at(i);
painter->save();
painter->setClipRect(clipRect, Qt::IntersectClip);
- if (!contents)
+ if (clipRenderToViewport)
view->paint(&context, clipRect);
else
view->paintContents(&context, clipRect);
@@ -250,6 +280,13 @@ void QWebFramePrivate::renderPrivate(QPainter *painter, const QRegion &clip, boo
\l{Elements of QWebView} for an explanation of how web
frames are related to a web page and web view.
+ The QWebFrame class also offers methods to retrieve both the URL currently
+ loaded by the frame (see url()) as well as the URL originally requested
+ to be loaded (see requestedUrl()). These methods make possible the retrieval
+ of the URL before and after a DNS resolution or a redirection occurs during
+ the load process. The requestedUrl() also matches to the URL added to the
+ frame history (\l{QWebHistory}) if load is successful.
+
The title of an HTML frame can be accessed with the title() property.
Additionally, a frame may also specify an icon, which can be accessed
using the icon() property. If the title or the icon changes, the
@@ -277,7 +314,7 @@ QWebFrame::QWebFrame(QWebPage *parent, QWebFrameData *frameData)
, d(new QWebFramePrivate)
{
d->page = parent;
- d->init(this, parent->d->page, frameData);
+ d->init(this, frameData);
if (!frameData->url.isEmpty()) {
WebCore::ResourceRequest request(frameData->url, frameData->referrer);
@@ -290,7 +327,7 @@ QWebFrame::QWebFrame(QWebFrame *parent, QWebFrameData *frameData)
, d(new QWebFramePrivate)
{
d->page = parent->d->page;
- d->init(this, parent->d->page->d->page, frameData);
+ d->init(this, frameData);
}
QWebFrame::~QWebFrame()
@@ -313,6 +350,8 @@ QWebFrame::~QWebFrame()
new URL, you should add them in a slot connected to the
javaScriptWindowObjectCleared() signal.
+ If Javascript is not enabled for this page, then this method does nothing.
+
The \a object will never be explicitly deleted by QtWebKit.
*/
void QWebFrame::addToJavaScriptWindowObject(const QString &name, QObject *object)
@@ -335,11 +374,16 @@ void QWebFrame::addToJavaScriptWindowObject(const QString &name, QObject *object
new URL, you should add them in a slot connected to the
javaScriptWindowObjectCleared() signal.
+ If Javascript is not enabled for this page, then this method does nothing.
+
The ownership of \a object is specified using \a own.
*/
void QWebFrame::addToJavaScriptWindowObject(const QString &name, QObject *object, QScriptEngine::ValueOwnership ownership)
{
- JSC::JSLock lock(false);
+ if (!page()->settings()->testAttribute(QWebSettings::JavascriptEnabled))
+ return;
+
+ JSC::JSLock lock(JSC::SilenceAssertionsOnly);
JSDOMWindow* window = toJSDOMWindow(d->frame);
JSC::Bindings::RootObject* root = d->frame->script()->bindingRootObject();
if (!window) {
@@ -357,7 +401,7 @@ void QWebFrame::addToJavaScriptWindowObject(const QString &name, QObject *object
}
/*!
- Returns the frame's content, converted to HTML.
+ Returns the frame's content as HTML, enclosed in HTML and BODY tags.
\sa setHtml(), toPlainText()
*/
@@ -369,7 +413,8 @@ QString QWebFrame::toHtml() const
}
/*!
- Returns the content of this frame converted to plain text.
+ Returns the content of this frame converted to plain text, completely
+ stripped of all HTML formatting.
\sa toHtml()
*/
@@ -405,7 +450,7 @@ QString QWebFrame::title() const
{
if (d->frame->document())
return d->frame->loader()->documentLoader()->title();
- else return QString();
+ return QString();
}
/*!
@@ -441,10 +486,10 @@ QString QWebFrame::title() const
*/
QMultiMap<QString, QString> QWebFrame::metaData() const
{
- if(!d->frame->document())
- return QMap<QString,QString>();
+ if (!d->frame->document())
+ return QMap<QString, QString>();
- QMultiMap<QString,QString> map;
+ QMultiMap<QString, QString> map;
Document* doc = d->frame->document();
RefPtr<NodeList> list = doc->getElementsByTagName("meta");
unsigned len = list->length();
@@ -483,6 +528,39 @@ QUrl QWebFrame::url() const
}
/*!
+ \since 4.6
+ \property QWebFrame::requestedUrl
+
+ The URL requested to loaded by the frame currently viewed. The URL may differ from
+ the one returned by url() if a DNS resolution or a redirection occurs.
+
+ \sa url(), setUrl()
+*/
+QUrl QWebFrame::requestedUrl() const
+{
+ // In the following edge cases (where the failing document
+ // loader does not get commited by the frame loader) it is
+ // safer to rely on outgoingReferrer than originalRequest.
+ if (!d->frame->loader()->activeDocumentLoader()
+ || (!d->frameLoaderClient->m_loadSucceeded
+ && !d->frame->loader()->outgoingReferrer().isEmpty()))
+ return QUrl(d->frame->loader()->outgoingReferrer());
+
+ return d->frame->loader()->originalRequest().url();
+}
+/*!
+ \since 4.6
+ \property QWebFrame::baseUrl
+ \brief the base URL of the frame, can be used to resolve relative URLs
+ \since 4.6
+*/
+
+QUrl QWebFrame::baseUrl() const
+{
+ return d->frame->loader()->baseURL();
+}
+
+/*!
\property QWebFrame::icon
\brief the icon associated with this frame
@@ -623,6 +701,8 @@ void QWebFrame::load(const QNetworkRequest &req,
Sets the content of this frame to \a html. \a baseUrl is optional and used to resolve relative
URLs in the document, such as referenced images or stylesheets.
+ The \a html is loaded immediately; external objects are loaded asynchronously.
+
When using this method WebKit assumes that external resources such as JavaScript programs or style
sheets are encoded in UTF-8 unless otherwise specified. For example, the encoding of an external
script can be specified through the charset attribute of the HTML script tag. It is also possible
@@ -647,6 +727,8 @@ void QWebFrame::setHtml(const QString &html, const QUrl &baseUrl)
External objects referenced in the content are located relative to \a baseUrl.
+ The \a data is loaded immediately; external objects are loaded asynchronously.
+
\sa toHtml()
*/
void QWebFrame::setContent(const QByteArray &data, const QString &mimeType, const QUrl &baseUrl)
@@ -762,9 +844,8 @@ int QWebFrame::scrollBarValue(Qt::Orientation orientation) const
{
Scrollbar *sb;
sb = (orientation == Qt::Horizontal) ? d->horizontalScrollBar() : d->verticalScrollBar();
- if (sb) {
+ if (sb)
return sb->value();
- }
return 0;
}
@@ -814,7 +895,7 @@ QRect QWebFrame::scrollBarGeometry(Qt::Orientation orientation) const
\since 4.5
Scrolls the frame \a dx pixels to the right and \a dy pixels downward. Both
\a dx and \a dy may be negative.
-
+
\sa QWebFrame::scrollPosition
*/
@@ -822,7 +903,7 @@ void QWebFrame::scroll(int dx, int dy)
{
if (!d->frame->view())
return;
-
+
d->frame->view()->scrollBy(IntSize(dx, dy));
}
@@ -835,7 +916,7 @@ void QWebFrame::scroll(int dx, int dy)
QPoint QWebFrame::scrollPosition() const
{
if (!d->frame->view())
- return QPoint(0,0);
+ return QPoint(0, 0);
IntSize ofs = d->frame->view()->scrollOffset();
return QPoint(ofs.width(), ofs.height());
@@ -871,12 +952,23 @@ void QWebFrame::render(QPainter *painter)
}
/*!
- \since 4.6
- Render the frame's \a contents into \a painter while clipping to \a contents.
+ \since 4.6
+ \property QWebFrame::clipRenderToViewport
+
+ Returns true if render will clip content to viewport; otherwise returns false.
+*/
+bool QWebFrame::clipRenderToViewport() const
+{
+ return d->clipRenderToViewport;
+}
+
+/*!
+ \since 4.6
+ Sets whether the content of a frame will be clipped to viewport when rendered.
*/
-void QWebFrame::renderContents(QPainter *painter, const QRegion &contents)
+void QWebFrame::setClipRenderToViewport(bool clipRenderToViewport)
{
- d->renderPrivate(painter, contents, true);
+ d->clipRenderToViewport = clipRenderToViewport;
}
/*!
@@ -925,6 +1017,27 @@ qreal QWebFrame::zoomFactor() const
}
/*!
+ \property QWebFrame::focus
+ \since 4.6
+
+ Returns true if this frame has keyboard input focus; otherwise, returns false.
+*/
+bool QWebFrame::hasFocus() const
+{
+ return QWebFramePrivate::kit(d->frame->page()->focusController()->focusedFrame()) == this;
+}
+
+/*!
+ \since 4.6
+
+ Gives keyboard input focus to this frame.
+*/
+void QWebFrame::setFocus()
+{
+ QWebFramePrivate::core(this)->page()->focusController()->setFocusedFrame(QWebFramePrivate::core(this));
+}
+
+/*!
Returns the position of the frame relative to it's parent frame.
*/
QPoint QWebFrame::pos() const
@@ -949,7 +1062,7 @@ QRect QWebFrame::geometry() const
\property QWebFrame::contentsSize
\brief the size of the contents in this frame
- \sa contentsSizeChanged
+ \sa contentsSizeChanged()
*/
QSize QWebFrame::contentsSize() const
{
@@ -960,6 +1073,53 @@ QSize QWebFrame::contentsSize() const
}
/*!
+ \since 4.6
+
+ Returns the document element of this frame.
+
+ The document element provides access to the entire structured
+ content of the frame.
+*/
+QWebElement QWebFrame::documentElement() const
+{
+ WebCore::Document *doc = d->frame->document();
+ if (!doc)
+ return QWebElement();
+ return QWebElement(doc->documentElement());
+}
+
+/*!
+ \since 4.6
+ Returns a new list of elements matching the given CSS selector \a selectorQuery.
+ If there are no matching elements, an empty list is returned.
+
+ \l{http://www.w3.org/TR/REC-CSS2/selector.html#q1}{Standard CSS2 selector} syntax is
+ used for the query.
+
+ \sa QWebElement::findAll()
+*/
+QList<QWebElement> QWebFrame::findAllElements(const QString &selectorQuery) const
+{
+ return documentElement().findAll(selectorQuery);
+}
+
+/*!
+ \since 4.6
+ Returns the first element in the frame's document that matches the
+ given CSS selector \a selectorQuery. If there is no matching element, a
+ null element is returned.
+
+ \l{http://www.w3.org/TR/REC-CSS2/selector.html#q1}{Standard CSS2 selector} syntax is
+ used for the query.
+
+ \sa QWebElement::findFirst()
+*/
+QWebElement QWebFrame::findFirstElement(const QString &selectorQuery) const
+{
+ return documentElement().findFirst(selectorQuery);
+}
+
+/*!
Performs a hit test on the frame contents at the given position \a pos and returns the hit test result.
*/
QWebHitTestResult QWebFrame::hitTestContent(const QPoint &pos) const
@@ -968,6 +1128,10 @@ QWebHitTestResult QWebFrame::hitTestContent(const QPoint &pos) const
return QWebHitTestResult();
HitTestResult result = d->frame->eventHandler()->hitTestResultAtPoint(d->frame->view()->windowToContents(pos), /*allowShadowContent*/ false, /*ignoreClipping*/ true);
+
+ if (result.scrollbar())
+ return QWebHitTestResult();
+
return QWebHitTestResult(new QWebHitTestResultPrivate(result));
}
@@ -1004,11 +1168,11 @@ void QWebFrame::print(QPrinter *printer) const
printContext.begin(pageRect.width());
- printContext.computePageRects(pageRect, /*headerHeight*/0, /*footerHeight*/0, /*userScaleFactor*/1.0, pageHeight);
+ printContext.computePageRects(pageRect, /* headerHeight */ 0, /* footerHeight */ 0, /* userScaleFactor */ 1.0, pageHeight);
int docCopies;
int pageCopies;
- if (printer->collateCopies() == true){
+ if (printer->collateCopies()) {
docCopies = 1;
pageCopies = printer->numCopies();
} else {
@@ -1082,11 +1246,9 @@ QVariant QWebFrame::evaluateJavaScript(const QString& scriptSource)
ScriptController *proxy = d->frame->script();
QVariant rc;
if (proxy) {
- JSC::JSValuePtr v = proxy->evaluate(ScriptSourceCode(scriptSource)).jsValue();
- if (v) {
- int distance = 0;
- rc = JSC::Bindings::convertValueToQVariant(proxy->globalObject()->globalExec(), v, QMetaType::Void, &distance);
- }
+ JSC::JSValue v = proxy->evaluate(ScriptSourceCode(scriptSource)).jsValue();
+ int distance = 0;
+ rc = JSC::Bindings::convertValueToQVariant(proxy->globalObject()->globalExec(), v, QMetaType::Void, &distance);
}
return rc;
}
@@ -1171,12 +1333,32 @@ QWebFrame* QWebFramePrivate::kit(WebCore::Frame* coreFrame)
\fn void QWebFrame::contentsSizeChanged(const QSize &size)
\since 4.6
- This signal is emitted when the frame's contents size changes.
+ This signal is emitted when the frame's contents size changes
+ to \a size.
\sa contentsSize()
*/
/*!
+ \fn void QWebFrame::loadStarted()
+ \since 4.6
+
+ This signal is emitted when a new load of this frame is started.
+
+ \sa loadFinished()
+*/
+
+/*!
+ \fn void QWebFrame::loadFinished(bool ok)
+ \since 4.6
+
+ This signal is emitted when a load of this frame is finished.
+ \a ok will indicate whether the load was successful or any error occurred.
+
+ \sa loadStarted()
+*/
+
+/*!
\class QWebHitTestResult
\since 4.4
\brief The QWebHitTestResult class provides information about the web
@@ -1203,7 +1385,8 @@ QWebHitTestResultPrivate::QWebHitTestResultPrivate(const WebCore::HitTestResult
return;
pos = hitTest.point();
boundingRect = hitTest.boundingBox();
- title = hitTest.title();
+ WebCore::TextDirection dir;
+ title = hitTest.title(dir);
linkText = hitTest.textContent();
linkUrl = hitTest.absoluteLinkURL();
linkTitle = hitTest.titleDisplayString();
@@ -1220,9 +1403,7 @@ QWebHitTestResultPrivate::QWebHitTestResultPrivate(const WebCore::HitTestResult
WebCore::Frame *wframe = hitTest.targetFrame();
if (wframe)
linkTargetFrame = QWebFramePrivate::kit(wframe);
- Element* urlElement = hitTest.URLElement();
- if (urlElement)
- linkTarget = urlElement->target();
+ linkElement = QWebElement(hitTest.URLElement());
isContentEditable = hitTest.isContentEditable();
isContentSelected = hitTest.isSelected();
@@ -1232,14 +1413,7 @@ QWebHitTestResultPrivate::QWebHitTestResultPrivate(const WebCore::HitTestResult
&& innerNonSharedNode->document()->frame())
frame = QWebFramePrivate::kit(innerNonSharedNode->document()->frame());
- if (Node *block = WebCore::enclosingBlock(innerNode.get())) {
- RenderObject *renderBlock = block->renderer();
- while (renderBlock && renderBlock->isListItem())
- renderBlock = renderBlock->containingBlock();
-
- if (renderBlock)
- enclosingBlock = renderBlock->absoluteClippedOverflowRect();
- }
+ enclosingBlock = QWebElement(WebCore::enclosingBlock(innerNode.get()));
}
/*!
@@ -1317,12 +1491,16 @@ QRect QWebHitTestResult::boundingRect() const
/*!
\since 4.6
- Returns the rect of the smallest enclosing block element.
+ Returns the block element that encloses the element hit.
+
+ A block element is an element that is rendered using the
+ CSS "block" style. This includes for example text
+ paragraphs.
*/
-QRect QWebHitTestResult::enclosingBlock() const
+QWebElement QWebHitTestResult::enclosingBlockElement() const
{
if (!d)
- return QRect();
+ return QWebElement();
return d->enclosingBlock;
}
@@ -1368,21 +1546,21 @@ QUrl QWebHitTestResult::linkTitle() const
/*!
\since 4.6
- Returns the name of the target frame that will load the link if it is activated.
+ Returns the element that represents the link.
- \sa linkTargetFrame
+ \sa linkTargetFrame()
*/
-QString QWebHitTestResult::linkTarget() const
+QWebElement QWebHitTestResult::linkElement() const
{
if (!d)
- return 0;
- return d->linkTarget;
+ return QWebElement();
+ return d->linkElement;
}
/*!
Returns the frame that will load the link if it is activated.
- \sa linkTarget
+ \sa linkElement()
*/
QWebFrame *QWebHitTestResult::linkTargetFrame() const
{
@@ -1443,22 +1621,24 @@ bool QWebHitTestResult::isContentSelected() const
}
/*!
- Returns the frame the hit test was executed in.
+ \since 4.6
+ Returns the underlying DOM element as QWebElement.
*/
-QWebFrame *QWebHitTestResult::frame() const
+QWebElement QWebHitTestResult::element() const
{
- if (!d)
- return 0;
- return d->frame;
+ if (!d || !d->innerNonSharedNode || !d->innerNonSharedNode->isElementNode())
+ return QWebElement();
+
+ return QWebElement(static_cast<WebCore::Element*>(d->innerNonSharedNode.get()));
}
/*!
- \since 4.6
- Returns true if the test includes a scrollbar.
+ Returns the frame the hit test was executed in.
*/
-bool QWebHitTestResult::isScrollBar() const
+QWebFrame *QWebHitTestResult::frame() const
{
if (!d)
- return false;
- return d->isScrollBar;
+ return 0;
+ return d->frame;
}
+
diff --git a/WebKit/qt/Api/qwebframe.h b/WebKit/qt/Api/qwebframe.h
index d0fa193..55c73b4 100644
--- a/WebKit/qt/Api/qwebframe.h
+++ b/WebKit/qt/Api/qwebframe.h
@@ -1,5 +1,5 @@
/*
- Copyright (C) 2008 Nokia Corporation and/or its subsidiary(-ies)
+ Copyright (C) 2008,2009 Nokia Corporation and/or its subsidiary(-ies)
Copyright (C) 2007 Staikos Computing Services Inc.
This library is free software; you can redistribute it and/or
@@ -49,6 +49,7 @@ class QWebPage;
class QWebHitTestResult;
class QWebHistoryItem;
class QWebSecurityOrigin;
+class QWebElement;
namespace WebCore {
class WidgetPrivate;
@@ -59,8 +60,7 @@ class QWebFrameData;
class QWebHitTestResultPrivate;
class QWebFrame;
-class QWEBKIT_EXPORT QWebHitTestResult
-{
+class QWEBKIT_EXPORT QWebHitTestResult {
public:
QWebHitTestResult();
QWebHitTestResult(const QWebHitTestResult &other);
@@ -71,14 +71,14 @@ public:
QPoint pos() const;
QRect boundingRect() const;
- QRect enclosingBlock() const;
+ QWebElement enclosingBlockElement() const;
QString title() const;
QString linkText() const;
QUrl linkUrl() const;
QUrl linkTitle() const;
QWebFrame *linkTargetFrame() const;
- QString linkTarget() const;
+ QWebElement linkElement() const;
QString alternateText() const; // for img, area, input and applet
@@ -88,9 +88,9 @@ public:
bool isContentEditable() const;
bool isContentSelected() const;
- QWebFrame *frame() const;
+ QWebElement element() const;
- bool isScrollBar() const;
+ QWebFrame *frame() const;
private:
QWebHitTestResult(QWebHitTestResultPrivate *priv);
@@ -101,16 +101,19 @@ private:
friend class QWebPage;
};
-class QWEBKIT_EXPORT QWebFrame : public QObject
-{
+class QWEBKIT_EXPORT QWebFrame : public QObject {
Q_OBJECT
Q_PROPERTY(qreal textSizeMultiplier READ textSizeMultiplier WRITE setTextSizeMultiplier DESIGNABLE false)
Q_PROPERTY(qreal zoomFactor READ zoomFactor WRITE setZoomFactor)
Q_PROPERTY(QString title READ title)
Q_PROPERTY(QUrl url READ url WRITE setUrl)
+ Q_PROPERTY(QUrl requestedUrl READ requestedUrl)
+ Q_PROPERTY(QUrl baseUrl READ baseUrl)
Q_PROPERTY(QIcon icon READ icon)
Q_PROPERTY(QSize contentsSize READ contentsSize)
Q_PROPERTY(QPoint scrollPosition READ scrollPosition WRITE setScrollPosition)
+ Q_PROPERTY(bool clipRenderToViewport READ clipRenderToViewport WRITE setClipRenderToViewport)
+ Q_PROPERTY(bool focus READ hasFocus)
private:
QWebFrame(QWebPage *parent, QWebFrameData *frameData);
QWebFrame(QWebFrame *parent, QWebFrameData *frameData);
@@ -139,6 +142,8 @@ public:
QString title() const;
void setUrl(const QUrl &url);
QUrl url() const;
+ QUrl requestedUrl() const;
+ QUrl baseUrl() const;
QIcon icon() const;
QMultiMap<QString, QString> metaData() const;
@@ -162,7 +167,8 @@ public:
void render(QPainter *painter, const QRegion &clip);
void render(QPainter *painter);
- void renderContents(QPainter *painter, const QRegion &contents);
+ bool clipRenderToViewport() const;
+ void setClipRenderToViewport(bool clipRenderToViewport);
void setTextSizeMultiplier(qreal factor);
qreal textSizeMultiplier() const;
@@ -170,10 +176,17 @@ public:
qreal zoomFactor() const;
void setZoomFactor(qreal factor);
+ bool hasFocus() const;
+ void setFocus();
+
QPoint pos() const;
QRect geometry() const;
QSize contentsSize() const;
+ QWebElement documentElement() const;
+ QList<QWebElement> findAllElements(const QString &selectorQuery) const;
+ QWebElement findFirstElement(const QString &selectorQuery) const;
+
QWebHitTestResult hitTestContent(const QPoint &pos) const;
virtual bool event(QEvent *);
@@ -199,6 +212,9 @@ Q_SIGNALS:
void contentsSizeChanged(const QSize &size);
+ void loadStarted();
+ void loadFinished(bool ok);
+
private:
friend class QWebPage;
friend class QWebPagePrivate;
diff --git a/WebKit/qt/Api/qwebframe_p.h b/WebKit/qt/Api/qwebframe_p.h
index c541cd3..d6afc01 100644
--- a/WebKit/qt/Api/qwebframe_p.h
+++ b/WebKit/qt/Api/qwebframe_p.h
@@ -27,11 +27,11 @@
#include "EventHandler.h"
#include "KURL.h"
#include "PlatformString.h"
+#include "qwebelement.h"
#include "wtf/RefPtr.h"
#include "Frame.h"
-namespace WebCore
-{
+namespace WebCore {
class FrameLoaderClientQt;
class FrameView;
class HTMLFrameOwnerElement;
@@ -39,13 +39,18 @@ namespace WebCore
}
class QWebPage;
-
-class QWebFrameData
-{
+class QWebFrameData {
public:
+ QWebFrameData(WebCore::Page*, WebCore::Frame* parentFrame = 0,
+ WebCore::HTMLFrameOwnerElement* = 0,
+ const WebCore::String& frameName = WebCore::String());
+
WebCore::KURL url;
WebCore::String name;
WebCore::HTMLFrameOwnerElement* ownerElement;
+ WebCore::Page* page;
+ RefPtr<WebCore::Frame> frame;
+ WebCore::FrameLoaderClientQt* frameLoaderClient;
WebCore::String referrer;
bool allowsScrolling;
@@ -53,8 +58,7 @@ public:
int marginHeight;
};
-class QWebFramePrivate
-{
+class QWebFramePrivate {
public:
QWebFramePrivate()
: q(0)
@@ -66,9 +70,9 @@ public:
, allowsScrolling(true)
, marginWidth(-1)
, marginHeight(-1)
+ , clipRenderToViewport(true)
{}
- void init(QWebFrame *qframe, WebCore::Page *page,
- QWebFrameData *frameData);
+ void init(QWebFrame* qframe, QWebFrameData* frameData);
inline QWebFrame *parentFrame() { return qobject_cast<QWebFrame*>(q->parent()); }
@@ -76,12 +80,12 @@ public:
WebCore::Scrollbar* verticalScrollBar() const;
Qt::ScrollBarPolicy horizontalScrollBarPolicy;
- Qt::ScrollBarPolicy verticalScrollBarPolicy;
+ Qt::ScrollBarPolicy verticalScrollBarPolicy;
static WebCore::Frame* core(QWebFrame*);
static QWebFrame* kit(WebCore::Frame*);
- void renderPrivate(QPainter *painter, const QRegion &clip, bool contents = false);
+ void renderPrivate(QPainter *painter, const QRegion &clip);
QWebFrame *q;
WebCore::FrameLoaderClientQt *frameLoaderClient;
@@ -91,23 +95,23 @@ public:
bool allowsScrolling;
int marginWidth;
int marginHeight;
+ bool clipRenderToViewport;
};
-class QWebHitTestResultPrivate
-{
+class QWebHitTestResultPrivate {
public:
QWebHitTestResultPrivate() : isContentEditable(false), isContentSelected(false), isScrollBar(false) {}
QWebHitTestResultPrivate(const WebCore::HitTestResult &hitTest);
QPoint pos;
QRect boundingRect;
- QRect enclosingBlock;
+ QWebElement enclosingBlock;
QString title;
QString linkText;
QUrl linkUrl;
QString linkTitle;
QPointer<QWebFrame> linkTargetFrame;
- QString linkTarget;
+ QWebElement linkElement;
QString alternateText;
QUrl imageUrl;
QPixmap pixmap;
diff --git a/WebKit/qt/Api/qwebhistory.cpp b/WebKit/qt/Api/qwebhistory.cpp
index 07d027d..1c1c72a 100644
--- a/WebKit/qt/Api/qwebhistory.cpp
+++ b/WebKit/qt/Api/qwebhistory.cpp
@@ -28,10 +28,10 @@
#include "PageGroup.h"
#include <QSharedData>
+#include <QDebug>
/*!
\class QWebHistoryItem
- \ingroup explicitly-shared
\since 4.4
\brief The QWebHistoryItem class represents one item in the history of a QWebPage
@@ -51,13 +51,17 @@
\row \o userData() \o The user specific data that was stored with the history item.
\endtable
- \note QWebHistoryItem objects are value based and \l{explicitly shared}.
+ \note QWebHistoryItem objects are value based, but \e{explicitly shared}. Changing
+ a QWebHistoryItem instance by calling setUserData() will change all copies of that
+ instance.
\sa QWebHistory, QWebPage::history(), QWebHistoryInterface
*/
/*!
- Constructs a history item from \a other.
+ Constructs a history item from \a other. The new item and \a other
+ will share their data, and modifying either this item or \a other will
+ modify both instances.
*/
QWebHistoryItem::QWebHistoryItem(const QWebHistoryItem &other)
: d(other.d)
@@ -65,7 +69,9 @@ QWebHistoryItem::QWebHistoryItem(const QWebHistoryItem &other)
}
/*!
- Assigns the \a other history item to this.
+ Assigns the \a other history item to this. This item and \a other
+ will share their data, and modifying either this item or \a other will
+ modify both instances.
*/
QWebHistoryItem &QWebHistoryItem::operator=(const QWebHistoryItem &other)
{
@@ -162,6 +168,8 @@ QVariant QWebHistoryItem::userData() const
\since 4.5
Stores user specific data \a userData with the history item.
+
+ \note All copies of this item will be modified.
\sa userData()
*/
@@ -213,6 +221,8 @@ bool QWebHistoryItem::isValid() const
number of items is given by count(), and the history can be cleared with the
clear() function.
+ QWebHistory's state can be saved with saveState() and loaded with restoreState().
+
\sa QWebHistoryItem, QWebHistoryInterface, QWebPage
*/
@@ -236,7 +246,7 @@ void QWebHistory::clear()
{
RefPtr<WebCore::HistoryItem> current = d->lst->currentItem();
int capacity = d->lst->capacity();
- d->lst->setCapacity(0);
+ d->lst->setCapacity(0);
WebCore::Page* page = d->lst->page();
if (page && page->groupPtr())
@@ -405,9 +415,13 @@ int QWebHistory::currentItemIndex() const
*/
QWebHistoryItem QWebHistory::itemAt(int i) const
{
- WebCore::HistoryItem *item = d->lst->itemAtIndex(i);
-
- QWebHistoryItemPrivate *priv = new QWebHistoryItemPrivate(item);
+ QWebHistoryItemPrivate *priv;
+ if (i < 0 || i >= count())
+ priv = new QWebHistoryItemPrivate(0);
+ else {
+ WebCore::HistoryItem *item = d->lst->entries()[i].get();
+ priv = new QWebHistoryItemPrivate(item);
+ }
return QWebHistoryItem(priv);
}
@@ -441,3 +455,129 @@ void QWebHistory::setMaximumItemCount(int count)
d->lst->setCapacity(count);
}
+/*!
+ \enum QWebHistory::HistoryStateVersion
+
+ This enum describes the versions available for QWebHistory's saveState() function:
+
+ \value HistoryVersion_1 Version 1 (Qt 4.6)
+ \value DefaultHistoryVersion The current default version in 1.
+*/
+
+/*!
+ \since 4.6
+
+ Restores the state of QWebHistory from the given \a buffer. Returns true
+ if the history was successfully restored; otherwise returns false.
+
+ \sa saveState()
+*/
+bool QWebHistory::restoreState(const QByteArray& buffer)
+{
+ QDataStream stream(buffer);
+ int version;
+ bool result = false;
+ stream >> version;
+
+ switch (version) {
+ case HistoryVersion_1: {
+ int count;
+ int currentIndex;
+ stream >> count >> currentIndex;
+
+ clear();
+ // only if there are elements
+ if (count) {
+ // after clear() is new clear HistoryItem (at the end we had to remove it)
+ WebCore::HistoryItem *nullItem = d->lst->currentItem();
+ for (int i = 0;i < count;i++) {
+ WTF::PassRefPtr<WebCore::HistoryItem> item = WebCore::HistoryItem::create();
+ item->restoreState(stream, version);
+ d->lst->addItem(item);
+ }
+ d->lst->removeItem(nullItem);
+ goToItem(itemAt(currentIndex));
+ result = stream.status() == QDataStream::Ok;
+ }
+ break;
+ }
+ default: {} // result is false;
+ }
+
+ return result;
+};
+
+/*!
+ \since 4.6
+ Saves the state of this QWebHistory into a QByteArray.
+
+ Saves the current state of this QWebHistory. The version number, \a version, is
+ stored as part of the data.
+
+ To restore the saved state, pass the return value to restoreState().
+
+ \sa restoreState()
+*/
+QByteArray QWebHistory::saveState(HistoryStateVersion version) const
+{
+ QByteArray buffer;
+ QDataStream stream(&buffer, QIODevice::WriteOnly);
+ stream << version;
+
+ switch (version) {
+ case HistoryVersion_1: {
+ stream << count() << currentItemIndex();
+
+ const WebCore::HistoryItemVector &items = d->lst->entries();
+ for (int i = 0; i < items.size(); i++)
+ items[i].get()->saveState(stream, version);
+
+ if (stream.status() != QDataStream::Ok)
+ buffer = QByteArray(); // make buffer isNull()==true and isEmpty()==true
+ break;
+ }
+ default:
+ buffer.clear();
+
+ }
+
+ return buffer;
+}
+
+/*!
+ \since 4.6
+ \fn QDataStream& operator<<(QDataStream& stream, const QWebHistory& history)
+ \relates QWebHistory
+
+ Saves the given \a history into the specified \a stream. This is a convenience function
+ and is equivalent to calling the saveState() method.
+
+ \sa QWebHistory::saveState()
+*/
+
+QDataStream& operator<<(QDataStream& stream, const QWebHistory& history)
+{
+ return stream << history.saveState();
+}
+
+/*!
+ \fn QDataStream& operator>>(QDataStream& stream, QWebHistory& history)
+ \relates QWebHistory
+ \since 4.6
+
+ Loads a QWebHistory from the specified \a stream into the given \a history.
+ This is a convenience function and it is equivalent to calling the restoreState()
+ method.
+
+ \sa QWebHistory::restoreState()
+*/
+
+QDataStream& operator>>(QDataStream& stream, QWebHistory& history)
+{
+ QByteArray buffer;
+ stream >> buffer;
+ history.restoreState(buffer);
+ return stream;
+}
+
+
diff --git a/WebKit/qt/Api/qwebhistory.h b/WebKit/qt/Api/qwebhistory.h
index c39077d..e46f124 100644
--- a/WebKit/qt/Api/qwebhistory.h
+++ b/WebKit/qt/Api/qwebhistory.h
@@ -35,13 +35,16 @@ namespace WebCore {
}
class QWebHistoryItemPrivate;
-class QWEBKIT_EXPORT QWebHistoryItem
-{
+
+class QWEBKIT_EXPORT QWebHistoryItem {
public:
QWebHistoryItem(const QWebHistoryItem &other);
QWebHistoryItem &operator=(const QWebHistoryItem &other);
~QWebHistoryItem();
+ //bool restoreState(QByteArray& buffer);
+ //QByteArray saveState(QWebHistory::HistoryStateVersion version = DefaultHistoryVersion) const;
+
QUrl originalUrl() const;
QUrl url() const;
@@ -60,13 +63,28 @@ private:
friend class QWebHistory;
friend class QWebPage;
friend class WebCore::FrameLoaderClientQt;
+ friend class QWebHistoryItemPrivate;
+ //friend QDataStream & operator<<(QDataStream& out,const QWebHistoryItem& hist);
+ //friend QDataStream & operator>>(QDataStream& in,QWebHistoryItem& hist);
QExplicitlySharedDataPointer<QWebHistoryItemPrivate> d;
};
+//QWEBKIT_EXPORT QDataStream & operator<<(QDataStream& out,const QWebHistoryItem& hist);
+//QWEBKIT_EXPORT QDataStream & operator>>(QDataStream& in,QWebHistoryItem& hist);
+
+
class QWebHistoryPrivate;
-class QWEBKIT_EXPORT QWebHistory
-{
+class QWEBKIT_EXPORT QWebHistory {
public:
+ enum HistoryStateVersion {
+ HistoryVersion_1,
+ /*, HistoryVersion_2, */
+ DefaultHistoryVersion = HistoryVersion_1
+ };
+
+ bool restoreState(const QByteArray& buffer);
+ QByteArray saveState(HistoryStateVersion version = DefaultHistoryVersion) const;
+
void clear();
QList<QWebHistoryItem> items() const;
@@ -98,10 +116,15 @@ private:
friend class QWebPage;
friend class QWebPagePrivate;
+ friend QWEBKIT_EXPORT QDataStream& operator>>(QDataStream&, QWebHistory&);
+ friend QWEBKIT_EXPORT QDataStream& operator<<(QDataStream&, const QWebHistory&);
Q_DISABLE_COPY(QWebHistory)
QWebHistoryPrivate *d;
};
+QWEBKIT_EXPORT QDataStream& operator<<(QDataStream& stream, const QWebHistory& history);
+QWEBKIT_EXPORT QDataStream& operator>>(QDataStream& stream, QWebHistory& history);
+
#endif
diff --git a/WebKit/qt/Api/qwebhistory_p.h b/WebKit/qt/Api/qwebhistory_p.h
index 32e69fe..e77adef 100644
--- a/WebKit/qt/Api/qwebhistory_p.h
+++ b/WebKit/qt/Api/qwebhistory_p.h
@@ -22,10 +22,15 @@
#include "BackForwardList.h"
#include "HistoryItem.h"
+#include <QtCore/qglobal.h>
+#include <QtCore/qshareddata.h>
-class QWebHistoryItemPrivate : public QSharedData
-{
+class Q_AUTOTEST_EXPORT QWebHistoryItemPrivate : public QSharedData {
public:
+ static QExplicitlySharedDataPointer<QWebHistoryItemPrivate> get(QWebHistoryItem *q)
+ {
+ return q->d;
+ }
QWebHistoryItemPrivate(WebCore::HistoryItem *i)
{
if (i)
@@ -37,11 +42,29 @@ public:
if (item)
item->deref();
}
+
+ /* QByteArray saveStateWithoutVersionControl(QWebHistory::HistoryStateVersion version)
+ {
+ QByteArray buffer;
+ switch(version){
+ case QWebHistory::HistoryVersion1:
+ buffer=item->saveState(version);
+ break;
+ default:{}
+ }
+ return buffer;
+ }
+
+ bool restoreStateWithoutVersionControl(QWebHistory::HistoryStateVersion version,QDataStream& stream)
+ {
+
+ }
+*/
+
WebCore::HistoryItem *item;
};
-class QWebHistoryPrivate : public QSharedData
-{
+class QWebHistoryPrivate : public QSharedData {
public:
QWebHistoryPrivate(WebCore::BackForwardList *l)
{
diff --git a/WebKit/qt/Api/qwebhistoryinterface.cpp b/WebKit/qt/Api/qwebhistoryinterface.cpp
index 8e2d35c..87d52ce 100644
--- a/WebKit/qt/Api/qwebhistoryinterface.cpp
+++ b/WebKit/qt/Api/qwebhistoryinterface.cpp
@@ -27,28 +27,14 @@
#include "PageGroup.h"
#include "PlatformString.h"
-// FIXME: It's not correct to just implement a WebCore function in WebKit!
-// This needs to be fixed to match other platforms.
-namespace WebCore {
-
-bool historyContains(const UChar* characters, unsigned length)
-{
- if (!QWebHistoryInterface::defaultInterface())
- return false;
-
- return QWebHistoryInterface::defaultInterface()->historyContains(QString(reinterpret_cast<const QChar*>(characters), length));
-}
-
-} // namespace WebCore
-
-static QWebHistoryInterface *default_interface;
+static QWebHistoryInterface* default_interface;
static bool gRoutineAdded;
static void gCleanupInterface()
{
- if (default_interface && default_interface->parent() == 0)
+ if (default_interface && !default_interface->parent())
delete default_interface;
default_interface = 0;
}
@@ -61,16 +47,20 @@ static void gCleanupInterface()
When the application exists QWebHistoryInterface will automatically delete the
\a defaultInterface if it does not have a parent.
*/
-void QWebHistoryInterface::setDefaultInterface(QWebHistoryInterface *defaultInterface)
+void QWebHistoryInterface::setDefaultInterface(QWebHistoryInterface* defaultInterface)
{
if (default_interface == defaultInterface)
return;
- if (default_interface && default_interface->parent() == 0)
+
+ if (default_interface && !default_interface->parent())
delete default_interface;
default_interface = defaultInterface;
WebCore::PageGroup::removeAllVisitedLinks();
+ //### enable after the introduction of a version
+ //WebCore::PageGroup::setShouldTrackVisitedLinks(true);
+
if (!gRoutineAdded) {
qAddPostRoutine(gCleanupInterface);
gRoutineAdded = true;
@@ -81,7 +71,7 @@ void QWebHistoryInterface::setDefaultInterface(QWebHistoryInterface *defaultInte
Returns the default interface that will be used by WebKit. If no
default interface has been set, QtWebkit will not track history.
*/
-QWebHistoryInterface *QWebHistoryInterface::defaultInterface()
+QWebHistoryInterface* QWebHistoryInterface::defaultInterface()
{
return default_interface;
}
@@ -102,7 +92,8 @@ QWebHistoryInterface *QWebHistoryInterface::defaultInterface()
/*!
Constructs a new QWebHistoryInterface with parent \a parent.
*/
-QWebHistoryInterface::QWebHistoryInterface(QObject *parent) : QObject(parent)
+QWebHistoryInterface::QWebHistoryInterface(QObject* parent)
+ : QObject(parent)
{
}
diff --git a/WebKit/qt/Api/qwebhistoryinterface.h b/WebKit/qt/Api/qwebhistoryinterface.h
index 670fca0..a49c586 100644
--- a/WebKit/qt/Api/qwebhistoryinterface.h
+++ b/WebKit/qt/Api/qwebhistoryinterface.h
@@ -26,8 +26,7 @@
#include "qwebkitglobal.h"
-class QWEBKIT_EXPORT QWebHistoryInterface : public QObject
-{
+class QWEBKIT_EXPORT QWebHistoryInterface : public QObject {
Q_OBJECT
public:
QWebHistoryInterface(QObject *parent = 0);
diff --git a/WebKit/qt/Api/qwebkitglobal.h b/WebKit/qt/Api/qwebkitglobal.h
index 19d9218..0885bdc 100644
--- a/WebKit/qt/Api/qwebkitglobal.h
+++ b/WebKit/qt/Api/qwebkitglobal.h
@@ -22,22 +22,14 @@
#include <QtCore/qglobal.h>
-#if defined(Q_OS_WIN)
-# if defined(QT_NODLL)
-# undef QT_MAKEDLL
-# undef QT_DLL
-# elif defined(QT_MAKEDLL) /* create a Qt DLL library */
-# if defined(QT_DLL)
-# undef QT_DLL
-# endif
-# if defined(BUILD_WEBKIT)
-# define QWEBKIT_EXPORT Q_DECL_EXPORT
-# else
-# define QWEBKIT_EXPORT Q_DECL_IMPORT
-# endif
-# elif defined(QT_DLL) /* use a Qt DLL library */
-# define QWEBKIT_EXPORT Q_DECL_IMPORT
+#if defined(QT_MAKEDLL) /* create a Qt DLL library */
+# if defined(BUILD_WEBKIT)
+# define QWEBKIT_EXPORT Q_DECL_EXPORT
+# else
+# define QWEBKIT_EXPORT Q_DECL_IMPORT
# endif
+#elif defined(QT_DLL) /* use a Qt DLL library */
+# define QWEBKIT_EXPORT Q_DECL_IMPORT
#endif
#if !defined(QWEBKIT_EXPORT)
diff --git a/WebKit/qt/Api/qwebkitversion.cpp b/WebKit/qt/Api/qwebkitversion.cpp
new file mode 100644
index 0000000..062839f
--- /dev/null
+++ b/WebKit/qt/Api/qwebkitversion.cpp
@@ -0,0 +1,58 @@
+/*
+ Copyright (C) 2009 Robert Hogan <robert@roberthogan.net>
+
+ This library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Library General Public
+ License as published by the Free Software Foundation; either
+ version 2 of the License, or (at your option) any later version.
+
+ This library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Library General Public License for more details.
+
+ You should have received a copy of the GNU Library General Public License
+ along with this library; see the file COPYING.LIB. If not, write to
+ the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+ Boston, MA 02110-1301, USA.
+*/
+
+#include "config.h"
+#include <qwebkitversion.h>
+#include <WebKitVersion.h>
+
+/*!
+
+ Returns the version number of WebKit at run-time as a string (for
+ example, "531.3"). This is the version of WebKit the application
+ was compiled against.
+
+*/
+QString qWebKitVersion()
+{
+ return QString("%1.%2").arg(WEBKIT_MAJOR_VERSION).arg(WEBKIT_MINOR_VERSION);
+}
+
+/*!
+
+ Returns the 'major' version number of WebKit at run-time as an integer
+ (for example, 531). This is the version of WebKit the application
+ was compiled against.
+
+*/
+int qWebKitMajorVersion()
+{
+ return WEBKIT_MAJOR_VERSION;
+}
+
+/*!
+
+ Returns the 'minor' version number of WebKit at run-time as an integer
+ (for example, 3). This is the version of WebKit the application
+ was compiled against.
+
+*/
+int qWebKitMinorVersion()
+{
+ return WEBKIT_MINOR_VERSION;
+}
diff --git a/WebKit/qt/Api/qwebkitversion.h b/WebKit/qt/Api/qwebkitversion.h
new file mode 100644
index 0000000..f0fbef0
--- /dev/null
+++ b/WebKit/qt/Api/qwebkitversion.h
@@ -0,0 +1,32 @@
+/*
+ Copyright (C) 2009 Robert Hogan <robert@roberthogan.net>
+
+ This library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Library General Public
+ License as published by the Free Software Foundation; either
+ version 2 of the License, or (at your option) any later version.
+
+ This library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Library General Public License for more details.
+
+ You should have received a copy of the GNU Library General Public License
+ along with this library; see the file COPYING.LIB. If not, write to
+ the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+ Boston, MA 02110-1301, USA.
+*/
+
+#include <qstring.h>
+
+#ifndef qwebkitversion_h
+#define qwebkitversion_h
+
+#include <QtCore/qstring.h>
+#include "qwebkitglobal.h"
+
+QWEBKIT_EXPORT QString qWebKitVersion();
+QWEBKIT_EXPORT int qWebKitMajorVersion();
+QWEBKIT_EXPORT int qWebKitMinorVersion();
+
+#endif // qwebkitversion_h
diff --git a/WebKit/qt/Api/qwebnetworkinterface.cpp b/WebKit/qt/Api/qwebnetworkinterface.cpp
index 8fba915..cf99183 100644
--- a/WebKit/qt/Api/qwebnetworkinterface.cpp
+++ b/WebKit/qt/Api/qwebnetworkinterface.cpp
@@ -19,6 +19,7 @@
Boston, MA 02110-1301, USA.
*/
+#include "config.h"
#include <qglobal.h>
#if QT_VERSION < 0x040400
#include "qwebframe.h"
@@ -84,11 +85,10 @@ static QByteArray decodePercentEncoding(const QByteArray& input)
for (int i = 0; i < input.length(); ++i)
if (state == State_Begin) {
- if (input.at(i) == '%') {
+ if (input.at(i) == '%')
state = State_FirstChar;
- } else {
+ else
output[actualLength++] = input[i];
- }
} else if (state == State_FirstChar) {
state = State_SecondChar;
tmpVal[0] = input[i];
@@ -109,7 +109,7 @@ void QWebNetworkRequestPrivate::init(const WebCore::ResourceRequest &resourceReq
init(resourceRequest.httpMethod(), qurl, &resourceRequest);
}
-void QWebNetworkRequestPrivate::init(const QString &method, const QUrl &url, const WebCore::ResourceRequest *resourceRequest)
+void QWebNetworkRequestPrivate::init(const QString& method, const QUrl& url, const WebCore::ResourceRequest* resourceRequest)
{
httpHeader = QHttpRequestHeader(method, url.toString(QUrl::RemoveScheme|QUrl::RemoveAuthority));
httpHeader.setValue(QLatin1String("Connection"), QLatin1String("Keep-Alive"));
@@ -140,7 +140,7 @@ void QWebNetworkRequestPrivate::init(const QString &method, const QUrl &url, con
}
}
-void QWebNetworkRequestPrivate::setURL(const QUrl &u)
+void QWebNetworkRequestPrivate::setURL(const QUrl& u)
{
url = u;
int port = url.port();
@@ -153,6 +153,7 @@ void QWebNetworkRequestPrivate::setURL(const QUrl &u)
/*!
\class QWebNetworkRequest
+ \internal
The QWebNetworkRequest class represents a request for data from the network with all the
necessary information needed for retrieval. This includes the url, extra HTTP header fields
@@ -164,7 +165,7 @@ QWebNetworkRequest::QWebNetworkRequest()
{
}
-QWebNetworkRequest::QWebNetworkRequest(const QUrl &url, Method method, const QByteArray &postData)
+QWebNetworkRequest::QWebNetworkRequest(const QUrl& url, Method method, const QByteArray& postData)
: d(new QWebNetworkRequestPrivate)
{
d->init(method == Get ? "GET" : "POST", url);
@@ -176,7 +177,7 @@ QWebNetworkRequest::QWebNetworkRequest(const QWebNetworkRequest &other)
{
}
-QWebNetworkRequest &QWebNetworkRequest::operator=(const QWebNetworkRequest &other)
+QWebNetworkRequest &QWebNetworkRequest::operator=(const QWebNetworkRequest& other)
{
*d = *other.d;
return *this;
@@ -185,7 +186,7 @@ QWebNetworkRequest &QWebNetworkRequest::operator=(const QWebNetworkRequest &othe
/*!
\internal
*/
-QWebNetworkRequest::QWebNetworkRequest(const QWebNetworkRequestPrivate &priv)
+QWebNetworkRequest::QWebNetworkRequest(const QWebNetworkRequestPrivate& priv)
: d(new QWebNetworkRequestPrivate(priv))
{
}
@@ -193,7 +194,7 @@ QWebNetworkRequest::QWebNetworkRequest(const QWebNetworkRequestPrivate &priv)
/*!
\internal
*/
-QWebNetworkRequest::QWebNetworkRequest(const WebCore::ResourceRequest &request)
+QWebNetworkRequest::QWebNetworkRequest(const WebCore::ResourceRequest& request)
: d(new QWebNetworkRequestPrivate)
{
d->init(request);
@@ -205,6 +206,7 @@ QWebNetworkRequest::~QWebNetworkRequest()
}
/*!
+ \internal
The requested URL
*/
QUrl QWebNetworkRequest::url() const
@@ -213,16 +215,18 @@ QUrl QWebNetworkRequest::url() const
}
/*!
+ \internal
Sets the URL to request.
Note that setting the URL also sets the "Host" field in the HTTP header.
*/
-void QWebNetworkRequest::setUrl(const QUrl &url)
+void QWebNetworkRequest::setUrl(const QUrl& url)
{
d->setURL(url);
}
/*!
+ \internal
The http request header information.
*/
QHttpRequestHeader QWebNetworkRequest::httpHeader() const
@@ -230,22 +234,23 @@ QHttpRequestHeader QWebNetworkRequest::httpHeader() const
return d->httpHeader;
}
-void QWebNetworkRequest::setHttpHeader(const QHttpRequestHeader &header) const
+void QWebNetworkRequest::setHttpHeader(const QHttpRequestHeader& header) const
{
d->httpHeader = header;
}
-QString QWebNetworkRequest::httpHeaderField(const QString &key) const
+QString QWebNetworkRequest::httpHeaderField(const QString& key) const
{
return d->httpHeader.value(key);
}
-void QWebNetworkRequest::setHttpHeaderField(const QString &key, const QString &value)
+void QWebNetworkRequest::setHttpHeaderField(const QString& key, const QString& value)
{
d->httpHeader.setValue(key, value);
}
/*!
+ \internal
Post data sent with HTTP POST requests.
*/
QByteArray QWebNetworkRequest::postData() const
@@ -253,13 +258,14 @@ QByteArray QWebNetworkRequest::postData() const
return d->postData;
}
-void QWebNetworkRequest::setPostData(const QByteArray &data)
+void QWebNetworkRequest::setPostData(const QByteArray& data)
{
d->postData = data;
}
/*!
\class QWebNetworkJob
+ \internal
The QWebNetworkJob class represents a network job, that needs to be
processed by the QWebNetworkInterface.
@@ -292,6 +298,7 @@ QWebNetworkJob::~QWebNetworkJob()
}
/*!
+ \internal
The requested URL
*/
QUrl QWebNetworkJob::url() const
@@ -300,6 +307,7 @@ QUrl QWebNetworkJob::url() const
}
/*!
+ \internal
Post data associated with the job
*/
QByteArray QWebNetworkJob::postData() const
@@ -308,6 +316,7 @@ QByteArray QWebNetworkJob::postData() const
}
/*!
+ \internal
The HTTP request header that should be used to download the job.
*/
QHttpRequestHeader QWebNetworkJob::httpHeader() const
@@ -316,6 +325,7 @@ QHttpRequestHeader QWebNetworkJob::httpHeader() const
}
/*!
+ \internal
The complete network request that should be used to download the job.
*/
QWebNetworkRequest QWebNetworkJob::request() const
@@ -324,6 +334,7 @@ QWebNetworkRequest QWebNetworkJob::request() const
}
/*!
+ \internal
The HTTP response header received from the network.
*/
QHttpResponseHeader QWebNetworkJob::response() const
@@ -332,6 +343,7 @@ QHttpResponseHeader QWebNetworkJob::response() const
}
/*!
+ \internal
The last error of the Job.
*/
QString QWebNetworkJob::errorString() const
@@ -340,10 +352,11 @@ QString QWebNetworkJob::errorString() const
}
/*!
+ \internal
Sets the HTTP reponse header. The response header has to be called before
emitting QWebNetworkInterface::started.
*/
-void QWebNetworkJob::setResponse(const QHttpResponseHeader &response)
+void QWebNetworkJob::setResponse(const QHttpResponseHeader& response)
{
d->response = response;
}
@@ -354,6 +367,7 @@ void QWebNetworkJob::setErrorString(const QString& errorString)
}
/*!
+ \internal
returns true if the job has been cancelled by the WebKit framework
*/
bool QWebNetworkJob::cancelled() const
@@ -362,6 +376,7 @@ bool QWebNetworkJob::cancelled() const
}
/*!
+ \internal
reference the job.
*/
void QWebNetworkJob::ref()
@@ -370,6 +385,7 @@ void QWebNetworkJob::ref()
}
/*!
+ \internal
derefence the job.
If the reference count drops to 0 this method also deletes the job.
@@ -386,6 +402,7 @@ bool QWebNetworkJob::deref()
}
/*!
+ \internal
Returns the network interface that is associated with this job.
*/
QWebNetworkInterface *QWebNetworkJob::networkInterface() const
@@ -394,15 +411,15 @@ QWebNetworkInterface *QWebNetworkJob::networkInterface() const
}
/*!
+ \internal
Returns the network interface that is associated with this job.
*/
QWebFrame *QWebNetworkJob::frame() const
{
- if (d->resourceHandle) {
+ if (!d->resourceHandle) {
ResourceHandleInternal *rhi = d->resourceHandle->getInternal();
- if (rhi) {
+ if (rhi)
return rhi->m_frame;
- }
}
return 0;
}
@@ -436,7 +453,7 @@ QWebNetworkManager *QWebNetworkManager::self()
return s_manager;
}
-bool QWebNetworkManager::add(ResourceHandle *handle, QWebNetworkInterface *interface, JobMode jobMode)
+bool QWebNetworkManager::add(ResourceHandle* handle, QWebNetworkInterface* interface, JobMode jobMode)
{
if (!interface)
interface = s_default_interface;
@@ -468,7 +485,7 @@ bool QWebNetworkManager::add(ResourceHandle *handle, QWebNetworkInterface *inter
return true;
}
-void QWebNetworkManager::cancel(ResourceHandle *handle)
+void QWebNetworkManager::cancel(ResourceHandle* handle)
{
QWebNetworkJob *job = handle->getInternal()->m_job;
if (!job)
@@ -479,7 +496,10 @@ void QWebNetworkManager::cancel(ResourceHandle *handle)
handle->getInternal()->m_job = 0;
}
-void QWebNetworkManager::started(QWebNetworkJob *job)
+/*!
+ \internal
+*/
+void QWebNetworkManager::started(QWebNetworkJob* job)
{
Q_ASSERT(job->d);
Q_ASSERT(job->status() == QWebNetworkJob::JobCreated ||
@@ -487,22 +507,23 @@ void QWebNetworkManager::started(QWebNetworkJob *job)
job->setStatus(QWebNetworkJob::JobStarted);
ResourceHandleClient* client = 0;
- if (job->d->resourceHandle) {
- client = job->d->resourceHandle->client();
- if (!client)
- return;
- } else {
+
+ if (!job->d->resourceHandle)
+ return;
+
+ client = job->d->resourceHandle->client();
+ if (!client)
return;
- }
DEBUG() << "ResourceHandleManager::receivedResponse:";
DEBUG() << job->d->response.toString();
QStringList cookies = job->d->response.allValues("Set-Cookie");
KURL url(job->url());
- foreach (QString c, cookies) {
+
+ foreach (QString c, cookies)
QCookieJar::cookieJar()->setCookies(url, url, c);
- }
+
QString contentType = job->d->response.value("Content-Type");
QString encoding;
int idx = contentType.indexOf(QLatin1Char(';'));
@@ -563,9 +584,9 @@ void QWebNetworkManager::started(QWebNetworkJob *job)
// with a 302 which must be GET'ed
method = "GET";
job->d->request.httpHeader.setContentLength(0);
- } else {
+ } else
method = job->d->request.httpHeader.method();
- }
+
job->d->request.httpHeader.setRequest(method,
newUrl.toString(QUrl::RemoveScheme|QUrl::RemoveAuthority));
job->d->request.setURL(newUrl);
@@ -579,31 +600,29 @@ void QWebNetworkManager::started(QWebNetworkJob *job)
}
-void QWebNetworkManager::data(QWebNetworkJob *job, const QByteArray &data)
+void QWebNetworkManager::data(QWebNetworkJob* job, const QByteArray& data)
{
Q_ASSERT(job->status() == QWebNetworkJob::JobStarted ||
job->status() == QWebNetworkJob::JobReceivingData);
job->setStatus(QWebNetworkJob::JobReceivingData);
ResourceHandleClient* client = 0;
- if (job->d->resourceHandle) {
- client = job->d->resourceHandle->client();
- if (!client)
- return;
- } else {
+
+ if (!job->d->resourceHandle)
+ return;
+
+ client = job->d->resourceHandle->client();
+ if (!client)
return;
- }
if (job->d->redirected)
return; // don't emit the "Document has moved here" type of HTML
DEBUG() << "receivedData" << job->d->request.url.path();
- if (client)
- client->didReceiveData(job->d->resourceHandle, data.constData(), data.length(), data.length() /*FixMe*/);
-
+ client->didReceiveData(job->d->resourceHandle, data.constData(), data.length(), data.length() /*FixMe*/);
}
-void QWebNetworkManager::finished(QWebNetworkJob *job, int errorCode)
+void QWebNetworkManager::finished(QWebNetworkJob* job, int errorCode)
{
Q_ASSERT(errorCode == 1 ||
job->status() == QWebNetworkJob::JobStarted ||
@@ -641,9 +660,8 @@ void QWebNetworkManager::finished(QWebNetworkJob *job, int errorCode)
client->didFail(job->d->resourceHandle,
ResourceError(job->d->request.url.host(), job->d->response.statusCode(),
job->d->request.url.toString(), job->d->errorString));
- } else {
+ } else
client->didFinishLoading(job->d->resourceHandle);
- }
}
DEBUG() << "receivedFinished done" << job->d->request.url;
@@ -651,7 +669,7 @@ void QWebNetworkManager::finished(QWebNetworkJob *job, int errorCode)
job->deref();
}
-void QWebNetworkManager::addHttpJob(QWebNetworkJob *job)
+void QWebNetworkManager::addHttpJob(QWebNetworkJob* job)
{
HostInfo hostInfo(job->url());
WebCoreHttp *httpConnection = m_hostMapping.value(hostInfo);
@@ -667,20 +685,20 @@ void QWebNetworkManager::addHttpJob(QWebNetworkJob *job)
httpConnection->request(job);
}
-void QWebNetworkManager::cancelHttpJob(QWebNetworkJob *job)
+void QWebNetworkManager::cancelHttpJob(QWebNetworkJob* job)
{
WebCoreHttp *httpConnection = m_hostMapping.value(job->url());
if (httpConnection)
httpConnection->cancel(job);
}
-void QWebNetworkManager::httpConnectionClosed(const WebCore::HostInfo &info)
+void QWebNetworkManager::httpConnectionClosed(const WebCore::HostInfo& info)
{
WebCoreHttp *connection = m_hostMapping.take(info);
connection->deleteLater();
}
-void QWebNetworkInterfacePrivate::sendFileData(QWebNetworkJob* job, int statusCode, const QByteArray &data)
+void QWebNetworkInterfacePrivate::sendFileData(QWebNetworkJob* job, int statusCode, const QByteArray& data)
{
int error = statusCode >= 400 ? 1 : 0;
if (!job->cancelled()) {
@@ -723,15 +741,13 @@ void QWebNetworkInterfacePrivate::parseDataUrl(QWebNetworkJob* job)
header = header.left(header.length() - 7);
//qDebug() << "mime=" << header;
}
- } else {
+ } else
data = QByteArray();
- }
- if (base64) {
+ if (base64)
data = QByteArray::fromBase64(data);
- } else {
+ else
data = decodePercentEncoding(data);
- }
if (header.isEmpty())
header = "text/plain;charset=US-ASCII";
@@ -830,13 +846,14 @@ void QWebNetworkManager::doWork()
}
m_queueMutex.lock();
- if (hasSyncJobs && m_synchronousJobs.size() == 0)
+ if (hasSyncJobs && !m_synchronousJobs.size())
doScheduleWork();
m_queueMutex.unlock();
}
/*!
\class QWebNetworkInterface
+ \internal
The QWebNetworkInterface class provides an abstraction layer for
WebKit's network interface. It allows to completely replace or
@@ -860,10 +877,11 @@ static void gCleanupInterface()
}
/*!
+ \internal
Sets a new default interface that will be used by all of WebKit
for downloading data from the internet.
*/
-void QWebNetworkInterface::setDefaultInterface(QWebNetworkInterface *defaultInterface)
+void QWebNetworkInterface::setDefaultInterface(QWebNetworkInterface* defaultInterface)
{
if (s_default_interface == defaultInterface)
return;
@@ -877,23 +895,25 @@ void QWebNetworkInterface::setDefaultInterface(QWebNetworkInterface *defaultInte
}
/*!
+ \internal
Returns the default interface that will be used by WebKit. If no
default interface has been set, QtWebkit will create an instance of
QWebNetworkInterface to do the work.
*/
QWebNetworkInterface *QWebNetworkInterface::defaultInterface()
{
- if (!s_default_interface) {
+ if (!s_default_interface)
setDefaultInterface(new QWebNetworkInterface);
- }
+
return s_default_interface;
}
/*!
+ \internal
Constructs a QWebNetworkInterface object.
*/
-QWebNetworkInterface::QWebNetworkInterface(QObject *parent)
+QWebNetworkInterface::QWebNetworkInterface(QObject* parent)
: QObject(parent)
{
d = new QWebNetworkInterfacePrivate;
@@ -904,6 +924,7 @@ QWebNetworkInterface::QWebNetworkInterface(QObject *parent)
}
/*!
+ \internal
Destructs the QWebNetworkInterface object.
*/
QWebNetworkInterface::~QWebNetworkInterface()
@@ -912,6 +933,7 @@ QWebNetworkInterface::~QWebNetworkInterface()
}
/*!
+ \internal
This virtual method gets called whenever QtWebkit needs to add a
new job to download.
@@ -923,7 +945,7 @@ QWebNetworkInterface::~QWebNetworkInterface()
After the finished signal has been emitted, the QWebNetworkInterface
is not allowed to access the job anymore.
*/
-void QWebNetworkInterface::addJob(QWebNetworkJob *job)
+void QWebNetworkInterface::addJob(QWebNetworkJob* job)
{
QString protocol = job->url().scheme();
if (protocol == QLatin1String("http") || protocol == QLatin1String("https")) {
@@ -966,9 +988,8 @@ void QWebNetworkInterface::addJob(QWebNetworkJob *job)
response.setStatusLine(200);
job->setResponse(response);
data = f.readAll();
- } else {
+ } else
statusCode = 404;
- }
}
if (statusCode == 404) {
@@ -981,6 +1002,7 @@ void QWebNetworkInterface::addJob(QWebNetworkJob *job)
}
/*!
+ \internal
This virtual method gets called whenever QtWebkit needs to cancel a
new job.
@@ -989,35 +1011,66 @@ void QWebNetworkInterface::addJob(QWebNetworkJob *job)
the finished signal, the interface should not access the job
anymore.
*/
-void QWebNetworkInterface::cancelJob(QWebNetworkJob *job)
+void QWebNetworkInterface::cancelJob(QWebNetworkJob* job)
{
QString protocol = job->url().scheme();
if (protocol == QLatin1String("http") || protocol == QLatin1String("https"))
QWebNetworkManager::self()->cancelHttpJob(job);
}
+/*!
+ \internal
+*/
void QWebNetworkInterface::started(QWebNetworkJob* job)
{
Q_ASSERT(s_manager);
s_manager->queueStart(job);
}
+/*!
+ \internal
+*/
void QWebNetworkInterface::data(QWebNetworkJob* job, const QByteArray& data)
{
Q_ASSERT(s_manager);
s_manager->queueData(job, data);
}
+/*!
+ \internal
+*/
void QWebNetworkInterface::finished(QWebNetworkJob* job, int errorCode)
{
Q_ASSERT(s_manager);
s_manager->queueFinished(job, errorCode);
}
+/*!
+ \fn void QWebNetworkInterface::sslErrors(QWebFrame *frame, const QUrl& url, const QList<QSslError>& errors, bool *continueAnyway);
+ \internal
+
+ Signal is emitted when an SSL error occurs.
+*/
+
+/*!
+ \fn void QWebNetworkInterface::authenticate(QWebFrame *frame, const QUrl& url, const QString& hostname, quint16 port, QAuthenticator *auth);
+ \internal
+
+ Signal is emitted when network authentication is required.
+*/
+
+/*!
+ \fn void QWebNetworkInterface::authenticateProxy(QWebFrame *frame, const QUrl& url, const QNetworkProxy& proxy, QAuthenticator *auth);
+ \internal
+
+ Signal is emitted when proxy authentication is required.
+*/
+
/////////////////////////////////////////////////////////////////////////////
-WebCoreHttp::WebCoreHttp(QObject* parent, const HostInfo &hi)
- : QObject(parent), info(hi),
- m_inCancel(false)
+WebCoreHttp::WebCoreHttp(QObject* parent, const HostInfo& hi)
+ : QObject(parent)
+ , info(hi)
+ , m_inCancel(false)
{
for (int i = 0; i < 2; ++i) {
connection[i].http = new QHttp(info.host, (hi.protocol == QLatin1String("https")) ? QHttp::ConnectionModeHttps : QHttp::ConnectionModeHttp, info.port);
@@ -1046,7 +1099,7 @@ WebCoreHttp::~WebCoreHttp()
connection[1].http->deleteLater();
}
-void WebCoreHttp::request(QWebNetworkJob *job)
+void WebCoreHttp::request(QWebNetworkJob* job)
{
m_pendingRequests.append(job);
scheduleNextRequest();
@@ -1073,7 +1126,7 @@ void WebCoreHttp::scheduleNextRequest()
if (!job)
return;
- QHttp *http = connection[c].http;
+ QHttp* http = connection[c].http;
connection[c].current = job;
connection[c].id = -1;
@@ -1094,7 +1147,7 @@ void WebCoreHttp::scheduleNextRequest()
int WebCoreHttp::getConnection()
{
- QObject *o = sender();
+ QObject* o = sender();
int c;
if (o == connection[0].http) {
c = 0;
@@ -1106,15 +1159,15 @@ int WebCoreHttp::getConnection()
return c;
}
-void WebCoreHttp::onResponseHeaderReceived(const QHttpResponseHeader &resp)
+void WebCoreHttp::onResponseHeaderReceived(const QHttpResponseHeader& resp)
{
- QHttp *http = qobject_cast<QHttp*>(sender());
- if (http->currentId() == 0) {
+ QHttp* http = qobject_cast<QHttp*>(sender());
+ if (!http->currentId()) {
qDebug() << "ERROR! Invalid job id. Why?"; // foxnews.com triggers this
return;
}
int c = getConnection();
- QWebNetworkJob *job = connection[c].current;
+ QWebNetworkJob* job = connection[c].current;
DEBUG() << "WebCoreHttp::slotResponseHeaderReceived connection=" << c;
DEBUG() << resp.toString();
@@ -1125,13 +1178,13 @@ void WebCoreHttp::onResponseHeaderReceived(const QHttpResponseHeader &resp)
void WebCoreHttp::onReadyRead()
{
- QHttp *http = qobject_cast<QHttp*>(sender());
- if (http->currentId() == 0) {
+ QHttp* http = qobject_cast<QHttp*>(sender());
+ if (!http->currentId()) {
qDebug() << "ERROR! Invalid job id. Why?"; // foxnews.com triggers this
return;
}
int c = getConnection();
- QWebNetworkJob *job = connection[c].current;
+ QWebNetworkJob* job = connection[c].current;
Q_ASSERT(http == connection[c].http);
//DEBUG() << "WebCoreHttp::slotReadyRead connection=" << c;
@@ -1144,17 +1197,16 @@ void WebCoreHttp::onReadyRead()
void WebCoreHttp::onRequestFinished(int id, bool error)
{
int c = getConnection();
- if (connection[c].id != id) {
+ if (connection[c].id != id)
return;
- }
- QWebNetworkJob *job = connection[c].current;
+ QWebNetworkJob* job = connection[c].current;
if (!job) {
scheduleNextRequest();
return;
}
- QHttp *http = connection[c].http;
+ QHttp* http = connection[c].http;
DEBUG() << "WebCoreHttp::slotFinished connection=" << c << error << job;
if (error) {
DEBUG() << " error: " << http->errorString();
@@ -1225,7 +1277,7 @@ void WebCoreHttp::onSslErrors(const QList<QSslError>& errors)
}
}
-void WebCoreHttp::onAuthenticationRequired(const QString& hostname, quint16 port, QAuthenticator *auth)
+void WebCoreHttp::onAuthenticationRequired(const QString& hostname, quint16 port, QAuthenticator* auth)
{
int c = getConnection();
QWebNetworkJob *job = connection[c].current;
@@ -1236,7 +1288,7 @@ void WebCoreHttp::onAuthenticationRequired(const QString& hostname, quint16 port
}
}
-void WebCoreHttp::onProxyAuthenticationRequired(const QNetworkProxy& proxy, QAuthenticator *auth)
+void WebCoreHttp::onProxyAuthenticationRequired(const QNetworkProxy& proxy, QAuthenticator* auth)
{
int c = getConnection();
QWebNetworkJob *job = connection[c].current;
diff --git a/WebKit/qt/Api/qwebnetworkinterface.h b/WebKit/qt/Api/qwebnetworkinterface.h
index b603e37..7f96155 100644
--- a/WebKit/qt/Api/qwebnetworkinterface.h
+++ b/WebKit/qt/Api/qwebnetworkinterface.h
@@ -44,8 +44,7 @@ namespace WebCore {
}
struct QWebNetworkRequestPrivate;
-class QWEBKIT_EXPORT QWebNetworkRequest
-{
+class QWEBKIT_EXPORT QWebNetworkRequest {
public:
enum Method {
Get,
@@ -82,8 +81,7 @@ private:
friend class QWebObjectPluginConnector;
};
-class QWEBKIT_EXPORT QWebNetworkJob
-{
+class QWEBKIT_EXPORT QWebNetworkJob {
public:
QUrl url() const;
@@ -102,7 +100,7 @@ public:
bool deref();
QWebNetworkInterface *networkInterface() const;
-
+
QWebFrame *frame() const;
protected:
@@ -130,8 +128,7 @@ private:
class QWebNetworkInterfacePrivate;
-class QWEBKIT_EXPORT QWebNetworkInterface : public QObject
-{
+class QWEBKIT_EXPORT QWebNetworkInterface : public QObject {
Q_OBJECT
public:
QWebNetworkInterface(QObject *parent = 0);
@@ -147,19 +144,10 @@ protected:
void started(QWebNetworkJob*);
void data(QWebNetworkJob*, const QByteArray &data);
void finished(QWebNetworkJob*, int errorCode);
-
+
signals:
- /**
- * Signal is emitted when an SSL error occurs.
- */
void sslErrors(QWebFrame *frame, const QUrl& url, const QList<QSslError>& errors, bool *continueAnyway);
- /**
- * Signal is emitted when network authentication is required.
- */
void authenticate(QWebFrame *frame, const QUrl& url, const QString& hostname, quint16 port, QAuthenticator *auth);
- /**
- * Signal is emitted when proxy authentication is required.
- */
void authenticateProxy(QWebFrame *frame, const QUrl& url, const QNetworkProxy& proxy, QAuthenticator *auth);
private:
diff --git a/WebKit/qt/Api/qwebnetworkinterface_p.h b/WebKit/qt/Api/qwebnetworkinterface_p.h
index 56e8617..aec104b 100644
--- a/WebKit/qt/Api/qwebnetworkinterface_p.h
+++ b/WebKit/qt/Api/qwebnetworkinterface_p.h
@@ -36,8 +36,7 @@ namespace WebCore {
class ResourceHandle;
}
-struct QWebNetworkRequestPrivate
-{
+struct QWebNetworkRequestPrivate {
QUrl url;
QHttpRequestHeader httpHeader;
QByteArray postData;
@@ -47,8 +46,7 @@ struct QWebNetworkRequestPrivate
void setURL(const QUrl &u);
};
-class QWebNetworkJobPrivate
-{
+class QWebNetworkJobPrivate {
public:
QWebNetworkJobPrivate()
: ref(1)
@@ -70,8 +68,7 @@ public:
QString errorString;
};
-class QWebNetworkManager : public QObject
-{
+class QWebNetworkManager : public QObject {
Q_OBJECT
public:
enum JobMode {
@@ -162,18 +159,17 @@ namespace WebCore {
int port;
};
- class WebCoreHttp : public QObject
- {
+ class WebCoreHttp : public QObject {
Q_OBJECT
public:
- WebCoreHttp(QObject *parent, const HostInfo&);
+ WebCoreHttp(QObject* parent, const HostInfo&);
~WebCoreHttp();
void request(QWebNetworkJob* resource);
void cancel(QWebNetworkJob*);
signals:
- void connectionClosed(const WebCore::HostInfo &);
+ void connectionClosed(const WebCore::HostInfo&);
private slots:
void onResponseHeaderReceived(const QHttpResponseHeader& resp);
@@ -182,8 +178,8 @@ namespace WebCore {
void onDone(bool);
void onStateChanged(int);
void onSslErrors(const QList<QSslError>&);
- void onAuthenticationRequired(const QString& hostname, quint16 port, QAuthenticator *);
- void onProxyAuthenticationRequired(const QNetworkProxy& proxy, QAuthenticator *);
+ void onAuthenticationRequired(const QString& hostname, quint16 port, QAuthenticator*);
+ void onProxyAuthenticationRequired(const QNetworkProxy& proxy, QAuthenticator*);
void scheduleNextRequest();
@@ -192,11 +188,11 @@ namespace WebCore {
public:
HostInfo info;
private:
- QList<QWebNetworkJob *> m_pendingRequests;
+ QList<QWebNetworkJob*> m_pendingRequests;
struct HttpConnection {
HttpConnection() : http(0), current(0), id(-1) {}
- QHttp *http;
- QWebNetworkJob *current;
+ QHttp* http;
+ QWebNetworkJob* current;
int id; // the QHttp id
};
HttpConnection connection[2];
@@ -205,13 +201,12 @@ namespace WebCore {
}
-class QWebNetworkInterfacePrivate
-{
+class QWebNetworkInterfacePrivate {
public:
- void sendFileData(QWebNetworkJob* job, int statusCode, const QByteArray &data);
+ void sendFileData(QWebNetworkJob* job, int statusCode, const QByteArray& data);
void parseDataUrl(QWebNetworkJob* job);
- QWebNetworkInterface *q;
+ QWebNetworkInterface* q;
};
#endif
diff --git a/WebKit/qt/Api/qwebpage.cpp b/WebKit/qt/Api/qwebpage.cpp
index ed94489..8e40339 100644
--- a/WebKit/qt/Api/qwebpage.cpp
+++ b/WebKit/qt/Api/qwebpage.cpp
@@ -28,12 +28,15 @@
#include "qwebhistory.h"
#include "qwebhistory_p.h"
#include "qwebsettings.h"
+#include "qwebkitversion.h"
#include "Frame.h"
#include "FrameTree.h"
#include "FrameLoader.h"
#include "FrameLoaderClientQt.h"
#include "FrameView.h"
+#include "FormState.h"
+#include "ApplicationCacheStorage.h"
#include "ChromeClientQt.h"
#include "ContextMenu.h"
#include "ContextMenuClientQt.h"
@@ -42,9 +45,9 @@
#include "DragController.h"
#include "DragData.h"
#include "EditorClientQt.h"
+#include "SecurityOrigin.h"
#include "Settings.h"
#include "Page.h"
-#include "PageGroup.h"
#include "Pasteboard.h"
#include "FrameLoader.h"
#include "FrameLoadRequest.h"
@@ -58,9 +61,11 @@
#include "Scrollbar.h"
#include "PlatformKeyboardEvent.h"
#include "PlatformWheelEvent.h"
+#include "PluginDatabase.h"
#include "ProgressTracker.h"
#include "RefPtr.h"
#include "HashMap.h"
+#include "HTMLFormElement.h"
#include "HitTestResult.h"
#include "WindowFeatures.h"
#include "LocalizedStrings.h"
@@ -71,6 +76,7 @@
#include <QBasicTimer>
#include <QBitArray>
#include <QDebug>
+#include <QDesktopServices>
#include <QDragEnterEvent>
#include <QDragLeaveEvent>
#include <QDragMoveEvent>
@@ -97,6 +103,18 @@
using namespace WebCore;
+void QWEBKIT_EXPORT qt_drt_overwritePluginDirectories()
+{
+ PluginDatabase* db = PluginDatabase::installedPlugins(/* populate */ false);
+
+ Vector<String> paths;
+ String qtPath(getenv("QTWEBKIT_PLUGIN_PATH"));
+ qtPath.split(UChar(':'), /* allowEmptyEntries */ false, paths);
+
+ db->setPluginDirectories(paths);
+ db->refresh();
+}
+
bool QWebPagePrivate::drtRun = false;
void QWEBKIT_EXPORT qt_drt_run(bool b)
{
@@ -114,29 +132,29 @@ QString QWEBKIT_EXPORT qt_webpage_groupName(QWebPage* page)
}
// Lookup table mapping QWebPage::WebActions to the associated Editor commands
-static const char* editorCommandWebActions[] =
+static const char* editorCommandWebActions[] =
{
0, // OpenLink,
0, // OpenLinkInNewWindow,
0, // OpenFrameInNewWindow,
-
+
0, // DownloadLinkToDisk,
0, // CopyLinkToClipboard,
-
+
0, // OpenImageInNewWindow,
0, // DownloadImageToDisk,
0, // CopyImageToClipboard,
-
+
0, // Back,
0, // Forward,
0, // Stop,
0, // Reload,
-
+
"Cut", // Cut,
"Copy", // Copy,
"Paste", // Paste,
-
+
"Undo", // Undo,
"Redo", // Redo,
"MoveForward", // MoveToNextChar,
@@ -165,21 +183,37 @@ static const char* editorCommandWebActions[] =
"MoveToEndOfDocumentAndModifySelection", // SelectEndOfDocument,
"DeleteWordBackward", // DeleteStartOfWord,
"DeleteWordForward", // DeleteEndOfWord,
-
+
0, // SetTextDirectionDefault,
0, // SetTextDirectionLeftToRight,
0, // SetTextDirectionRightToLeft,
-
+
"ToggleBold", // ToggleBold,
"ToggleItalic", // ToggleItalic,
"ToggleUnderline", // ToggleUnderline,
-
+
0, // InspectElement,
"InsertNewline", // InsertParagraphSeparator
"InsertLineBreak", // InsertLineSeparator
"SelectAll", // SelectAll
+ 0, // ReloadAndBypassCache,
+
+ "PasteAndMatchStyle", // PasteAndMatchStyle
+ "RemoveFormat", // RemoveFormat
+ "Strikethrough", // ToggleStrikethrough,
+ "Subscript", // ToggleSubscript
+ "Superscript", // ToggleSuperscript
+ "InsertUnorderedList", // InsertUnorderedList
+ "InsertOrderedList", // InsertOrderedList
+ "Indent", // Indent
+ "Outdent", // Outdent,
+
+ "AlignCenter", // AlignCenter,
+ "AlignJustified", // AlignJustified,
+ "AlignLeft", // AlignLeft,
+ "AlignRight", // AlignRight,
0 // WebActionCount
};
@@ -189,7 +223,6 @@ const char* QWebPagePrivate::editorCommandForWebActions(QWebPage::WebAction acti
{
if ((action > QWebPage::NoWebAction) && (action < int(sizeof(editorCommandWebActions) / sizeof(const char*))))
return editorCommandWebActions[action];
-
return 0;
}
@@ -232,15 +265,39 @@ static inline Qt::DropAction dragOpToDropAction(unsigned actions)
return result;
}
+static void initializeApplicationCachePathIfNecessary()
+{
+#if ENABLE(OFFLINE_WEB_APPLICATIONS)
+ static bool initialized = false;
+
+ if (initialized)
+ return;
+
+ // Determine the path for HTML5 Application Cache DB
+ QString appCachePath;
+#if QT_VERSION >= 0x040500
+ appCachePath = QDesktopServices::storageLocation(QDesktopServices::CacheLocation);
+#else
+ appCachePath = QDesktopServices::storageLocation(QDesktopServices::DataLocation);
+#endif
+
+ if (appCachePath.isEmpty())
+ appCachePath = QDir::homePath() + QLatin1String("/.") + QCoreApplication::applicationName();
+
+ WebCore::cacheStorage().setCacheDirectory(appCachePath);
+ initialized = true;
+#endif
+}
+
QWebPagePrivate::QWebPagePrivate(QWebPage *qq)
: q(qq)
, view(0)
- , viewportSize(QSize(0,0))
+ , viewportSize(QSize(0, 0))
{
WebCore::InitializeLoggingChannelsIfNecessary();
- WebCore::PageGroup::setShouldTrackVisitedLinks(true);
JSC::initializeThreading();
WebCore::FrameLoader::setLocalLoadPolicy(WebCore::FrameLoader::AllowLocalLoadsForLocalAndSubstituteData);
+ initializeApplicationCachePathIfNecessary();
chromeClient = new ChromeClientQt(q);
contextMenuClient = new ContextMenuClientQt();
@@ -309,11 +366,7 @@ bool QWebPagePrivate::acceptNavigationRequest(QWebFrame *frame, const QNetworkRe
void QWebPagePrivate::createMainFrame()
{
if (!mainFrame) {
- QWebFrameData frameData;
- frameData.ownerElement = 0;
- frameData.allowsScrolling = true;
- frameData.marginWidth = 0;
- frameData.marginHeight = 0;
+ QWebFrameData frameData(page);
mainFrame = new QWebFrame(q, &frameData);
emit q->frameCreated(mainFrame);
@@ -393,9 +446,8 @@ QMenu *QWebPagePrivate::createContextMenu(const WebCore::ContextMenu *webcoreMen
if (anyEnabledAction) {
subMenu->setTitle(item.title());
menu->addAction(subMenu->menuAction());
- } else {
+ } else
delete subMenu;
- }
break;
}
}
@@ -404,23 +456,6 @@ QMenu *QWebPagePrivate::createContextMenu(const WebCore::ContextMenu *webcoreMen
}
#endif // QT_NO_CONTEXTMENU
-QWebFrame *QWebPagePrivate::frameAt(const QPoint &pos) const
-{
- QWebFrame *frame = mainFrame;
-
-redo:
- QList<QWebFrame*> children = frame->childFrames();
- for (int i = 0; i < children.size(); ++i) {
- if (children.at(i)->geometry().contains(pos)) {
- frame = children.at(i);
- goto redo;
- }
- }
- if (frame->geometry().contains(pos))
- return frame;
- return 0;
-}
-
void QWebPagePrivate::_q_webActionTriggered(bool checked)
{
QAction *a = qobject_cast<QAction *>(q->sender());
@@ -461,6 +496,7 @@ void QWebPagePrivate::updateAction(QWebPage::WebAction action)
enabled = loader->isLoading();
break;
case QWebPage::Reload:
+ case QWebPage::ReloadAndBypassCache:
enabled = !loader->isLoading();
break;
#ifndef QT_NO_UNDOSTACK
@@ -506,6 +542,7 @@ void QWebPagePrivate::updateNavigationActions()
updateAction(QWebPage::Forward);
updateAction(QWebPage::Stop);
updateAction(QWebPage::Reload);
+ updateAction(QWebPage::ReloadAndBypassCache);
}
void QWebPagePrivate::updateEditorActions()
@@ -547,6 +584,19 @@ void QWebPagePrivate::updateEditorActions()
updateAction(QWebPage::ToggleUnderline);
updateAction(QWebPage::InsertParagraphSeparator);
updateAction(QWebPage::InsertLineSeparator);
+ updateAction(QWebPage::PasteAndMatchStyle);
+ updateAction(QWebPage::RemoveFormat);
+ updateAction(QWebPage::ToggleStrikethrough);
+ updateAction(QWebPage::ToggleSubscript);
+ updateAction(QWebPage::ToggleSuperscript);
+ updateAction(QWebPage::InsertUnorderedList);
+ updateAction(QWebPage::InsertOrderedList);
+ updateAction(QWebPage::Indent);
+ updateAction(QWebPage::Outdent);
+ updateAction(QWebPage::AlignCenter);
+ updateAction(QWebPage::AlignJustified);
+ updateAction(QWebPage::AlignLeft);
+ updateAction(QWebPage::AlignRight);
}
void QWebPagePrivate::timerEvent(QTimerEvent *ev)
@@ -639,12 +689,12 @@ void QWebPagePrivate::mouseReleaseEvent(QMouseEvent *ev)
Pasteboard::generalPasteboard()->setSelectionMode(true);
WebCore::Frame* focusFrame = page->focusController()->focusedOrMainFrame();
if (ev->button() == Qt::LeftButton) {
- if(focusFrame && (focusFrame->editor()->canCopy() || focusFrame->editor()->canDHTMLCopy())) {
+ if (focusFrame && (focusFrame->editor()->canCopy() || focusFrame->editor()->canDHTMLCopy())) {
focusFrame->editor()->copy();
ev->setAccepted(true);
}
} else if (ev->button() == Qt::MidButton) {
- if(focusFrame && (focusFrame->editor()->canPaste() || focusFrame->editor()->canDHTMLPaste())) {
+ if (focusFrame && (focusFrame->editor()->canPaste() || focusFrame->editor()->canDHTMLPaste())) {
focusFrame->editor()->paste();
ev->setAccepted(true);
}
@@ -767,13 +817,26 @@ void QWebPagePrivate::keyPressEvent(QKeyEvent *ev)
defaultFont = view->font();
QFontMetrics fm(defaultFont);
int fontHeight = fm.height();
- if (!handleScrolling(ev)) {
+ if (!handleScrolling(ev, frame)) {
switch (ev->key()) {
+ case Qt::Key_Back:
+ q->triggerAction(QWebPage::Back);
+ break;
+ case Qt::Key_Forward:
+ q->triggerAction(QWebPage::Forward);
+ break;
+ case Qt::Key_Stop:
+ q->triggerAction(QWebPage::Stop);
+ break;
+ case Qt::Key_Refresh:
+ q->triggerAction(QWebPage::Reload);
+ break;
case Qt::Key_Backspace:
if (ev->modifiers() == Qt::ShiftModifier)
q->triggerAction(QWebPage::Forward);
else
q->triggerAction(QWebPage::Back);
+ break;
default:
handled = false;
break;
@@ -801,11 +864,10 @@ void QWebPagePrivate::focusInEvent(QFocusEvent *ev)
FocusController *focusController = page->focusController();
Frame *frame = focusController->focusedFrame();
focusController->setActive(true);
- if (frame) {
- frame->selection()->setFocused(true);
- } else {
+ if (frame)
+ focusController->setFocused(true);
+ else
focusController->setFocusedFrame(QWebFramePrivate::core(mainFrame));
- }
}
void QWebPagePrivate::focusOutEvent(QFocusEvent *ev)
@@ -815,10 +877,7 @@ void QWebPagePrivate::focusOutEvent(QFocusEvent *ev)
// focusInEvent() we can re-activate the frame.
FocusController *focusController = page->focusController();
focusController->setActive(false);
- Frame *frame = focusController->focusedFrame();
- if (frame) {
- frame->selection()->setFocused(false);
- }
+ focusController->setFocused(false);
}
void QWebPagePrivate::dragEnterEvent(QDragEnterEvent *ev)
@@ -908,14 +967,14 @@ void QWebPagePrivate::inputMethodEvent(QInputMethodEvent *ev)
return;
}
- if (!ev->preeditString().isEmpty()) {
+ if (!ev->commitString().isEmpty())
+ editor->confirmComposition(ev->commitString());
+ else {
QString preedit = ev->preeditString();
// ### FIXME: use the provided QTextCharFormat (use color at least)
Vector<CompositionUnderline> underlines;
- underlines.append(CompositionUnderline(0, preedit.length(), Color(0,0,0), false));
+ underlines.append(CompositionUnderline(0, preedit.length(), Color(0, 0, 0), false));
editor->setComposition(preedit, underlines, preedit.length(), 0);
- } else if (!ev->commitString().isEmpty()) {
- editor->confirmComposition(ev->commitString());
}
ev->accept();
}
@@ -950,14 +1009,13 @@ void QWebPagePrivate::shortcutOverrideEvent(QKeyEvent* event)
}
}
#ifndef QT_NO_SHORTCUT
- else if (editorActionForKeyEvent(event) != QWebPage::NoWebAction) {
+ else if (editorActionForKeyEvent(event) != QWebPage::NoWebAction)
event->accept();
- }
#endif
}
}
-bool QWebPagePrivate::handleScrolling(QKeyEvent *ev)
+bool QWebPagePrivate::handleScrolling(QKeyEvent *ev, Frame *frame)
{
ScrollDirection direction;
ScrollGranularity granularity;
@@ -1004,10 +1062,7 @@ bool QWebPagePrivate::handleScrolling(QKeyEvent *ev)
}
}
- if (!mainFrame->d->frame->eventHandler()->scrollOverflow(direction, granularity))
- mainFrame->d->frame->view()->scroll(direction, granularity);
-
- return true;
+ return frame->eventHandler()->scrollRecursively(direction, granularity);
}
/*!
@@ -1021,12 +1076,11 @@ bool QWebPagePrivate::handleScrolling(QKeyEvent *ev)
*/
QVariant QWebPage::inputMethodQuery(Qt::InputMethodQuery property) const
{
- switch(property) {
+ switch (property) {
case Qt::ImMicroFocus: {
Frame *frame = d->page->focusController()->focusedFrame();
- if (frame) {
+ if (frame)
return QVariant(frame->selection()->absoluteCaretBounds());
- }
return QVariant();
}
case Qt::ImFont: {
@@ -1039,9 +1093,8 @@ QVariant QWebPage::inputMethodQuery(Qt::InputMethodQuery property) const
Frame *frame = d->page->focusController()->focusedFrame();
if (frame) {
VisibleSelection selection = frame->selection()->selection();
- if (selection.isCaret()) {
- return QVariant(selection.start().m_offset);
- }
+ if (selection.isCaret())
+ return QVariant(selection.start().deprecatedEditingOffset());
}
return QVariant();
}
@@ -1049,9 +1102,8 @@ QVariant QWebPage::inputMethodQuery(Qt::InputMethodQuery property) const
Frame *frame = d->page->focusController()->focusedFrame();
if (frame) {
Document *document = frame->document();
- if (document->focusedNode()) {
+ if (document->focusedNode())
return QVariant(document->focusedNode()->nodeValue());
- }
}
return QVariant();
}
@@ -1073,6 +1125,7 @@ QVariant QWebPage::inputMethodQuery(Qt::InputMethodQuery property) const
changes the behaviour to a case sensitive find operation.
\value FindWrapsAroundDocument Makes findText() restart from the beginning of the document if the end
was reached and the text was not found.
+ \value HighlightAllOccurrences Highlights all existing occurrences of a specific string.
*/
/*!
@@ -1107,7 +1160,7 @@ QVariant QWebPage::inputMethodQuery(Qt::InputMethodQuery property) const
This enum describes the types of action which can be performed on the web page.
Actions only have an effect when they are applicable. The availability of
- actions can be be determined by checking \l{QAction::}{enabled()} on the
+ actions can be be determined by checking \l{QAction::}{isEnabled()} on the
action returned by \l{QWebPage::}{action()}.
One method of enabling the text editing, cursor movement, and text selection actions
@@ -1126,6 +1179,7 @@ QVariant QWebPage::inputMethodQuery(Qt::InputMethodQuery property) const
\value Forward Navigate forward in the history of navigated links.
\value Stop Stop loading the current page.
\value Reload Reload the current page.
+ \value ReloadAndBypassCache Reload the current page, but do not use any local cache. (Added in Qt 4.6)
\value Cut Cut the content currently selected into the clipboard.
\value Copy Copy the content currently selected into the clipboard.
\value Paste Paste content from the clipboard.
@@ -1167,6 +1221,21 @@ QVariant QWebPage::inputMethodQuery(Qt::InputMethodQuery property) const
\value InsertParagraphSeparator Insert a new paragraph.
\value InsertLineSeparator Insert a new line.
\value SelectAll Selects all content.
+ \value PasteAndMatchStyle Paste content from the clipboard with current style.
+ \value RemoveFormat Removes formatting and style.
+ \value ToggleStrikethrough Toggle the formatting between strikethrough and normal style.
+ \value ToggleSubscript Toggle the formatting between subscript and baseline.
+ \value ToggleSuperscript Toggle the formatting between supercript and baseline.
+ \value InsertUnorderedList Toggles the selection between an ordered list and a normal block.
+ \value InsertOrderedList Toggles the selection between an ordered list and a normal block.
+ \value Indent Increases the indentation of the currently selected format block by one increment.
+ \value Outdent Decreases the indentation of the currently selected format block by one increment.
+ \value AlignCenter Applies center alignment to content.
+ \value AlignJustified Applies full justification to content.
+ \value AlignLeft Applies left justification to content.
+ \value AlignRight Applies right justification to content.
+
+
\omitvalue WebActionCount
*/
@@ -1210,18 +1279,18 @@ QVariant QWebPage::inputMethodQuery(Qt::InputMethodQuery property) const
Suppose we have a \c Thumbnail class as follows:
- \snippet doc/src/snippets/webkit/webpage/main.cpp 0
+ \snippet webkitsnippets/webpage/main.cpp 0
The \c Thumbnail's constructor takes in a \a url. We connect our QWebPage
object's \l{QWebPage::}{loadFinished()} signal to our private slot,
\c render().
- \snippet doc/src/snippets/webkit/webpage/main.cpp 1
+ \snippet webkitsnippets/webpage/main.cpp 1
The \c render() function shows how we can paint a thumbnail using a
QWebPage object.
- \snippet doc/src/snippets/webkit/webpage/main.cpp 2
+ \snippet webkitsnippets/webpage/main.cpp 2
We begin by setting the \l{QWebPage::viewportSize()}{viewportSize} and
then we instantiate a QImage object, \c image, with the same size as our
@@ -1282,6 +1351,23 @@ QWebFrame *QWebPage::currentFrame() const
return static_cast<WebCore::FrameLoaderClientQt *>(d->page->focusController()->focusedOrMainFrame()->loader()->client())->webFrame();
}
+
+/*!
+ \since 4.6
+
+ Returns the frame at the given point \a pos.
+
+ \sa mainFrame(), currentFrame()
+*/
+QWebFrame* QWebPage::frameAt(const QPoint& pos) const
+{
+ QWebFrame* webFrame = mainFrame();
+ if (!webFrame->geometry().contains(pos))
+ return 0;
+ QWebHitTestResult hitTestResult = webFrame->hitTestContent(pos);
+ return hitTestResult.frame();
+}
+
/*!
Returns a pointer to the view's history of navigated web pages.
*/
@@ -1367,14 +1453,35 @@ bool QWebPage::javaScriptPrompt(QWebFrame *frame, const QString& msg, const QStr
bool ok = false;
#ifndef QT_NO_INPUTDIALOG
QString x = QInputDialog::getText(d->view, tr("JavaScript Prompt - %1").arg(mainFrame()->url().host()), msg, QLineEdit::Normal, defaultValue, &ok);
- if (ok && result) {
+ if (ok && result)
*result = x;
- }
#endif
return ok;
}
/*!
+ \fn bool QWebPage::shouldInterruptJavaScript()
+ \since 4.6
+ This function is called when a JavaScript program is running for a long period of time.
+
+ If the user wanted to stop the JavaScript the implementation should return true; otherwise false.
+
+ The default implementation executes the query using QMessageBox::information with QMessageBox::Yes and QMessageBox::No buttons.
+
+ \warning Because of binary compatibility constraints, this function is not virtual. If you want to
+ provide your own implementation in a QWebPage subclass, reimplement the shouldInterruptJavaScript()
+ slot in your subclass instead. QtWebKit will dynamically detect the slot and call it.
+*/
+bool QWebPage::shouldInterruptJavaScript()
+{
+#ifdef QT_NO_MESSAGEBOX
+ return false;
+#else
+ return QMessageBox::Yes == QMessageBox::information(d->view, tr("JavaScript Problem - %1").arg(mainFrame()->url().host()), tr("The script on this page appears to have a problem. Do you want to stop the script?"), QMessageBox::Yes, QMessageBox::No);
+#endif
+}
+
+/*!
This function is called whenever WebKit wants to create a new window of the given \a type, for
example when a JavaScript program requests to open a document in a new window.
@@ -1448,10 +1555,9 @@ void QWebPage::triggerAction(WebAction action, bool checked)
case OpenLink:
if (QWebFrame *targetFrame = d->hitTestResult.linkTargetFrame()) {
WTF::RefPtr<WebCore::Frame> wcFrame = targetFrame->d->frame;
- targetFrame->d->frame->loader()->loadFrameRequestWithFormAndValues(frameLoadRequest(d->hitTestResult.linkUrl(), wcFrame.get()),
- /*lockHistory*/ false, /*lockBackForwardList*/ false, /*event*/ 0,
- /*HTMLFormElement*/ 0, /*formValues*/
- WTF::HashMap<String, String>());
+ targetFrame->d->frame->loader()->loadFrameRequest(frameLoadRequest(d->hitTestResult.linkUrl(), wcFrame.get()),
+ /*lockHistory*/ false, /*lockBackForwardList*/ false, /*event*/ 0,
+ /*FormState*/ 0);
break;
}
// fall through
@@ -1499,7 +1605,10 @@ void QWebPage::triggerAction(WebAction action, bool checked)
mainFrame()->d->frame->loader()->stopForUserCancel();
break;
case Reload:
- mainFrame()->d->frame->loader()->reload();
+ mainFrame()->d->frame->loader()->reload(/*endtoendreload*/false);
+ break;
+ case ReloadAndBypassCache:
+ mainFrame()->d->frame->loader()->reload(/*endtoendreload*/true);
break;
case SetTextDirectionDefault:
editor->setBaseWritingDirection(NaturalWritingDirection);
@@ -1556,16 +1665,20 @@ void QWebPage::setViewportSize(const QSize &size) const
}
}
-QSize QWebPage::fixedLayoutSize() const
+QSize QWebPage::fixedContentsSize() const
{
- if (d->mainFrame && d->mainFrame->d->frame->view())
- return d->mainFrame->d->frame->view()->fixedLayoutSize();
+ QWebFrame* frame = d->mainFrame;
+ if (frame) {
+ WebCore::FrameView* view = frame->d->frame->view();
+ if (view && view->useFixedLayout())
+ return d->mainFrame->d->frame->view()->fixedLayoutSize();
+ }
return d->fixedLayoutSize;
}
/*!
- \property QWebPage::fixedLayoutSize
+ \property QWebPage::fixedContentsSize
\since 4.6
\brief the size of the fixed layout
@@ -1573,37 +1686,22 @@ QSize QWebPage::fixedLayoutSize() const
1024x768 for example then webkit will layout the page as if the viewport were that size
rather than something different.
*/
-void QWebPage::setFixedLayoutSize(const QSize &size) const
+void QWebPage::setFixedContentsSize(const QSize &size) const
{
d->fixedLayoutSize = size;
QWebFrame *frame = mainFrame();
if (frame->d->frame && frame->d->frame->view()) {
WebCore::FrameView* view = frame->d->frame->view();
- view->setFixedLayoutSize(size);
- view->forceLayout();
- }
-}
-
-bool QWebPage::useFixedLayout() const
-{
- return d->useFixedLayout;
-}
-/*!
- \property QWebPage::usedFixedLayout
- \since 4.6
- \brief whether to use a fixed layout size
-*/
-void QWebPage::setUseFixedLayout(bool useFixedLayout)
-{
- d->useFixedLayout = useFixedLayout;
-
- QWebFrame *frame = mainFrame();
- if (frame->d->frame && frame->d->frame->view()) {
- WebCore::FrameView* view = frame->d->frame->view();
- view->setUseFixedLayout(useFixedLayout);
- view->forceLayout();
+ if (size.isValid()) {
+ view->setUseFixedLayout(true);
+ view->setFixedLayoutSize(size);
+ view->forceLayout();
+ } else if (view->useFixedLayout()) {
+ view->setUseFixedLayout(false);
+ view->forceLayout();
+ }
}
}
@@ -1633,7 +1731,7 @@ bool QWebPage::acceptNavigationRequest(QWebFrame *frame, const QWebNetworkReques
return true;
case DelegateExternalLinks:
- if (WebCore::FrameLoader::shouldTreatURLSchemeAsLocal(request.url().scheme()))
+ if (WebCore::SecurityOrigin::shouldTreatURLSchemeAsLocal(request.url().scheme()))
return true;
emit linkClicked(request.url());
return false;
@@ -1873,6 +1971,52 @@ QAction *QWebPage::action(WebAction action) const
text = tr("Insert a new line");
break;
+ case PasteAndMatchStyle:
+ text = tr("Paste and Match Style");
+ break;
+ case RemoveFormat:
+ text = tr("Remove formatting");
+ break;
+
+ case ToggleStrikethrough:
+ text = tr("Strikethrough");
+ checkable = true;
+ break;
+ case ToggleSubscript:
+ text = tr("Subscript");
+ checkable = true;
+ break;
+ case ToggleSuperscript:
+ text = tr("Superscript");
+ checkable = true;
+ break;
+ case InsertUnorderedList:
+ text = tr("Insert Bulleted List");
+ checkable = true;
+ break;
+ case InsertOrderedList:
+ text = tr("Insert Numbered List");
+ checkable = true;
+ break;
+ case Indent:
+ text = tr("Indent");
+ break;
+ case Outdent:
+ text = tr("Outdent");
+ break;
+ case AlignCenter:
+ text = tr("Center");
+ break;
+ case AlignJustified:
+ text = tr("Justify");
+ break;
+ case AlignLeft:
+ text = tr("Align Left");
+ break;
+ case AlignRight:
+ text = tr("Align Right");
+ break;
+
case NoWebAction:
return 0;
}
@@ -2035,9 +2179,8 @@ void QWebPage::setContentEditable(bool editable)
frame->applyEditingStyleToBodyElement();
// FIXME: mac port calls this if there is no selectedDOMRange
//frame->setSelectionFromNone();
- } else {
+ } else
frame->removeEditingStyleFromBodyElement();
- }
}
d->updateEditorActions();
@@ -2051,10 +2194,12 @@ bool QWebPage::isContentEditable() const
/*!
\property QWebPage::forwardUnsupportedContent
- \brief whether QWebPage should forward unsupported content through the
- unsupportedContent signal
+ \brief whether QWebPage should forward unsupported content
+
+ If enabled, the unsupportedContent() signal is emitted with a network reply that
+ can be used to read the content.
- If disabled the download of such content is aborted immediately.
+ If disabled, the download of such content is aborted immediately.
By default unsupported content is not forwarded.
*/
@@ -2101,11 +2246,10 @@ bool QWebPage::swallowContextMenuEvent(QContextMenuEvent *event)
{
d->page->contextMenuController()->clearContextMenu();
- if (QWebFrame* webFrame = d->frameAt(event->pos())) {
+ if (QWebFrame* webFrame = frameAt(event->pos())) {
Frame* frame = QWebFramePrivate::core(webFrame);
- if (Scrollbar* scrollbar = frame->view()->scrollbarUnderMouse(PlatformMouseEvent(event, 1))) {
+ if (Scrollbar* scrollbar = frame->view()->scrollbarAtPoint(PlatformMouseEvent(event, 1).pos()))
return scrollbar->contextMenu(PlatformMouseEvent(event, 1));
- }
}
WebCore::Frame* focusedFrame = d->page->focusController()->focusedOrMainFrame();
@@ -2138,7 +2282,10 @@ void QWebPage::updatePositionDependentActions(const QPoint &pos)
WebCore::Frame* focusedFrame = d->page->focusController()->focusedOrMainFrame();
HitTestResult result = focusedFrame->eventHandler()->hitTestResultAtPoint(focusedFrame->view()->windowToContents(pos), /*allowShadowContent*/ false);
- d->hitTestResult = QWebHitTestResult(new QWebHitTestResultPrivate(result));
+ if (result.scrollbar())
+ d->hitTestResult = QWebHitTestResult();
+ else
+ d->hitTestResult = QWebHitTestResult(new QWebHitTestResultPrivate(result));
WebCore::ContextMenu menu(result);
menu.populate();
if (d->page->inspectorController()->enabled())
@@ -2157,9 +2304,8 @@ void QWebPage::updatePositionDependentActions(const QPoint &pos)
originallyEnabledWebActions &= ~visitedWebActions; // Mask out visited actions (they're part of the menu)
for (int i = 0; i < QWebPage::WebActionCount; ++i) {
if (originallyEnabledWebActions.at(i)) {
- if (QAction *a = this->action(QWebPage::WebAction(i))) {
+ if (QAction *a = this->action(QWebPage::WebAction(i)))
a->setEnabled(true);
- }
}
}
@@ -2259,8 +2405,18 @@ bool QWebPage::supportsExtension(Extension extension) const
}
/*!
- Finds the next occurrence of the string, \a subString, in the page, using the given \a options.
- Returns true of \a subString was found and selects the match visually; otherwise returns false.
+ Finds the specified string, \a subString, in the page, using the given \a options.
+
+ If the HighlightAllOccurrences flag is passed, the function will highlight all occurrences
+ that exist in the page. All subsequent calls will extend the highlight, rather than
+ replace it, with occurrences of the new string.
+
+ If the HighlightAllOccurrences flag is not passed, the function will select an occurrence
+ and all subsequent calls will replace the current occurrence with the next one.
+
+ To clear the selection, just pass an empty string.
+
+ Returns true if \a subString was found; otherwise returns false.
*/
bool QWebPage::findText(const QString &subString, FindFlags options)
{
@@ -2268,13 +2424,21 @@ bool QWebPage::findText(const QString &subString, FindFlags options)
if (options & FindCaseSensitively)
caseSensitivity = ::TextCaseSensitive;
- ::FindDirection direction = ::FindDirectionForward;
- if (options & FindBackward)
- direction = ::FindDirectionBackward;
+ if (options & HighlightAllOccurrences) {
+ if (subString.isEmpty()) {
+ d->page->unmarkAllTextMatches();
+ return true;
+ } else
+ return d->page->markAllMatchesForText(subString, caseSensitivity, true, 0);
+ } else {
+ ::FindDirection direction = ::FindDirectionForward;
+ if (options & FindBackward)
+ direction = ::FindDirectionBackward;
- const bool shouldWrap = options & FindWrapsAroundDocument;
+ const bool shouldWrap = options & FindWrapsAroundDocument;
- return d->page->findString(subString, caseSensitivity, direction, shouldWrap);
+ return d->page->findString(subString, caseSensitivity, direction, shouldWrap);
+ }
}
/*!
@@ -2394,7 +2558,7 @@ QWebPluginFactory *QWebPage::pluginFactory() const
The default implementation returns the following value:
- "Mozilla/5.0 (%Platform%; %Security%; %Subplatform%; %Locale%) AppleWebKit/%WebKitVersion% (KHTML, like Gecko, Safari/419.3) %AppVersion"
+ "Mozilla/5.0 (%Platform%; %Security%; %Subplatform%; %Locale%) AppleWebKit/%WebKitVersion% (KHTML, like Gecko) %AppVersion Safari/%WebKitVersion%"
In this string the following values are replaced at run-time:
\list
@@ -2402,7 +2566,7 @@ QWebPluginFactory *QWebPage::pluginFactory() const
\o %Security% expands to U if SSL is enabled, otherwise N. SSL is enabled if QSslSocket::supportsSsl() returns true.
\o %Locale% is replaced with QLocale::name(). The locale is determined from the view of the QWebPage. If no view is set on the QWebPage,
then a default constructed QLocale is used instead.
- \o %WebKitVersion% currently expands to 527+
+ \o %WebKitVersion% is the version of WebKit the application was compiled against.
\o %AppVersion% expands to QCoreApplication::applicationName()/QCoreApplication::applicationVersion() if they're set; otherwise defaulting to Qt and the current Qt version.
\endlist
*/
@@ -2495,14 +2659,18 @@ QString QWebPage::userAgentForUrl(const QUrl& url) const
QChar securityStrength(QLatin1Char('N'));
#if !defined(QT_NO_OPENSSL)
- if (QSslSocket::supportsSsl())
- securityStrength = QLatin1Char('U');
+ // we could check QSslSocket::supportsSsl() here, but this makes
+ // OpenSSL, certificates etc being loaded in all cases were QWebPage
+ // is used. This loading is not needed for non-https.
+ securityStrength = QLatin1Char('U');
+ // this may lead to a false positive: We indicate SSL since it is
+ // compiled in even though supportsSsl() might return false
#endif
ua = ua.arg(securityStrength);
#if defined Q_OS_WIN32
QString ver;
- switch(QSysInfo::WindowsVersion) {
+ switch (QSysInfo::WindowsVersion) {
case QSysInfo::WV_32s:
ver = "Windows 3.1";
break;
@@ -2556,12 +2724,13 @@ QString QWebPage::userAgentForUrl(const QUrl& url) const
ua.append(QLatin1String(") "));
// webkit/qt version
- ua.append(QLatin1String("AppleWebKit/" WEBKIT_VERSION " (KHTML, like Gecko, Safari/419.3) "));
+ ua.append(QString(QLatin1String("AppleWebKit/%1 (KHTML, like Gecko) "))
+ .arg(QString(qWebKitVersion())));
// Application name/version
QString appName = QCoreApplication::applicationName();
if (!appName.isEmpty()) {
- ua.append(QLatin1Char(' ') + appName);
+ ua.append(appName);
#if QT_VERSION >= 0x040400
QString appVer = QCoreApplication::applicationVersion();
if (!appVer.isEmpty())
@@ -2572,11 +2741,16 @@ QString QWebPage::userAgentForUrl(const QUrl& url) const
ua.append(QLatin1String("Qt/"));
ua.append(QLatin1String(qVersion()));
}
+
+ ua.append(QString(QLatin1String(" Safari/%1"))
+ .arg(qWebKitVersion()));
+
return ua;
}
-void QWebPagePrivate::_q_onLoadProgressChanged(int) {
+void QWebPagePrivate::_q_onLoadProgressChanged(int)
+{
m_totalBytes = page->progress()->totalPageAndResourceBytesToLoad();
m_bytesReceived = page->progress()->totalBytesReceived();
}
@@ -2588,7 +2762,8 @@ void QWebPagePrivate::_q_onLoadProgressChanged(int) {
\sa bytesReceived()
*/
-quint64 QWebPage::totalBytes() const {
+quint64 QWebPage::totalBytes() const
+{
return d->m_totalBytes;
}
@@ -2598,7 +2773,8 @@ quint64 QWebPage::totalBytes() const {
\sa totalBytes()
*/
-quint64 QWebPage::bytesReceived() const {
+quint64 QWebPage::bytesReceived() const
+{
return d->m_bytesReceived;
}
diff --git a/WebKit/qt/Api/qwebpage.h b/WebKit/qt/Api/qwebpage.h
index 2853fcc..24741a1 100644
--- a/WebKit/qt/Api/qwebpage.h
+++ b/WebKit/qt/Api/qwebpage.h
@@ -52,21 +52,20 @@ namespace WebCore {
class ChromeClientQt;
class EditorClientQt;
class FrameLoaderClientQt;
- class FrameLoadRequest;
class InspectorClientQt;
class ResourceHandle;
class HitTestResult;
+
+ struct FrameLoadRequest;
}
-class QWEBKIT_EXPORT QWebPage : public QObject
-{
+class QWEBKIT_EXPORT QWebPage : public QObject {
Q_OBJECT
Q_PROPERTY(bool modified READ isModified)
Q_PROPERTY(QString selectedText READ selectedText)
Q_PROPERTY(QSize viewportSize READ viewportSize WRITE setViewportSize)
- Q_PROPERTY(QSize fixedLayoutSize READ fixedLayoutSize WRITE setFixedLayoutSize)
- Q_PROPERTY(bool useFixedLayout READ useFixedLayout WRITE setUseFixedLayout)
+ Q_PROPERTY(QSize fixedContentsSize READ fixedContentsSize WRITE setFixedContentsSize)
Q_PROPERTY(bool forwardUnsupportedContent READ forwardUnsupportedContent WRITE setForwardUnsupportedContent)
Q_PROPERTY(LinkDelegationPolicy linkDelegationPolicy READ linkDelegationPolicy WRITE setLinkDelegationPolicy)
Q_PROPERTY(QPalette palette READ palette WRITE setPalette)
@@ -149,6 +148,23 @@ public:
InsertLineSeparator,
SelectAll,
+ ReloadAndBypassCache,
+
+ PasteAndMatchStyle,
+ RemoveFormat,
+
+ ToggleStrikethrough,
+ ToggleSubscript,
+ ToggleSuperscript,
+ InsertUnorderedList,
+ InsertOrderedList,
+ Indent,
+ Outdent,
+
+ AlignCenter,
+ AlignJustified,
+ AlignLeft,
+ AlignRight,
WebActionCount
};
@@ -156,7 +172,8 @@ public:
enum FindFlag {
FindBackward = 1,
FindCaseSensitively = 2,
- FindWrapsAroundDocument = 4
+ FindWrapsAroundDocument = 4,
+ HighlightAllOccurrences = 8
};
Q_DECLARE_FLAGS(FindFlags, FindFlag)
@@ -176,6 +193,7 @@ public:
QWebFrame *mainFrame() const;
QWebFrame *currentFrame() const;
+ QWebFrame* frameAt(const QPoint& pos) const;
QWebHistory *history() const;
QWebSettings *settings() const;
@@ -217,11 +235,8 @@ public:
QSize viewportSize() const;
void setViewportSize(const QSize &size) const;
- QSize fixedLayoutSize() const;
- void setFixedLayoutSize(const QSize &size) const;
-
- bool useFixedLayout() const;
- void setUseFixedLayout(bool useFixedLayout);
+ QSize fixedContentsSize() const;
+ void setFixedContentsSize(const QSize &size) const;
virtual bool event(QEvent*);
bool focusNextPrevChild(bool next);
@@ -273,6 +288,9 @@ public:
inline QWebPagePrivate* handle() const { return d; }
+public Q_SLOTS:
+ bool shouldInterruptJavaScript();
+
Q_SIGNALS:
void loadStarted();
void loadProgress(int progress);
diff --git a/WebKit/qt/Api/qwebpage_p.h b/WebKit/qt/Api/qwebpage_p.h
index a897bf1..87c624d 100644
--- a/WebKit/qt/Api/qwebpage_p.h
+++ b/WebKit/qt/Api/qwebpage_p.h
@@ -35,8 +35,7 @@
#include <wtf/RefPtr.h>
-namespace WebCore
-{
+namespace WebCore {
class ChromeClientQt;
class ContextMenuClientQt;
class ContextMenuItem;
@@ -45,6 +44,7 @@ namespace WebCore
class Element;
class Node;
class Page;
+ class Frame;
#ifndef QT_NO_CURSOR
class SetCursorEvent : public QEvent {
@@ -65,18 +65,14 @@ class QMenu;
class QBitArray;
QT_END_NAMESPACE
-class QWebPagePrivate
-{
+class QWebPagePrivate {
public:
- QWebPagePrivate(QWebPage *);
+ QWebPagePrivate(QWebPage*);
~QWebPagePrivate();
void createMainFrame();
#ifndef QT_NO_CONTEXTMENU
- QMenu *createContextMenu(const WebCore::ContextMenu *webcoreMenu, const QList<WebCore::ContextMenuItem> *items, QBitArray *visitedWebActions);
+ QMenu* createContextMenu(const WebCore::ContextMenu* webcoreMenu, const QList<WebCore::ContextMenuItem>* items, QBitArray* visitedWebActions);
#endif
-
- QWebFrame *frameAt(const QPoint &pos) const;
-
void _q_onLoadProgressChanged(int);
void _q_webActionTriggered(bool checked);
#ifndef NDEBUG
@@ -113,7 +109,7 @@ public:
void shortcutOverrideEvent(QKeyEvent*);
void leaveEvent(QEvent *);
- bool handleScrolling(QKeyEvent*);
+ bool handleScrolling(QKeyEvent*, WebCore::Frame*);
#ifndef QT_NO_SHORTCUT
static QWebPage::WebAction editorActionForKeyEvent(QKeyEvent* event);
diff --git a/WebKit/qt/Api/qwebplugindatabase.cpp b/WebKit/qt/Api/qwebplugindatabase.cpp
new file mode 100644
index 0000000..8758c60
--- /dev/null
+++ b/WebKit/qt/Api/qwebplugindatabase.cpp
@@ -0,0 +1,382 @@
+/*
+ Copyright (C) 2009 Jakub Wieczorek <faw217@gmail.com>
+
+ This library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Library General Public
+ License as published by the Free Software Foundation; either
+ version 2 of the License, or (at your option) any later version.
+
+ This library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Library General Public License for more details.
+
+ You should have received a copy of the GNU Library General Public License
+ along with this library; see the file COPYING.LIB. If not, write to
+ the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+ Boston, MA 02110-1301, USA.
+*/
+
+#include "config.h"
+#include "qwebplugindatabase.h"
+#include "qwebplugindatabase_p.h"
+
+#include "PluginDatabase.h"
+#include "PluginPackage.h"
+
+using namespace WebCore;
+
+/*!
+ \typedef QWebPluginInfo::MimeType
+ \since 4.6
+ \brief Represents a single MIME type supported by a plugin.
+*/
+
+QWebPluginInfoPrivate::QWebPluginInfoPrivate(RefPtr<PluginPackage> pluginPackage)
+ : plugin(pluginPackage)
+{
+}
+
+QWebPluginDatabasePrivate::QWebPluginDatabasePrivate(PluginDatabase* pluginDatabase)
+ : database(pluginDatabase)
+{
+}
+
+/*!
+ \class QWebPluginInfo
+ \since 4.6
+ \brief The QWebPluginInfo class represents a single Netscape plugin.
+
+ A QWebPluginInfo object represents a Netscape plugin picked up by WebKit
+ and included in the plugin database. This class contains information about
+ the plugin, such as its name(), description(), a list of MIME types that it
+ supports (can be accessed with mimeTypes()) and the path of the plugin
+ file.
+
+ Plugins can be enabled and disabled with setEnabled(). If a plugin is
+ disabled, it will not be used by WebKit to handle supported MIME types. To
+ check if a plugin is enabled or not, use enabled().
+
+ \sa QWebPluginDatabase
+*/
+
+/*!
+ Constructs a null QWebPluginInfo.
+*/
+QWebPluginInfo::QWebPluginInfo()
+ : d(new QWebPluginInfoPrivate(0))
+{
+}
+
+QWebPluginInfo::QWebPluginInfo(PluginPackage* plugin)
+ : d(new QWebPluginInfoPrivate(plugin))
+{
+}
+
+/*!
+ Contructs a copy of \a other.
+*/
+QWebPluginInfo::QWebPluginInfo(const QWebPluginInfo& other)
+ : d(new QWebPluginInfoPrivate(other.d->plugin))
+{
+}
+
+/*!
+ Destroys the plugin info.
+*/
+QWebPluginInfo::~QWebPluginInfo()
+{
+ delete d;
+}
+
+/*!
+ Returns the name of the plugin.
+
+ \sa description()
+*/
+QString QWebPluginInfo::name() const
+{
+ if (!d->plugin)
+ return QString();
+ return d->plugin->name();
+}
+
+/*!
+ Returns the description of the plugin.
+
+ \sa name()
+*/
+QString QWebPluginInfo::description() const
+{
+ if (!d->plugin)
+ return QString();
+ return d->plugin->description();
+}
+
+/*!
+ Returns a list of MIME types supported by the plugin.
+
+ \sa supportsMimeType()
+*/
+QList<QWebPluginInfo::MimeType> QWebPluginInfo::mimeTypes() const
+{
+ if (!d->plugin)
+ return QList<MimeType>();
+
+ QList<MimeType> mimeTypes;
+ const MIMEToDescriptionsMap& mimeToDescriptions = d->plugin->mimeToDescriptions();
+ MIMEToDescriptionsMap::const_iterator end = mimeToDescriptions.end();
+ for (MIMEToDescriptionsMap::const_iterator it = mimeToDescriptions.begin(); it != end; ++it) {
+ MimeType mimeType;
+ mimeType.name = it->first;
+ mimeType.description = it->second;
+
+ QStringList fileExtensions;
+ Vector<String> extensions = d->plugin->mimeToExtensions().get(mimeType.name);
+
+ for (unsigned i = 0; i < extensions.size(); ++i)
+ fileExtensions.append(extensions[i]);
+
+ mimeType.fileExtensions = fileExtensions;
+ mimeTypes.append(mimeType);
+ }
+
+ return mimeTypes;
+}
+
+/*!
+ Returns true if the plugin supports a specific \a mimeType; otherwise
+ returns false.
+
+ \sa mimeTypes()
+*/
+bool QWebPluginInfo::supportsMimeType(const QString& mimeType) const
+{
+ QList<MimeType> types = mimeTypes();
+ foreach (const MimeType& type, types) {
+ if (type.name == mimeType)
+ return true;
+ }
+
+ return false;
+}
+
+/*!
+ Returns an absolute path to the plugin file.
+*/
+QString QWebPluginInfo::path() const
+{
+ if (!d->plugin)
+ return QString();
+ return d->plugin->path();
+}
+
+/*!
+ Returns true if the plugin is a null plugin; otherwise returns false.
+*/
+bool QWebPluginInfo::isNull() const
+{
+ return !d->plugin;
+}
+
+/*!
+ Enables or disables the plugin, depending on the \a enabled parameter.
+
+ Disabled plugins will not be picked up by WebKit when looking for a plugin
+ supporting a particular MIME type.
+
+ \sa isEnabled()
+*/
+void QWebPluginInfo::setEnabled(bool enabled)
+{
+ if (!d->plugin)
+ return;
+ d->plugin->setEnabled(enabled);
+}
+
+/*!
+ Returns true if the plugin is enabled; otherwise returns false.
+
+ \sa setEnabled()
+*/
+bool QWebPluginInfo::isEnabled() const
+{
+ if (!d->plugin)
+ return false;
+ return d->plugin->isEnabled();
+}
+
+bool QWebPluginInfo::operator==(const QWebPluginInfo& other) const
+{
+ return d->plugin == other.d->plugin;
+}
+
+bool QWebPluginInfo::operator!=(const QWebPluginInfo& other) const
+{
+ return d->plugin != other.d->plugin;
+}
+
+QWebPluginInfo &QWebPluginInfo::operator=(const QWebPluginInfo& other)
+{
+ if (this == &other)
+ return *this;
+
+ d->plugin = other.d->plugin;
+ return *this;
+}
+
+/*!
+ \class QWebPluginDatabase
+ \since 4.6
+ \brief The QWebPluginDatabase class provides an interface for managing
+ Netscape plugins used by WebKit in QWebPages.
+
+ The QWebPluginDatabase class is a database of Netscape plugins that are used
+ by WebKit. The plugins are picked up by WebKit by looking up a set of search paths.
+ The default set can be accessed using defaultSearchPaths(). The search paths
+ can be changed, see searchPaths() and setSearchPaths(). Additional search paths
+ can also be added using addSearchPath().
+
+ The plugins that have been detected are exposed by the plugins() method.
+ The list contains QWebPlugin objects that hold both the metadata and the MIME
+ types that are supported by particular plugins.
+
+ WebKit specifies a plugin for a MIME type by looking for the first plugin that
+ supports the specific MIME type. To get a plugin, that is used by WebKit to
+ handle a specific MIME type, you can use the pluginForMimeType() function.
+
+ To change the way of resolving MIME types ambiguity, you can explicitly set
+ a preferred plugin for a specific MIME type, using setPreferredPluginForMimeType().
+
+ \sa QWebPluginInfo, QWebSettings::pluginDatabase()
+*/
+
+QWebPluginDatabase::QWebPluginDatabase(QObject* parent)
+ : QObject(parent)
+ , d(new QWebPluginDatabasePrivate(PluginDatabase::installedPlugins()))
+{
+}
+
+QWebPluginDatabase::~QWebPluginDatabase()
+{
+ delete d;
+}
+
+/*!
+ Returns a list of plugins installed in the search paths.
+
+ This list will contain disabled plugins, although they will not be used by
+ WebKit.
+
+ \sa pluginForMimeType()
+*/
+QList<QWebPluginInfo> QWebPluginDatabase::plugins() const
+{
+ QList<QWebPluginInfo> qwebplugins;
+ const Vector<PluginPackage*>& plugins = d->database->plugins();
+
+ for (unsigned int i = 0; i < plugins.size(); ++i) {
+ PluginPackage* plugin = plugins[i];
+ qwebplugins.append(QWebPluginInfo(plugin));
+ }
+
+ return qwebplugins;
+}
+
+/*!
+ Returns a default set of search paths.
+
+ \sa searchPaths(), setSearchPaths()
+*/
+QStringList QWebPluginDatabase::defaultSearchPaths()
+{
+ QStringList paths;
+
+ const Vector<String>& directories = PluginDatabase::defaultPluginDirectories();
+ for (unsigned int i = 0; i < directories.size(); ++i)
+ paths.append(directories[i]);
+
+ return paths;
+}
+
+/*!
+ Returns a list of search paths that are used by WebKit to look for plugins.
+
+ \sa defaultSearchPaths(), setSearchPaths()
+*/
+QStringList QWebPluginDatabase::searchPaths() const
+{
+ QStringList paths;
+
+ const Vector<String>& directories = d->database->pluginDirectories();
+ for (unsigned int i = 0; i < directories.size(); ++i)
+ paths.append(directories[i]);
+
+ return paths;
+}
+
+/*!
+ Changes the search paths to \a paths.
+ The database is automatically refreshed.
+
+ \sa searchPaths(), defaultSearchPaths()
+*/
+void QWebPluginDatabase::setSearchPaths(const QStringList& paths)
+{
+ Vector<String> directories;
+
+ for (unsigned int i = 0; i < paths.count(); ++i)
+ directories.append(paths.at(i));
+
+ d->database->setPluginDirectories(directories);
+ // PluginDatabase::setPluginDirectories() does not refresh the database.
+ d->database->refresh();
+}
+
+/*!
+ Adds an additional \a path to the current set.
+ The database is automatically refreshed.
+
+ \sa searchPaths(), setSearchPaths()
+*/
+void QWebPluginDatabase::addSearchPath(const QString& path)
+{
+ d->database->addExtraPluginDirectory(path);
+ // PluginDatabase::addExtraPluginDirectory() does refresh the database.
+}
+
+/*!
+ Refreshes the plugin database, adds new plugins that have been found and removes
+ the ones that are no longer available in the search paths.
+
+ You can call this function when the set of plugins installed in the search paths
+ changes. You do not need to call this function when changing search paths,
+ in that case WebKit automatically refreshes the database.
+*/
+void QWebPluginDatabase::refresh()
+{
+ d->database->refresh();
+}
+
+/*!
+ Returns the plugin that is currently used by WebKit for a given \a mimeType.
+
+ \sa setPreferredPluginForMimeType()
+*/
+QWebPluginInfo QWebPluginDatabase::pluginForMimeType(const QString& mimeType)
+{
+ return QWebPluginInfo(d->database->pluginForMIMEType(mimeType));
+}
+
+/*!
+ Changes the preferred plugin for a given \a mimeType to \a plugin. The \a plugin
+ has to support the given \a mimeType, otherwise the setting will have no effect.
+
+ Calling the function with a null \a plugin resets the setting.
+
+ \sa pluginForMimeType()
+*/
+void QWebPluginDatabase::setPreferredPluginForMimeType(const QString& mimeType, const QWebPluginInfo& plugin)
+{
+ d->database->setPreferredPluginForMIMEType(mimeType, plugin.d->plugin.get());
+}
diff --git a/WebKit/qt/Api/qwebplugindatabase.h b/WebKit/qt/Api/qwebplugindatabase.h
new file mode 100644
index 0000000..4b50119
--- /dev/null
+++ b/WebKit/qt/Api/qwebplugindatabase.h
@@ -0,0 +1,94 @@
+/*
+ Copyright (C) 2009 Jakub Wieczorek <faw217@gmail.com>
+
+ This library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Library General Public
+ License as published by the Free Software Foundation; either
+ version 2 of the License, or (at your option) any later version.
+
+ This library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Library General Public License for more details.
+
+ You should have received a copy of the GNU Library General Public License
+ along with this library; see the file COPYING.LIB. If not, write to
+ the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+ Boston, MA 02110-1301, USA.
+*/
+
+#ifndef QWEBPLUGINDATABASE_H
+#define QWEBPLUGINDATABASE_H
+
+#include "qwebkitglobal.h"
+#include "qwebpluginfactory.h"
+
+#include <QtCore/qobject.h>
+#include <QtCore/qstringlist.h>
+
+namespace WebCore {
+ class PluginPackage;
+}
+
+class QWebPluginInfoPrivate;
+class QWEBKIT_EXPORT QWebPluginInfo {
+public:
+ QWebPluginInfo();
+ QWebPluginInfo(const QWebPluginInfo& other);
+ QWebPluginInfo &operator=(const QWebPluginInfo& other);
+ ~QWebPluginInfo();
+
+private:
+ QWebPluginInfo(WebCore::PluginPackage* plugin);
+
+public:
+ typedef QWebPluginFactory::MimeType MimeType;
+
+ QString name() const;
+ QString description() const;
+ QList<MimeType> mimeTypes() const;
+ bool supportsMimeType(const QString& mimeType) const;
+ QString path() const;
+
+ bool isNull() const;
+
+ void setEnabled(bool enabled);
+ bool isEnabled() const;
+
+ bool operator==(const QWebPluginInfo& other) const;
+ bool operator!=(const QWebPluginInfo& other) const;
+
+ friend class QWebPluginDatabase;
+
+private:
+ QWebPluginInfoPrivate *d;
+};
+
+class QWebPluginDatabasePrivate;
+class QWEBKIT_EXPORT QWebPluginDatabase : public QObject {
+ Q_OBJECT
+
+private:
+ QWebPluginDatabase(QObject* parent = 0);
+ ~QWebPluginDatabase();
+
+public:
+ QList<QWebPluginInfo> plugins() const;
+
+ static QStringList defaultSearchPaths();
+ QStringList searchPaths() const;
+ void setSearchPaths(const QStringList& paths);
+ void addSearchPath(const QString& path);
+
+ void refresh();
+
+ QWebPluginInfo pluginForMimeType(const QString& mimeType);
+ void setPreferredPluginForMimeType(const QString& mimeType, const QWebPluginInfo& plugin);
+
+ friend class QWebSettings;
+
+private:
+ QWebPluginDatabasePrivate *d;
+};
+
+#endif // QWEBPLUGINDATABASE_H
diff --git a/WebKit/qt/Api/qwebplugindatabase_p.h b/WebKit/qt/Api/qwebplugindatabase_p.h
new file mode 100644
index 0000000..714458f
--- /dev/null
+++ b/WebKit/qt/Api/qwebplugindatabase_p.h
@@ -0,0 +1,46 @@
+/*
+ Copyright (C) 2009 Jakub Wieczorek <faw217@gmail.com>
+
+ This library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Library General Public
+ License as published by the Free Software Foundation; either
+ version 2 of the License, or (at your option) any later version.
+
+ This library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Library General Public License for more details.
+
+ You should have received a copy of the GNU Library General Public License
+ along with this library; see the file COPYING.LIB. If not, write to
+ the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+ Boston, MA 02110-1301, USA.
+*/
+
+#ifndef QWEBPLUGINDATABASE_P_H
+#define QWEBPLUGINDATABASE_P_H
+
+#include "qwebkitglobal.h"
+
+#include <wtf/RefPtr.h>
+
+namespace WebCore {
+ class PluginPackage;
+ class PluginDatabase;
+};
+
+class QWebPluginInfoPrivate {
+public:
+ QWebPluginInfoPrivate(RefPtr<WebCore::PluginPackage> pluginPackage);
+
+ RefPtr<WebCore::PluginPackage> plugin;
+};
+
+class QWebPluginDatabasePrivate {
+public:
+ QWebPluginDatabasePrivate(WebCore::PluginDatabase* pluginDatabase);
+
+ WebCore::PluginDatabase* database;
+};
+
+#endif // QWEBPLUGINDATABASE_P_H
diff --git a/WebKit/qt/Api/qwebpluginfactory.cpp b/WebKit/qt/Api/qwebpluginfactory.cpp
index d2bb124..7a8cabe 100644
--- a/WebKit/qt/Api/qwebpluginfactory.cpp
+++ b/WebKit/qt/Api/qwebpluginfactory.cpp
@@ -70,6 +70,13 @@
\brief The QWebPluginFactory::MimeType structure describes a mime type supported by a plugin.
*/
+bool QWebPluginFactory::MimeType::operator==(const MimeType& other) const
+{
+ return name == other.name
+ && description == other.description
+ && fileExtensions == other.fileExtensions;
+}
+
/*!
\variable QWebPluginFactory::MimeType::name
diff --git a/WebKit/qt/Api/qwebpluginfactory.h b/WebKit/qt/Api/qwebpluginfactory.h
index 3531b06..4a06b59 100644
--- a/WebKit/qt/Api/qwebpluginfactory.h
+++ b/WebKit/qt/Api/qwebpluginfactory.h
@@ -31,14 +31,15 @@ class QString;
QT_END_NAMESPACE
class QWebPluginFactoryPrivate;
-class QWEBKIT_EXPORT QWebPluginFactory : public QObject
-{
+class QWEBKIT_EXPORT QWebPluginFactory : public QObject {
Q_OBJECT
public:
- struct MimeType {
+ struct QWEBKIT_EXPORT MimeType {
QString name;
QString description;
QStringList fileExtensions;
+ bool operator==(const MimeType& other) const;
+ inline bool operator!=(const MimeType& other) const { return !operator==(other); }
};
struct Plugin {
@@ -47,16 +48,16 @@ public:
QList<MimeType> mimeTypes;
};
- explicit QWebPluginFactory(QObject *parent = 0);
+ explicit QWebPluginFactory(QObject* parent = 0);
virtual ~QWebPluginFactory();
virtual QList<Plugin> plugins() const = 0;
virtual void refreshPlugins();
- virtual QObject *create(const QString &mimeType,
- const QUrl &url,
- const QStringList &argumentNames,
- const QStringList &argumentValues) const = 0;
+ virtual QObject *create(const QString& mimeType,
+ const QUrl&,
+ const QStringList& argumentNames,
+ const QStringList& argumentValues) const = 0;
enum Extension {
};
@@ -64,11 +65,11 @@ public:
{};
class ExtensionReturn
{};
- virtual bool extension(Extension extension, const ExtensionOption *option = 0, ExtensionReturn *output = 0);
+ virtual bool extension(Extension extension, const ExtensionOption* option = 0, ExtensionReturn* output = 0);
virtual bool supportsExtension(Extension extension) const;
private:
- QWebPluginFactoryPrivate *d;
+ QWebPluginFactoryPrivate* d;
};
#endif
diff --git a/WebKit/qt/Api/qwebsecurityorigin.cpp b/WebKit/qt/Api/qwebsecurityorigin.cpp
index c08785f..d2eaf10 100644
--- a/WebKit/qt/Api/qwebsecurityorigin.cpp
+++ b/WebKit/qt/Api/qwebsecurityorigin.cpp
@@ -36,10 +36,9 @@ using namespace WebCore;
\brief The QWebSecurityOrigin class defines a security boundary for web sites.
QWebSecurityOrigin provides access to the security domains defined by web sites.
- An origin consists of a host name, a scheme, and a port number. Web sites with the same
- security origin can access each other's resources for client-side scripting or databases.
-
- ### diagram
+ An origin consists of a host name, a scheme, and a port number. Web sites
+ with the same security origin can access each other's resources for client-side
+ scripting or databases.
For example the site \c{http://www.example.com/my/page.html} is allowed to share the same
database as \c{http://www.example.com/my/overview.html}, or access each other's
@@ -47,7 +46,13 @@ using namespace WebCore;
\c{http://www.malicious.com/evil.html} from accessing \c{http://www.example.com/}'s resources,
because they are of a different security origin.
- QWebSecurity also provides access to all databases defined within a security origin.
+ Call QWebFrame::securityOrigin() to get the QWebSecurityOrigin for a frame in a
+ web page, and use host(), scheme() and port() to identify the security origin.
+
+ Use databases() to access the databases defined within a security origin. The
+ disk usage of the origin's databases can be limited with setDatabaseQuota().
+ databaseQuota() and databaseUsage() report the current limit as well as the
+ current usage.
For more information refer to the
\l{http://en.wikipedia.org/wiki/Same_origin_policy}{"Same origin policy" Wikipedia Article}.
@@ -154,14 +159,18 @@ QWebSecurityOrigin::QWebSecurityOrigin(QWebSecurityOriginPrivate* priv)
*/
QList<QWebSecurityOrigin> QWebSecurityOrigin::allOrigins()
{
+ QList<QWebSecurityOrigin> webOrigins;
+
+#if ENABLE(DATABASE)
Vector<RefPtr<SecurityOrigin> > coreOrigins;
DatabaseTracker::tracker().origins(coreOrigins);
- QList<QWebSecurityOrigin> webOrigins;
for (unsigned i = 0; i < coreOrigins.size(); ++i) {
QWebSecurityOriginPrivate* priv = new QWebSecurityOriginPrivate(coreOrigins[i].get());
webOrigins.append(priv);
}
+#endif
+
return webOrigins;
}
@@ -170,8 +179,11 @@ QList<QWebSecurityOrigin> QWebSecurityOrigin::allOrigins()
*/
QList<QWebDatabase> QWebSecurityOrigin::databases() const
{
- Vector<String> nameVector;
QList<QWebDatabase> databases;
+
+#if ENABLE(DATABASE)
+ Vector<String> nameVector;
+
if (!DatabaseTracker::tracker().databaseNamesForOrigin(d->origin.get(), nameVector))
return databases;
for (unsigned i = 0; i < nameVector.size(); ++i) {
@@ -181,6 +193,8 @@ QList<QWebDatabase> QWebSecurityOrigin::databases() const
QWebDatabase webDatabase(priv);
databases.append(webDatabase);
}
+#endif
+
return databases;
}
diff --git a/WebKit/qt/Api/qwebsecurityorigin.h b/WebKit/qt/Api/qwebsecurityorigin.h
index b52194d..3cfb0f4 100644
--- a/WebKit/qt/Api/qwebsecurityorigin.h
+++ b/WebKit/qt/Api/qwebsecurityorigin.h
@@ -34,8 +34,7 @@ class QWebSecurityOriginPrivate;
class QWebDatabase;
class QWebFrame;
-class QWEBKIT_EXPORT QWebSecurityOrigin
-{
+class QWEBKIT_EXPORT QWebSecurityOrigin {
public:
static QList<QWebSecurityOrigin> allOrigins();
diff --git a/WebKit/qt/Api/qwebsecurityorigin_p.h b/WebKit/qt/Api/qwebsecurityorigin_p.h
index 73fe8ed..cdc93bd 100644
--- a/WebKit/qt/Api/qwebsecurityorigin_p.h
+++ b/WebKit/qt/Api/qwebsecurityorigin_p.h
@@ -23,8 +23,7 @@
#include "SecurityOrigin.h"
#include "RefPtr.h"
-class QWebSecurityOriginPrivate : public QSharedData
-{
+class QWebSecurityOriginPrivate : public QSharedData {
public:
QWebSecurityOriginPrivate(WebCore::SecurityOrigin* o)
{
diff --git a/WebKit/qt/Api/qwebsettings.cpp b/WebKit/qt/Api/qwebsettings.cpp
index f6acc42..47b2818 100644
--- a/WebKit/qt/Api/qwebsettings.cpp
+++ b/WebKit/qt/Api/qwebsettings.cpp
@@ -22,8 +22,11 @@
#include "qwebpage.h"
#include "qwebpage_p.h"
+#include "qwebplugindatabase.h"
#include "Cache.h"
+#include "CrossOriginPreflightResultCache.h"
+#include "FontCache.h"
#include "Page.h"
#include "PageCache.h"
#include "Settings.h"
@@ -40,10 +43,9 @@
#include <QUrl>
#include <QFileInfo>
-class QWebSettingsPrivate
-{
+class QWebSettingsPrivate {
public:
- QWebSettingsPrivate(WebCore::Settings *wcSettings = 0)
+ QWebSettingsPrivate(WebCore::Settings* wcSettings = 0)
: settings(wcSettings)
{
}
@@ -52,12 +54,13 @@ public:
QHash<int, int> fontSizes;
QHash<int, bool> attributes;
QUrl userStyleSheetLocation;
+ QString defaultTextEncoding;
QString localStorageDatabasePath;
QString offlineWebApplicationCachePath;
qint64 offlineStorageDefaultQuota;
void apply();
- WebCore::Settings *settings;
+ WebCore::Settings* settings;
};
typedef QHash<int, QPixmap> WebGraphicHash;
@@ -77,14 +80,14 @@ static WebGraphicHash* graphics()
return hash;
}
-Q_GLOBAL_STATIC(QList<QWebSettingsPrivate *>, allSettings);
+Q_GLOBAL_STATIC(QList<QWebSettingsPrivate*>, allSettings);
void QWebSettingsPrivate::apply()
{
if (settings) {
settings->setTextAreasAreResizable(true);
- QWebSettingsPrivate *global = QWebSettings::globalSettings()->d;
+ QWebSettingsPrivate* global = QWebSettings::globalSettings()->d;
QString family = fontFamilies.value(QWebSettings::StandardFont,
global->fontFamilies.value(QWebSettings::StandardFont));
@@ -161,6 +164,9 @@ void QWebSettingsPrivate::apply()
QUrl location = !userStyleSheetLocation.isEmpty() ? userStyleSheetLocation : global->userStyleSheetLocation;
settings->setUserStyleSheetLocation(WebCore::KURL(location));
+ QString encoding = !defaultTextEncoding.isEmpty() ? defaultTextEncoding: global->defaultTextEncoding;
+ settings->setDefaultTextEncodingName(encoding);
+
QString localStoragePath = !localStorageDatabasePath.isEmpty() ? localStorageDatabasePath : global->localStorageDatabasePath;
settings->setLocalStorageDatabasePath(localStoragePath);
@@ -184,11 +190,11 @@ void QWebSettingsPrivate::apply()
global->attributes.value(QWebSettings::LocalStorageDatabaseEnabled));
settings->setLocalStorageEnabled(value);
- value = attributes.value(QWebSettings::AllowUniversalAccessFromFileUrls,
- global->attributes.value(QWebSettings::AllowUniversalAccessFromFileUrls));
+ value = attributes.value(QWebSettings::LocalContentCanAccessRemoteUrls,
+ global->attributes.value(QWebSettings::LocalContentCanAccessRemoteUrls));
settings->setAllowUniversalAccessFromFileURLs(value);
} else {
- QList<QWebSettingsPrivate *> settings = *::allSettings();
+ QList<QWebSettingsPrivate*> settings = *::allSettings();
for (int i = 0; i < settings.count(); ++i)
settings[i]->apply();
}
@@ -200,9 +206,9 @@ void QWebSettingsPrivate::apply()
Any setting changed on the default object is automatically applied to all
QWebPage instances where the particular setting is not overriden already.
*/
-QWebSettings *QWebSettings::globalSettings()
+QWebSettings* QWebSettings::globalSettings()
{
- static QWebSettings *global = 0;
+ static QWebSettings* global = 0;
if (!global)
global = new QWebSettings;
return global;
@@ -217,17 +223,25 @@ QWebSettings *QWebSettings::globalSettings()
Each QWebPage object has its own QWebSettings object, which configures the
settings for that page. If a setting is not configured, then it is looked
up in the global settings object, which can be accessed using
- QWebSettings::globalSettings().
+ globalSettings().
- QWebSettings allows configuring font properties such as font size and font
- family, the location of a custom stylesheet, and generic attributes like java
- script, plugins, etc. The \l{QWebSettings::WebAttribute}{WebAttribute}
- enum further describes this.
+ QWebSettings allows configuration of browser properties, such as font sizes and
+ families, the location of a custom style sheet, and generic attributes like
+ JavaScript and plugins. Individual attributes are set using the setAttribute()
+ function. The \l{QWebSettings::WebAttribute}{WebAttribute} enum further describes
+ each attribute.
- QWebSettings also configures global properties such as the web page memory
- cache and the web page icon database, local database storage and offline
+ QWebSettings also configures global properties such as the Web page memory
+ cache and the Web page icon database, local database storage and offline
applications storage.
+ \section1 Enabling Plugins
+
+ Support for browser plugins can enabled by setting the
+ \l{QWebSettings::PluginsEnabled}{PluginsEnabled} attribute. For many applications,
+ this attribute is enabled for all pages by setting it on the
+ \l{globalSettings()}{global settings object}.
+
\section1 Web Application Support
WebKit provides support for features specified in \l{HTML 5} that improve the
@@ -314,8 +328,7 @@ QWebSettings *QWebSettings::globalSettings()
web application cache feature is enabled or not.
\value LocalStorageDatabaseEnabled Specifies whether support for the HTML 5
local storage feature is enabled or not.
- \value AllowUniversalAccessFromFileUrls Specifies whether documents from file
- Urls should be granted universal access (e.g., to HTTP and HTTPS documents).
+ \value LocalContentCanAccessRemoteUrls Specifies whether locally loaded documents are allowed to access remote urls.
*/
/*!
@@ -344,15 +357,14 @@ QWebSettings::QWebSettings()
d->attributes.insert(QWebSettings::OfflineStorageDatabaseEnabled, true);
d->attributes.insert(QWebSettings::OfflineWebApplicationCacheEnabled, true);
d->attributes.insert(QWebSettings::LocalStorageDatabaseEnabled, true);
- d->attributes.insert(QWebSettings::AllowUniversalAccessFromFileUrls, true);
+ d->attributes.insert(QWebSettings::LocalContentCanAccessRemoteUrls, true);
d->offlineStorageDefaultQuota = 5 * 1024 * 1024;
-
}
/*!
\internal
*/
-QWebSettings::QWebSettings(WebCore::Settings *settings)
+QWebSettings::QWebSettings(WebCore::Settings* settings)
: d(new QWebSettingsPrivate(settings))
{
d->settings = settings;
@@ -387,7 +399,7 @@ int QWebSettings::fontSize(FontSize type) const
{
int defaultValue = 0;
if (d->settings) {
- QWebSettingsPrivate *global = QWebSettings::globalSettings()->d;
+ QWebSettingsPrivate* global = QWebSettings::globalSettings()->d;
defaultValue = global->fontSizes.value(type);
}
return d->fontSizes.value(type, defaultValue);
@@ -414,7 +426,7 @@ void QWebSettings::resetFontSize(FontSize type)
\sa userStyleSheetUrl()
*/
-void QWebSettings::setUserStyleSheetUrl(const QUrl &location)
+void QWebSettings::setUserStyleSheetUrl(const QUrl& location)
{
d->userStyleSheetLocation = location;
d->apply();
@@ -431,6 +443,33 @@ QUrl QWebSettings::userStyleSheetUrl() const
}
/*!
+ \since 4.6
+ Specifies the default text encoding system.
+
+ The \a encoding, must be a string describing an encoding such as "utf-8",
+ "iso-8859-1", etc. If left empty a default value will be used. For a more
+ extensive list of encoding names see \l{QTextCodec}
+
+ \sa defaultTextEncoding()
+*/
+void QWebSettings::setDefaultTextEncoding(const QString& encoding)
+{
+ d->defaultTextEncoding = encoding;
+ d->apply();
+}
+
+/*!
+ \since 4.6
+ Returns the default text encoding.
+
+ \sa setDefaultTextEncoding()
+*/
+QString QWebSettings::defaultTextEncoding() const
+{
+ return d->defaultTextEncoding;
+}
+
+/*!
Sets the path of the icon database to \a path. The icon database is used
to store "favicons" associated with web sites.
@@ -438,7 +477,7 @@ QUrl QWebSettings::userStyleSheetUrl() const
Setting an empty path disables the icon database.
*/
-void QWebSettings::setIconDatabasePath(const QString &path)
+void QWebSettings::setIconDatabasePath(const QString& path)
{
WebCore::iconDatabase()->delayDatabaseCleanup();
@@ -461,11 +500,10 @@ void QWebSettings::setIconDatabasePath(const QString &path)
*/
QString QWebSettings::iconDatabasePath()
{
- if (WebCore::iconDatabase()->isEnabled() && WebCore::iconDatabase()->isOpen()) {
+ if (WebCore::iconDatabase()->isEnabled() && WebCore::iconDatabase()->isOpen())
return WebCore::iconDatabase()->databasePath();
- } else {
+ else
return QString();
- }
}
/*!
@@ -487,18 +525,29 @@ void QWebSettings::clearIconDatabase()
\sa setIconDatabasePath()
*/
-QIcon QWebSettings::iconForUrl(const QUrl &url)
+QIcon QWebSettings::iconForUrl(const QUrl& url)
{
WebCore::Image* image = WebCore::iconDatabase()->iconForPageURL(WebCore::KURL(url).string(),
WebCore::IntSize(16, 16));
- if (!image) {
+ if (!image)
return QPixmap();
- }
- QPixmap *icon = image->nativeImageForCurrentFrame();
- if (!icon) {
+
+ QPixmap* icon = image->nativeImageForCurrentFrame();
+ if (!icon)
return QPixmap();
- }
- return *icon;
+
+ return* icon;
+}
+
+/*!
+ Returns the plugin database object.
+*/
+QWebPluginDatabase *QWebSettings::pluginDatabase()
+{
+ static QWebPluginDatabase* database = 0;
+ if (!database)
+ database = new QWebPluginDatabase();
+ return database;
}
/*!
@@ -510,9 +559,9 @@ QIcon QWebSettings::iconForUrl(const QUrl &url)
\sa webGraphic()
*/
-void QWebSettings::setWebGraphic(WebGraphic type, const QPixmap &graphic)
+void QWebSettings::setWebGraphic(WebGraphic type, const QPixmap& graphic)
{
- WebGraphicHash *h = graphics();
+ WebGraphicHash* h = graphics();
if (graphic.isNull())
h->remove(type);
else
@@ -534,6 +583,40 @@ QPixmap QWebSettings::webGraphic(WebGraphic type)
}
/*!
+ Frees up as much memory as possible by cleaning all memory caches such
+ as page, object and font cache.
+
+ \since 4.6
+ */
+void QWebSettings::clearMemoryCaches()
+{
+ // Turn the cache on and off. Disabling the object cache will remove all
+ // resources from the cache. They may still live on if they are referenced
+ // by some Web page though.
+ if (!WebCore::cache()->disabled()) {
+ WebCore::cache()->setDisabled(true);
+ WebCore::cache()->setDisabled(false);
+ }
+
+ int pageCapacity = WebCore::pageCache()->capacity();
+ // Setting size to 0, makes all pages be released.
+ WebCore::pageCache()->setCapacity(0);
+ WebCore::pageCache()->releaseAutoreleasedPagesNow();
+ WebCore::pageCache()->setCapacity(pageCapacity);
+
+ // Invalidating the font cache and freeing all inactive font data.
+ WebCore::fontCache()->invalidate();
+
+#if ENABLE(OFFLINE_WEB_APPLICATIONS)
+ // Empty the application cache.
+ WebCore::cacheStorage().empty();
+#endif
+
+ // Empty the Cross-Origin Preflight cache
+ WebCore::CrossOriginPreflightResultCache::shared().empty();
+}
+
+/*!
Sets the maximum number of pages to hold in the memory cache to \a pages.
*/
void QWebSettings::setMaximumPagesInCache(int pages)
@@ -555,7 +638,7 @@ int QWebSettings::maximumPagesInCache()
The \a cacheMinDeadCapacity specifies the \e minimum number of bytes that
dead objects should consume when the cache is under pressure.
-
+
\a cacheMaxDead is the \e maximum number of bytes that dead objects should
consume when the cache is \bold not under pressure.
@@ -567,7 +650,7 @@ int QWebSettings::maximumPagesInCache()
*/
void QWebSettings::setObjectCacheCapacities(int cacheMinDeadCapacity, int cacheMaxDead, int totalCapacity)
{
- bool disableCache = cacheMinDeadCapacity == 0 && cacheMaxDead == 0 && totalCapacity == 0;
+ bool disableCache = !cacheMinDeadCapacity && !cacheMaxDead && !totalCapacity;
WebCore::cache()->setDisabled(disableCache);
WebCore::cache()->setCapacities(qMax(0, cacheMinDeadCapacity),
@@ -579,7 +662,7 @@ void QWebSettings::setObjectCacheCapacities(int cacheMinDeadCapacity, int cacheM
Sets the actual font family to \a family for the specified generic family,
\a which.
*/
-void QWebSettings::setFontFamily(FontFamily which, const QString &family)
+void QWebSettings::setFontFamily(FontFamily which, const QString& family)
{
d->fontFamilies.insert(which, family);
d->apply();
@@ -593,7 +676,7 @@ QString QWebSettings::fontFamily(FontFamily which) const
{
QString defaultValue;
if (d->settings) {
- QWebSettingsPrivate *global = QWebSettings::globalSettings()->d;
+ QWebSettingsPrivate* global = QWebSettings::globalSettings()->d;
defaultValue = global->fontFamilies.value(which);
}
return d->fontFamilies.value(which, defaultValue);
@@ -615,7 +698,7 @@ void QWebSettings::resetFontFamily(FontFamily which)
/*!
\fn void QWebSettings::setAttribute(WebAttribute attribute, bool on)
-
+
Enables or disables the specified \a attribute feature depending on the
value of \a on.
*/
@@ -634,7 +717,7 @@ bool QWebSettings::testAttribute(WebAttribute attr) const
{
bool defaultValue = false;
if (d->settings) {
- QWebSettingsPrivate *global = QWebSettings::globalSettings()->d;
+ QWebSettingsPrivate* global = QWebSettings::globalSettings()->d;
defaultValue = global->attributes.value(attr);
}
return d->attributes.value(attr, defaultValue);
@@ -712,35 +795,43 @@ qint64 QWebSettings::offlineStorageDefaultQuota()
return QWebSettings::globalSettings()->d->offlineStorageDefaultQuota;
}
-/*
- \internal
+/*!
+ \since 4.6
\relates QWebSettings
-
+
Sets the path for HTML5 offline web application cache storage to \a path.
+ An application cache acts like an HTTP cache in some sense. For documents
+ that use the application cache via JavaScript, the loader mechinery will
+ first ask the application cache for the contents, before hitting the
+ network.
+
+ The feature is described in details at:
+ http://dev.w3.org/html5/spec/Overview.html#appcache
+
\a path must point to an existing directory where the cache is stored.
Setting an empty path disables the feature.
\sa offlineWebApplicationCachePath()
*/
-void QWEBKIT_EXPORT qt_websettings_setOfflineWebApplicationCachePath(const QString& path)
+void QWebSettings::setOfflineWebApplicationCachePath(const QString& path)
{
#if ENABLE(OFFLINE_WEB_APPLICATIONS)
WebCore::cacheStorage().setCacheDirectory(path);
#endif
}
-/*
- \internal
+/*!
+ \since 4.6
\relates QWebSettings
-
+
Returns the path of the HTML5 offline web application cache storage
or an empty string if the feature is disabled.
\sa setOfflineWebApplicationCachePath()
*/
-QString QWEBKIT_EXPORT qt_websettings_offlineWebApplicationCachePath()
+QString QWebSettings::offlineWebApplicationCachePath()
{
#if ENABLE(OFFLINE_WEB_APPLICATIONS)
return WebCore::cacheStorage().cacheDirectory();
@@ -749,6 +840,33 @@ QString QWEBKIT_EXPORT qt_websettings_offlineWebApplicationCachePath()
#endif
}
+/*!
+ \since 4.6
+
+ Sets the value of the quota for the offline web application cache
+ to \a maximumSize.
+*/
+void QWebSettings::setOfflineWebApplicationCacheQuota(qint64 maximumSize)
+{
+#if ENABLE(OFFLINE_WEB_APPLICATIONS)
+ WebCore::cacheStorage().setMaximumSize(maximumSize);
+#endif
+}
+
+/*!
+ \since 4.6
+
+ Returns the value of the quota for the offline web application cache.
+*/
+qint64 QWebSettings::offlineWebApplicationCacheQuota()
+{
+#if ENABLE(OFFLINE_WEB_APPLICATIONS)
+ return WebCore::cacheStorage().maximumSize();
+#else
+ return 0;
+#endif
+}
+
/*
\since 4.5
\relates QWebSettings
@@ -763,7 +881,7 @@ QString QWEBKIT_EXPORT qt_websettings_offlineWebApplicationCachePath()
*/
void QWEBKIT_EXPORT qt_websettings_setLocalStorageDatabasePath(QWebSettings* settings, const QString& path)
{
- QWebSettingsPrivate *d = settings->handle();
+ QWebSettingsPrivate* d = settings->handle();
d->localStorageDatabasePath = path;
d->apply();
}
diff --git a/WebKit/qt/Api/qwebsettings.h b/WebKit/qt/Api/qwebsettings.h
index 5610797..b7ea54b 100644
--- a/WebKit/qt/Api/qwebsettings.h
+++ b/WebKit/qt/Api/qwebsettings.h
@@ -27,19 +27,18 @@
#include <QtGui/qicon.h>
#include <QtCore/qshareddata.h>
-namespace WebCore
-{
+namespace WebCore {
class Settings;
}
class QWebPage;
+class QWebPluginDatabase;
class QWebSettingsPrivate;
QT_BEGIN_NAMESPACE
class QUrl;
QT_END_NAMESPACE
-class QWEBKIT_EXPORT QWebSettings
-{
+class QWEBKIT_EXPORT QWebSettings {
public:
enum FontFamily {
StandardFont,
@@ -64,7 +63,7 @@ public:
OfflineStorageDatabaseEnabled,
OfflineWebApplicationCacheEnabled,
LocalStorageDatabaseEnabled,
- AllowUniversalAccessFromFileUrls
+ LocalContentCanAccessRemoteUrls
};
enum WebGraphic {
MissingImageGraphic,
@@ -96,11 +95,16 @@ public:
void setUserStyleSheetUrl(const QUrl &location);
QUrl userStyleSheetUrl() const;
+ void setDefaultTextEncoding(const QString &encoding);
+ QString defaultTextEncoding() const;
+
static void setIconDatabasePath(const QString &location);
static QString iconDatabasePath();
static void clearIconDatabase();
static QIcon iconForUrl(const QUrl &url);
+ static QWebPluginDatabase *pluginDatabase();
+
static void setWebGraphic(WebGraphic type, const QPixmap &graphic);
static QPixmap webGraphic(WebGraphic type);
@@ -113,6 +117,13 @@ public:
static void setOfflineStorageDefaultQuota(qint64 maximumSize);
static qint64 offlineStorageDefaultQuota();
+ static void setOfflineWebApplicationCachePath(const QString& path);
+ static QString offlineWebApplicationCachePath();
+ static void setOfflineWebApplicationCacheQuota(qint64 maximumSize);
+ static qint64 offlineWebApplicationCacheQuota();
+
+ static void clearMemoryCaches();
+
inline QWebSettingsPrivate* handle() const { return d; }
private:
diff --git a/WebKit/qt/Api/qwebview.cpp b/WebKit/qt/Api/qwebview.cpp
index ea503a1..e1a0c98 100644
--- a/WebKit/qt/Api/qwebview.cpp
+++ b/WebKit/qt/Api/qwebview.cpp
@@ -27,13 +27,15 @@
#include "qevent.h"
#include "qpainter.h"
#include "qprinter.h"
+#include "qdir.h"
+#include "qfile.h"
-class QWebViewPrivate
-{
+class QWebViewPrivate {
public:
QWebViewPrivate(QWebView *view)
: view(view)
, page(0)
+ , renderHints(QPainter::TextAntialiasing)
#ifndef QT_NO_CURSOR
, cursorSetByWebCore(false)
, usesWebCoreCursor(true)
@@ -43,6 +45,7 @@ public:
QWebView *view;
QWebPage *page;
+ QPainter::RenderHints renderHints;
#ifndef QT_NO_CURSOR
/*
@@ -83,10 +86,10 @@ public:
\image qwebview-url.png
A web site can be loaded onto QWebView with the load() function. Like all
- Qt Widgets, the show() function must be invoked in order to display
+ Qt widgets, the show() function must be invoked in order to display
QWebView. The snippet below illustrates this:
- \snippet doc/src/snippets/webkit/simple/main.cpp Using QWebView
+ \snippet webkitsnippets/simple/main.cpp Using QWebView
Alternatively, setUrl() can also be used to load a web site. If you have
the HTML content readily available, you can use setHtml() instead.
@@ -143,7 +146,8 @@ public:
if you do not require QWidget attributes. Nevertheless, QtWebKit depends
on QtGui, so you should use a QApplication instead of QCoreApplication.
- \sa {Previewer Example}, {Browser}
+ \sa {Previewer Example}, {Web Browser}, {Form Extractor Example},
+ {Google Chat Example}, {Fancy Browser Example}
*/
/*!
@@ -202,16 +206,15 @@ QWebPage *QWebView::page() const
\sa page()
*/
-void QWebView::setPage(QWebPage *page)
+void QWebView::setPage(QWebPage* page)
{
if (d->page == page)
return;
if (d->page) {
- if (d->page->parent() == this) {
+ if (d->page->parent() == this)
delete d->page;
- } else {
+ else
d->page->disconnect(this);
- }
}
d->page = page;
if (d->page) {
@@ -245,11 +248,84 @@ void QWebView::setPage(QWebPage *page)
}
/*!
+ Returns a valid URL from a user supplied \a string if one can be deducted.
+ In the case that is not possible, an invalid QUrl() is returned.
+
+ \since 4.6
+
+ Most applications that can browse the web, allow the user to input a URL
+ in the form of a plain string. This string can be manually typed into
+ a location bar, obtained from the clipboard, or passed in via command
+ line arguments.
+
+ When the string is not already a valid URL, a best guess is performed,
+ making various web related assumptions.
+
+ In the case the string corresponds to a valid file path on the system,
+ a file:// URL is constructed, using QUrl::fromLocalFile().
+
+ If that is not the case, an attempt is made to turn the string into a
+ http:// or ftp:// URL. The latter in the case the string starts with
+ 'ftp'. The result is then passed through QUrl's tolerant parser, and
+ in the case or success, a valid QUrl is returned, or else a QUrl().
+
+ \section1 Examples:
+
+ \list
+ \o webkit.org becomes http://webkit.org
+ \o ftp.webkit.org becomes ftp://ftp.webkit.org
+ \o localhost becomes http://localhost
+ \o /home/user/test.html becomes file:///home/user/test.html (if exists)
+ \endlist
+
+ \section2 Tips when dealing with URLs and strings:
+
+ \list
+ \o When creating a QString from a QByteArray or a char*, always use
+ QString::fromUtf8().
+ \o Do not use QUrl(string), nor QUrl::toString() anywhere where the URL might
+ be used, such as in the location bar, as those functions loose data.
+ Instead use QUrl::fromEncoded() and QUrl::toEncoded(), respectively.
+ \endlist
+ */
+QUrl QWebView::guessUrlFromString(const QString &string)
+{
+ QString trimmedString = string.trimmed();
+
+ // Check the most common case of a valid url with scheme and host first
+ QUrl url = QUrl::fromEncoded(trimmedString.toUtf8(), QUrl::TolerantMode);
+ if (url.isValid() && !url.scheme().isEmpty() && !url.host().isEmpty())
+ return url;
+
+ // Absolute files that exists
+ if (QDir::isAbsolutePath(trimmedString) && QFile::exists(trimmedString))
+ return QUrl::fromLocalFile(trimmedString);
+
+ // If the string is missing the scheme or the scheme is not valid prepend a scheme
+ QString scheme = url.scheme();
+ if (scheme.isEmpty() || scheme.contains(QLatin1Char('.')) || scheme == QLatin1String("localhost")) {
+ // Do not do anything for strings such as "foo", only "foo.com"
+ int dotIndex = trimmedString.indexOf(QLatin1Char('.'));
+ if (dotIndex != -1 || trimmedString.startsWith(QLatin1String("localhost"))) {
+ const QString hostscheme = trimmedString.left(dotIndex).toLower();
+ QByteArray scheme = (hostscheme == QLatin1String("ftp")) ? "ftp" : "http";
+ trimmedString = QLatin1String(scheme) + QLatin1String("://") + trimmedString;
+ }
+ url = QUrl::fromEncoded(trimmedString.toUtf8(), QUrl::TolerantMode);
+ }
+
+ if (url.isValid())
+ return url;
+
+ return QUrl();
+}
+
+/*!
Loads the specified \a url and displays it.
\note The view remains the same until enough data has arrived to display the new \a url.
- \sa setUrl(), url(), urlChanged()
+ \sa setUrl(), url(), urlChanged(), guessUrlFromString()
*/
void QWebView::load(const QUrl &url)
{
@@ -289,6 +365,8 @@ void QWebView::load(const QNetworkRequest &request,
External objects such as stylesheets or images referenced in the HTML
document are located relative to \a baseUrl.
+ The \a html is loaded immediately; external objects are loaded asynchronously.
+
When using this method, WebKit assumes that external resources such as
JavaScript programs or style sheets are encoded in UTF-8 unless otherwise
specified. For example, the encoding of an external script can be specified
@@ -309,6 +387,8 @@ void QWebView::setHtml(const QString &html, const QUrl &baseUrl)
External objects referenced in the content are located relative to \a baseUrl.
+ The \a data is loaded immediately; external objects are loaded asynchronously.
+
\sa load(), setHtml(), QWebFrame::toHtml()
*/
void QWebView::setContent(const QByteArray &data, const QString &mimeType, const QUrl &baseUrl)
@@ -321,7 +401,7 @@ void QWebView::setContent(const QByteArray &data, const QString &mimeType, const
It is equivalent to
- \snippet doc/src/snippets/code/src_3rdparty_webkit_WebKit_qt_Api_qwebview.cpp 0
+ \snippet webkitsnippets/qtwebkit_qwebview_snippet.cpp 0
*/
QWebHistory *QWebView::history() const
{
@@ -333,7 +413,7 @@ QWebHistory *QWebView::history() const
It is equivalent to
- \snippet doc/src/snippets/code/src_3rdparty_webkit_WebKit_qt_Api_qwebview.cpp 1
+ \snippet webkitsnippets/qtwebkit_qwebview_snippet.cpp 1
\sa QWebSettings::globalSettings()
*/
@@ -425,7 +505,7 @@ QAction *QWebView::pageAction(QWebPage::WebAction action) const
The following example triggers the copy action and therefore copies any
selected text to the clipboard.
- \snippet doc/src/snippets/code/src_3rdparty_webkit_WebKit_qt_Api_qwebview.cpp 2
+ \snippet webkitsnippets/qtwebkit_qwebview_snippet.cpp 2
\sa pageAction()
*/
@@ -529,9 +609,61 @@ qreal QWebView::textSizeMultiplier() const
}
/*!
- Finds the next occurrence of the string, \a subString, in the page, using
- the given \a options. Returns true of \a subString was found and selects
- the match visually; otherwise returns false.
+ \property QWebView::renderHints
+ \since 4.6
+ \brief the default render hints for the view
+
+ These hints are used to initialize QPainter before painting the web page.
+
+ QPainter::TextAntialiasing is enabled by default.
+
+ \sa QPainter::renderHints()
+*/
+QPainter::RenderHints QWebView::renderHints() const
+{
+ return d->renderHints;
+}
+
+void QWebView::setRenderHints(QPainter::RenderHints hints)
+{
+ if (hints == d->renderHints)
+ return;
+ d->renderHints = hints;
+ update();
+}
+
+/*!
+ If \a enabled is true, the render hint \a hint is enabled; otherwise it
+ is disabled.
+
+ \since 4.6
+ \sa renderHints
+*/
+void QWebView::setRenderHint(QPainter::RenderHint hint, bool enabled)
+{
+ QPainter::RenderHints oldHints = d->renderHints;
+ if (enabled)
+ d->renderHints |= hint;
+ else
+ d->renderHints &= ~hint;
+ if (oldHints != d->renderHints)
+ update();
+}
+
+
+/*!
+ Finds the specified string, \a subString, in the page, using the given \a options.
+
+ If the HighlightAllOccurrences flag is passed, the function will highlight all occurrences
+ that exist in the page. All subsequent calls will extend the highlight, rather than
+ replace it, with occurrences of the new string.
+
+ If the HighlightAllOccurrences flag is not passed, the function will select an occurrence
+ and all subsequent calls will replace the current occurrence with the next one.
+
+ To clear the selection, just pass an empty string.
+
+ Returns true if \a subString was found; otherwise returns false.
\sa selectedText(), selectionChanged()
*/
@@ -577,9 +709,8 @@ bool QWebView::event(QEvent *e)
}
#endif
#endif
- } else if (e->type() == QEvent::Leave) {
+ } else if (e->type() == QEvent::Leave)
d->page->event(e);
- }
}
return QWidget::event(e);
@@ -602,7 +733,7 @@ void QWebView::print(QPrinter *printer) const
It is equivalent to
- \snippet doc/src/snippets/code/src_3rdparty_webkit_WebKit_qt_Api_qwebview.cpp 3
+ \snippet webkitsnippets/qtwebkit_qwebview_snippet.cpp 3
\sa reload(), pageAction(), loadFinished()
*/
@@ -618,7 +749,7 @@ void QWebView::stop()
It is equivalent to
- \snippet doc/src/snippets/code/src_3rdparty_webkit_WebKit_qt_Api_qwebview.cpp 4
+ \snippet webkitsnippets/qtwebkit_qwebview_snippet.cpp 4
\sa forward(), pageAction()
*/
@@ -634,7 +765,7 @@ void QWebView::back()
It is equivalent to
- \snippet doc/src/snippets/code/src_3rdparty_webkit_WebKit_qt_Api_qwebview.cpp 5
+ \snippet webkitsnippets/qtwebkit_qwebview_snippet.cpp 5
\sa back(), pageAction()
*/
@@ -676,12 +807,13 @@ void QWebView::paintEvent(QPaintEvent *ev)
QWebFrame *frame = d->page->mainFrame();
QPainter p(this);
+ p.setRenderHints(d->renderHints);
frame->render(&p, ev->region());
#ifdef QWEBKIT_TIME_RENDERING
int elapsed = time.elapsed();
- qDebug()<<"paint event on "<<ev->region()<<", took to render = "<<elapsed;
+ qDebug() << "paint event on " << ev->region() << ", took to render = " << elapsed;
#endif
}
@@ -877,9 +1009,8 @@ void QWebView::inputMethodEvent(QInputMethodEvent *e)
*/
void QWebView::changeEvent(QEvent *e)
{
- if (d->page && e->type() == QEvent::PaletteChange) {
+ if (d->page && e->type() == QEvent::PaletteChange)
d->page->setPalette(palette());
- }
QWidget::changeEvent(e);
}
@@ -910,7 +1041,10 @@ void QWebView::changeEvent(QEvent *e)
This signal is emitted whenever the icon of the page is loaded or changes.
- \sa icon()
+ In order for icons to be loaded, you will need to set an icon database path
+ using QWebSettings::setIconDatabasePath().
+
+ \sa icon(), QWebSettings::setIconDatabasePath()
*/
/*!
diff --git a/WebKit/qt/Api/qwebview.h b/WebKit/qt/Api/qwebview.h
index 1172f39..e886144 100644
--- a/WebKit/qt/Api/qwebview.h
+++ b/WebKit/qt/Api/qwebview.h
@@ -25,6 +25,7 @@
#include "qwebpage.h"
#include <QtGui/qwidget.h>
#include <QtGui/qicon.h>
+#include <QtGui/qpainter.h>
#include <QtCore/qurl.h>
#if QT_VERSION >= 0x040400
#include <QtNetwork/qnetworkaccessmanager.h>
@@ -39,8 +40,7 @@ class QWebPage;
class QWebViewPrivate;
class QWebNetworkRequest;
-class QWEBKIT_EXPORT QWebView : public QWidget
-{
+class QWEBKIT_EXPORT QWebView : public QWidget {
Q_OBJECT
Q_PROPERTY(QString title READ title)
Q_PROPERTY(QUrl url READ url WRITE setUrl)
@@ -50,26 +50,30 @@ class QWEBKIT_EXPORT QWebView : public QWidget
//Q_PROPERTY(Qt::TextInteractionFlags textInteractionFlags READ textInteractionFlags WRITE setTextInteractionFlags)
Q_PROPERTY(qreal textSizeMultiplier READ textSizeMultiplier WRITE setTextSizeMultiplier DESIGNABLE false)
Q_PROPERTY(qreal zoomFactor READ zoomFactor WRITE setZoomFactor)
+ Q_PROPERTY(QPainter::RenderHints renderHints READ renderHints WRITE setRenderHints)
+ Q_FLAGS(QPainter::RenderHints)
public:
- explicit QWebView(QWidget *parent = 0);
+ explicit QWebView(QWidget* parent = 0);
virtual ~QWebView();
- QWebPage *page() const;
- void setPage(QWebPage *page);
+ QWebPage* page() const;
+ void setPage(QWebPage* page);
- void load(const QUrl &url);
+ static QUrl guessUrlFromString(const QString& string);
+
+ void load(const QUrl& url);
#if QT_VERSION < 0x040400 && !defined(qdoc)
- void load(const QWebNetworkRequest &request);
+ void load(const QWebNetworkRequest& request);
#else
- void load(const QNetworkRequest &request,
+ void load(const QNetworkRequest& request,
QNetworkAccessManager::Operation operation = QNetworkAccessManager::GetOperation,
const QByteArray &body = QByteArray());
#endif
- void setHtml(const QString &html, const QUrl &baseUrl = QUrl());
- void setContent(const QByteArray &data, const QString &mimeType = QString(), const QUrl &baseUrl = QUrl());
+ void setHtml(const QString& html, const QUrl& baseUrl = QUrl());
+ void setContent(const QByteArray& data, const QString& mimeType = QString(), const QUrl& baseUrl = QUrl());
- QWebHistory *history() const;
- QWebSettings *settings() const;
+ QWebHistory* history() const;
+ QWebSettings* settings() const;
QString title() const;
void setUrl(const QUrl &url);
@@ -78,7 +82,7 @@ public:
QString selectedText() const;
- QAction *pageAction(QWebPage::WebAction action) const;
+ QAction* pageAction(QWebPage::WebAction action) const;
void triggerPageAction(QWebPage::WebAction action, bool checked = false);
bool isModified() const;
@@ -99,9 +103,13 @@ public:
void setTextSizeMultiplier(qreal factor);
qreal textSizeMultiplier() const;
- bool findText(const QString &subString, QWebPage::FindFlags options = 0);
+ QPainter::RenderHints renderHints() const;
+ void setRenderHints(QPainter::RenderHints hints);
+ void setRenderHint(QPainter::RenderHint hint, bool enabled = true);
+
+ bool findText(const QString& subString, QWebPage::FindFlags options = 0);
- virtual bool event(QEvent *);
+ virtual bool event(QEvent*);
public Q_SLOTS:
void stop();
@@ -109,7 +117,7 @@ public Q_SLOTS:
void forward();
void reload();
- void print(QPrinter *printer) const;
+ void print(QPrinter*) const;
Q_SIGNALS:
void loadStarted();
@@ -117,14 +125,14 @@ Q_SIGNALS:
void loadFinished(bool);
void titleChanged(const QString& title);
void statusBarMessage(const QString& text);
- void linkClicked(const QUrl &url);
+ void linkClicked(const QUrl&);
void selectionChanged();
void iconChanged();
- void urlChanged(const QUrl &url);
+ void urlChanged(const QUrl&);
protected:
- void resizeEvent(QResizeEvent *e);
- void paintEvent(QPaintEvent *ev);
+ void resizeEvent(QResizeEvent*);
+ void paintEvent(QPaintEvent*);
virtual QWebView *createWindow(QWebPage::WebWindowType type);
@@ -141,10 +149,10 @@ protected:
#endif
virtual void keyPressEvent(QKeyEvent*);
virtual void keyReleaseEvent(QKeyEvent*);
- virtual void dragEnterEvent(QDragEnterEvent *);
- virtual void dragLeaveEvent(QDragLeaveEvent *);
- virtual void dragMoveEvent(QDragMoveEvent *);
- virtual void dropEvent(QDropEvent *);
+ virtual void dragEnterEvent(QDragEnterEvent*);
+ virtual void dragLeaveEvent(QDragLeaveEvent*);
+ virtual void dragMoveEvent(QDragMoveEvent*);
+ virtual void dropEvent(QDropEvent*);
virtual void focusInEvent(QFocusEvent*);
virtual void focusOutEvent(QFocusEvent*);
virtual void inputMethodEvent(QInputMethodEvent*);
@@ -153,7 +161,7 @@ protected:
private:
friend class QWebPage;
- QWebViewPrivate *d;
+ QWebViewPrivate* d;
};
#endif // QWEBVIEW_H