summaryrefslogtreecommitdiffstats
path: root/WebKit/qt/Api
diff options
context:
space:
mode:
authorThe Android Open Source Project <initial-contribution@android.com>2008-12-17 18:05:15 -0800
committerThe Android Open Source Project <initial-contribution@android.com>2008-12-17 18:05:15 -0800
commit1cbdecfa9fc428ac2d8aca0fa91c9580b3d57353 (patch)
tree4457a7306ea5acb43fe05bfe0973b1f7faf97ba2 /WebKit/qt/Api
parent9364f22aed35e1a1e9d07c121510f80be3ab0502 (diff)
downloadexternal_webkit-1cbdecfa9fc428ac2d8aca0fa91c9580b3d57353.zip
external_webkit-1cbdecfa9fc428ac2d8aca0fa91c9580b3d57353.tar.gz
external_webkit-1cbdecfa9fc428ac2d8aca0fa91c9580b3d57353.tar.bz2
Code drop from //branches/cupcake/...@124589
Diffstat (limited to 'WebKit/qt/Api')
-rw-r--r--WebKit/qt/Api/qwebframe.cpp958
-rw-r--r--WebKit/qt/Api/qwebframe.h134
-rw-r--r--WebKit/qt/Api/qwebframe_p.h56
-rw-r--r--WebKit/qt/Api/qwebhistory.cpp238
-rw-r--r--WebKit/qt/Api/qwebhistory.h33
-rw-r--r--WebKit/qt/Api/qwebhistory_p.h26
-rw-r--r--WebKit/qt/Api/qwebhistoryinterface.cpp65
-rw-r--r--WebKit/qt/Api/qwebhistoryinterface.h28
-rw-r--r--WebKit/qt/Api/qwebkitglobal.h19
-rw-r--r--WebKit/qt/Api/qwebnetworkinterface.cpp75
-rw-r--r--WebKit/qt/Api/qwebnetworkinterface.h36
-rw-r--r--WebKit/qt/Api/qwebnetworkinterface_p.h38
-rw-r--r--WebKit/qt/Api/qwebobjectplugin.cpp192
-rw-r--r--WebKit/qt/Api/qwebobjectplugin.h66
-rw-r--r--WebKit/qt/Api/qwebobjectplugin_p.h76
-rw-r--r--WebKit/qt/Api/qwebobjectpluginconnector.cpp64
-rw-r--r--WebKit/qt/Api/qwebobjectpluginconnector.h69
-rw-r--r--WebKit/qt/Api/qwebpage.cpp1900
-rw-r--r--WebKit/qt/Api/qwebpage.h148
-rw-r--r--WebKit/qt/Api/qwebpage_p.h101
-rw-r--r--WebKit/qt/Api/qwebpluginfactory.cpp216
-rw-r--r--WebKit/qt/Api/qwebpluginfactory.h74
-rw-r--r--WebKit/qt/Api/qwebsettings.cpp316
-rw-r--r--WebKit/qt/Api/qwebsettings.h47
-rw-r--r--WebKit/qt/Api/qwebview.cpp538
-rw-r--r--WebKit/qt/Api/qwebview.h70
26 files changed, 3965 insertions, 1618 deletions
diff --git a/WebKit/qt/Api/qwebframe.cpp b/WebKit/qt/Api/qwebframe.cpp
index 058a283..892949d 100644
--- a/WebKit/qt/Api/qwebframe.cpp
+++ b/WebKit/qt/Api/qwebframe.cpp
@@ -1,5 +1,5 @@
/*
- Copyright (C) 2007 Trolltech ASA
+ Copyright (C) 2008 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
@@ -16,10 +16,8 @@
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.
-
- This class provides all functionality needed for loading images, style sheets and html
- pages from the web. It has a memory cache for these objects.
*/
+
#include "config.h"
#include "qwebframe.h"
#include "qwebpage.h"
@@ -34,9 +32,12 @@
#include "FrameView.h"
#include "IconDatabase.h"
#include "Page.h"
+#include "PutPropertySlot.h"
#include "ResourceRequest.h"
+#include "RenderView.h"
#include "SelectionController.h"
-#include "PlatformScrollBar.h"
+#include "Scrollbar.h"
+#include "PrintContext.h"
#include "SubstituteData.h"
#include "markup.h"
@@ -44,26 +45,30 @@
#include "Element.h"
#include "Document.h"
#include "DragData.h"
-#include "RenderObject.h"
+#include "RenderView.h"
#include "GraphicsContext.h"
-#include "PlatformScrollBar.h"
#include "PlatformMouseEvent.h"
#include "PlatformWheelEvent.h"
#include "GraphicsContext.h"
#include "HitTestResult.h"
-#include "bindings/runtime.h"
-#include "bindings/runtime_root.h"
-#include "kjs_proxy.h"
-#include "kjs_window.h"
-#include "kjs_binding.h"
+#include "runtime.h"
+#include "runtime_object.h"
+#include "runtime_root.h"
+#include "JSDOMWindow.h"
+#include "qt_instance.h"
+#include "ScriptController.h"
+#include "JSDOMBinding.h"
#include "ExecState.h"
-#include "object.h"
+#include "JSLock.h"
+#include "JSObject.h"
+#include "qt_runtime.h"
#include "wtf/HashMap.h"
#include <qdebug.h>
#include <qevent.h>
+#include <qfileinfo.h>
#include <qpainter.h>
#if QT_VERSION >= 0x040400
#include <qnetworkrequest.h>
@@ -71,44 +76,57 @@
#include "qwebnetworkinterface.h"
#endif
#include <qregion.h>
+#include <qprinter.h>
using namespace WebCore;
+// from text/qfont.cpp
+QT_BEGIN_NAMESPACE
+extern Q_GUI_EXPORT int qt_defaultDpi();
+QT_END_NAMESPACE
+
void QWebFramePrivate::init(QWebFrame *qframe, WebCore::Page *webcorePage, QWebFrameData *frameData)
{
q = qframe;
+ allowsScrolling = frameData->allowsScrolling;
+ marginWidth = frameData->marginWidth;
+ marginHeight = frameData->marginHeight;
+
frameLoaderClient = new FrameLoaderClientQt();
- frame = new Frame(webcorePage, frameData->ownerElement, frameLoaderClient);
- frameLoaderClient->setFrame(qframe, frame.get());
-
- frameView = new FrameView(frame.get());
- frameView->deref();
- frameView->setQWebFrame(qframe);
- if (!frameData->allowsScrolling)
- frameView->setScrollbarsMode(ScrollbarAlwaysOff);
- if (frameData->marginWidth != -1)
- frameView->setMarginWidth(frameData->marginWidth);
- if (frameData->marginHeight != -1)
- frameView->setMarginHeight(frameData->marginHeight);
-
- frame->setView(frameView.get());
+ RefPtr<Frame> newFrame = Frame::create(webcorePage, frameData->ownerElement, frameLoaderClient);
+ frame = newFrame.get();
+ if (frameData->ownerElement)
+ frame->ref(); // balanced by adoptRef in FrameLoaderClientQt::createFrame
+ frameLoaderClient->setFrame(qframe, frame);
frame->init();
+}
- QObject::connect(q, SIGNAL(hoveringOverLink(const QString&, const QString&, const QString&)),
- page, SIGNAL(hoveringOverLink(const QString&, const QString&, const QString&)));
+WebCore::Scrollbar* QWebFramePrivate::horizontalScrollBar() const
+{
+ if (!frame->view())
+ return 0;
+ return frame->view()->horizontalScrollbar();
}
-WebCore::PlatformScrollbar *QWebFramePrivate::horizontalScrollBar() const
+WebCore::Scrollbar* QWebFramePrivate::verticalScrollBar() const
{
- Q_ASSERT(frameView);
- return frameView->horizontalScrollBar();
+ if (!frame->view())
+ return 0;
+ return frame->view()->verticalScrollbar();
}
-WebCore::PlatformScrollbar *QWebFramePrivate::verticalScrollBar() const
+void QWebFramePrivate::updateBackground()
{
- Q_ASSERT(frameView);
- return frameView->verticalScrollBar();
+ WebCore::FrameView *view = frame->view();
+ if (!view)
+ return;
+ QBrush brush = page->palette().brush(QPalette::Background);
+ if (brush.style() == Qt::SolidPattern) {
+ view->setBaseBackgroundColor(brush.color());
+ if (!brush.color().alpha())
+ view->setTransparent(true);
+ }
}
/*!
@@ -117,13 +135,35 @@ WebCore::PlatformScrollbar *QWebFramePrivate::verticalScrollBar() const
\brief The QWebFrame class represents a frame in a web page.
QWebFrame represents a frame inside a web page. Each QWebPage
- object contains at least one frame, the mainFrame(). Additional
- frames will be created for HTML &lt;frame&gt; or &lt;iframe&gt;
- elements.
+ object contains at least one frame, the main frame, obtained using
+ QWebPage::mainFrame(). Additional frames will be created for HTML
+ \c{<frame>} or \c{<iframe>} elements.
+
+ A frame can be loaded using load() or setUrl(). Alternatively, if you have
+ the HTML content readily available, you can use setHtml() instead.
+
+ The page() function returns a pointer to the web page object. See
+ \l{Elements of QWebView} for an explanation of how web
+ frames are related to a web page and web view.
+
+ 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
+ corresponding titleChanged() and iconChanged() signals will be emitted.
+ The zoomFactor() property can be used to change the overall size
+ of the content displayed in the frame.
QWebFrame objects are created and controlled by the web page. You
- can connect to the web pages frameCreated() signal to find out
- about creation of new frames.
+ can connect to the web page's \l{QWebPage::}{frameCreated()} signal
+ to be notified when a new frame is created.
+
+ The hitTestContent() function can be used to programmatically examine the
+ contents of a frame.
+
+ A QWebFrame can be printed onto a QPrinter using the print() function.
+ This function is marked as a slot and can be conveniently connected to
+ \l{QPrintPreviewDialog}'s \l{QPrintPreviewDialog::}{paintRequested()}
+ signal.
\sa QWebPage
*/
@@ -136,7 +176,7 @@ QWebFrame::QWebFrame(QWebPage *parent, QWebFrameData *frameData)
d->init(this, parent->d->page, frameData);
if (!frameData->url.isEmpty()) {
- ResourceRequest request(frameData->url, frameData->referrer);
+ WebCore::ResourceRequest request(frameData->url, frameData->referrer);
d->frame->loader()->load(request, frameData->name);
}
}
@@ -151,40 +191,49 @@ QWebFrame::QWebFrame(QWebFrame *parent, QWebFrameData *frameData)
QWebFrame::~QWebFrame()
{
- Q_ASSERT(d->frame == 0);
- Q_ASSERT(d->frameView == 0);
+ if (d->frame && d->frame->loader() && d->frame->loader()->client())
+ static_cast<FrameLoaderClientQt*>(d->frame->loader()->client())->m_webFrame = 0;
+
delete d;
}
/*!
- Make \a object available under \a name from within the frames
- JavaScript context. The \a object will be inserted as a child of the
- frames window object.
+ Make \a object available under \a name from within the frame's JavaScript
+ context. The \a object will be inserted as a child of the frame's window
+ object.
- Qt properties will be exposed as JavaScript properties and slots as
- JavaScript methods.
+ Qt properties will be exposed as JavaScript properties and slots as
+ JavaScript methods.
+
+ If you want to ensure that your QObjects remain accessible after loading a
+ new URL, you should add them in a slot connected to the
+ javaScriptWindowObjectCleared() signal.
*/
-void QWebFrame::addToJSWindowObject(const QString &name, QObject *object)
+void QWebFrame::addToJavaScriptWindowObject(const QString &name, QObject *object)
{
- KJS::JSLock lock;
- KJS::Window *window = KJS::Window::retrieveWindow(d->frame.get());
- KJS::Bindings::RootObject *root = d->frame->bindingRootObject();
+ JSC::JSLock lock(false);
+ JSDOMWindow *window = toJSDOMWindow(d->frame);
+ JSC::Bindings::RootObject *root = d->frame->script()->bindingRootObject();
if (!window) {
qDebug() << "Warning: couldn't get window object";
return;
}
- KJS::JSObject *runtimeObject =
- KJS::Bindings::Instance::createRuntimeObject(KJS::Bindings::Instance::QtLanguage,
- object, root);
+ JSC::ExecState* exec = window->globalExec();
+
+ JSC::JSObject *runtimeObject =
+ JSC::Bindings::Instance::createRuntimeObject(exec, JSC::Bindings::QtInstance::getQtInstance(object, root));
- window->put(window->globalExec(), KJS::Identifier((const KJS::UChar *) name.constData(), name.length()), runtimeObject);
+ JSC::PutPropertySlot slot;
+ window->put(exec, JSC::Identifier(exec, (const UChar *) name.constData(), name.length()), runtimeObject, slot);
}
/*!
- returns the markup (HTML) contained in the current frame.
+ Returns the frame's content, converted to HTML.
+
+ \sa setHtml(), toPlainText()
*/
-QString QWebFrame::markup() const
+QString QWebFrame::toHtml() const
{
if (!d->frame->document())
return QString();
@@ -192,32 +241,38 @@ QString QWebFrame::markup() const
}
/*!
- returns the content of this frame as plain text.
+ Returns the content of this frame converted to plain text.
+
+ \sa toHtml()
*/
-QString QWebFrame::innerText() const
+QString QWebFrame::toPlainText() const
{
- if (d->frameView->layoutPending())
- d->frameView->layout();
+ if (d->frame->view() && d->frame->view()->layoutPending())
+ d->frame->view()->layout();
Element *documentElement = d->frame->document()->documentElement();
return documentElement->innerText();
}
/*!
- returns a dump of the rendering tree. Mainly useful for debugging html.
+ Returns a dump of the rendering tree. This is mainly useful for debugging
+ html.
*/
QString QWebFrame::renderTreeDump() const
{
- if (d->frameView->layoutPending())
- d->frameView->layout();
+ if (d->frame->view() && d->frame->view()->layoutPending())
+ d->frame->view()->layout();
- return externalRepresentation(d->frame->renderer());
+ return externalRepresentation(d->frame->contentRenderer());
}
/*!
- The title of the frame as defined by the HTML &lt;title&gt;
- element.
+ \property QWebFrame::title
+ \brief the title of the frame as defined by the HTML &lt;title&gt; element
+
+ \sa titleChanged()
*/
+
QString QWebFrame::title() const
{
if (d->frame->document())
@@ -225,45 +280,49 @@ QString QWebFrame::title() const
else return QString();
}
-/*!
- The url of this frame.
-*/
-QUrl QWebFrame::url() const
+static inline QUrl ensureAbsoluteUrl(const QUrl &url)
{
- return d->frame->loader()->url();
+ if (!url.isRelative())
+ return url;
+
+ return QUrl::fromLocalFile(QFileInfo(url.toLocalFile()).absoluteFilePath());
}
/*!
- The icon associated with this frame.
+ \property QWebFrame::url
+ \brief the url of the frame currently viewed
+
+ \sa urlChanged()
*/
-QPixmap QWebFrame::icon() const
+
+void QWebFrame::setUrl(const QUrl &url)
{
- String url = d->frame->loader()->url().string();
+ d->frame->loader()->begin(ensureAbsoluteUrl(url));
+ d->frame->loader()->end();
+ load(ensureAbsoluteUrl(url));
+}
- Image* image = 0;
- if (!url.isEmpty()) {
- image = iconDatabase()->iconForPageURL(url, IntSize(16, 16));
- }
+QUrl QWebFrame::url() const
+{
+ return d->frame->loader()->url();
+}
- if (!image || image->isNull()) {
- image = iconDatabase()->defaultIcon(IntSize(16, 16));
- }
+/*!
+ \property QWebFrame::icon
+ \brief the icon associated with this frame
- if (!image) {
- return QPixmap();
- }
+ \sa iconChanged(), QWebSettings::iconForUrl()
+*/
- QPixmap *icon = image->getPixmap();
- if (!icon) {
- return QPixmap();
- }
- return *icon;
+QIcon QWebFrame::icon() const
+{
+ return QWebSettings::iconForUrl(d->frame->loader()->url());
}
/*!
The name of this frame as defined by the parent frame.
*/
-QString QWebFrame::name() const
+QString QWebFrame::frameName() const
{
return d->frame->tree()->name();
}
@@ -277,27 +336,33 @@ QWebPage *QWebFrame::page() const
}
/*!
- Load \a url into this frame.
+ Loads \a url into this frame.
+
+ \note The view remains the same until enough data has arrived to display the new \a url.
+
+ \sa setUrl(), setHtml(), setContent()
*/
void QWebFrame::load(const QUrl &url)
{
#if QT_VERSION < 0x040400
- load(QWebNetworkRequest(url));
+ load(QWebNetworkRequest(ensureAbsoluteUrl(url)));
#else
- load(QNetworkRequest(url));
+ load(QNetworkRequest(ensureAbsoluteUrl(url)));
#endif
}
#if QT_VERSION < 0x040400
/*!
- Load network request \a req into this frame.
+ Loads a network request, \a req, into this frame.
+
+ \note The view remains the same until enough data has arrived to display the new url.
*/
void QWebFrame::load(const QWebNetworkRequest &req)
{
if (d->parentFrame())
d->page->d->insideOpenCall = true;
- QUrl url = req.url();
+ QUrl url = ensureAbsoluteUrl(req.url());
QHttpRequestHeader httpHeader = req.httpHeader();
QByteArray postData = req.postData();
@@ -313,10 +378,8 @@ void QWebFrame::load(const QWebNetworkRequest &req)
request.addHTTPHeaderField(val.first, val.second);
}
- if (!postData.isEmpty()) {
- WTF::RefPtr<WebCore::FormData> formData = new WebCore::FormData(postData.constData(), postData.size());
- request.setHTTPBody(formData);
- }
+ if (!postData.isEmpty())
+ request.setHTTPBody(WebCore::FormData::create(postData.constData(), postData.size()));
d->frame->loader()->load(request);
@@ -327,8 +390,14 @@ void QWebFrame::load(const QWebNetworkRequest &req)
#else
/*!
- Load network request \a req into this frame. Use the method specified in \a
- operation. \a body is optional and is only used for POST operations.
+ Loads a network request, \a req, into this frame, using the method specified in \a
+ operation.
+
+ \a body is optional and is only used for POST operations.
+
+ \note The view remains the same until enough data has arrived to display the new \a url.
+
+ \sa setUrl()
*/
void QWebFrame::load(const QNetworkRequest &req,
QNetworkAccessManager::Operation operation,
@@ -337,7 +406,7 @@ void QWebFrame::load(const QNetworkRequest &req,
if (d->parentFrame())
d->page->d->insideOpenCall = true;
- QUrl url = req.url();
+ QUrl url = ensureAbsoluteUrl(req.url());
WebCore::ResourceRequest request(url);
@@ -365,10 +434,8 @@ void QWebFrame::load(const QNetworkRequest &req,
request.addHTTPHeaderField(QString::fromLatin1(headerName), QString::fromLatin1(req.rawHeader(headerName)));
}
- if (!body.isEmpty()) {
- WTF::RefPtr<WebCore::FormData> formData = new WebCore::FormData(body.constData(), body.size());
- request.setHTTPBody(formData);
- }
+ if (!body.isEmpty())
+ request.setHTTPBody(WebCore::FormData::create(body.constData(), body.size()));
d->frame->loader()->load(request);
@@ -380,34 +447,38 @@ 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.
+
+ 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
+ for the encoding to be specified by web server.
+
+ \sa toHtml()
*/
void QWebFrame::setHtml(const QString &html, const QUrl &baseUrl)
{
KURL kurl(baseUrl);
WebCore::ResourceRequest request(kurl);
- WTF::RefPtr<WebCore::SharedBuffer> data = new WebCore::SharedBuffer(reinterpret_cast<const uchar *>(html.unicode()), html.length() * 2);
- WebCore::SubstituteData substituteData(data, WebCore::String("text/html"), WebCore::String("utf-16"), kurl);
+ const QByteArray utf8 = html.toUtf8();
+ WTF::RefPtr<WebCore::SharedBuffer> data = WebCore::SharedBuffer::create(utf8.constData(), utf8.length());
+ WebCore::SubstituteData substituteData(data, WebCore::String("text/html"), WebCore::String("utf-8"), kurl);
d->frame->loader()->load(request, substituteData);
}
/*!
- \overload
-*/
-void QWebFrame::setHtml(const QByteArray &html, const QUrl &baseUrl)
-{
- setContent(html, QString(), baseUrl);
-}
+ Sets the content of this frame to the specified content \a data. If the \a mimeType argument
+ is empty it is currently assumed that the content is HTML but in future versions we may introduce
+ auto-detection.
-/*!
- Sets the content of this frame to \a data assuming \a mimeType. If
- \a mimeType is not specified it defaults to 'text/html'. \a baseUrl
- us optional and used to resolve relative URLs in the document.
+ External objects referenced in the content are located relative to \a baseUrl.
+
+ \sa toHtml()
*/
void QWebFrame::setContent(const QByteArray &data, const QString &mimeType, const QUrl &baseUrl)
{
KURL kurl(baseUrl);
WebCore::ResourceRequest request(kurl);
- WTF::RefPtr<WebCore::SharedBuffer> buffer = new WebCore::SharedBuffer(data.constData(), data.length());
+ WTF::RefPtr<WebCore::SharedBuffer> buffer = WebCore::SharedBuffer::create(data.constData(), data.length());
QString actualMimeType = mimeType;
if (actualMimeType.isEmpty())
actualMimeType = QLatin1String("text/html");
@@ -421,6 +492,8 @@ void QWebFrame::setContent(const QByteArray &data, const QString &mimeType, cons
main frame.
This is equivalent to qobject_cast<QWebFrame*>(frame->parent()).
+
+ \sa childFrames()
*/
QWebFrame *QWebFrame::parentFrame() const
{
@@ -429,6 +502,8 @@ QWebFrame *QWebFrame::parentFrame() const
/*!
Returns a list of all frames that are direct children of this frame.
+
+ \sa parentFrame()
*/
QList<QWebFrame*> QWebFrame::childFrames() const
{
@@ -447,98 +522,374 @@ QList<QWebFrame*> QWebFrame::childFrames() const
}
/*!
- \property QWebFrame::verticalScrollBarPolicy
-
- This property defines the vertical scrollbar policy.
-
- \sa Qt::ScrollBarPolicy
+ Returns the scrollbar policy for the scrollbar defined by \a orientation.
*/
-Qt::ScrollBarPolicy QWebFrame::verticalScrollBarPolicy() const
+Qt::ScrollBarPolicy QWebFrame::scrollBarPolicy(Qt::Orientation orientation) const
{
- return (Qt::ScrollBarPolicy) d->frameView->vScrollbarMode();
+ if (orientation == Qt::Horizontal)
+ return d->horizontalScrollBarPolicy;
+ return d->verticalScrollBarPolicy;
}
-void QWebFrame::setVerticalScrollBarPolicy(Qt::ScrollBarPolicy policy)
+/*!
+ Sets the scrollbar policy for the scrollbar defined by \a orientation to \a policy.
+*/
+void QWebFrame::setScrollBarPolicy(Qt::Orientation orientation, Qt::ScrollBarPolicy policy)
{
Q_ASSERT((int)ScrollbarAuto == (int)Qt::ScrollBarAsNeeded);
Q_ASSERT((int)ScrollbarAlwaysOff == (int)Qt::ScrollBarAlwaysOff);
Q_ASSERT((int)ScrollbarAlwaysOn == (int)Qt::ScrollBarAlwaysOn);
- d->frameView->setVScrollbarMode((ScrollbarMode)policy);
+
+ if (orientation == Qt::Horizontal) {
+ d->horizontalScrollBarPolicy = policy;
+ if (d->frame->view())
+ d->frame->view()->setHorizontalScrollbarMode((ScrollbarMode)policy);
+ } else {
+ d->verticalScrollBarPolicy = policy;
+ if (d->frame->view())
+ d->frame->view()->setVerticalScrollbarMode((ScrollbarMode)policy);
+ }
}
/*!
- \property QWebFrame::horizontalScrollBarPolicy
+ Sets the current \a value for the scrollbar with orientation \a orientation.
- This property defines the horizontal scrollbar policy.
+ The scrollbar forces the \a value to be within the legal range: minimum <= value <= maximum.
- \sa Qt::ScrollBarPolicy
+ Changing the value also updates the thumb position.
+
+ \sa scrollBarMinimum(), scrollBarMaximum()
*/
-Qt::ScrollBarPolicy QWebFrame::horizontalScrollBarPolicy() const
+void QWebFrame::setScrollBarValue(Qt::Orientation orientation, int value)
{
- return (Qt::ScrollBarPolicy) d->frameView->hScrollbarMode();
+ Scrollbar *sb;
+ sb = (orientation == Qt::Horizontal) ? d->horizontalScrollBar() : d->verticalScrollBar();
+ if (sb) {
+ if (value < 0)
+ value = 0;
+ else if (value > scrollBarMaximum(orientation))
+ value = scrollBarMaximum(orientation);
+ sb->setValue(value);
+ }
}
-void QWebFrame::setHorizontalScrollBarPolicy(Qt::ScrollBarPolicy policy)
+/*!
+ Returns the current value for the scrollbar with orientation \a orientation, or 0
+ if no scrollbar is found for \a orientation.
+
+ \sa scrollBarMinimum(), scrollBarMaximum()
+*/
+int QWebFrame::scrollBarValue(Qt::Orientation orientation) const
{
- d->frameView->setHScrollbarMode((ScrollbarMode)policy);
+ Scrollbar *sb;
+ sb = (orientation == Qt::Horizontal) ? d->horizontalScrollBar() : d->verticalScrollBar();
+ if (sb) {
+ return sb->value();
+ }
+ return 0;
+}
+
+/*!
+ Returns the maximum value for the scrollbar with orientation \a orientation, or 0
+ if no scrollbar is found for \a orientation.
+
+ \sa scrollBarMinimum()
+*/
+int QWebFrame::scrollBarMaximum(Qt::Orientation orientation) const
+{
+ Scrollbar *sb;
+ sb = (orientation == Qt::Horizontal) ? d->horizontalScrollBar() : d->verticalScrollBar();
+ if (sb)
+ return sb->maximum();
+ return 0;
+}
+
+/*!
+ Returns the minimum value for the scrollbar with orientation \a orientation.
+
+ The minimum value is always 0.
+
+ \sa scrollBarMaximum()
+*/
+int QWebFrame::scrollBarMinimum(Qt::Orientation orientation) const
+{
+ return 0;
+}
+
+/*!
+ \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::scrollOffset
+*/
+
+void QWebFrame::scroll(int dx, int dy) const
+{
+ if (!d->frame->view())
+ return;
+
+ d->frame->view()->scrollBy(IntSize(dx, dy));
+}
+
+/*!
+ \property QWebFrame::scrollOffset
+ \brief The offset from the start this frame is currently scrolled to.
+*/
+
+QSize QWebFrame::scrollOffset() const
+{
+ if (!d->frame->view())
+ return QSize(0,0);
+
+ return d->frame->view()->scrollOffset();
+}
+
+void QWebFrame::setScrollOffset(const QSize &offset) const
+{
+ QSize current = scrollOffset();
+ int dx = offset.width() - current.width();
+ int dy = offset.height() - current.height();
+ scroll(dx, dy);
}
/*!
Render the frame into \a painter clipping to \a clip.
+
+ \sa print()
*/
void QWebFrame::render(QPainter *painter, const QRegion &clip)
{
- if (!d->frameView || !d->frame->renderer())
+ if (!d->frame->view() || !d->frame->contentRenderer())
return;
- layout();
+ d->frame->view()->layoutIfNeededRecursive();
GraphicsContext ctx(painter);
QVector<QRect> vector = clip.rects();
- for (int i = 0; i < vector.size(); ++i)
- d->frameView->paint(&ctx, vector.at(i));
+ WebCore::FrameView* view = d->frame->view();
+ for (int i = 0; i < vector.size(); ++i) {
+ if (i > 0) {
+ painter->save();
+ painter->setClipRect(vector.at(i), Qt::IntersectClip);
+ }
+
+ view->paint(&ctx, vector.at(i));
+
+ if (i > 0)
+ painter->restore();
+ }
}
/*!
- Ensure that the content of the frame and all subframes are correctly layouted.
+ Render the frame into \a painter.
*/
-void QWebFrame::layout()
+void QWebFrame::render(QPainter *painter)
{
- if (!d->frameView)
+ if (!d->frame->view() || !d->frame->contentRenderer())
return;
- d->frameView->layoutIfNeededRecursive();
+ d->frame->view()->layoutIfNeededRecursive();
+
+ GraphicsContext ctx(painter);
+ WebCore::FrameView* view = d->frame->view();
+ view->paint(&ctx, view->frameRect());
+}
+
+/*!
+ \property QWebFrame::textSizeMultiplier
+ \brief the scaling factor for all text in the frame
+ \obsolete
+
+ Use setZoomFactor instead, in combination with the ZoomTextOnly attribute in
+ QWebSettings.
+
+ \note Setting this property also enables the ZoomTextOnly attribute in
+ QWebSettings.
+*/
+
+void QWebFrame::setTextSizeMultiplier(qreal factor)
+{
+ d->frame->setZoomFactor(factor, /*isTextOnly*/true);
+}
+
+qreal QWebFrame::textSizeMultiplier() const
+{
+ return d->frame->zoomFactor();
+}
+
+/*!
+ \property QWebFrame::zoomFactor
+ \since 4.5
+ \brief the zoom factor for the frame
+*/
+
+void QWebFrame::setZoomFactor(qreal factor)
+{
+ d->frame->setZoomFactor(factor, d->frame->isZoomFactorTextOnly());
+}
+
+qreal QWebFrame::zoomFactor() const
+{
+ return d->frame->zoomFactor();
}
/*!
- returns the position of the frame relative to it's parent frame.
+ Returns the position of the frame relative to it's parent frame.
*/
QPoint QWebFrame::pos() const
{
- Q_ASSERT(d->frameView);
- return d->pos();
+ if (!d->frame->view())
+ return QPoint();
+
+ return d->frame->view()->frameRect().topLeft();
}
/*!
- return the geometry of the frame relative to it's parent frame.
+ Return the geometry of the frame relative to it's parent frame.
*/
QRect QWebFrame::geometry() const
{
- Q_ASSERT(d->frameView);
- return d->frameView->frameGeometry();
+ if (!d->frame->view())
+ return QRect();
+ return d->frame->view()->frameRect();
}
/*!
- Evaluate JavaScript defined by \a scriptSource using this frame as context.
+ \property QWebFrame::contentsSize
+ \brief the size of the contents in this frame
*/
-QString QWebFrame::evaluateJavaScript(const QString& scriptSource)
+QSize QWebFrame::contentsSize() const
{
- KJSProxy *proxy = d->frame->scriptProxy();
- QString rc;
+ FrameView *view = d->frame->view();
+ if (!view)
+ return QSize();
+ return QSize(view->contentsWidth(), view->contentsHeight());
+}
+
+/*!
+ 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
+{
+ if (!d->frame->view() || !d->frame->contentRenderer())
+ return QWebHitTestResult();
+
+ HitTestResult result = d->frame->eventHandler()->hitTestResultAtPoint(d->frame->view()->windowToContents(pos), /*allowShadowContent*/ false);
+ return QWebHitTestResult(new QWebHitTestResultPrivate(result));
+}
+
+/*! \reimp
+*/
+bool QWebFrame::event(QEvent *e)
+{
+ return QObject::event(e);
+}
+
+#ifndef QT_NO_PRINTER
+/*!
+ Prints the frame to the given \a printer.
+
+ \sa render()
+*/
+void QWebFrame::print(QPrinter *printer) const
+{
+ const qreal zoomFactorX = printer->logicalDpiX() / qt_defaultDpi();
+ const qreal zoomFactorY = printer->logicalDpiY() / qt_defaultDpi();
+
+ PrintContext printContext(d->frame);
+ float pageHeight = 0;
+
+ QRect qprinterRect = printer->pageRect();
+
+ IntRect pageRect(0, 0,
+ int(qprinterRect.width() / zoomFactorX),
+ int(qprinterRect.height() / zoomFactorY));
+
+ printContext.begin(pageRect.width());
+
+ printContext.computePageRects(pageRect, /*headerHeight*/0, /*footerHeight*/0, /*userScaleFactor*/1.0, pageHeight);
+
+ int docCopies;
+ int pageCopies;
+ if (printer->collateCopies() == true){
+ docCopies = 1;
+ pageCopies = printer->numCopies();
+ } else {
+ docCopies = printer->numCopies();
+ pageCopies = 1;
+ }
+
+ int fromPage = printer->fromPage();
+ int toPage = printer->toPage();
+ bool ascending = true;
+
+ if (fromPage == 0 && toPage == 0) {
+ fromPage = 1;
+ toPage = printContext.pageCount();
+ }
+ // paranoia check
+ fromPage = qMax(1, fromPage);
+ toPage = qMin(printContext.pageCount(), toPage);
+
+ if (printer->pageOrder() == QPrinter::LastPageFirst) {
+ int tmp = fromPage;
+ fromPage = toPage;
+ toPage = tmp;
+ ascending = false;
+ }
+
+ QPainter painter(printer);
+ painter.scale(zoomFactorX, zoomFactorY);
+ GraphicsContext ctx(&painter);
+
+ for (int i = 0; i < docCopies; ++i) {
+ int page = fromPage;
+ while (true) {
+ for (int j = 0; j < pageCopies; ++j) {
+ if (printer->printerState() == QPrinter::Aborted
+ || printer->printerState() == QPrinter::Error) {
+ printContext.end();
+ return;
+ }
+ printContext.spoolPage(ctx, page - 1, pageRect.width());
+ if (j < pageCopies - 1)
+ printer->newPage();
+ }
+
+ if (page == toPage)
+ break;
+
+ if (ascending)
+ ++page;
+ else
+ --page;
+
+ printer->newPage();
+ }
+
+ if ( i < docCopies - 1)
+ printer->newPage();
+ }
+
+ printContext.end();
+}
+#endif // QT_NO_PRINTER
+
+/*!
+ Evaluate JavaScript defined by \a scriptSource using this frame as context.
+
+ \sa addToJavaScriptWindowObject(), javaScriptWindowObjectCleared()
+*/
+QVariant QWebFrame::evaluateJavaScript(const QString& scriptSource)
+{
+ ScriptController *proxy = d->frame->script();
+ QVariant rc;
if (proxy) {
- KJS::JSValue *v = proxy->evaluate(String(), 0, scriptSource);
+ JSC::JSValue* v = proxy->evaluate(String(), 1, scriptSource);
if (v) {
- rc = String(v->toString(proxy->globalObject()->globalExec()));
+ int distance = 0;
+ rc = JSC::Bindings::convertValueToQVariant(proxy->globalObject()->globalExec(), v, QMetaType::Void, &distance);
}
}
return rc;
@@ -546,7 +897,7 @@ QString QWebFrame::evaluateJavaScript(const QString& scriptSource)
WebCore::Frame* QWebFramePrivate::core(QWebFrame* webFrame)
{
- return webFrame->d->frame.get();
+ return webFrame->d->frame;
}
QWebFrame* QWebFramePrivate::kit(WebCore::Frame* coreFrame)
@@ -556,74 +907,301 @@ QWebFrame* QWebFramePrivate::kit(WebCore::Frame* coreFrame)
/*!
- \fn void QWebFrame::cleared()
+ \fn void QWebFrame::javaScriptWindowObjectCleared()
+
+ This signal is emitted whenever the global window object of the JavaScript
+ environment is cleared, e.g., before starting a new load.
+
+ If you intend to add QObjects to a QWebFrame using
+ addToJavaScriptWindowObject(), you should add them in a slot connected
+ to this signal. This ensures that your objects remain accessible when
+ loading new URLs.
+*/
- This signal is emitted whenever the content of the frame is cleared
- (e.g. before starting a new load).
+/*!
+ \fn void QWebFrame::provisionalLoad()
+ \internal
*/
/*!
- \fn void QWebFrame::loadDone(bool ok)
+ \fn void QWebFrame::titleChanged(const QString &title)
- This signal is emitted when the frame is completely loaded. \a ok will indicate whether the load
- was successful or any error occurred.
+ This signal is emitted whenever the title of the frame changes.
+ The \a title string specifies the new title.
+
+ \sa title()
*/
/*!
- \fn void QWebFrame::provisionalLoad()
+ \fn void QWebFrame::urlChanged(const QUrl &url)
+
+ This signal is emitted with the URL of the frame when the frame's title is
+ received. The new URL is specified by \a url.
- \internal
+ \sa url()
*/
/*!
- \fn void QWebFrame::titleChanged(const QString &title)
+ \fn void QWebFrame::initialLayoutCompleted()
- This signal is emitted whenever the title of the frame changes.
- The \a title string specifies the new title.
+ This signal is emitted when the frame is laid out the first time.
+ This is the first time you will see contents displayed on the frame.
- \sa title()
+ \note A frame can be laid out multiple times.
*/
/*!
- \fn void QWebFrame::urlChanged(const QUrl &url)
+ \fn void QWebFrame::iconChanged()
- This signal is emitted whenever the \a url of the frame changes.
+ This signal is emitted when the icon ("favicon") associated with the frame
+ has been loaded.
- \sa url()
+ \sa icon()
*/
/*!
- \fn void QWebFrame::hoveringOverLink(const QString &link, const QString &title, const QString &textContent)
+ \since 4.5
+ \fn void QWebFrame::aboutToUpdateHistory(QWebHistoryItem* item);
- This signal is emitted whenever the mouse cursor is hovering over a
- link. It can be used to display information about the link in
- e.g. the status bar. The signal arguments consist of the \a link destination, the \a title and the
- link text as \a textContent .
+ This signal is emitted shortly before the history of navigated pages
+ is changed, for example when navigating back in the history.
+
+ A potential use-case for this signal is to store custom data in
+ the QWebHistoryItem associated to the frame, using QWebHistoryItem::setUserData().
*/
+/*!
+ \class QWebHitTestResult
+ \since 4.4
+ \brief The QWebHitTestResult class provides information about the web
+ page content after a hit test.
+
+ QWebHitTestResult is returned by QWebFrame::hitTestContent() to provide
+ information about the content of the web page at the specified position.
+*/
+
+/*!
+ \internal
+*/
+QWebHitTestResult::QWebHitTestResult(QWebHitTestResultPrivate *priv)
+ : d(priv)
+{
+}
+
+QWebHitTestResultPrivate::QWebHitTestResultPrivate(const WebCore::HitTestResult &hitTest)
+ : isContentEditable(false)
+ , isContentSelected(false)
+{
+ if (!hitTest.innerNode())
+ return;
+ pos = hitTest.point();
+ boundingRect = hitTest.boundingBox();
+ title = hitTest.title();
+ linkText = hitTest.textContent();
+ linkUrl = hitTest.absoluteLinkURL();
+ linkTitle = hitTest.titleDisplayString();
+ alternateText = hitTest.altDisplayString();
+ imageUrl = hitTest.absoluteImageURL();
+ innerNonSharedNode = hitTest.innerNonSharedNode();
+ WebCore::Image *img = hitTest.image();
+ if (img) {
+ QPixmap *pix = img->nativeImageForCurrentFrame();
+ if (pix)
+ pixmap = *pix;
+ }
+ WebCore::Frame *wframe = hitTest.targetFrame();
+ if (wframe)
+ linkTargetFrame = QWebFramePrivate::kit(wframe);
+
+ isContentEditable = hitTest.isContentEditable();
+ isContentSelected = hitTest.isSelected();
+
+ if (innerNonSharedNode && innerNonSharedNode->document()
+ && innerNonSharedNode->document()->frame())
+ frame = QWebFramePrivate::kit(innerNonSharedNode->document()->frame());
+}
/*!
- \fn void QWebFrame::loadStarted()
+ Constructs a null hit test result.
+*/
+QWebHitTestResult::QWebHitTestResult()
+ : d(0)
+{
+}
- This signal is emitted when a new load of the frame is started.
+/*!
+ Constructs a hit test result from \a other.
*/
+QWebHitTestResult::QWebHitTestResult(const QWebHitTestResult &other)
+ : d(0)
+{
+ if (other.d)
+ d = new QWebHitTestResultPrivate(*other.d);
+}
/*!
- \fn void QWebFrame::loadFinished()
-
- This signal is emitted when a load of the frame is finished.
+ Assigns the \a other hit test result to this.
*/
+QWebHitTestResult &QWebHitTestResult::operator=(const QWebHitTestResult &other)
+{
+ if (this != &other) {
+ if (other.d) {
+ if (!d)
+ d = new QWebHitTestResultPrivate;
+ *d = *other.d;
+ } else {
+ delete d;
+ d = 0;
+ }
+ }
+ return *this;
+}
/*!
- \fn void QWebFrame::initialLayoutComplete()
+ Destructor.
+*/
+QWebHitTestResult::~QWebHitTestResult()
+{
+ delete d;
+}
- This signal is emitted when the first (initial) layout of the frame
- has happened. This is the earliest time something can be shown on
- the screen.
+/*!
+ Returns true if the hit test result is null; otherwise returns false.
*/
-
+bool QWebHitTestResult::isNull() const
+{
+ return !d;
+}
+
+/*!
+ Returns the position where the hit test occured.
+*/
+QPoint QWebHitTestResult::pos() const
+{
+ if (!d)
+ return QPoint();
+ return d->pos;
+}
+
+/*!
+ \since 4.5
+ Returns the bounding box of the element.
+*/
+QRect QWebHitTestResult::boundingRect() const
+{
+ if (!d)
+ return QRect();
+ return d->boundingRect;
+}
+
/*!
- \fn void QWebFrame::iconLoaded()
+ Returns the title of the nearest enclosing HTML element.
+*/
+QString QWebHitTestResult::title() const
+{
+ if (!d)
+ return QString();
+ return d->title;
+}
- This signal is emitted when the icon ("favicon") associated with the frame has been loaded.
+/*!
+ Returns the text of the link.
*/
+QString QWebHitTestResult::linkText() const
+{
+ if (!d)
+ return QString();
+ return d->linkText;
+}
+
+/*!
+ Returns the url to which the link points to.
+*/
+QUrl QWebHitTestResult::linkUrl() const
+{
+ if (!d)
+ return QUrl();
+ return d->linkUrl;
+}
+
+/*!
+ Returns the title of the link.
+*/
+QUrl QWebHitTestResult::linkTitle() const
+{
+ if (!d)
+ return QUrl();
+ return d->linkTitle;
+}
+
+/*!
+ Returns the frame that will load the link if it is activated.
+*/
+QWebFrame *QWebHitTestResult::linkTargetFrame() const
+{
+ if (!d)
+ return 0;
+ return d->linkTargetFrame;
+}
+
+/*!
+ Returns the alternate text of the element. This corresponds to the HTML alt attribute.
+*/
+QString QWebHitTestResult::alternateText() const
+{
+ if (!d)
+ return QString();
+ return d->alternateText;
+}
+
+/*!
+ Returns the url of the image.
+*/
+QUrl QWebHitTestResult::imageUrl() const
+{
+ if (!d)
+ return QUrl();
+ return d->imageUrl;
+}
+
+/*!
+ Returns a QPixmap containing the image. A null pixmap is returned if the
+ element being tested is not an image.
+*/
+QPixmap QWebHitTestResult::pixmap() const
+{
+ if (!d)
+ return QPixmap();
+ return d->pixmap;
+}
+
+/*!
+ Returns true if the content is editable by the user; otherwise returns false.
+*/
+bool QWebHitTestResult::isContentEditable() const
+{
+ if (!d)
+ return false;
+ return d->isContentEditable;
+}
+
+/*!
+ Returns true if the content tested is part of the selection; otherwise returns false.
+*/
+bool QWebHitTestResult::isContentSelected() const
+{
+ if (!d)
+ return false;
+ return d->isContentSelected;
+}
+
+/*!
+ Returns the frame the hit test was executed in.
+*/
+QWebFrame *QWebHitTestResult::frame() const
+{
+ if (!d)
+ return 0;
+ return d->frame;
+}
+
diff --git a/WebKit/qt/Api/qwebframe.h b/WebKit/qt/Api/qwebframe.h
index a1cdb25..4d37205 100644
--- a/WebKit/qt/Api/qwebframe.h
+++ b/WebKit/qt/Api/qwebframe.h
@@ -1,5 +1,5 @@
/*
- Copyright (C) 2007 Trolltech ASA
+ Copyright (C) 2008 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
@@ -16,9 +16,6 @@
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.
-
- This class provides all functionality needed for loading images, style sheets and html
- pages from the web. It has a memory cache for these objects.
*/
#ifndef QWEBFRAME_H
@@ -26,23 +23,30 @@
#include <QtCore/qobject.h>
#include <QtCore/qurl.h>
+#include <QtCore/qvariant.h>
+#include <QtGui/qicon.h>
#if QT_VERSION >= 0x040400
#include <QtNetwork/qnetworkaccessmanager.h>
#endif
#include "qwebkitglobal.h"
+QT_BEGIN_NAMESPACE
class QRect;
class QPoint;
class QPainter;
class QPixmap;
class QMouseEvent;
class QWheelEvent;
-class QWebNetworkRequest;
class QNetworkRequest;
+class QRegion;
+class QPrinter;
+QT_END_NAMESPACE
+class QWebNetworkRequest;
class QWebFramePrivate;
class QWebPage;
-class QRegion;
+class QWebHitTestResult;
+class QWebHistoryItem;
namespace WebCore {
class WidgetPrivate;
@@ -50,12 +54,57 @@ namespace WebCore {
class ChromeClientQt;
}
class QWebFrameData;
+class QWebHitTestResultPrivate;
+class QWebFrame;
+
+class QWEBKIT_EXPORT QWebHitTestResult
+{
+public:
+ QWebHitTestResult();
+ QWebHitTestResult(const QWebHitTestResult &other);
+ QWebHitTestResult &operator=(const QWebHitTestResult &other);
+ ~QWebHitTestResult();
+
+ bool isNull() const;
+
+ QPoint pos() const;
+ QRect boundingRect() const;
+ QString title() const;
+
+ QString linkText() const;
+ QUrl linkUrl() const;
+ QUrl linkTitle() const;
+ QWebFrame *linkTargetFrame() const;
+
+ QString alternateText() const; // for img, area, input and applet
+
+ QUrl imageUrl() const;
+ QPixmap pixmap() const;
+
+ bool isContentEditable() const;
+ bool isContentSelected() const;
+
+ QWebFrame *frame() const;
+
+private:
+ QWebHitTestResult(QWebHitTestResultPrivate *priv);
+ QWebHitTestResultPrivate *d;
+
+ friend class QWebFrame;
+ friend class QWebPagePrivate;
+ friend class QWebPage;
+};
class QWEBKIT_EXPORT QWebFrame : public QObject
{
Q_OBJECT
- Q_PROPERTY(Qt::ScrollBarPolicy verticalScrollBarPolicy READ verticalScrollBarPolicy WRITE setVerticalScrollBarPolicy)
- Q_PROPERTY(Qt::ScrollBarPolicy horizontalScrollBarPolicy READ horizontalScrollBarPolicy WRITE setHorizontalScrollBarPolicy)
+ 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(QIcon icon READ icon)
+ Q_PROPERTY(QSize contentsSize READ contentsSize)
+ Q_PROPERTY(QSize scrollOffset READ scrollOffset WRITE setScrollOffset)
private:
QWebFrame(QWebPage *parent, QWebFrameData *frameData);
QWebFrame(QWebFrame *parent, QWebFrameData *frameData);
@@ -73,57 +122,70 @@ public:
const QByteArray &body = QByteArray());
#endif
void setHtml(const QString &html, const QUrl &baseUrl = QUrl());
- void setHtml(const QByteArray &html, const QUrl &baseUrl = QUrl());
void setContent(const QByteArray &data, const QString &mimeType = QString(), const QUrl &baseUrl = QUrl());
- void addToJSWindowObject(const QString &name, QObject *object);
- QString markup() const;
- QString innerText() const;
+ void addToJavaScriptWindowObject(const QString &name, QObject *object);
+ QString toHtml() const;
+ QString toPlainText() const;
QString renderTreeDump() const;
QString title() const;
+ void setUrl(const QUrl &url);
QUrl url() const;
- QPixmap icon() const;
-
- QString name() const;
+ QIcon icon() const;
+
+ QString frameName() const;
QWebFrame *parentFrame() const;
QList<QWebFrame*> childFrames() const;
- Qt::ScrollBarPolicy verticalScrollBarPolicy() const;
- void setVerticalScrollBarPolicy(Qt::ScrollBarPolicy);
- Qt::ScrollBarPolicy horizontalScrollBarPolicy() const;
- void setHorizontalScrollBarPolicy(Qt::ScrollBarPolicy);
+ Qt::ScrollBarPolicy scrollBarPolicy(Qt::Orientation orientation) const;
+ void setScrollBarPolicy(Qt::Orientation orientation, Qt::ScrollBarPolicy policy);
+
+ void setScrollBarValue(Qt::Orientation orientation, int value);
+ int scrollBarValue(Qt::Orientation orientation) const;
+ int scrollBarMinimum(Qt::Orientation orientation) const;
+ int scrollBarMaximum(Qt::Orientation orientation) const;
+
+ void scroll(int, int) const;
+ QSize scrollOffset() const;
+ void setScrollOffset(const QSize &offset) const;
void render(QPainter *painter, const QRegion &clip);
- void layout();
+ void render(QPainter *painter);
+
+ void setTextSizeMultiplier(qreal factor);
+ qreal textSizeMultiplier() const;
+
+ qreal zoomFactor() const;
+ void setZoomFactor(qreal factor);
QPoint pos() const;
QRect geometry() const;
+ QSize contentsSize() const;
+
+ QWebHitTestResult hitTestContent(const QPoint &pos) const;
+
+ virtual bool event(QEvent *);
public Q_SLOTS:
- QString evaluateJavaScript(const QString& scriptSource);
+ QVariant evaluateJavaScript(const QString& scriptSource);
+#ifndef QT_NO_PRINTER
+ void print(QPrinter *printer) const;
+#endif
Q_SIGNALS:
- void cleared();
- void loadDone(bool ok);
+ void javaScriptWindowObjectCleared();
+
void provisionalLoad();
void titleChanged(const QString &title);
- void hoveringOverLink(const QString &link, const QString &title, const QString &textContent);
void urlChanged(const QUrl &url);
- void loadStarted();
- void loadFinished();
-
- /**
- * Signal is emitted when the mainframe()'s initial layout is completed.
- */
- void initialLayoutComplete();
-
- /**
- * Signal is emitted when an icon ("favicon") is loaded from the site.
- */
- void iconLoaded();
+ void initialLayoutCompleted();
+
+ void iconChanged();
+
+ void aboutToUpdateHistory(QWebHistoryItem* item);
private:
friend class QWebPage;
diff --git a/WebKit/qt/Api/qwebframe_p.h b/WebKit/qt/Api/qwebframe_p.h
index 136cf78..2b497e6 100644
--- a/WebKit/qt/Api/qwebframe_p.h
+++ b/WebKit/qt/Api/qwebframe_p.h
@@ -1,5 +1,5 @@
/*
- Copyright (C) 2007 Trolltech ASA
+ Copyright (C) 2008 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
@@ -16,10 +16,8 @@
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.
-
- This class provides all functionality needed for loading images, style sheets and html
- pages from the web. It has a memory cache for these objects.
*/
+
#ifndef QWEBFRAME_P_H
#define QWEBFRAME_P_H
@@ -27,18 +25,17 @@
#include "qwebpage_p.h"
#include "EventHandler.h"
-#include "FrameView.h"
#include "KURL.h"
#include "PlatformString.h"
#include "wtf/RefPtr.h"
+#include "Frame.h"
namespace WebCore
{
class FrameLoaderClientQt;
- class Frame;
class FrameView;
class HTMLFrameOwnerElement;
- class PlatformScrollbar;
+ class Scrollbar;
}
class QWebPage;
@@ -61,30 +58,61 @@ class QWebFramePrivate
public:
QWebFramePrivate()
: q(0)
+ , horizontalScrollBarPolicy(Qt::ScrollBarAsNeeded)
+ , verticalScrollBarPolicy(Qt::ScrollBarAsNeeded)
, frameLoaderClient(0)
, frame(0)
- , frameView(0)
, page(0)
+ , allowsScrolling(true)
+ , marginWidth(-1)
+ , marginHeight(-1)
{}
void init(QWebFrame *qframe, WebCore::Page *page,
QWebFrameData *frameData);
inline QWebFrame *parentFrame() { return qobject_cast<QWebFrame*>(q->parent()); }
- WebCore::PlatformScrollbar *horizontalScrollBar() const;
- WebCore::PlatformScrollbar *verticalScrollBar() const;
+ WebCore::Scrollbar* horizontalScrollBar() const;
+ WebCore::Scrollbar* verticalScrollBar() const;
+
+ Qt::ScrollBarPolicy horizontalScrollBarPolicy;
+ Qt::ScrollBarPolicy verticalScrollBarPolicy;
- inline QPoint pos() const
- { return frameView->frameGeometry().topLeft(); }
+ void updateBackground();
static WebCore::Frame* core(QWebFrame*);
static QWebFrame* kit(WebCore::Frame*);
QWebFrame *q;
WebCore::FrameLoaderClientQt *frameLoaderClient;
- WTF::RefPtr<WebCore::Frame> frame;
- WTF::RefPtr<WebCore::FrameView> frameView;
+ WebCore::Frame *frame;
QWebPage *page;
+
+ bool allowsScrolling;
+ int marginWidth;
+ int marginHeight;
+};
+
+class QWebHitTestResultPrivate
+{
+public:
+ QWebHitTestResultPrivate() : isContentEditable(false), isContentSelected(false) {}
+ QWebHitTestResultPrivate(const WebCore::HitTestResult &hitTest);
+
+ QPoint pos;
+ QRect boundingRect;
+ QString title;
+ QString linkText;
+ QUrl linkUrl;
+ QString linkTitle;
+ QPointer<QWebFrame> linkTargetFrame;
+ QString alternateText;
+ QUrl imageUrl;
+ QPixmap pixmap;
+ bool isContentEditable;
+ bool isContentSelected;
+ QPointer<QWebFrame> frame;
+ RefPtr<WebCore::Node> innerNonSharedNode;
};
#endif
diff --git a/WebKit/qt/Api/qwebhistory.cpp b/WebKit/qt/Api/qwebhistory.cpp
index eab7d22..962aeb2 100644
--- a/WebKit/qt/Api/qwebhistory.cpp
+++ b/WebKit/qt/Api/qwebhistory.cpp
@@ -1,5 +1,5 @@
/*
- Copyright (C) 2007 Trolltech ASA
+ Copyright (C) 2008 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
@@ -15,29 +15,44 @@
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.
-
- This class provides all functionality needed for loading images, style sheets and html
- pages from the web. It has a memory cache for these objects.
*/
+
+#include "config.h"
#include "qwebhistory.h"
#include "qwebhistory_p.h"
-#include "DeprecatedString.h"
#include "PlatformString.h"
#include "Image.h"
+#include "Page.h"
+#include "PageGroup.h"
#include <QSharedData>
/*!
\class QWebHistoryItem
+ \ingroup explicitly-shared
\since 4.4
\brief The QWebHistoryItem class represents one item in the history of a QWebPage
- QWebHistoryItem represents on entry in the history stack of a web page.
+ Each QWebHistoryItem instance represents an entry in the history stack of a Web page,
+ containing information about the page, its location, and when it was last visited.
+
+ The following table shows the properties of the page held by the history item, and
+ the functions used to access them.
+
+ \table
+ \header \o Function \o Description
+ \row \o title() \o The page title.
+ \row \o url() \o The location of the page.
+ \row \o originalUrl() \o The URL used to access the page.
+ \row \o lastVisited() \o The date and time of the user's last visit to the page.
+ \row \o icon() \o The icon associated with the page that was provided by the server.
+ \row \o userData() \o The user specific data that was stored with the history item.
+ \endtable
- \sa QWebPage::history() QWebHistory
+ \note QWebHistoryItem objects are value based and \l{explicitly shared}.
- QWebHistoryItem objects are value based and explicitly shared.
+ \sa QWebHistory, QWebPage::history(), QWebHistoryInterface
*/
/*!
@@ -58,58 +73,104 @@ QWebHistoryItem &QWebHistoryItem::operator=(const QWebHistoryItem &other)
}
/*!
- Destructs a history item.
+ Destroys the history item.
*/
QWebHistoryItem::~QWebHistoryItem()
{
}
/*!
- The original url associated with the history item.
+ Returns the original URL associated with the history item.
+
+ \sa url()
*/
QUrl QWebHistoryItem::originalUrl() const
{
- return QUrl(d->item->originalURL().string());
+ if (d->item)
+ return QUrl(d->item->originalURL().string());
+ return QUrl();
}
/*!
- The current url associated with the history item.
+ Returns the URL associated with the history item.
+
+ \sa originalUrl(), title(), lastVisited()
*/
-QUrl QWebHistoryItem::currentUrl() const
+QUrl QWebHistoryItem::url() const
{
- return QUrl(d->item->url().string());
+ if (d->item)
+ return QUrl(d->item->url().string());
+ return QUrl();
}
/*!
- The title of the page associated with the history item.
+ Returns the title of the page associated with the history item.
+
+ \sa icon(), url(), lastVisited()
*/
QString QWebHistoryItem::title() const
{
- return d->item->title();
+ if (d->item)
+ return d->item->title();
+ return QString();
}
/*!
- The time when the apge associated with the item was last visited.
+ Returns the date and time that the page associated with the item was last visited.
+
+ \sa title(), icon(), url()
*/
QDateTime QWebHistoryItem::lastVisited() const
{
//FIXME : this will be wrong unless we correctly set lastVisitedTime ourselves
- return QDateTime::fromTime_t((uint)d->item->lastVisitedTime());
+ if (d->item)
+ return QDateTime::fromTime_t((uint)d->item->lastVisitedTime());
+ return QDateTime();
}
/*!
- The icon associated with the history item.
+ Returns the icon associated with the history item.
+
+ \sa title(), url(), lastVisited()
+*/
+QIcon QWebHistoryItem::icon() const
+{
+ if (d->item)
+ return *d->item->icon()->nativeImageForCurrentFrame();
+ return QIcon();
+}
+
+/*!
+ \since 4.5
+ Returns the user specific data that was stored with the history item.
+
+ \sa setUserData()
*/
-QPixmap QWebHistoryItem::icon() const
+QVariant QWebHistoryItem::userData() const
{
- return *d->item->icon()->getPixmap();
+ if (d->item)
+ return d->item->userData();
+ return QVariant();
}
/*!
+ \since 4.5
+
+ Stores user specific data with the history item.
+
+ \sa userData()
+*/
+void QWebHistoryItem::setUserData(const QVariant& userData)
+{
+ if (d->item)
+ d->item->setUserData(userData);
+}
+
+/*!*
\internal
*/
QWebHistoryItem::QWebHistoryItem(QWebHistoryItemPrivate *priv)
@@ -118,12 +179,40 @@ QWebHistoryItem::QWebHistoryItem(QWebHistoryItemPrivate *priv)
}
/*!
+ \since 4.5
+ Returns whether this is a valid history item.
+*/
+bool QWebHistoryItem::isValid() const
+{
+ return d->item;
+}
+
+/*!
\class QWebHistory
\since 4.4
\brief The QWebHistory class represents the history of a QWebPage
- Each QWebPage contains a history of visited pages that can be accessed by QWebPage::history().
- QWebHistory represents this history and makes it possible to navigate it.
+ Each QWebPage instance contains a history of visited pages that can be accessed
+ by QWebPage::history(). QWebHistory represents this history and makes it possible
+ to navigate it.
+
+ The history uses the concept of a \e{current item}, dividing the pages visited
+ into those that can be visited by navigating \e back and \e forward using the
+ back() and forward() functions. The current item can be obtained by calling
+ currentItem(), and an arbitrary item in the history can be made the current
+ item by passing it to goToItem().
+
+ A list of items describing the pages that can be visited by going back can be
+ obtained by calling the backItems() function; similarly, items describing the
+ pages ahead of the current page can be obtained with the forwardItems() function.
+ The total list of items is obtained with the items() function.
+
+ Just as with containers, functions are available to examine the history in terms
+ of a list. Arbitrary items in the history can be obtained with itemAt(), the total
+ number of items is given by count(), and the history can be cleared with the
+ clear() function.
+
+ \sa QWebHistoryItem, QWebHistoryInterface, QWebPage
*/
@@ -139,19 +228,28 @@ QWebHistory::~QWebHistory()
/*!
Clears the history.
+
+ \sa count(), items()
*/
void QWebHistory::clear()
{
RefPtr<WebCore::HistoryItem> current = d->lst->currentItem();
int capacity = d->lst->capacity();
d->lst->setCapacity(0);
+
+ WebCore::Page* page = d->lst->page();
+ if (page && page->groupPtr())
+ page->groupPtr()->removeVisitedLinks();
+
d->lst->setCapacity(capacity);
d->lst->addItem(current.get());
d->lst->goToItem(current.get());
}
/*!
- returns a list of all items currently in the history.
+ Returns a list of all items currently in the history.
+
+ \sa count(), clear()
*/
QList<QWebHistoryItem> QWebHistory::items() const
{
@@ -166,8 +264,10 @@ QList<QWebHistoryItem> QWebHistory::items() const
}
/*!
- Returns the list of items that are in the backwards history.
+ Returns the list of items in the backwards history list.
At most \a maxItems entries are returned.
+
+ \sa forwardItems()
*/
QList<QWebHistoryItem> QWebHistory::backItems(int maxItems) const
{
@@ -183,8 +283,10 @@ QList<QWebHistoryItem> QWebHistory::backItems(int maxItems) const
}
/*!
- Returns the list of items that are in the forward history.
+ Returns the list of items in the forward history list.
At most \a maxItems entries are returned.
+
+ \sa backItems()
*/
QList<QWebHistoryItem> QWebHistory::forwardItems(int maxItems) const
{
@@ -200,7 +302,10 @@ QList<QWebHistoryItem> QWebHistory::forwardItems(int maxItems) const
}
/*!
- returns true if we have an item to go back to.
+ Returns true if there is an item preceding the current item in the history;
+ otherwise returns false.
+
+ \sa canGoForward()
*/
bool QWebHistory::canGoBack() const
{
@@ -208,7 +313,9 @@ bool QWebHistory::canGoBack() const
}
/*!
- returns true if we have an item to go forward to.
+ Returns true if we have an item to go forward to; otherwise returns false.
+
+ \sa canGoBack()
*/
bool QWebHistory::canGoForward() const
{
@@ -216,31 +323,45 @@ bool QWebHistory::canGoForward() const
}
/*!
- goes back one history item.
+ Set the current item to be the previous item in the history and goes to the
+ corresponding page; i.e., goes back one history item.
+
+ \sa forward(), goToItem()
*/
-void QWebHistory::goBack()
+void QWebHistory::back()
{
d->lst->goBack();
+ WebCore::Page* page = d->lst->page();
+ page->goToItem(currentItem().d->item, WebCore::FrameLoadTypeIndexedBackForward);
}
/*!
- goes forward one history item.
+ Sets the current item to be the next item in the history and goes to the
+ corresponding page; i.e., goes forward one history item.
+
+ \sa back(), goToItem()
*/
-void QWebHistory::goForward()
+void QWebHistory::forward()
{
- d->lst->goBack();
+ d->lst->goForward();
+ WebCore::Page* page = d->lst->page();
+ page->goToItem(currentItem().d->item, WebCore::FrameLoadTypeIndexedBackForward);
}
/*!
- goes to item \a item in the history.
+ Sets the current item to be the specified \a item in the history and goes to the page.
+
+ \sa back(), forward()
*/
void QWebHistory::goToItem(const QWebHistoryItem &item)
{
d->lst->goToItem(item.d->item);
+ WebCore::Page* page = d->lst->page();
+ page->goToItem(currentItem().d->item, WebCore::FrameLoadTypeIndexedBackForward);
}
/*!
- returns the item before the current item.
+ Returns the item before the current item in the history.
*/
QWebHistoryItem QWebHistory::backItem() const
{
@@ -250,7 +371,7 @@ QWebHistoryItem QWebHistory::backItem() const
}
/*!
- returns the current item.
+ Returns the current item in the history.
*/
QWebHistoryItem QWebHistory::currentItem() const
{
@@ -260,7 +381,7 @@ QWebHistoryItem QWebHistory::currentItem() const
}
/*!
- returns the item after the current item.
+ Returns the item after the current item in the history.
*/
QWebHistoryItem QWebHistory::forwardItem() const
{
@@ -270,9 +391,18 @@ QWebHistoryItem QWebHistory::forwardItem() const
}
/*!
- returns the item at index \a i.
+ \since 4.5
+ Returns the index of the current item in history.
+*/
+int QWebHistory::currentItemIndex() const
+{
+ return d->lst->backListCount();
+}
+
+/*!
+ Returns the item at index \a i in the history.
*/
-QWebHistoryItem QWebHistory::itemAtIndex(int i) const
+QWebHistoryItem QWebHistory::itemAt(int i) const
{
WebCore::HistoryItem *item = d->lst->itemAtIndex(i);
@@ -280,3 +410,33 @@ QWebHistoryItem QWebHistory::itemAtIndex(int i) const
return QWebHistoryItem(priv);
}
+/*!
+ Returns the total number of items in the history.
+*/
+int QWebHistory::count() const
+{
+ return d->lst->entries().size();
+}
+
+/*!
+ \since 4.5
+ Returns the maximum number of items in the history.
+
+ \sa setMaximumItemCount()
+*/
+int QWebHistory::maximumItemCount() const
+{
+ return d->lst->capacity();
+}
+
+/*!
+ \since 4.5
+ Sets the maximum number of items in the history.
+
+ \sa maximumItemCount()
+*/
+void QWebHistory::setMaximumItemCount(int count)
+{
+ d->lst->setCapacity(count);
+}
+
diff --git a/WebKit/qt/Api/qwebhistory.h b/WebKit/qt/Api/qwebhistory.h
index 6c8a4f4..2747c90 100644
--- a/WebKit/qt/Api/qwebhistory.h
+++ b/WebKit/qt/Api/qwebhistory.h
@@ -1,5 +1,5 @@
/*
- Copyright (C) 2007 Trolltech ASA
+ Copyright (C) 2008 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
@@ -15,10 +15,8 @@
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.
-
- This class provides all functionality needed for loading images, style sheets and html
- pages from the web. It has a memory cache for these objects.
*/
+
#ifndef QWEBHISTORY_H
#define QWEBHISTORY_H
@@ -32,6 +30,10 @@
class QWebPage;
+namespace WebCore {
+ class FrameLoaderClientQt;
+};
+
class QWebHistoryItemPrivate;
class QWEBKIT_EXPORT QWebHistoryItem
{
@@ -41,17 +43,23 @@ public:
~QWebHistoryItem();
QUrl originalUrl() const;
- QUrl currentUrl() const;
+ QUrl url() const;
QString title() const;
QDateTime lastVisited() const;
- QPixmap icon() const;
+ QIcon icon() const;
+
+ QVariant userData() const;
+ void setUserData(const QVariant& userData);
+
+ bool isValid() const;
private:
QWebHistoryItem(QWebHistoryItemPrivate *priv);
friend class QWebHistory;
friend class QWebPage;
+ friend class WebCore::FrameLoaderClientQt;
QExplicitlySharedDataPointer<QWebHistoryItemPrivate> d;
};
@@ -68,14 +76,21 @@ public:
bool canGoBack() const;
bool canGoForward() const;
- void goBack();
- void goForward();
+ void back();
+ void forward();
void goToItem(const QWebHistoryItem &item);
QWebHistoryItem backItem() const;
QWebHistoryItem currentItem() const;
QWebHistoryItem forwardItem() const;
- QWebHistoryItem itemAtIndex(int i) const;
+ QWebHistoryItem itemAt(int i) const;
+
+ int currentItemIndex() const;
+
+ int count() const;
+
+ int maximumItemCount() const;
+ void setMaximumItemCount(int count);
private:
QWebHistory();
diff --git a/WebKit/qt/Api/qwebhistory_p.h b/WebKit/qt/Api/qwebhistory_p.h
index 5b56667..32e69fe 100644
--- a/WebKit/qt/Api/qwebhistory_p.h
+++ b/WebKit/qt/Api/qwebhistory_p.h
@@ -1,3 +1,22 @@
+/*
+ Copyright (C) 2008 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 QWEBHISTORY_P_H
#define QWEBHISTORY_P_H
@@ -9,14 +28,15 @@ class QWebHistoryItemPrivate : public QSharedData
public:
QWebHistoryItemPrivate(WebCore::HistoryItem *i)
{
- i->ref();
+ if (i)
+ i->ref();
item = i;
}
~QWebHistoryItemPrivate()
{
- item->deref();
+ if (item)
+ item->deref();
}
-
WebCore::HistoryItem *item;
};
diff --git a/WebKit/qt/Api/qwebhistoryinterface.cpp b/WebKit/qt/Api/qwebhistoryinterface.cpp
index d3e7efd..8e2d35c 100644
--- a/WebKit/qt/Api/qwebhistoryinterface.cpp
+++ b/WebKit/qt/Api/qwebhistoryinterface.cpp
@@ -1,30 +1,31 @@
/*
- Copyright (C) 2007 Staikos Computing Services Inc. <info@staikos.net>
+ Copyright (C) 2007 Staikos Computing Services Inc. <info@staikos.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 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.
+ 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.
+ 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.
- This class provides all functionality needed for tracking global history.
+ This class provides all functionality needed for tracking global history.
*/
+#include "config.h"
#include "qwebhistoryinterface.h"
#include <QCoreApplication>
-#include <wtf/Platform.h>
-#include "DeprecatedString.h"
+#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.
@@ -47,21 +48,29 @@ static bool gRoutineAdded;
static void gCleanupInterface()
{
- delete default_interface;
+ if (default_interface && default_interface->parent() == 0)
+ delete default_interface;
default_interface = 0;
}
/*!
- Sets a new default interface that will be used by all of WebKit
+ Sets a new default interface, \a defaultInterface, that will be used by all of WebKit
for managing history.
+
+ If an interface without a parent has already been set, the old interface will be deleted.
+ When the application exists QWebHistoryInterface will automatically delete the
+ \a defaultInterface if it does not have a parent.
*/
void QWebHistoryInterface::setDefaultInterface(QWebHistoryInterface *defaultInterface)
{
if (default_interface == defaultInterface)
return;
- if (default_interface)
+ if (default_interface && default_interface->parent() == 0)
delete default_interface;
+
default_interface = defaultInterface;
+ WebCore::PageGroup::removeAllVisitedLinks();
+
if (!gRoutineAdded) {
qAddPostRoutine(gCleanupInterface);
gRoutineAdded = true;
@@ -89,22 +98,32 @@ QWebHistoryInterface *QWebHistoryInterface::defaultInterface()
historyContains() is used to query whether this page has been
visited by the user.
*/
+
+/*!
+ Constructs a new QWebHistoryInterface with parent \a parent.
+*/
QWebHistoryInterface::QWebHistoryInterface(QObject *parent) : QObject(parent)
{
}
+/*!
+ Destructor. If this is currently the default interface it will be unset.
+*/
QWebHistoryInterface::~QWebHistoryInterface()
{
+ if (default_interface == this)
+ default_interface = 0;
}
/*!
- \fn bool QWebHistoryInterface::historyContains(const QString &url) const
+ \fn bool QWebHistoryInterface::historyContains(const QString &url) const = 0
- Called by the WebKit engine to query whether a certain url has been visited by the user already.
+ Called by the WebKit engine to query whether a certain \a url has been visited by the user already.
+ Returns true if the \a url is part of the history of visited links; otherwise returns false.
*/
/*!
- \fn void QWebHistoryInterface::addHistoryEntry(const QString &url) const
+ \fn void QWebHistoryInterface::addHistoryEntry(const QString &url) = 0
- Called by WebKit to add another url to the list of visited pages.
+ Called by WebKit to add another \a url to the list of visited pages.
*/
diff --git a/WebKit/qt/Api/qwebhistoryinterface.h b/WebKit/qt/Api/qwebhistoryinterface.h
index 87dc88c..670fca0 100644
--- a/WebKit/qt/Api/qwebhistoryinterface.h
+++ b/WebKit/qt/Api/qwebhistoryinterface.h
@@ -1,22 +1,22 @@
/*
- Copyright (C) 2007 Staikos Computing Services, Inc. <info@staikos.net>
+ Copyright (C) 2007 Staikos Computing Services, Inc. <info@staikos.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 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.
+ 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.
+ 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.
- This class provides all functionality needed for tracking global history.
+ This class provides all functionality needed for tracking global history.
*/
#ifndef QWEBHISTORYINTERFACE_H
diff --git a/WebKit/qt/Api/qwebkitglobal.h b/WebKit/qt/Api/qwebkitglobal.h
index 25fe0f9..2486fb6 100644
--- a/WebKit/qt/Api/qwebkitglobal.h
+++ b/WebKit/qt/Api/qwebkitglobal.h
@@ -1,5 +1,5 @@
/*
- Copyright (C) 2007 Trolltech ASA
+ Copyright (C) 2008 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
@@ -15,14 +15,12 @@
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.
-
- This class provides all functionality needed for loading images, style sheets and html
- pages from the web. It has a memory cache for these objects.
*/
+
#ifndef QWEBKITGLOBAL_H
#define QWEBKITGLOBAL_H
-#include <qglobal.h>
+#include <QtCore/qglobal.h>
#if defined(Q_OS_WIN)
# if defined(BUILD_WEBKIT)
@@ -36,4 +34,15 @@
#define QWEBKIT_EXPORT Q_DECL_EXPORT
#endif
+#if QT_VERSION < 0x040400
+ #ifndef QT_BEGIN_NAMESPACE
+ #define QT_BEGIN_NAMESPACE
+ #endif
+
+ #ifndef QT_END_NAMESPACE
+ #define QT_END_NAMESPACE
+ #endif
+#endif
+
+
#endif // QWEBKITGLOBAL_H
diff --git a/WebKit/qt/Api/qwebnetworkinterface.cpp b/WebKit/qt/Api/qwebnetworkinterface.cpp
index d68140d..8fba915 100644
--- a/WebKit/qt/Api/qwebnetworkinterface.cpp
+++ b/WebKit/qt/Api/qwebnetworkinterface.cpp
@@ -1,32 +1,29 @@
/*
- Copyright (C) 2006 Enrico Ros <enrico.ros@m31engineering.it>
- Copyright (C) 2007 Trolltech ASA
- Copyright (C) 2007 Staikos Computing Services Inc. <info@staikos.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.
-
- This class provides all functionality needed for loading images, style sheets and html
- pages from the web. It has a memory cache for these objects.
+ Copyright (C) 2006 Enrico Ros <enrico.ros@m31engineering.it>
+ Copyright (C) 2008 Nokia Corporation and/or its subsidiary(-ies)
+ Copyright (C) 2007 Staikos Computing Services Inc. <info@staikos.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 <qglobal.h>
#if QT_VERSION < 0x040400
#include "qwebframe.h"
#include "qwebnetworkinterface.h"
#include "qwebnetworkinterface_p.h"
-#include "qwebobjectpluginconnector.h"
#include "qwebpage.h"
#include "qcookiejar.h"
#include <qdebug.h>
@@ -135,8 +132,9 @@ void QWebNetworkRequestPrivate::init(const QString &method, const QUrl &url, con
// handle and perform a 'POST' request
if (method == "POST") {
- DeprecatedString pd = resourceRequest->httpBody()->flattenToString().deprecatedString();
- postData = QByteArray(pd.ascii(), pd.length());
+ Vector<char> data;
+ resourceRequest->httpBody()->flatten(data);
+ postData = QByteArray(data.data(), data.size());
httpHeader.setValue(QLatin1String("content-length"), QString::number(postData.size()));
}
}
@@ -360,7 +358,7 @@ void QWebNetworkJob::setErrorString(const QString& errorString)
*/
bool QWebNetworkJob::cancelled() const
{
- return !d->resourceHandle && !d->connector;
+ return !d->resourceHandle;
}
/*!
@@ -449,7 +447,6 @@ bool QWebNetworkManager::add(ResourceHandle *handle, QWebNetworkInterface *inter
handle->getInternal()->m_job = job;
job->d->resourceHandle = handle;
job->d->interface = interface;
- job->d->connector = 0;
job->d->request.init(handle->request());
@@ -478,7 +475,6 @@ void QWebNetworkManager::cancel(ResourceHandle *handle)
return;
DEBUG() << "QWebNetworkManager::cancel:" << job->d->request.httpHeader.toString();
job->d->resourceHandle = 0;
- job->d->connector = 0;
job->d->interface->cancelJob(job);
handle->getInternal()->m_job = 0;
}
@@ -495,7 +491,7 @@ void QWebNetworkManager::started(QWebNetworkJob *job)
client = job->d->resourceHandle->client();
if (!client)
return;
- } else if (!job->d->connector) {
+ } else {
return;
}
@@ -560,7 +556,17 @@ void QWebNetworkManager::started(QWebNetworkJob *job)
client->willSendRequest(job->d->resourceHandle, newRequest, response);
}
- job->d->request.httpHeader.setRequest(job->d->request.httpHeader.method(),
+ QString method;
+ if (statusCode == 302 || statusCode == 303) {
+ // this is standard-correct for 303 and practically-correct (no standard-correct) for 302
+ // also, it's required for Yahoo's login process for flickr.com which responds to a POST
+ // with a 302 which must be GET'ed
+ method = "GET";
+ job->d->request.httpHeader.setContentLength(0);
+ } else {
+ method = job->d->request.httpHeader.method();
+ }
+ job->d->request.httpHeader.setRequest(method,
newUrl.toString(QUrl::RemoveScheme|QUrl::RemoveAuthority));
job->d->request.setURL(newUrl);
job->d->redirected = true;
@@ -570,8 +576,6 @@ void QWebNetworkManager::started(QWebNetworkJob *job)
if (client)
client->didReceiveResponse(job->d->resourceHandle, response);
- if (job->d->connector)
- emit job->d->connector->started(job);
}
@@ -586,7 +590,7 @@ void QWebNetworkManager::data(QWebNetworkJob *job, const QByteArray &data)
client = job->d->resourceHandle->client();
if (!client)
return;
- } else if (!job->d->connector) {
+ } else {
return;
}
@@ -596,8 +600,6 @@ void QWebNetworkManager::data(QWebNetworkJob *job, const QByteArray &data)
DEBUG() << "receivedData" << job->d->request.url.path();
if (client)
client->didReceiveData(job->d->resourceHandle, data.constData(), data.length(), data.length() /*FixMe*/);
- if (job->d->connector)
- emit job->d->connector->data(job, data);
}
@@ -616,7 +618,7 @@ void QWebNetworkManager::finished(QWebNetworkJob *job, int errorCode)
client = job->d->resourceHandle->client();
if (!client)
return;
- } else if (!job->d->connector) {
+ } else {
job->deref();
return;
}
@@ -644,9 +646,6 @@ void QWebNetworkManager::finished(QWebNetworkJob *job, int errorCode)
}
}
- if (job->d->connector)
- emit job->d->connector->finished(job, errorCode);
-
DEBUG() << "receivedFinished done" << job->d->request.url;
job->deref();
diff --git a/WebKit/qt/Api/qwebnetworkinterface.h b/WebKit/qt/Api/qwebnetworkinterface.h
index fdc38d1..b603e37 100644
--- a/WebKit/qt/Api/qwebnetworkinterface.h
+++ b/WebKit/qt/Api/qwebnetworkinterface.h
@@ -1,24 +1,22 @@
/*
- Copyright (C) 2007 Trolltech ASA
-
- 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.
-
- This class provides all functionality needed for loading images, style sheets and html
- pages from the web. It has a memory cache for these objects.
+ Copyright (C) 2008 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 QWEBNETWORKINTERFACE_H
#define QWEBNETWORKINTERFACE_H
diff --git a/WebKit/qt/Api/qwebnetworkinterface_p.h b/WebKit/qt/Api/qwebnetworkinterface_p.h
index c712ae4..56e8617 100644
--- a/WebKit/qt/Api/qwebnetworkinterface_p.h
+++ b/WebKit/qt/Api/qwebnetworkinterface_p.h
@@ -1,24 +1,22 @@
/*
- Copyright (C) 2007 Trolltech ASA
-
- 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.
-
- This class provides all functionality needed for loading images, style sheets and html
- pages from the web. It has a memory cache for these objects.
+ Copyright (C) 2008 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 QWEBNETWORKINTERFACE_P_H
#define QWEBNETWORKINTERFACE_P_H
@@ -57,7 +55,6 @@ public:
, resourceHandle(0)
, redirected(false)
, interface(0)
- , connector(0)
, jobStatus(QWebNetworkJob::JobCreated)
{}
int ref;
@@ -69,7 +66,6 @@ public:
bool redirected;
QWebNetworkInterface *interface;
- QWebObjectPluginConnector *connector;
QWebNetworkJob::JobStatus jobStatus;
QString errorString;
};
diff --git a/WebKit/qt/Api/qwebobjectplugin.cpp b/WebKit/qt/Api/qwebobjectplugin.cpp
deleted file mode 100644
index b24d604..0000000
--- a/WebKit/qt/Api/qwebobjectplugin.cpp
+++ /dev/null
@@ -1,192 +0,0 @@
-/*
- Copyright (C) 2007 Trolltech ASA
-
- 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 "qwebobjectplugin_p.h"
-#include <qwebobjectpluginconnector.h>
-#include <qcoreapplication.h>
-#include <qfileinfo.h>
-
-#if QT_VERSION < 0x040400
-
-#ifndef QT_NO_LIBRARY
-Q_GLOBAL_STATIC_WITH_ARGS(QWebFactoryLoader, loader,
- (QWebObjectPluginFactoryInterface_iid, QCoreApplication::libraryPaths(), QLatin1String("/webplugins")))
-#endif
-
-
-QWebFactoryLoader::QWebFactoryLoader(const char *iid, const QStringList &paths, const QString &suffix, Qt::CaseSensitivity)
- : QFactoryLoader(iid, paths, suffix)
-{
- QStringList plugins = keys();
- foreach(QString k, plugins) {
- QWebObjectPlugin *plugin = qobject_cast<QWebObjectPlugin *>(instance(k));
- if (!plugin)
- continue;
- Info info;
- info.name = k;
- info.description = plugin->descriptionForKey(k);
- QStringList mimetypes = plugin->mimetypesForKey(k);
- foreach(QString m, mimetypes) {
- MimeInfo mime;
- mime.type = m;
- mime.extensions = plugin->extensionsForMimetype(m);
- info.mimes << mime;
- }
- m_pluginInfo.append(info);
- }
-}
-
-QWebFactoryLoader *QWebFactoryLoader::self()
-{
- return loader();
-}
-
-
-QString QWebFactoryLoader::descriptionForName(const QString &key) const
-{
- foreach(const Info &info, m_pluginInfo) {
- if (info.name == key)
- return info.description;
- }
- return QString();
-}
-
-QStringList QWebFactoryLoader::mimetypesForName(const QString &key) const
-{
- foreach(const Info &info, m_pluginInfo) {
- if (info.name == key) {
- QStringList mimetypes;
- foreach (const MimeInfo &m, info.mimes)
- mimetypes.append(m.type);
- return mimetypes;
- }
- }
- return QStringList();
-}
-
-QString QWebFactoryLoader::mimeTypeForExtension(const QString &extension)
-{
- foreach(const Info &info, m_pluginInfo) {
- foreach (const MimeInfo &m, info.mimes) {
- if (m.extensions.contains(extension))
- return m.type;
- }
- }
- return QString();
-}
-
-
-QStringList QWebFactoryLoader::extensions() const
-{
- QStringList extensions;
- foreach(const Info &info, m_pluginInfo) {
- foreach (const MimeInfo &m, info.mimes)
- extensions << m.extensions;
- }
- return QStringList();
-
-}
-
-QString QWebFactoryLoader::nameForMimetype(const QString &mimeType) const
-{
- foreach(const Info &info, m_pluginInfo) {
- foreach (const MimeInfo &m, info.mimes)
- if (m.type == mimeType)
- return info.name;
- }
- return QString();
-}
-
-QObject *QWebFactoryLoader::create(QWebFrame *frame,
- const QUrl &url,
- const QString &_mimeType,
- const QStringList &argumentNames,
- const QStringList &argumentValues)
-{
- QString mimeType = _mimeType;
- if (mimeType.isEmpty()) {
- QFileInfo fi(url.path());
- mimeType = mimeTypeForExtension(fi.suffix());
- }
- QString name = nameForMimetype(mimeType);
- QWebObjectPlugin *plugin = qobject_cast<QWebObjectPlugin *>(instance(name));
- if (!plugin)
- return 0;
- QWebObjectPluginConnector *connector = new QWebObjectPluginConnector(frame);
- return plugin->create(connector, url, mimeType, argumentNames, argumentValues);
-}
-
-
-
-/*! \class QWebObjectPlugin
-
- This class is a plugin for the HTML object tag. It can be used to embed arbitrary content in a web page.
-*/
-
-
-QWebObjectPlugin::QWebObjectPlugin(QObject *parent)
- : QObject(parent)
-{
-}
-
-QWebObjectPlugin::~QWebObjectPlugin()
-{
-}
-
-/*!
- \fn QStringList QWebObjectPlugin::keys() const
-
- The keys should be unique names.
-*/
-
-/*!
- A description for \a key.
-*/
-QString QWebObjectPlugin::descriptionForKey(const QString &key) const
-{
- return QString();
-}
-
-/*!
- returns the mimetypes that can be handled by \a key.
-*/
-QStringList QWebObjectPlugin::mimetypesForKey(const QString &key) const
-{
- return QStringList();
-}
-
-
-/*!
- \fn QStringList QWebObjectPlugin::extensionsForMimetype() const
-
- Should return a list of extensions that are recognised to match the \a mimeType.
-*/
-QStringList QWebObjectPlugin::extensionsForMimetype(const QString &mimeType) const
-{
- return QStringList();
-}
-
-/*!
- \fn QObject *QWebObjectPlugin::create(QWebObjectPluginConnector *connector, const QUrl &url, const QString &mimeType, const QStringList &argumentNames, const QStringList &argumentValues) const
-
- Creates a QObject with \a connector to handle \a mimeType. \a argumentNames and \a argumentValues are a set of key-value pairs passed directly
- from the &lt;param&gt; elements contained in the HTML object tag.
-*/
-
-#endif
diff --git a/WebKit/qt/Api/qwebobjectplugin.h b/WebKit/qt/Api/qwebobjectplugin.h
deleted file mode 100644
index 3c7caf7..0000000
--- a/WebKit/qt/Api/qwebobjectplugin.h
+++ /dev/null
@@ -1,66 +0,0 @@
-/*
- Copyright (C) 2007 Trolltech ASA
-
- 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 QWEBOBJECTPLUGIN_H
-#define QWEBOBJECTPLUGIN_H
-
-#include "qwebkitglobal.h"
-#include <QtCore/qplugin.h>
-#include <QtCore/qfactoryinterface.h>
-
-#if QT_VERSION < 0x040400
-
-class QWebObjectPluginConnector;
-class QUrl;
-
-struct QWEBKIT_EXPORT QWebObjectPluginFactoryInterface : public QFactoryInterface
-{
- virtual QObject *create(QWebObjectPluginConnector *connector,
- const QUrl &url,
- const QString &mimeType,
- const QStringList &argumentNames,
- const QStringList &argumentValues) const = 0;
-};
-
-#define QWebObjectPluginFactoryInterface_iid "com.trolltech.Qt.QWebObjectPluginFactoryInterface"
-Q_DECLARE_INTERFACE(QWebObjectPluginFactoryInterface, QWebObjectPluginFactoryInterface_iid)
-
-class QWEBKIT_EXPORT QWebObjectPlugin : public QObject, public QWebObjectPluginFactoryInterface
-{
- Q_OBJECT
- Q_INTERFACES(QWebObjectPluginFactoryInterface:QFactoryInterface)
-public:
- explicit QWebObjectPlugin(QObject *parent = 0);
- virtual ~QWebObjectPlugin();
-
- virtual QStringList keys() const = 0;
-
- virtual QString descriptionForKey(const QString &key) const;
- virtual QStringList mimetypesForKey(const QString &key) const;
- virtual QStringList extensionsForMimetype(const QString &mimeType) const;
- virtual QObject *create(QWebObjectPluginConnector *connector,
- const QUrl &url,
- const QString &mimeType,
- const QStringList &argumentNames,
- const QStringList &argumentValues) const = 0;
-};
-
-#endif
-
-#endif
diff --git a/WebKit/qt/Api/qwebobjectplugin_p.h b/WebKit/qt/Api/qwebobjectplugin_p.h
deleted file mode 100644
index e20261f..0000000
--- a/WebKit/qt/Api/qwebobjectplugin_p.h
+++ /dev/null
@@ -1,76 +0,0 @@
-#ifndef QWEBOBJECTPLUGIN_P_H
-#define QWEBOBJECTPLUGIN_P_H
-
-#include <QtCore/qglobal.h>
-#include "qwebobjectplugin.h"
-
-#if QT_VERSION < 0x040400
-
-/*
- FIXME: This is copied from qfactoryloader_p.h.
- Remove this once we made qfactoryloader public in Qt
-*/
-class QFactoryLoaderPrivate;
-
-class Q_CORE_EXPORT QFactoryLoader : public QObject
-{
- Q_OBJECT_FAKE
- Q_DECLARE_PRIVATE(QFactoryLoader)
-
-public:
- QFactoryLoader(const char *iid,
- const QStringList &paths = QStringList(),
- const QString &suffix = QString(),
- Qt::CaseSensitivity = Qt::CaseSensitive);
- ~QFactoryLoader();
-
- QStringList keys() const;
- QObject *instance(const QString &key) const;
-
-};
-
-class QWebFrame;
-
-class QWebFactoryLoader : public QFactoryLoader
-{
- Q_OBJECT
-public:
- QWebFactoryLoader(const char *iid,
- const QStringList &paths = QStringList(),
- const QString &suffix = QString(),
- Qt::CaseSensitivity = Qt::CaseSensitive);
-
- static QWebFactoryLoader *self();
-
- QStringList names() const { return keys(); }
- QStringList extensions() const;
- QString descriptionForName(const QString &key) const;
- QStringList mimetypesForName(const QString &key) const;
- QString nameForMimetype(const QString &mimeType) const;
- inline bool supportsMimeType(const QString &mimeType) const {
- return !nameForMimetype(mimeType).isEmpty();
- }
-
- QString mimeTypeForExtension(const QString &extension);
-
- QObject *create(QWebFrame *frame,
- const QUrl &url,
- const QString &mimeType,
- const QStringList &argumentNames,
- const QStringList &argumentValues);
-
- struct MimeInfo {
- QString type;
- QStringList extensions;
- };
- struct Info {
- QString name;
- QString description;
- QList<MimeInfo> mimes;
- };
- QList<Info> m_pluginInfo;
-};
-
-#endif
-
-#endif
diff --git a/WebKit/qt/Api/qwebobjectpluginconnector.cpp b/WebKit/qt/Api/qwebobjectpluginconnector.cpp
deleted file mode 100644
index f53c164..0000000
--- a/WebKit/qt/Api/qwebobjectpluginconnector.cpp
+++ /dev/null
@@ -1,64 +0,0 @@
-/*
- Copyright (C) 2007 Trolltech ASA
-
- 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 "qwebobjectpluginconnector.h"
-#if QT_VERSION < 0x040400
-#include "qwebnetworkinterface.h"
-#include "qwebnetworkinterface_p.h"
-#include "qwebframe.h"
-#include "qwebpage.h"
-
-struct QWebObjectPluginConnectorPrivate
-{
- QWebFrame *frame;
-};
-
-QWebObjectPluginConnector::QWebObjectPluginConnector(QWebFrame *frame)
-{
- d = new QWebObjectPluginConnectorPrivate;
- d->frame = frame;
-}
-
-QWebFrame *QWebObjectPluginConnector::frame() const
-{
- return d->frame;
-}
-
-QWidget *QWebObjectPluginConnector::pluginParentWidget() const
-{
- return d->frame->page()->view();
-}
-
-QWebNetworkJob *QWebObjectPluginConnector::requestUrl(const QWebNetworkRequest &request, Target target)
-{
- if (target != Plugin)
- return 0;
-
- QWebNetworkJob *job = new QWebNetworkJob;
- QWebNetworkJobPrivate *p = job->d;
- p->interface = d->frame->page()->networkInterface();
- p->connector = this;
-
- p->request = *request.d;
-
- d->frame->page()->networkInterface()->addJob(job);
- return job;
-}
-
-#endif
diff --git a/WebKit/qt/Api/qwebobjectpluginconnector.h b/WebKit/qt/Api/qwebobjectpluginconnector.h
deleted file mode 100644
index 62251a3..0000000
--- a/WebKit/qt/Api/qwebobjectpluginconnector.h
+++ /dev/null
@@ -1,69 +0,0 @@
-/*
- Copyright (C) 2007 Trolltech ASA
-
- 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 QWEBOBJECTPLUGINCONNECTOR_H
-#define QWEBOBJECTPLUGINCONNECTOR_H
-
-#include "qwebkitglobal.h"
-#include <QtCore/qobject.h>
-
-#if QT_VERSION < 0x040400
-
-#include "qwebnetworkinterface.h"
-
-class QWebFrame;
-class QWebPage;
-class QWidget;
-class QUrl;
-class QWebObjectPluginConnectorPrivate;
-class QWebFactoryLoader;
-class QWebNetworkManager;
-
-class QWEBKIT_EXPORT QWebObjectPluginConnector : public QObject
-{
- Q_OBJECT
-public:
- QWebFrame *frame() const;
- QWidget *pluginParentWidget() const;
-
- enum Target {
- Plugin,
- New,
- Self,
- Parent,
- Top
- };
- QWebNetworkJob *requestUrl(const QWebNetworkRequest &request, Target target = Plugin);
-
-signals:
- void started(QWebNetworkJob*);
- void data(QWebNetworkJob*, const QByteArray &data);
- void finished(QWebNetworkJob*, int errorCode);
-
-private:
- friend class QWebFactoryLoader;
- friend class QWebNetworkManager;
- QWebObjectPluginConnector(QWebFrame *frame);
-
- QWebObjectPluginConnectorPrivate *d;
-};
-
-#endif
-
-#endif
diff --git a/WebKit/qt/Api/qwebpage.cpp b/WebKit/qt/Api/qwebpage.cpp
index 6e5e984..b7285d6 100644
--- a/WebKit/qt/Api/qwebpage.cpp
+++ b/WebKit/qt/Api/qwebpage.cpp
@@ -1,5 +1,5 @@
/*
- Copyright (C) 2007 Trolltech ASA
+ Copyright (C) 2008 Nokia Corporation and/or its subsidiary(-ies)
Copyright (C) 2007 Staikos Computing Services Inc.
Copyright (C) 2007 Apple Inc.
@@ -17,10 +17,8 @@
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.
-
- This class provides all functionality needed for loading images, style sheets and html
- pages from the web. It has a memory cache for these objects.
*/
+
#include "config.h"
#include "qwebpage.h"
#include "qwebview.h"
@@ -32,25 +30,31 @@
#include "qwebsettings.h"
#include "Frame.h"
+#include "FrameTree.h"
#include "FrameLoaderClientQt.h"
+#include "FrameView.h"
#include "ChromeClientQt.h"
#include "ContextMenu.h"
#include "ContextMenuClientQt.h"
+#include "DocumentLoader.h"
#include "DragClientQt.h"
#include "DragController.h"
#include "DragData.h"
#include "EditorClientQt.h"
#include "Settings.h"
#include "Page.h"
+#include "PageGroup.h"
+#include "Pasteboard.h"
#include "FrameLoader.h"
#include "FrameLoadRequest.h"
#include "KURL.h"
+#include "Logging.h"
#include "Image.h"
#include "InspectorClientQt.h"
#include "InspectorController.h"
#include "FocusController.h"
#include "Editor.h"
-#include "PlatformScrollBar.h"
+#include "Scrollbar.h"
#include "PlatformKeyboardEvent.h"
#include "PlatformWheelEvent.h"
#include "ProgressTracker.h"
@@ -59,7 +63,11 @@
#include "HitTestResult.h"
#include "WindowFeatures.h"
#include "LocalizedStrings.h"
+#include "runtime/InitializeThreading.h"
+#include <QApplication>
+#include <QBasicTimer>
+#include <QBitArray>
#include <QDebug>
#include <QDragEnterEvent>
#include <QDragLeaveEvent>
@@ -68,11 +76,16 @@
#include <QFileDialog>
#include <QHttpRequestHeader>
#include <QInputDialog>
+#include <QLocale>
#include <QMessageBox>
#include <QNetworkProxy>
#include <QUndoStack>
#include <QUrl>
#include <QPainter>
+#include <QClipboard>
+#include <QSslSocket>
+#include <QStyle>
+#include <QSysInfo>
#if QT_VERSION >= 0x040400
#include <QNetworkAccessManager>
#include <QNetworkRequest>
@@ -82,6 +95,99 @@
using namespace WebCore;
+// Lookup table mapping QWebPage::WebActions to the associated Editor commands
+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,
+ "MoveBackward", // MoveToPreviousChar,
+ "MoveWordForward", // MoveToNextWord,
+ "MoveWordBackward", // MoveToPreviousWord,
+ "MoveDown", // MoveToNextLine,
+ "MoveUp", // MoveToPreviousLine,
+ "MoveToBeginningOfLine", // MoveToStartOfLine,
+ "MoveToEndOfLine", // MoveToEndOfLine,
+ "MoveToBeginningOfParagraph", // MoveToStartOfBlock,
+ "MoveToEndOfParagraph", // MoveToEndOfBlock,
+ "MoveToBeginningOfDocument", // MoveToStartOfDocument,
+ "MoveToEndOfDocument", // MoveToEndOfDocument,
+ "MoveForwardAndModifySelection", // SelectNextChar,
+ "MoveBackwardAndModifySelection", // SelectPreviousChar,
+ "MoveWordForwardAndModifySelection", // SelectNextWord,
+ "MoveWordBackwardAndModifySelection", // SelectPreviousWord,
+ "MoveDownAndModifySelection", // SelectNextLine,
+ "MoveUpAndModifySelection", // SelectPreviousLine,
+ "MoveToBeginningOfLineAndModifySelection", // SelectStartOfLine,
+ "MoveToEndOfLineAndModifySelection", // SelectEndOfLine,
+ "MoveToBeginningOfParagraphAndModifySelection", // SelectStartOfBlock,
+ "MoveToEndOfParagraphAndModifySelection", // SelectEndOfBlock,
+ "MoveToBeginningOfDocumentAndModifySelection", //SelectStartOfDocument,
+ "MoveToEndOfDocumentAndModifySelection", // SelectEndOfDocument,
+ "DeleteWordBackward", // DeleteStartOfWord,
+ "DeleteWordForward", // DeleteEndOfWord,
+
+ 0, // SetTextDirectionDefault,
+ 0, // SetTextDirectionLeftToRight,
+ 0, // SetTextDirectionRightToLeft,
+
+ "ToggleBold", // ToggleBold,
+ "ToggleItalic", // ToggleItalic,
+ "ToggleUnderline", // ToggleUnderline,
+
+ 0, // InspectElement,
+
+ "InsertNewline", // InsertParagraphSeparator
+ "InsertLineBreak", // InsertLineSeparator
+
+ 0 // WebActionCount
+};
+
+// Lookup the appropriate editor command to use for WebAction \a action
+static const char* editorCommandForWebActions(QWebPage::WebAction action)
+{
+ if ((action > QWebPage::NoWebAction) && (action < int(sizeof(editorCommandWebActions) / sizeof(const char*))))
+ return editorCommandWebActions[action];
+
+ return 0;
+}
+
+#ifndef QT_NO_CURSOR
+SetCursorEvent::SetCursorEvent(const QCursor& cursor)
+ : QEvent(static_cast<QEvent::Type>(EventType))
+ , m_cursor(cursor)
+{}
+
+QCursor SetCursorEvent::cursor() const
+{
+ return m_cursor;
+}
+#endif
+
+// If you change this make sure to also adjust the docs for QWebPage::userAgentForUrl
+#define WEBKIT_VERSION "527+"
+
static inline DragOperation dropActionToDragOp(Qt::DropActions actions)
{
unsigned result = 0;
@@ -109,8 +215,12 @@ static inline Qt::DropAction dragOpToDropAction(unsigned actions)
QWebPagePrivate::QWebPagePrivate(QWebPage *qq)
: q(qq)
, view(0)
- , modified(false)
+ , viewportSize(QSize(0,0))
{
+ WebCore::InitializeLoggingChannelsIfNecessary();
+ WebCore::PageGroup::setShouldTrackVisitedLinks(true);
+ JSC::initializeThreading();
+
chromeClient = new ChromeClientQt(q);
contextMenuClient = new ContextMenuClientQt();
editorClient = new EditorClientQt(q);
@@ -122,14 +232,23 @@ QWebPagePrivate::QWebPagePrivate(QWebPage *qq)
settings = new QWebSettings(page->settings());
+#ifndef QT_NO_UNDOSTACK
undoStack = 0;
+#endif
mainFrame = 0;
#if QT_VERSION < 0x040400
networkInterface = 0;
#else
networkManager = 0;
#endif
+ pluginFactory = 0;
insideOpenCall = false;
+ forwardUnsupportedContent = false;
+ editable = false;
+ linkPolicy = QWebPage::DontDelegateLinks;
+#ifndef QT_NO_CONTEXTMENU
+ currentContextMenu = 0;
+#endif
history.d = new QWebHistoryPrivate(page->backForwardList());
memset(actions, 0, sizeof(actions));
@@ -137,29 +256,31 @@ QWebPagePrivate::QWebPagePrivate(QWebPage *qq)
QWebPagePrivate::~QWebPagePrivate()
{
+#ifndef QT_NO_CONTEXTMENU
+ delete currentContextMenu;
+#endif
+#ifndef QT_NO_UNDOSTACK
delete undoStack;
+#endif
delete settings;
delete page;
-#if QT_VERSION >= 0x040400
- delete networkManager;
-#endif
}
#if QT_VERSION < 0x040400
-QWebPage::NavigationRequestResponse QWebPagePrivate::navigationRequested(QWebFrame *frame, const QWebNetworkRequest &request, QWebPage::NavigationType type)
+bool QWebPagePrivate::acceptNavigationRequest(QWebFrame *frame, const QWebNetworkRequest &request, QWebPage::NavigationType type)
{
if (insideOpenCall
&& frame == mainFrame)
- return QWebPage::AcceptNavigationRequest;
- return q->navigationRequested(frame, request, type);
+ return true;
+ return q->acceptNavigationRequest(frame, request, type);
}
#else
-QWebPage::NavigationRequestResponse QWebPagePrivate::navigationRequested(QWebFrame *frame, const QNetworkRequest &request, QWebPage::NavigationType type)
+bool QWebPagePrivate::acceptNavigationRequest(QWebFrame *frame, const QNetworkRequest &request, QWebPage::NavigationType type)
{
if (insideOpenCall
&& frame == mainFrame)
- return QWebPage::AcceptNavigationRequest;
- return q->navigationRequested(frame, request, type);
+ return true;
+ return q->acceptNavigationRequest(frame, request, type);
}
#endif
@@ -172,7 +293,6 @@ void QWebPagePrivate::createMainFrame()
frameData.marginWidth = 0;
frameData.marginHeight = 0;
mainFrame = new QWebFrame(q, &frameData);
- mainFrame->d->frameView->setFrameGeometry(IntRect(IntPoint(0,0), q->viewportSize()));
emit q->frameCreated(mainFrame);
}
@@ -190,8 +310,8 @@ static QWebPage::WebAction webActionForContextMenuAction(WebCore::ContextMenuAct
case WebCore::ContextMenuItemTagCopyImageToClipboard: return QWebPage::CopyImageToClipboard;
case WebCore::ContextMenuItemTagOpenFrameInNewWindow: return QWebPage::OpenFrameInNewWindow;
case WebCore::ContextMenuItemTagCopy: return QWebPage::Copy;
- case WebCore::ContextMenuItemTagGoBack: return QWebPage::GoBack;
- case WebCore::ContextMenuItemTagGoForward: return QWebPage::GoForward;
+ case WebCore::ContextMenuItemTagGoBack: return QWebPage::Back;
+ case WebCore::ContextMenuItemTagGoForward: return QWebPage::Forward;
case WebCore::ContextMenuItemTagStop: return QWebPage::Stop;
case WebCore::ContextMenuItemTagReload: return QWebPage::Reload;
case WebCore::ContextMenuItemTagCut: return QWebPage::Cut;
@@ -208,9 +328,11 @@ static QWebPage::WebAction webActionForContextMenuAction(WebCore::ContextMenuAct
return QWebPage::NoWebAction;
}
-QMenu *QWebPagePrivate::createContextMenu(const WebCore::ContextMenu *webcoreMenu, const QList<WebCore::ContextMenuItem> *items)
+#ifndef QT_NO_CONTEXTMENU
+QMenu *QWebPagePrivate::createContextMenu(const WebCore::ContextMenu *webcoreMenu,
+ const QList<WebCore::ContextMenuItem> *items, QBitArray *visitedWebActions)
{
- QMenu *menu = new QMenu;
+ QMenu* menu = new QMenu(view);
for (int i = 0; i < items->count(); ++i) {
const ContextMenuItem &item = items->at(i);
switch (item.type()) {
@@ -227,6 +349,7 @@ QMenu *QWebPagePrivate::createContextMenu(const WebCore::ContextMenu *webcoreMen
a->setCheckable(item.type() == WebCore::CheckableActionType);
menu->addAction(a);
+ visitedWebActions->setBit(action);
}
break;
}
@@ -234,8 +357,18 @@ QMenu *QWebPagePrivate::createContextMenu(const WebCore::ContextMenu *webcoreMen
menu->addSeparator();
break;
case WebCore::SubmenuType: {
- QMenu *subMenu = createContextMenu(webcoreMenu, item.platformSubMenu());
- if (!subMenu->actions().isEmpty()) {
+ QMenu *subMenu = createContextMenu(webcoreMenu, item.platformSubMenu(), visitedWebActions);
+
+ bool anyEnabledAction = false;
+
+ QList<QAction *> actions = subMenu->actions();
+ for (int i = 0; i < actions.count(); ++i) {
+ if (actions.at(i)->isVisible())
+ anyEnabledAction |= actions.at(i)->isEnabled();
+ }
+
+ // don't show sub-menus with just disabled actions
+ if (anyEnabledAction) {
subMenu->setTitle(item.title());
menu->addAction(subMenu->menuAction());
} else {
@@ -247,6 +380,7 @@ QMenu *QWebPagePrivate::createContextMenu(const WebCore::ContextMenu *webcoreMen
}
return menu;
}
+#endif // QT_NO_CONTEXTMENU
QWebFrame *QWebPagePrivate::frameAt(const QPoint &pos) const
{
@@ -284,12 +418,13 @@ void QWebPagePrivate::updateAction(QWebPage::WebAction action)
WebCore::Editor *editor = page->focusController()->focusedOrMainFrame()->editor();
bool enabled = a->isEnabled();
+ bool checked = a->isChecked();
switch (action) {
- case QWebPage::GoBack:
+ case QWebPage::Back:
enabled = loader->canGoBackOrForward(-1);
break;
- case QWebPage::GoForward:
+ case QWebPage::Forward:
enabled = loader->canGoBackOrForward(1);
break;
case QWebPage::Stop:
@@ -307,20 +442,34 @@ void QWebPagePrivate::updateAction(QWebPage::WebAction action)
case QWebPage::Paste:
enabled = editor->canPaste();
break;
+#ifndef QT_NO_UNDOSTACK
case QWebPage::Undo:
case QWebPage::Redo:
// those two are handled by QUndoStack
break;
+#endif // QT_NO_UNDOSTACK
+ case QWebPage::ToggleBold:
+ case QWebPage::ToggleItalic:
+ case QWebPage::ToggleUnderline:
+ enabled = editor->canEditRichly();
+ if (enabled)
+ checked = editor->command(editorCommandForWebActions(action)).state() != FalseTriState;
+ else
+ checked = false;
+ break;
default: break;
}
a->setEnabled(enabled);
+
+ if (a->isCheckable())
+ a->setChecked(checked);
}
void QWebPagePrivate::updateNavigationActions()
{
- updateAction(QWebPage::GoBack);
- updateAction(QWebPage::GoForward);
+ updateAction(QWebPage::Back);
+ updateAction(QWebPage::Forward);
updateAction(QWebPage::Stop);
updateAction(QWebPage::Reload);
}
@@ -330,214 +479,230 @@ void QWebPagePrivate::updateEditorActions()
updateAction(QWebPage::Cut);
updateAction(QWebPage::Copy);
updateAction(QWebPage::Paste);
+ updateAction(QWebPage::ToggleBold);
+ updateAction(QWebPage::ToggleItalic);
+ updateAction(QWebPage::ToggleUnderline);
+}
+
+void QWebPagePrivate::timerEvent(QTimerEvent *ev)
+{
+ int timerId = ev->timerId();
+ if (timerId == tripleClickTimer.timerId())
+ tripleClickTimer.stop();
+ else
+ q->QObject::timerEvent(ev);
}
void QWebPagePrivate::mouseMoveEvent(QMouseEvent *ev)
{
- QWebFramePrivate::core(mainFrame)->eventHandler()->mouseMoved(PlatformMouseEvent(ev, 0));
+ WebCore::Frame* frame = QWebFramePrivate::core(mainFrame);
+ if (!frame->view())
+ return;
+
+ bool accepted = frame->eventHandler()->mouseMoved(PlatformMouseEvent(ev, 0));
+ ev->setAccepted(accepted);
}
void QWebPagePrivate::mousePressEvent(QMouseEvent *ev)
{
- QWebFramePrivate::core(mainFrame)->eventHandler()->handleMousePressEvent(PlatformMouseEvent(ev, 1));
+ WebCore::Frame* frame = QWebFramePrivate::core(mainFrame);
+ if (!frame->view())
+ return;
+
+ if (tripleClickTimer.isActive()
+ && (ev->pos() - tripleClick).manhattanLength()
+ < QApplication::startDragDistance()) {
+ mouseTripleClickEvent(ev);
+ return;
+ }
+
+ bool accepted = frame->eventHandler()->handleMousePressEvent(PlatformMouseEvent(ev, 1));
+ ev->setAccepted(accepted);
}
void QWebPagePrivate::mouseDoubleClickEvent(QMouseEvent *ev)
{
- QWebFramePrivate::core(mainFrame)->eventHandler()->handleMousePressEvent(PlatformMouseEvent(ev, 2));
+ WebCore::Frame* frame = QWebFramePrivate::core(mainFrame);
+ if (!frame->view())
+ return;
+
+ bool accepted = frame->eventHandler()->handleMousePressEvent(PlatformMouseEvent(ev, 2));
+ ev->setAccepted(accepted);
+
+ tripleClickTimer.start(QApplication::doubleClickInterval(), q);
+ tripleClick = ev->pos();
}
-void QWebPagePrivate::mouseReleaseEvent(QMouseEvent *ev)
+void QWebPagePrivate::mouseTripleClickEvent(QMouseEvent *ev)
{
- QWebFramePrivate::core(mainFrame)->eventHandler()->handleMouseReleaseEvent(PlatformMouseEvent(ev, 0));
+ WebCore::Frame* frame = QWebFramePrivate::core(mainFrame);
+ if (!frame->view())
+ return;
+
+ bool accepted = frame->eventHandler()->handleMousePressEvent(PlatformMouseEvent(ev, 3));
+ ev->setAccepted(accepted);
}
-void QWebPagePrivate::contextMenuEvent(QContextMenuEvent *ev)
+void QWebPagePrivate::mouseReleaseEvent(QMouseEvent *ev)
{
- page->contextMenuController()->clearContextMenu();
-
- WebCore::Frame* focusedFrame = page->focusController()->focusedOrMainFrame();
- focusedFrame->eventHandler()->sendContextMenuEvent(PlatformMouseEvent(ev, 1));
- ContextMenu *menu = page->contextMenuController()->contextMenu();
- // If the website defines its own handler then sendContextMenuEvent takes care of
- // calling/showing it and the context menu pointer will be zero. This is the case
- // on maps.google.com for example.
- if (!menu)
+ WebCore::Frame* frame = QWebFramePrivate::core(mainFrame);
+ if (!frame->view())
return;
- QWebPageContext oldContext = currentContext;
- currentContext = QWebPageContext(menu->hitTestResult());
+ bool accepted = frame->eventHandler()->handleMouseReleaseEvent(PlatformMouseEvent(ev, 0));
+ ev->setAccepted(accepted);
+
+#ifndef QT_NO_CLIPBOARD
+ if (QApplication::clipboard()->supportsSelection()) {
+ bool oldSelectionMode = Pasteboard::generalPasteboard()->isSelectionMode();
+ Pasteboard::generalPasteboard()->setSelectionMode(true);
+ WebCore::Frame* focusFrame = page->focusController()->focusedOrMainFrame();
+ if (ev->button() == Qt::LeftButton) {
+ 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())) {
+ focusFrame->editor()->paste();
+ ev->setAccepted(true);
+ }
+ }
+ Pasteboard::generalPasteboard()->setSelectionMode(oldSelectionMode);
+ }
+#endif
+}
- const QList<ContextMenuItem> *items = menu->platformDescription();
- QMenu *qmenu = createContextMenu(menu, items);
- if (qmenu) {
- qmenu->exec(ev->globalPos());
- delete qmenu;
+#ifndef QT_NO_CONTEXTMENU
+void QWebPagePrivate::contextMenuEvent(QContextMenuEvent *ev)
+{
+ QMenu *menu = q->createStandardContextMenu();
+ if (menu) {
+ menu->exec(ev->globalPos());
+ delete menu;
}
- currentContext = oldContext;
+}
+#endif // QT_NO_CONTEXTMENU
+
+/*!
+ \since 4.5
+ This function creates the standard context menu which is shown when
+ the user clicks on the web page with the right mouse button. It is
+ called from the default contextMenuEvent() handler. The popup menu's
+ ownership is transferred to the caller.
+ */
+QMenu *QWebPage::createStandardContextMenu()
+{
+#ifndef QT_NO_CONTEXTMENU
+ QMenu *menu = d->currentContextMenu;
+ d->currentContextMenu = 0;
+ return menu;
+#else
+ return 0;
+#endif
}
+#ifndef QT_NO_WHEELEVENT
void QWebPagePrivate::wheelEvent(QWheelEvent *ev)
{
+ WebCore::Frame* frame = QWebFramePrivate::core(mainFrame);
+ if (!frame->view())
+ return;
+
WebCore::PlatformWheelEvent pev(ev);
- bool accepted = QWebFramePrivate::core(mainFrame)->eventHandler()->handleWheelEvent(pev);
+ bool accepted = frame->eventHandler()->handleWheelEvent(pev);
ev->setAccepted(accepted);
}
+#endif // QT_NO_WHEELEVENT
+
+#ifndef QT_NO_SHORTCUT
+static QWebPage::WebAction editorActionForKeyEvent(QKeyEvent* event)
+{
+ static struct {
+ QKeySequence::StandardKey standardKey;
+ QWebPage::WebAction action;
+ } editorActions[] = {
+ { QKeySequence::Cut, QWebPage::Cut },
+ { QKeySequence::Copy, QWebPage::Copy },
+ { QKeySequence::Paste, QWebPage::Paste },
+ { QKeySequence::Undo, QWebPage::Undo },
+ { QKeySequence::Redo, QWebPage::Redo },
+ { QKeySequence::MoveToNextChar, QWebPage::MoveToNextChar },
+ { QKeySequence::MoveToPreviousChar, QWebPage::MoveToPreviousChar },
+ { QKeySequence::MoveToNextWord, QWebPage::MoveToNextWord },
+ { QKeySequence::MoveToPreviousWord, QWebPage::MoveToPreviousWord },
+ { QKeySequence::MoveToNextLine, QWebPage::MoveToNextLine },
+ { QKeySequence::MoveToPreviousLine, QWebPage::MoveToPreviousLine },
+ { QKeySequence::MoveToStartOfLine, QWebPage::MoveToStartOfLine },
+ { QKeySequence::MoveToEndOfLine, QWebPage::MoveToEndOfLine },
+ { QKeySequence::MoveToStartOfBlock, QWebPage::MoveToStartOfBlock },
+ { QKeySequence::MoveToEndOfBlock, QWebPage::MoveToEndOfBlock },
+ { QKeySequence::MoveToStartOfDocument, QWebPage::MoveToStartOfDocument },
+ { QKeySequence::MoveToEndOfDocument, QWebPage::MoveToEndOfDocument },
+ { QKeySequence::SelectNextChar, QWebPage::SelectNextChar },
+ { QKeySequence::SelectPreviousChar, QWebPage::SelectPreviousChar },
+ { QKeySequence::SelectNextWord, QWebPage::SelectNextWord },
+ { QKeySequence::SelectPreviousWord, QWebPage::SelectPreviousWord },
+ { QKeySequence::SelectNextLine, QWebPage::SelectNextLine },
+ { QKeySequence::SelectPreviousLine, QWebPage::SelectPreviousLine },
+ { QKeySequence::SelectStartOfLine, QWebPage::SelectStartOfLine },
+ { QKeySequence::SelectEndOfLine, QWebPage::SelectEndOfLine },
+ { QKeySequence::SelectStartOfBlock, QWebPage::SelectStartOfBlock },
+ { QKeySequence::SelectEndOfBlock, QWebPage::SelectEndOfBlock },
+ { QKeySequence::SelectStartOfDocument, QWebPage::SelectStartOfDocument },
+ { QKeySequence::SelectEndOfDocument, QWebPage::SelectEndOfDocument },
+ { QKeySequence::DeleteStartOfWord, QWebPage::DeleteStartOfWord },
+ { QKeySequence::DeleteEndOfWord, QWebPage::DeleteEndOfWord },
+#if QT_VERSION >= 0x040500
+ { QKeySequence::InsertParagraphSeparator, QWebPage::InsertParagraphSeparator },
+ { QKeySequence::InsertLineSeparator, QWebPage::InsertLineSeparator },
+#endif
+ { QKeySequence::UnknownKey, QWebPage::NoWebAction }
+ };
+
+ for (int i = 0; editorActions[i].standardKey != QKeySequence::UnknownKey; ++i)
+ if (event == editorActions[i].standardKey)
+ return editorActions[i].action;
+
+ return QWebPage::NoWebAction;
+}
+#endif // QT_NO_SHORTCUT
void QWebPagePrivate::keyPressEvent(QKeyEvent *ev)
{
bool handled = false;
- WebCore::Frame *frame = page->focusController()->focusedOrMainFrame();
- WebCore::Editor *editor = frame->editor();
+ WebCore::Frame* frame = page->focusController()->focusedOrMainFrame();
+ WebCore::Editor* editor = frame->editor();
+#ifndef QT_NO_SHORTCUT
if (editor->canEdit()) {
- if (ev == QKeySequence::Cut) {
- q->triggerAction(QWebPage::Cut);
+ QWebPage::WebAction action = editorActionForKeyEvent(ev);
+ if (action != QWebPage::NoWebAction) {
+ q->triggerAction(action);
handled = true;
- } else if (ev == QKeySequence::Copy) {
+ }
+ } else {
+ if (ev == QKeySequence::Copy) {
q->triggerAction(QWebPage::Copy);
handled = true;
- } else if (ev == QKeySequence::Paste) {
- q->triggerAction(QWebPage::Paste);
- handled = true;
- } else if (ev == QKeySequence::Undo) {
- q->triggerAction(QWebPage::Undo);
- handled = true;
- } else if (ev == QKeySequence::Redo) {
- q->triggerAction(QWebPage::Redo);
- handled = true;
- } else if(ev == QKeySequence::MoveToNextChar) {
- q->triggerAction(QWebPage::MoveToNextChar);
- handled = true;
- } else if(ev == QKeySequence::MoveToPreviousChar) {
- q->triggerAction(QWebPage::MoveToPreviousChar);
- handled = true;
- } else if(ev == QKeySequence::MoveToNextWord) {
- q->triggerAction(QWebPage::MoveToNextWord);
- handled = true;
- } else if(ev == QKeySequence::MoveToPreviousWord) {
- q->triggerAction(QWebPage::MoveToPreviousWord);
- handled = true;
- } else if(ev == QKeySequence::MoveToNextLine) {
- q->triggerAction(QWebPage::MoveToNextLine);
- handled = true;
- } else if(ev == QKeySequence::MoveToPreviousLine) {
- q->triggerAction(QWebPage::MoveToPreviousLine);
- handled = true;
-// } else if(ev == QKeySequence::MoveToNextPage) {
-// } else if(ev == QKeySequence::MoveToPreviousPage) {
- } else if(ev == QKeySequence::MoveToStartOfLine) {
- q->triggerAction(QWebPage::MoveToStartOfLine);
- handled = true;
- } else if(ev == QKeySequence::MoveToEndOfLine) {
- q->triggerAction(QWebPage::MoveToEndOfLine);
- handled = true;
- } else if(ev == QKeySequence::MoveToStartOfBlock) {
- q->triggerAction(QWebPage::MoveToStartOfBlock);
- handled = true;
- } else if(ev == QKeySequence::MoveToEndOfBlock) {
- q->triggerAction(QWebPage::MoveToEndOfBlock);
- handled = true;
- } else if(ev == QKeySequence::MoveToStartOfDocument) {
- q->triggerAction(QWebPage::MoveToStartOfDocument);
- handled = true;
- } else if(ev == QKeySequence::MoveToEndOfDocument) {
- q->triggerAction(QWebPage::MoveToEndOfDocument);
- handled = true;
- } else if(ev == QKeySequence::SelectNextChar) {
- q->triggerAction(QWebPage::SelectNextChar);
- handled = true;
- } else if(ev == QKeySequence::SelectPreviousChar) {
- q->triggerAction(QWebPage::SelectPreviousChar);
- handled = true;
- } else if(ev == QKeySequence::SelectNextWord) {
- q->triggerAction(QWebPage::SelectNextWord);
- handled = true;
- } else if(ev == QKeySequence::SelectPreviousWord) {
- q->triggerAction(QWebPage::SelectPreviousWord);
- handled = true;
- } else if(ev == QKeySequence::SelectNextLine) {
- q->triggerAction(QWebPage::SelectNextLine);
- handled = true;
- } else if(ev == QKeySequence::SelectPreviousLine) {
- q->triggerAction(QWebPage::SelectPreviousLine);
- handled = true;
-// } else if(ev == QKeySequence::SelectNextPage) {
-// } else if(ev == QKeySequence::SelectPreviousPage) {
- } else if(ev == QKeySequence::SelectStartOfLine) {
- q->triggerAction(QWebPage::SelectStartOfLine);
- handled = true;
- } else if(ev == QKeySequence::SelectEndOfLine) {
- q->triggerAction(QWebPage::SelectEndOfLine);
- handled = true;
- } else if(ev == QKeySequence::SelectStartOfBlock) {
- q->triggerAction(QWebPage::SelectStartOfBlock);
- handled = true;
- } else if(ev == QKeySequence::SelectEndOfBlock) {
- q->triggerAction(QWebPage::SelectEndOfBlock);
- handled = true;
- } else if(ev == QKeySequence::SelectStartOfDocument) {
- q->triggerAction(QWebPage::SelectStartOfDocument);
- handled = true;
- } else if(ev == QKeySequence::SelectEndOfDocument) {
- q->triggerAction(QWebPage::SelectEndOfDocument);
- handled = true;
- } else if(ev == QKeySequence::DeleteStartOfWord) {
- q->triggerAction(QWebPage::DeleteStartOfWord);
- handled = true;
- } else if(ev == QKeySequence::DeleteEndOfWord) {
- q->triggerAction(QWebPage::DeleteEndOfWord);
- handled = true;
-// } else if(ev == QKeySequence::DeleteEndOfLine) {
}
}
+#endif // QT_NO_SHORTCUT
if (!handled)
handled = frame->eventHandler()->keyEvent(ev);
if (!handled) {
handled = true;
- PlatformScrollbar *h, *v;
- h = mainFrame->d->horizontalScrollBar();
- v = mainFrame->d->verticalScrollBar();
QFont defaultFont;
if (view)
defaultFont = view->font();
QFontMetrics fm(defaultFont);
int fontHeight = fm.height();
- if (ev == QKeySequence::MoveToNextPage
- || ev->key() == Qt::Key_Space) {
- if (v)
- v->setValue(v->value() + q->viewportSize().height() - fontHeight);
- } else if (ev == QKeySequence::MoveToPreviousPage) {
- if (v)
- v->setValue(v->value() - q->viewportSize().height() + fontHeight);
- } else if (ev->key() == Qt::Key_Up && ev->modifiers() == Qt::ControlModifier) {
- if (v)
- v->setValue(0);
- } else if (ev->key() == Qt::Key_Down && ev->modifiers() == Qt::ControlModifier) {
- if (v)
- v->setValue(INT_MAX);
- } else {
+ if (!handleScrolling(ev)) {
switch (ev->key()) {
- case Qt::Key_Up:
- if (v)
- v->setValue(v->value() - fontHeight);
- break;
- case Qt::Key_Down:
- if (v)
- v->setValue(v->value() + fontHeight);
- break;
- case Qt::Key_Left:
- if (h)
- h->setValue(h->value() - fontHeight);
- break;
- case Qt::Key_Right:
- if (h)
- h->setValue(h->value() + fontHeight);
- break;
case Qt::Key_Backspace:
if (ev->modifiers() == Qt::ShiftModifier)
- q->triggerAction(QWebPage::GoForward);
+ q->triggerAction(QWebPage::Forward);
else
- q->triggerAction(QWebPage::GoBack);
+ q->triggerAction(QWebPage::Back);
default:
handled = false;
break;
@@ -562,14 +727,33 @@ void QWebPagePrivate::keyReleaseEvent(QKeyEvent *ev)
void QWebPagePrivate::focusInEvent(QFocusEvent *ev)
{
- if (ev->reason() != Qt::PopupFocusReason)
- page->focusController()->setFocusedFrame(QWebFramePrivate::core(mainFrame));
+ if (ev->reason() == Qt::PopupFocusReason)
+ return;
+
+ FocusController *focusController = page->focusController();
+ Frame *frame = focusController->focusedFrame();
+ focusController->setActive(true);
+ if (frame) {
+ frame->selection()->setFocused(true);
+ } else {
+ focusController->setFocusedFrame(QWebFramePrivate::core(mainFrame));
+ }
}
void QWebPagePrivate::focusOutEvent(QFocusEvent *ev)
{
- if (ev->reason() != Qt::PopupFocusReason)
- page->focusController()->setFocusedFrame(0);
+ if (ev->reason() == Qt::PopupFocusReason)
+ return;
+
+ // only set the focused frame inactive so that we stop painting the caret
+ // and the focus frame. But don't tell the focus controller so that upon
+ // focusInEvent() we can re-activate the frame.
+ FocusController *focusController = page->focusController();
+ focusController->setActive(false);
+ Frame *frame = focusController->focusedFrame();
+ if (frame) {
+ frame->selection()->setFocused(false);
+ }
}
void QWebPagePrivate::dragEnterEvent(QDragEnterEvent *ev)
@@ -579,7 +763,8 @@ void QWebPagePrivate::dragEnterEvent(QDragEnterEvent *ev)
dropActionToDragOp(ev->possibleActions()));
Qt::DropAction action = dragOpToDropAction(page->dragController()->dragEntered(&dragData));
ev->setDropAction(action);
- ev->accept();
+ if (action != Qt::IgnoreAction)
+ ev->accept();
#endif
}
@@ -599,7 +784,8 @@ void QWebPagePrivate::dragMoveEvent(QDragMoveEvent *ev)
dropActionToDragOp(ev->possibleActions()));
Qt::DropAction action = dragOpToDropAction(page->dragController()->dragUpdated(&dragData));
ev->setDropAction(action);
- ev->accept();
+ if (action != Qt::IgnoreAction)
+ ev->accept();
#endif
}
@@ -609,11 +795,244 @@ void QWebPagePrivate::dropEvent(QDropEvent *ev)
DragData dragData(ev->mimeData(), ev->pos(), QCursor::pos(),
dropActionToDragOp(ev->possibleActions()));
Qt::DropAction action = dragOpToDropAction(page->dragController()->performDrag(&dragData));
+ if (action != Qt::IgnoreAction)
+ ev->accept();
+#endif
+}
+
+void QWebPagePrivate::leaveEvent(QEvent *ev)
+{
+ // Fake a mouse move event just outside of the widget, since all
+ // the interesting mouse-out behavior like invalidating scrollbars
+ // is handled by the WebKit event handler's mouseMoved function.
+ QMouseEvent fakeEvent(QEvent::MouseMove, QCursor::pos(), Qt::NoButton, Qt::NoButton, Qt::NoModifier);
+ mouseMoveEvent(&fakeEvent);
+}
+
+/*!
+ \property QWebPage::palette
+ \brief the page's palette
+
+ The background brush of the palette is used to draw the background of the main frame.
+
+ By default, this property contains the application's default palette.
+*/
+void QWebPage::setPalette(const QPalette &pal)
+{
+ d->palette = pal;
+ if (d->mainFrame)
+ d->mainFrame->d->updateBackground();
+}
+
+QPalette QWebPage::palette() const
+{
+ return d->palette;
+}
+
+void QWebPagePrivate::inputMethodEvent(QInputMethodEvent *ev)
+{
+ WebCore::Frame *frame = page->focusController()->focusedOrMainFrame();
+ WebCore::Editor *editor = frame->editor();
+
+ if (!editor->canEdit()) {
+ ev->ignore();
+ return;
+ }
+
+ if (!ev->preeditString().isEmpty()) {
+ 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));
+ editor->setComposition(preedit, underlines, preedit.length(), 0);
+ } else if (!ev->commitString().isEmpty()) {
+ editor->confirmComposition(ev->commitString());
+ }
ev->accept();
+}
+
+void QWebPagePrivate::shortcutOverrideEvent(QKeyEvent* event)
+{
+ WebCore::Frame* frame = page->focusController()->focusedOrMainFrame();
+ WebCore::Editor* editor = frame->editor();
+ if (editor->canEdit()) {
+ if (event->modifiers() == Qt::NoModifier
+ || event->modifiers() == Qt::ShiftModifier
+ || event->modifiers() == Qt::KeypadModifier) {
+ if (event->key() < Qt::Key_Escape) {
+ event->accept();
+ } else {
+ switch (event->key()) {
+ case Qt::Key_Return:
+ case Qt::Key_Enter:
+ case Qt::Key_Delete:
+ case Qt::Key_Home:
+ case Qt::Key_End:
+ case Qt::Key_Backspace:
+ case Qt::Key_Left:
+ case Qt::Key_Right:
+ case Qt::Key_Up:
+ case Qt::Key_Down:
+ case Qt::Key_Tab:
+ event->accept();
+ default:
+ break;
+ }
+ }
+ }
+#ifndef QT_NO_SHORTCUT
+ else if (editorActionForKeyEvent(event) != QWebPage::NoWebAction) {
+ event->accept();
+ }
#endif
+ }
+}
+
+bool QWebPagePrivate::handleScrolling(QKeyEvent *ev)
+{
+ ScrollDirection direction;
+ ScrollGranularity granularity;
+
+#ifndef QT_NO_SHORTCUT
+ if (ev == QKeySequence::MoveToNextPage
+ || (ev->key() == Qt::Key_Space && !(ev->modifiers() & Qt::ShiftModifier))) {
+ granularity = ScrollByPage;
+ direction = ScrollDown;
+ } else if (ev == QKeySequence::MoveToPreviousPage
+ || (ev->key() == Qt::Key_Space) && (ev->modifiers() & Qt::ShiftModifier)) {
+ granularity = ScrollByPage;
+ direction = ScrollUp;
+ } else
+#endif // QT_NO_SHORTCUT
+ if (ev->key() == Qt::Key_Up && ev->modifiers() & Qt::ControlModifier
+ || ev->key() == Qt::Key_Home) {
+ granularity = ScrollByDocument;
+ direction = ScrollUp;
+ } else if (ev->key() == Qt::Key_Down && ev->modifiers() & Qt::ControlModifier
+ || ev->key() == Qt::Key_End) {
+ granularity = ScrollByDocument;
+ direction = ScrollDown;
+ } else {
+ switch (ev->key()) {
+ case Qt::Key_Up:
+ granularity = ScrollByLine;
+ direction = ScrollUp;
+ break;
+ case Qt::Key_Down:
+ granularity = ScrollByLine;
+ direction = ScrollDown;
+ break;
+ case Qt::Key_Left:
+ granularity = ScrollByLine;
+ direction = ScrollLeft;
+ break;
+ case Qt::Key_Right:
+ granularity = ScrollByLine;
+ direction = ScrollRight;
+ break;
+ default:
+ return false;
+ }
+ }
+
+ if (!mainFrame->d->frame->eventHandler()->scrollOverflow(direction, granularity))
+ mainFrame->d->frame->view()->scroll(direction, granularity);
+
+ return true;
}
/*!
+ This method is used by the input method to query a set of properties of the page
+ to be able to support complex input method operations as support for surrounding
+ text and reconversions.
+
+ \a property specifies which property is queried.
+
+ \sa QWidget::inputMethodEvent(), QInputMethodEvent, QInputContext
+*/
+QVariant QWebPage::inputMethodQuery(Qt::InputMethodQuery property) const
+{
+ switch(property) {
+ case Qt::ImMicroFocus: {
+ Frame *frame = d->page->focusController()->focusedFrame();
+ if (frame) {
+ return QVariant(frame->selection()->caretRect());
+ }
+ return QVariant();
+ }
+ case Qt::ImFont: {
+ QWebView *webView = qobject_cast<QWebView *>(d->view);
+ if (webView)
+ return QVariant(webView->font());
+ return QVariant();
+ }
+ case Qt::ImCursorPosition: {
+ Frame *frame = d->page->focusController()->focusedFrame();
+ if (frame) {
+ Selection selection = frame->selection()->selection();
+ if (selection.isCaret()) {
+ return QVariant(selection.start().offset());
+ }
+ }
+ return QVariant();
+ }
+ case Qt::ImSurroundingText: {
+ Frame *frame = d->page->focusController()->focusedFrame();
+ if (frame) {
+ Document *document = frame->document();
+ if (document->focusedNode()) {
+ return QVariant(document->focusedNode()->nodeValue());
+ }
+ }
+ return QVariant();
+ }
+ case Qt::ImCurrentSelection:
+ return QVariant(selectedText());
+ default:
+ return QVariant();
+ }
+}
+
+/*!
+ \enum QWebPage::FindFlag
+
+ This enum describes the options available to QWebPage's findText() function. The options
+ can be OR-ed together from the following list:
+
+ \value FindBackward Searches backwards instead of forwards.
+ \value FindCaseSensitively By default findText() works case insensitive. Specifying this option
+ 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.
+*/
+
+/*!
+ \enum QWebPage::LinkDelegationPolicy
+
+ This enum defines the delegation policies a webpage can have when activating links and emitting
+ the linkClicked() signal.
+
+ \value DontDelegateLinks No links are delegated. Instead, QWebPage tries to handle them all.
+ \value DelegateExternalLinks When activating links that point to documents not stored on the
+ local filesystem or an equivalent - such as the Qt resource system - then linkClicked() is emitted.
+ \value DelegateAllLinks Whenever a link is activated the linkClicked() signal is emitted.
+*/
+
+/*!
+ \enum QWebPage::NavigationType
+
+ This enum describes the types of navigation available when browsing through hyperlinked
+ documents.
+
+ \value NavigationTypeLinkClicked The user clicked on a link or pressed return on a focused link.
+ \value NavigationTypeFormSubmitted The user activated a submit button for an HTML form.
+ \value NavigationTypeBackOrForward Navigation to a previously shown document in the back or forward history is requested.
+ \value NavigationTypeReload The user activated the reload action.
+ \value NavigationTypeFormResubmitted An HTML form was submitted a second time.
+ \value NavigationTypeOther A navigation to another document using a method not listed above.
+*/
+
+/*!
\enum QWebPage::WebAction
\value NoWebAction No action is triggered.
@@ -625,8 +1044,8 @@ void QWebPagePrivate::dropEvent(QDropEvent *ev)
\value OpenImageInNewWindow Open the highlighted image in a new window.
\value DownloadImageToDisk Download the highlighted image to the disk.
\value CopyImageToClipboard Copy the highlighted image to the clipboard.
- \value GoBack Navigate back in the history of navigated links.
- \value GoForward Navigate forward in the history of navigated links.
+ \value Back Navigate back in the history of navigated links.
+ \value Forward Navigate forward in the history of navigated links.
\value Stop Stop loading the current page.
\value Reload Reload the current page.
\value Cut Cut the content currently selected into the clipboard.
@@ -667,18 +1086,71 @@ void QWebPagePrivate::dropEvent(QDropEvent *ev)
\value ToggleItalic Toggle the formatting between italic and normal style.
\value ToggleUnderline Toggle underlining.
\value InspectElement Show the Web Inspector with the currently highlighted HTML element.
+ \value InsertParagraphSeparator Insert a new paragraph.
+ \value InsertLineSeparator Insert a new line.
\omitvalue WebActionCount
*/
/*!
+ \enum QWebPage::WebWindowType
+
+ \value WebBrowserWindow The window is a regular web browser window.
+ \value WebModalDialog The window acts as modal dialog.
+*/
+
+/*!
\class QWebPage
\since 4.4
- \brief The QWebPage class provides a widget that is used to view and edit web documents.
+ \brief The QWebPage class provides an object to view and edit web documents.
QWebPage holds a main frame responsible for web content, settings, the history
- of navigated links as well as actions. This class can be used, together with QWebFrame,
- if you want to provide functionality like QWebView in a setup without widgets.
+ of navigated links and actions. This class can be used, together with QWebFrame,
+ to provide functionality like QWebView in a widget-less environment.
+
+ QWebPage's API is very similar to QWebView, as you are still provided with
+ common functions like action() (known as \l{QWebView::}{pageAction()} in
+ QWebView), triggerAction(), findText() and settings(). More QWebView-like
+ functions can be found in the main frame of QWebPage, obtained via
+ QWebPage::mainFrame(). For example, the load(), setUrl() and setHtml()
+ unctions for QWebPage can be accessed using QWebFrame.
+
+ The loadStarted() signal is emitted when the page begins to load.The
+ loadProgress() signal, on the other hand, is emitted whenever an element
+ of the web page completes loading, such as an embedded image, a script,
+ etc. Finally, the loadFinished() signal is emitted when the page has
+ loaded completely. Its argument, either true or false, indicates whether
+ or not the load operation succeeded.
+
+ \section1 Using QWebPage in a Widget-less Environment
+
+ Before you begin painting a QWebPage object, you need to set the size of
+ the viewport by calling setViewportSize(). Then, you invoke the main
+ frame's render function (QWebFrame::render()). An example of this
+ is shown in the code snippet below.
+
+ Suppose we have a \c Thumbnail class as follows:
+
+ \snippet doc/src/snippets/webkit/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
+
+ The \c render() function shows how we can paint a thumbnail using a
+ QWebPage object.
+
+ \snippet doc/src/snippets/webkit/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
+ \l{QWebPage::viewportSize()}{viewportSize}. This image is then sent
+ as a parameter to \c painter. Next, we render the contents of the main
+ frame and its subframes into \c painter. Finally, we save the scaled image.
+
+ \sa QWebFrame
*/
/*!
@@ -690,11 +1162,11 @@ QWebPage::QWebPage(QObject *parent)
{
setView(qobject_cast<QWidget *>(parent));
- connect(this, SIGNAL(loadProgressChanged(int)), this, SLOT(_q_onLoadProgressChanged(int)));
+ connect(this, SIGNAL(loadProgress(int)), this, SLOT(_q_onLoadProgressChanged(int)));
}
/*!
- Destructor.
+ Destroys the web page.
*/
QWebPage::~QWebPage()
{
@@ -709,6 +1181,8 @@ QWebPage::~QWebPage()
The main frame provides access to the hierarchy of sub-frames and is also needed if you
want to explicitly render a web page into a given painter.
+
+ \sa currentFrame()
*/
QWebFrame *QWebPage::mainFrame() const
{
@@ -718,6 +1192,8 @@ QWebFrame *QWebPage::mainFrame() const
/*!
Returns the frame currently active.
+
+ \sa mainFrame(), frameCreated()
*/
QWebFrame *QWebPage::currentFrame() const
{
@@ -726,7 +1202,6 @@ QWebFrame *QWebPage::currentFrame() const
/*!
Returns a pointer to the view's history of navigated web pages.
-
*/
QWebHistory *QWebPage::history() const
{
@@ -754,32 +1229,56 @@ QWidget *QWebPage::view() const
return d->view;
}
-
/*!
- This function is called whenever a JavaScript program tries to print to what is the console in web browsers.
+ This function is called whenever a JavaScript program tries to print a \a message to the web browser's console.
+
+ For example in case of evaluation errors the source URL may be provided in \a sourceID as well as the \a lineNumber.
+
+ The default implementation prints nothing.
*/
-void QWebPage::javaScriptConsoleMessage(const QString& message, unsigned int lineNumber, const QString& sourceID)
+void QWebPage::javaScriptConsoleMessage(const QString& message, int lineNumber, const QString& sourceID)
{
+ Q_UNUSED(message)
+ Q_UNUSED(lineNumber)
+ Q_UNUSED(sourceID)
}
/*!
- This function is called whenever a JavaScript program calls the alert() function.
+ This function is called whenever a JavaScript program running inside \a frame calls the alert() function with
+ the message \a msg.
+
+ The default implementation shows the message, \a msg, with QMessageBox::information.
*/
void QWebPage::javaScriptAlert(QWebFrame *frame, const QString& msg)
{
+#ifndef QT_NO_MESSAGEBOX
QMessageBox::information(d->view, mainFrame()->title(), msg, QMessageBox::Ok);
+#endif
}
/*!
- This function is called whenever a JavaScript program calls the confirm() function.
+ This function is called whenever a JavaScript program running inside \a frame calls the confirm() function
+ with the message, \a msg. Returns true if the user confirms the message; otherwise returns false.
+
+ The default implementation executes the query using QMessageBox::information with QMessageBox::Yes and QMessageBox::No buttons.
*/
bool QWebPage::javaScriptConfirm(QWebFrame *frame, const QString& msg)
{
- return 0 == QMessageBox::information(d->view, mainFrame()->title(), msg, QMessageBox::Yes, QMessageBox::No);
+#ifdef QT_NO_MESSAGEBOX
+ return true;
+#else
+ return QMessageBox::Yes == QMessageBox::information(d->view, mainFrame()->title(), msg, QMessageBox::Yes, QMessageBox::No);
+#endif
}
/*!
- This function is called whenever a JavaScript program tries to prompt the user of input.
+ This function is called whenever a JavaScript program running inside \a frame tries to prompt the user for input.
+ The program may provide an optional message, \a msg, as well as a default value for the input in \a defaultValue.
+
+ If the prompt was cancelled by the user the implementation should return false; otherwise the
+ result should be written to \a result and true should be returned.
+
+ The default implementation uses QInputDialog::getText.
*/
bool QWebPage::javaScriptPrompt(QWebFrame *frame, const QString& msg, const QString& defaultValue, QString* result)
{
@@ -794,14 +1293,21 @@ bool QWebPage::javaScriptPrompt(QWebFrame *frame, const QString& msg, const QStr
}
/*!
- This function is called whenever WebKit wants to create a new window, for example as a result of
- a JavaScript request to open a document in a new window.
+ 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.
+
+ If the new window can be created, the new window's QWebPage is returned; otherwise a null pointer is returned.
+
+ If the view associated with the web page is a QWebView object, then the default implementation forwards
+ the request to QWebView's createWindow() function; otherwise it returns a null pointer.
+
+ \sa acceptNavigationRequest()
*/
-QWebPage *QWebPage::createWindow()
+QWebPage *QWebPage::createWindow(WebWindowType type)
{
QWebView *webView = qobject_cast<QWebView *>(d->view);
if (webView) {
- QWebView *newView = webView->createWindow();
+ QWebView *newView = webView->createWindow(type);
if (newView)
return newView->page();
}
@@ -809,14 +1315,6 @@ QWebPage *QWebPage::createWindow()
}
/*!
- This function is called whenever WebKit wants to create a new window that should act as a modal dialog.
-*/
-QWebPage *QWebPage::createModalDialog()
-{
- return 0;
-}
-
-/*!
This function is called whenever WebKit encounters a HTML object element with type "application/x-qt-plugin".
The \a classid, \a url, \a paramNames and \a paramValues correspond to the HTML object element attributes and
child elements to configure the embeddable object.
@@ -853,49 +1351,59 @@ static void openNewWindow(const QUrl& url, WebCore::Frame* frame)
If \a action is a checkable action then \a checked specified whether the action
is toggled or not.
+
+ \sa action()
*/
void QWebPage::triggerAction(WebAction action, bool checked)
{
WebCore::Frame *frame = d->page->focusController()->focusedOrMainFrame();
+ if (!frame)
+ return;
WebCore::Editor *editor = frame->editor();
const char *command = 0;
switch (action) {
case OpenLink:
- if (QWebFrame *targetFrame = d->currentContext.targetFrame()) {
+ if (QWebFrame *targetFrame = d->hitTestResult.linkTargetFrame()) {
WTF::RefPtr<WebCore::Frame> wcFrame = targetFrame->d->frame;
- targetFrame->d->frame->loader()->load(frameLoadRequest(d->currentContext.linkUrl(), wcFrame.get()),
- /*lockHistory*/ false,
- /*userGesture*/ true,
- /*event*/ 0,
- /*HTMLFormElement*/ 0,
- /*formValues*/
- WTF::HashMap<String, String>());
+ targetFrame->d->frame->loader()->loadFrameRequestWithFormAndValues(frameLoadRequest(d->hitTestResult.linkUrl(), wcFrame.get()),
+ /*lockHistory*/ false, /*event*/ 0,
+ /*HTMLFormElement*/ 0, /*formValues*/
+ WTF::HashMap<String, String>());
break;
- } else {
}
// fall through
case OpenLinkInNewWindow:
- openNewWindow(d->currentContext.linkUrl(), frame);
+ openNewWindow(d->hitTestResult.linkUrl(), frame);
break;
- case OpenFrameInNewWindow:
+ case OpenFrameInNewWindow: {
+ KURL url = frame->loader()->documentLoader()->unreachableURL();
+ if (url.isEmpty())
+ url = frame->loader()->documentLoader()->url();
+ openNewWindow(url, frame);
break;
+ }
case CopyLinkToClipboard:
- editor->copyURL(d->currentContext.linkUrl(), d->currentContext.text());
+ editor->copyURL(d->hitTestResult.linkUrl(), d->hitTestResult.linkText());
break;
case OpenImageInNewWindow:
- openNewWindow(d->currentContext.imageUrl(), frame);
+ openNewWindow(d->hitTestResult.imageUrl(), frame);
break;
case DownloadImageToDisk:
+ frame->loader()->client()->startDownload(WebCore::ResourceRequest(d->hitTestResult.imageUrl(), frame->loader()->outgoingReferrer()));
+ break;
case DownloadLinkToDisk:
- frame->loader()->client()->startDownload(WebCore::ResourceRequest(d->currentContext.linkUrl(), frame->loader()->outgoingReferrer()));
+ frame->loader()->client()->startDownload(WebCore::ResourceRequest(d->hitTestResult.linkUrl(), frame->loader()->outgoingReferrer()));
break;
+#ifndef QT_NO_CLIPBOARD
case CopyImageToClipboard:
+ QApplication::clipboard()->setPixmap(d->hitTestResult.pixmap());
break;
- case GoBack:
+#endif
+ case Back:
d->page->goBack();
break;
- case GoForward:
+ case Forward:
d->page->goForward();
break;
case Stop:
@@ -904,126 +1412,21 @@ void QWebPage::triggerAction(WebAction action, bool checked)
case Reload:
mainFrame()->d->frame->loader()->reload();
break;
- case Cut:
- command = "Cut";
- break;
- case Copy:
- command = "Copy";
- break;
- case Paste:
- command = "Paste";
- break;
-
- case Undo:
- command = "Undo";
- break;
- case Redo:
- command = "Redo";
- break;
-
- case MoveToNextChar:
- command = "MoveForward";
- break;
- case MoveToPreviousChar:
- command = "MoveBackward";
- break;
- case MoveToNextWord:
- command = "MoveWordForward";
- break;
- case MoveToPreviousWord:
- command = "MoveWordBackward";
- break;
- case MoveToNextLine:
- command = "MoveDown";
- break;
- case MoveToPreviousLine:
- command = "MoveUp";
- break;
- case MoveToStartOfLine:
- command = "MoveToBeginningOfLine";
- break;
- case MoveToEndOfLine:
- command = "MoveToEndOfLine";
- break;
- case MoveToStartOfBlock:
- command = "MoveToBeginningOfParagraph";
- break;
- case MoveToEndOfBlock:
- command = "MoveToEndOfParagraph";
- break;
- case MoveToStartOfDocument:
- command = "MoveToBeginningOfDocument";
- break;
- case MoveToEndOfDocument:
- command = "MoveToEndOfDocument";
- break;
- case SelectNextChar:
- command = "MoveForwardAndModifySelection";
- break;
- case SelectPreviousChar:
- command = "MoveBackwardAndModifySelection";
- break;
- case SelectNextWord:
- command = "MoveWordForwardAndModifySelection";
- break;
- case SelectPreviousWord:
- command = "MoveWordBackwardAndModifySelection";
- break;
- case SelectNextLine:
- command = "MoveDownAndModifySelection";
- break;
- case SelectPreviousLine:
- command = "MoveUpAndModifySelection";
- break;
- case SelectStartOfLine:
- command = "MoveToBeginningOfLineAndModifySelection";
- break;
- case SelectEndOfLine:
- command = "MoveToEndOfLineAndModifySelection";
- break;
- case SelectStartOfBlock:
- command = "MoveToBeginningOfParagraphAndModifySelection";
- break;
- case SelectEndOfBlock:
- command = "MoveToEndOfParagraphAndModifySelection";
- break;
- case SelectStartOfDocument:
- command = "MoveToBeginningOfDocumentAndModifySelection";
- break;
- case SelectEndOfDocument:
- command = "MoveToEndOfDocumentAndModifySelection";
- break;
- case DeleteStartOfWord:
- command = "DeleteWordBackward";
- break;
- case DeleteEndOfWord:
- command = "DeleteWordForward";
- break;
-
case SetTextDirectionDefault:
- editor->setBaseWritingDirection("inherit");
+ editor->setBaseWritingDirection(NaturalWritingDirection);
break;
case SetTextDirectionLeftToRight:
- editor->setBaseWritingDirection("ltr");
+ editor->setBaseWritingDirection(LeftToRightWritingDirection);
break;
case SetTextDirectionRightToLeft:
- editor->setBaseWritingDirection("rtl");
+ editor->setBaseWritingDirection(RightToLeftWritingDirection);
break;
-
- case ToggleBold:
- command = "ToggleBold";
- break;
- case ToggleItalic:
- command = "ToggleItalic";
- break;
- case ToggleUnderline:
- editor->toggleUnderline();
-
case InspectElement:
- d->page->inspectorController()->inspect(d->currentContext.d->innerNonSharedNode.get());
+ d->page->inspectorController()->inspect(d->hitTestResult.d->innerNonSharedNode.get());
+ break;
+ default:
+ command = editorCommandForWebActions(action);
break;
-
- default: break;
}
if (command)
@@ -1032,43 +1435,82 @@ void QWebPage::triggerAction(WebAction action, bool checked)
QSize QWebPage::viewportSize() const
{
- QWebFrame *frame = mainFrame();
- if (frame->d->frame && frame->d->frameView)
- return frame->d->frameView->frameGeometry().size();
- return QSize(0, 0);
+ if (d->mainFrame && d->mainFrame->d->frame->view())
+ return d->mainFrame->d->frame->view()->frameRect().size();
+
+ return d->viewportSize;
}
/*!
\property QWebPage::viewportSize
+ \brief the size of the viewport
- Specifies the size of the viewport. The size affects for example the visibility of scrollbars
+ The size affects for example the visibility of scrollbars
if the document is larger than the viewport.
+
+ By default, for a newly-created Web page, this property contains a size with
+ zero width and height.
*/
void QWebPage::setViewportSize(const QSize &size) const
{
+ d->viewportSize = size;
+
QWebFrame *frame = mainFrame();
- if (frame->d->frame && frame->d->frameView) {
- frame->d->frameView->setFrameGeometry(QRect(QPoint(0, 0), size));
+ if (frame->d->frame && frame->d->frame->view()) {
+ WebCore::FrameView* view = frame->d->frame->view();
+ view->setFrameRect(QRect(QPoint(0, 0), size));
frame->d->frame->forceLayout();
- frame->d->frame->view()->adjustViewSize();
+ view->adjustViewSize();
}
}
-#if QT_VERSION < 0x040400
-QWebPage::NavigationRequestResponse QWebPage::navigationRequested(QWebFrame *frame, const QWebNetworkRequest &request, QWebPage::NavigationType type)
+/*!
+ \fn bool QWebPage::acceptNavigationRequest(QWebFrame *frame, const QNetworkRequest &request, QWebPage::NavigationType type)
+
+ This function is called whenever WebKit requests to navigate \a frame to the resource specified by \a request by means of
+ the specified navigation type \a type.
+
+ If \a frame is a null pointer then navigation to a new window is requested. If the request is
+ accepted createWindow() will be called.
+
+ The default implementation interprets the page's linkDelegationPolicy and emits linkClicked accordingly or returns true
+ to let QWebPage handle the navigation itself.
+
+ \sa createWindow()
+*/
+#if QT_VERSION >= 0x040400
+bool QWebPage::acceptNavigationRequest(QWebFrame *frame, const QNetworkRequest &request, QWebPage::NavigationType type)
#else
-QWebPage::NavigationRequestResponse QWebPage::navigationRequested(QWebFrame *frame, const QNetworkRequest &request, QWebPage::NavigationType type)
+bool QWebPage::acceptNavigationRequest(QWebFrame *frame, const QWebNetworkRequest &request, QWebPage::NavigationType type)
#endif
{
- Q_UNUSED(request)
- return AcceptNavigationRequest;
+ if (type == NavigationTypeLinkClicked) {
+ switch (d->linkPolicy) {
+ case DontDelegateLinks:
+ return true;
+
+ case DelegateExternalLinks:
+ if (WebCore::FrameLoader::shouldTreatSchemeAsLocal(request.url().scheme()))
+ return true;
+ emit linkClicked(request.url());
+ return false;
+
+ case DelegateAllLinks:
+ emit linkClicked(request.url());
+ return false;
+ }
+ }
+ return true;
}
/*!
\property QWebPage::selectedText
+ \brief the text currently selected
- Returns the text currently selected.
+ By default, this property contains an empty string.
+
+ \sa selectionChanged()
*/
QString QWebPage::selectedText() const
{
@@ -1083,6 +1525,8 @@ QString QWebPage::selectedText() const
QWebPage also takes care of implementing the action, so that upon
triggering the corresponding action is performed on the page.
+
+ \sa triggerAction()
*/
QAction *QWebPage::action(WebAction action) const
{
@@ -1091,6 +1535,8 @@ QAction *QWebPage::action(WebAction action) const
return d->actions[action];
QString text;
+ QIcon icon;
+ QStyle *style = view() ? view()->style() : qApp->style();
bool checkable = false;
switch (action) {
@@ -1121,17 +1567,29 @@ QAction *QWebPage::action(WebAction action) const
text = contextMenuItemTagCopyImageToClipboard();
break;
- case GoBack:
+ case Back:
text = contextMenuItemTagGoBack();
+#if QT_VERSION >= 0x040400
+ icon = style->standardIcon(QStyle::SP_ArrowBack);
+#endif
break;
- case GoForward:
+ case Forward:
text = contextMenuItemTagGoForward();
+#if QT_VERSION >= 0x040400
+ icon = style->standardIcon(QStyle::SP_ArrowForward);
+#endif
break;
case Stop:
text = contextMenuItemTagStop();
+#if QT_VERSION >= 0x040400
+ icon = style->standardIcon(QStyle::SP_BrowserStop);
+#endif
break;
case Reload:
text = contextMenuItemTagReload();
+#if QT_VERSION >= 0x040400
+ icon = style->standardIcon(QStyle::SP_BrowserReload);
+#endif
break;
case Cut:
@@ -1143,7 +1601,7 @@ QAction *QWebPage::action(WebAction action) const
case Paste:
text = contextMenuItemTagPaste();
break;
-
+#ifndef QT_NO_UNDOSTACK
case Undo: {
QAction *a = undoStack()->createUndoAction(d->q);
d->actions[action] = a;
@@ -1154,6 +1612,7 @@ QAction *QWebPage::action(WebAction action) const
d->actions[action] = a;
return a;
}
+#endif // QT_NO_UNDOSTACK
case MoveToNextChar:
case MoveToPreviousChar:
case MoveToNextWord:
@@ -1222,6 +1681,7 @@ QAction *QWebPage::action(WebAction action) const
a->setText(text);
a->setData(action);
a->setCheckable(checkable);
+ a->setIcon(icon);
connect(a, SIGNAL(triggered(bool)),
this, SLOT(_q_webActionTriggered(bool)));
@@ -1233,15 +1693,22 @@ QAction *QWebPage::action(WebAction action) const
/*!
\property QWebPage::modified
+ \brief whether the page contains unsubmitted form data
- Specifies if the page contains unsubmitted form data.
+ By default, this property is false.
*/
bool QWebPage::isModified() const
{
- return d->modified;
+#ifdef QT_NO_UNDOSTACK
+ return false;
+#else
+ if (!d->undoStack)
+ return false;
+ return d->undoStack->canUndo();
+#endif // QT_NO_UNDOSTACK
}
-
+#ifndef QT_NO_UNDOSTACK
/*!
Returns a pointer to the undo stack used for editable content.
*/
@@ -1252,12 +1719,16 @@ QUndoStack *QWebPage::undoStack() const
return d->undoStack;
}
+#endif // QT_NO_UNDOSTACK
/*! \reimp
*/
bool QWebPage::event(QEvent *ev)
{
switch (ev->type()) {
+ case QEvent::Timer:
+ d->timerEvent(static_cast<QTimerEvent*>(ev));
+ break;
case QEvent::MouseMove:
d->mouseMoveEvent(static_cast<QMouseEvent*>(ev));
break;
@@ -1270,12 +1741,16 @@ bool QWebPage::event(QEvent *ev)
case QEvent::MouseButtonRelease:
d->mouseReleaseEvent(static_cast<QMouseEvent*>(ev));
break;
+#ifndef QT_NO_CONTEXTMENU
case QEvent::ContextMenu:
d->contextMenuEvent(static_cast<QContextMenuEvent*>(ev));
break;
+#endif
+#ifndef QT_NO_WHEELEVENT
case QEvent::Wheel:
d->wheelEvent(static_cast<QWheelEvent*>(ev));
break;
+#endif
case QEvent::KeyPress:
d->keyPressEvent(static_cast<QKeyEvent*>(ev));
break;
@@ -1302,6 +1777,14 @@ bool QWebPage::event(QEvent *ev)
d->dropEvent(static_cast<QDropEvent*>(ev));
break;
#endif
+ case QEvent::InputMethod:
+ d->inputMethodEvent(static_cast<QInputMethodEvent*>(ev));
+ case QEvent::ShortcutOverride:
+ d->shortcutOverrideEvent(static_cast<QKeyEvent*>(ev));
+ break;
+ case QEvent::Leave:
+ d->leaveEvent(ev);
+ break;
default:
return QObject::event(ev);
}
@@ -1311,7 +1794,9 @@ bool QWebPage::event(QEvent *ev)
/*!
Similar to QWidget::focusNextPrevChild it focuses the next focusable web element
- if \a next is true. Otherwise the previous element is focused.
+ if \a next is true; otherwise the previous element is focused.
+
+ Returns true if it can find a new focusable element, or false if it can't.
*/
bool QWebPage::focusNextPrevChild(bool next)
{
@@ -1328,9 +1813,242 @@ bool QWebPage::focusNextPrevChild(bool next)
}
/*!
- Returns a pointe to the page's settings object.
+ \property QWebPage::editable
+ \brief whether the content in this QWebPage is editable or not
+ \since 4.5
+
+ If this property is enabled the contents of the page can be edited by the user through a visible
+ cursor. If disabled (the default) only HTML elements in the web page with their
+ \c{contenteditable} attribute set are editable.
+*/
+void QWebPage::setEditable(bool editable)
+{
+ if (d->editable != editable) {
+ d->editable = editable;
+ d->page->setTabKeyCyclesThroughElements(!editable);
+ if (d->mainFrame) {
+ WebCore::Frame* frame = d->mainFrame->d->frame;
+ if (editable) {
+ frame->applyEditingStyleToBodyElement();
+ // FIXME: mac port calls this if there is no selectedDOMRange
+ //frame->setSelectionFromNone();
+ } else {
+ frame->removeEditingStyleFromBodyElement();
+ }
+ }
+
+ d->updateEditorActions();
+ }
+}
+
+bool QWebPage::isEditable() const
+{
+ return d->editable;
+}
+
+/*!
+ \property QWebPage::forwardUnsupportedContent
+ \brief whether QWebPage should forward unsupported content through the
+ unsupportedContent signal
+
+ If disabled the download of such content is aborted immediately.
+
+ By default unsupported content is not forwarded.
+*/
+
+void QWebPage::setForwardUnsupportedContent(bool forward)
+{
+ d->forwardUnsupportedContent = forward;
+}
+
+bool QWebPage::forwardUnsupportedContent() const
+{
+ return d->forwardUnsupportedContent;
+}
+
+/*!
+ \property QWebPage::linkDelegationPolicy
+ \brief how QWebPage should delegate the handling of links through the
+ linkClicked() signal
+
+ The default is to delegate no links.
+*/
+
+void QWebPage::setLinkDelegationPolicy(LinkDelegationPolicy policy)
+{
+ d->linkPolicy = policy;
+}
+
+QWebPage::LinkDelegationPolicy QWebPage::linkDelegationPolicy() const
+{
+ return d->linkPolicy;
+}
+
+#ifndef QT_NO_CONTEXTMENU
+/*!
+ Filters the context menu event, \a event, through handlers for scrollbars and
+ custom event handlers in the web page. Returns true if the event was handled;
+ otherwise false.
+
+ A web page may swallow a context menu event through a custom event handler, allowing for context
+ menus to be implemented in HTML/JavaScript. This is used by \l{http://maps.google.com/}{Google
+ Maps}, for example.
+*/
+bool QWebPage::swallowContextMenuEvent(QContextMenuEvent *event)
+{
+ d->page->contextMenuController()->clearContextMenu();
+
+ if (QWebFrame* webFrame = d->frameAt(event->pos())) {
+ Frame* frame = QWebFramePrivate::core(webFrame);
+ if (Scrollbar* scrollbar = frame->view()->scrollbarUnderMouse(PlatformMouseEvent(event, 1))) {
+ return scrollbar->contextMenu(PlatformMouseEvent(event, 1));
+ }
+ }
+
+ WebCore::Frame* focusedFrame = d->page->focusController()->focusedOrMainFrame();
+ focusedFrame->eventHandler()->sendContextMenuEvent(PlatformMouseEvent(event, 1));
+ ContextMenu *menu = d->page->contextMenuController()->contextMenu();
+ // If the website defines its own handler then sendContextMenuEvent takes care of
+ // calling/showing it and the context menu pointer will be zero. This is the case
+ // on maps.google.com for example.
+
+ return !menu;
+}
+#endif // QT_NO_CONTEXTMENU
+
+/*!
+ Updates the page's actions depending on the position \a pos. For example if \a pos is over an image
+ element the CopyImageToClipboard action is enabled.
+*/
+void QWebPage::updatePositionDependentActions(const QPoint &pos)
+{
+ // First we disable all actions, but keep track of which ones were originally enabled.
+ QBitArray originallyEnabledWebActions(QWebPage::WebActionCount);
+ for (int i = ContextMenuItemTagNoAction; i < ContextMenuItemBaseApplicationTag; ++i) {
+ QWebPage::WebAction action = webActionForContextMenuAction(WebCore::ContextMenuAction(i));
+ if (QAction *a = this->action(action)) {
+ originallyEnabledWebActions.setBit(action, a->isEnabled());
+ a->setEnabled(false);
+ }
+ }
+
+ WebCore::Frame* focusedFrame = d->page->focusController()->focusedOrMainFrame();
+ HitTestResult result = focusedFrame->eventHandler()->hitTestResultAtPoint(focusedFrame->view()->windowToContents(pos), /*allowShadowContent*/ false);
+
+ d->hitTestResult = QWebHitTestResult(new QWebHitTestResultPrivate(result));
+ WebCore::ContextMenu menu(result);
+ menu.populate();
+ if (d->page->inspectorController()->enabled())
+ menu.addInspectElementItem();
+
+ QBitArray visitedWebActions(QWebPage::WebActionCount);
+
+#ifndef QT_NO_CONTEXTMENU
+ delete d->currentContextMenu;
+
+ // Then we let createContextMenu() enable the actions that are put into the menu
+ d->currentContextMenu = d->createContextMenu(&menu, menu.platformDescription(), &visitedWebActions);
+#endif // QT_NO_CONTEXTMENU
+
+ // Finally, we restore the original enablement for the actions that were not put into the menu.
+ 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))) {
+ a->setEnabled(true);
+ }
+ }
+ }
+
+ // This whole process ensures that any actions put into to the context menu has the right
+ // enablement, while also keeping the correct enablement for actions that were left out of
+ // the menu.
+
+}
+
+
+
+/*!
+ \enum QWebPage::Extension
+
+ This enum describes the types of extensions that the page can support. Before using these extensions, you
+ should verify that the extension is supported by calling supportsExtension().
+
+ Currently there are no extensions.
+*/
+
+/*!
+ \class QWebPage::ExtensionOption
+ \since 4.4
+ \brief The ExtensionOption class provides an extended input argument to QWebPage's extension support.
+
+ \sa QWebPage::extension()
+*/
+
+/*!
+ \class QWebPage::ExtensionReturn
+ \since 4.4
+ \brief The ExtensionOption class provides an extended output argument to QWebPage's extension support.
+
+ \sa QWebPage::extension()
+*/
+
+/*!
+ This virtual function can be reimplemented in a QWebPage subclass to provide support for extensions. The \a option
+ argument is provided as input to the extension; the output results can be stored in \a output.
+
+ The behavior of this function is determined by \a extension.
+
+ You can call supportsExtension() to check if an extension is supported by the page.
+
+ By default, no extensions are supported, and this function returns false.
+
+ \sa supportsExtension(), Extension
+*/
+bool QWebPage::extension(Extension extension, const ExtensionOption *option, ExtensionReturn *output)
+{
+ Q_UNUSED(extension)
+ Q_UNUSED(option)
+ Q_UNUSED(output)
+ return false;
+}
+
+/*!
+ This virtual function returns true if the web page supports \a extension; otherwise false is returned.
+
+ \sa extension()
+*/
+bool QWebPage::supportsExtension(Extension extension) const
+{
+ Q_UNUSED(extension)
+ return false;
+}
+
+/*!
+ 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.
*/
-QWebSettings *QWebPage::settings()
+bool QWebPage::findText(const QString &subString, FindFlags options)
+{
+ ::TextCaseSensitivity caseSensitivity = ::TextCaseInsensitive;
+ if (options & FindCaseSensitively)
+ caseSensitivity = ::TextCaseSensitive;
+
+ ::FindDirection direction = ::FindDirectionForward;
+ if (options & FindBackward)
+ direction = ::FindDirectionBackward;
+
+ const bool shouldWrap = options & FindWrapsAroundDocument;
+
+ return d->page->findString(subString, caseSensitivity, direction, shouldWrap);
+}
+
+/*!
+ Returns a pointer to the page's settings object.
+
+ \sa QWebSettings::globalSettings()
+*/
+QWebSettings *QWebPage::settings() const
{
return d->settings;
}
@@ -1338,17 +2056,20 @@ QWebSettings *QWebPage::settings()
/*!
This function is called when the web content requests a file name, for example
as a result of the user clicking on a "file upload" button in a HTML form.
+
+ A suggested filename may be provided in \a suggestedFile. The frame originating the
+ request is provided as \a parentFrame.
*/
-QString QWebPage::chooseFile(QWebFrame *parentFrame, const QString& oldFile)
+QString QWebPage::chooseFile(QWebFrame *parentFrame, const QString& suggestedFile)
{
#ifndef QT_NO_FILEDIALOG
- return QFileDialog::getOpenFileName(d->view, QString::null, oldFile);
+ return QFileDialog::getOpenFileName(d->view, QString::null, suggestedFile);
#else
return QString::null;
#endif
}
-#if QT_VERSION < 0x040400
+#if QT_VERSION < 0x040400 && !defined qdoc
void QWebPage::setNetworkInterface(QWebNetworkInterface *interface)
{
@@ -1378,24 +2099,25 @@ QNetworkProxy QWebPage::networkProxy() const
#else
/*!
- Sets the QNetworkAccessManager \a manager that is responsible for serving network
- requests for this QWebPage.
+ Sets the QNetworkAccessManager \a manager responsible for serving network requests for this
+ QWebPage.
- \sa networkAccessManager
+ \sa networkAccessManager()
*/
void QWebPage::setNetworkAccessManager(QNetworkAccessManager *manager)
{
if (manager == d->networkManager)
return;
- delete d->networkManager;
+ if (d->networkManager && d->networkManager->parent() == this)
+ delete d->networkManager;
d->networkManager = manager;
}
/*!
- Returns the QNetworkAccessManager \a manager that is responsible for serving network
+ Returns the QNetworkAccessManager that is responsible for serving network
requests for this QWebPage.
- \sa setNetworkAccessManager
+ \sa setNetworkAccessManager()
*/
QNetworkAccessManager *QWebPage::networkAccessManager() const
{
@@ -1409,13 +2131,213 @@ QNetworkAccessManager *QWebPage::networkAccessManager() const
#endif
/*!
+ Sets the QWebPluginFactory \a factory responsible for creating plugins embedded into this
+ QWebPage.
+
+ Note: The plugin factory is only used if the QWebSettings::PluginsEnabled attribute is enabled.
+
+ \sa pluginFactory()
+*/
+void QWebPage::setPluginFactory(QWebPluginFactory *factory)
+{
+ d->pluginFactory = factory;
+}
+
+/*!
+ Returns the QWebPluginFactory that is responsible for creating plugins embedded into
+ this QWebPage. If no plugin factory is installed a null pointer is returned.
+
+ \sa setPluginFactory()
+*/
+QWebPluginFactory *QWebPage::pluginFactory() const
+{
+ return d->pluginFactory;
+}
+
+/*!
This function is called when a user agent for HTTP requests is needed. You can re-implement this
function to dynamically return different user agent's for different urls, based on the \a url parameter.
+
+ The default implementation returns the following value:
+
+ "Mozilla/5.0 (%Platform%; %Security%; %Subplatform%; %Locale%) AppleWebKit/%WebKitVersion% (KHTML, like Gecko, Safari/419.3) %AppVersion"
+
+ In this string the following values are replaced at run-time:
+ \list
+ \o %Platform% and %Subplatform% are expanded to the windowing system and the operation system.
+ \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().
+ \o %WebKitVersion% currently expands to 527+
+ \o %AppVersion% expands to QCoreApplication::applicationName()/QCoreApplication::applicationVersion() if they're set; otherwise defaulting to Qt and the current Qt version.
+ \endlist
*/
-QString QWebPage::userAgentFor(const QUrl& url) const
+QString QWebPage::userAgentForUrl(const QUrl& url) const
{
Q_UNUSED(url)
- return QLatin1String("Mozilla/5.0 (Macintosh; U; Intel Mac OS X; en) AppleWebKit/523.15 (KHTML, like Gecko) Safari/419.3 Qt");
+ QString ua = QLatin1String("Mozilla/5.0 ("
+
+ // Plastform
+#ifdef Q_WS_MAC
+ "Macintosh"
+#elif defined Q_WS_QWS
+ "QtEmbedded"
+#elif defined Q_WS_WIN
+ "Windows"
+#elif defined Q_WS_X11
+ "X11"
+#else
+ "Unknown"
+#endif
+ "; "
+
+ // Placeholder for security strength (N or U)
+ "%1; "
+
+ // Subplatform"
+#ifdef Q_OS_AIX
+ "AIX"
+#elif defined Q_OS_WIN32
+ "%2"
+#elif defined Q_OS_DARWIN
+#ifdef __i386__ || __x86_64__
+ "Intel Mac OS X"
+#else
+ "PPC Mac OS X"
+#endif
+
+#elif defined Q_OS_BSDI
+ "BSD"
+#elif defined Q_OS_BSD4
+ "BSD Four"
+#elif defined Q_OS_CYGWIN
+ "Cygwin"
+#elif defined Q_OS_DGUX
+ "DG/UX"
+#elif defined Q_OS_DYNIX
+ "DYNIX/ptx"
+#elif defined Q_OS_FREEBSD
+ "FreeBSD"
+#elif defined Q_OS_HPUX
+ "HP-UX"
+#elif defined Q_OS_HURD
+ "GNU Hurd"
+#elif defined Q_OS_IRIX
+ "SGI Irix"
+#elif defined Q_OS_LINUX
+ "Linux"
+#elif defined Q_OS_LYNX
+ "LynxOS"
+#elif defined Q_OS_NETBSD
+ "NetBSD"
+#elif defined Q_OS_OS2
+ "OS/2"
+#elif defined Q_OS_OPENBSD
+ "OpenBSD"
+#elif defined Q_OS_OS2EMX
+ "OS/2"
+#elif defined Q_OS_OSF
+ "HP Tru64 UNIX"
+#elif defined Q_OS_QNX6
+ "QNX RTP Six"
+#elif defined Q_OS_QNX
+ "QNX"
+#elif defined Q_OS_RELIANT
+ "Reliant UNIX"
+#elif defined Q_OS_SCO
+ "SCO OpenServer"
+#elif defined Q_OS_SOLARIS
+ "Sun Solaris"
+#elif defined Q_OS_ULTRIX
+ "DEC Ultrix"
+#elif defined Q_OS_UNIX
+ "UNIX BSD/SYSV system"
+#elif defined Q_OS_UNIXWARE
+ "UnixWare Seven, Open UNIX Eight"
+#else
+ "Unknown"
+#endif
+ "; ");
+
+ QChar securityStrength(QLatin1Char('N'));
+#if !defined(QT_NO_OPENSSL)
+ if (QSslSocket::supportsSsl())
+ securityStrength = QLatin1Char('U');
+#endif
+ ua = ua.arg(securityStrength);
+
+#if defined Q_OS_WIN32
+ QString ver;
+ switch(QSysInfo::WindowsVersion) {
+ case QSysInfo::WV_32s:
+ ver = "Windows 3.1";
+ break;
+ case QSysInfo::WV_95:
+ ver = "Windows 95";
+ break;
+ case QSysInfo::WV_98:
+ ver = "Windows 98";
+ break;
+ case QSysInfo::WV_Me:
+ ver = "Windows 98; Win 9x 4.90";
+ break;
+ case QSysInfo::WV_NT:
+ ver = "WinNT4.0";
+ break;
+ case QSysInfo::WV_2000:
+ ver = "Windows NT 5.0";
+ break;
+ case QSysInfo::WV_XP:
+ ver = "Windows NT 5.1";
+ break;
+ case QSysInfo::WV_2003:
+ ver = "Windows NT 5.2";
+ break;
+ case QSysInfo::WV_VISTA:
+ ver = "Windows NT 6.0";
+ break;
+ case QSysInfo::WV_CE:
+ ver = "Windows CE";
+ break;
+ case QSysInfo::WV_CENET:
+ ver = "Windows CE .NET";
+ break;
+ case QSysInfo::WV_CE_5:
+ ver = "Windows CE 5.x";
+ break;
+ case QSysInfo::WV_CE_6:
+ ver = "Windows CE 6.x";
+ break;
+ }
+ ua = QString(ua).arg(ver);
+#endif
+
+ // Language
+ QLocale locale;
+ if (d->view)
+ locale = d->view->locale();
+ QString name = locale.name();
+ name[2] = QLatin1Char('-');
+ ua.append(name);
+ ua.append(QLatin1String(") "));
+
+ // webkit/qt version
+ ua.append(QLatin1String("AppleWebKit/" WEBKIT_VERSION " (KHTML, like Gecko, Safari/419.3) "));
+
+ // Application name/version
+ QString appName = QCoreApplication::applicationName();
+ if (!appName.isEmpty()) {
+ ua.append(QLatin1Char(' ') + appName);
+#if QT_VERSION >= 0x040400
+ QString appVer = QCoreApplication::applicationVersion();
+ if (!appVer.isEmpty())
+ ua.append(QLatin1Char('/') + appVer);
+#endif
+ } else {
+ // Qt version
+ ua.append(QLatin1String("Qt/"));
+ ua.append(QLatin1String(qVersion()));
+ }
+ return ua;
}
@@ -1428,6 +2350,8 @@ void QWebPagePrivate::_q_onLoadProgressChanged(int) {
/*!
Returns the total number of bytes that were received from the network to render the current page,
including extra content such as embedded images.
+
+ \sa bytesReceived()
*/
quint64 QWebPage::totalBytes() const {
return d->m_bytesReceived;
@@ -1436,123 +2360,54 @@ quint64 QWebPage::totalBytes() const {
/*!
Returns the number of bytes that were received from the network to render the current page.
+
+ \sa totalBytes()
*/
quint64 QWebPage::bytesReceived() const {
return d->m_totalBytes;
}
-QWebPageContext::QWebPageContext(const WebCore::HitTestResult &hitTest)
- : d(new QWebPageContextPrivate)
-{
- d->pos = hitTest.point();
- d->text = hitTest.textContent();
- d->linkUrl = hitTest.absoluteLinkURL().string();
- d->imageUrl = hitTest.absoluteImageURL().string();
- d->innerNonSharedNode = hitTest.innerNonSharedNode();
- WebCore::Image *img = hitTest.image();
- if (img) {
- QPixmap *pix = img->getPixmap();
- if (pix)
- d->image = *pix;
- }
- WebCore::Frame *frame = hitTest.targetFrame();
- if (frame)
- d->targetFrame = frame->view()->qwebframe();
-}
-
-QWebPageContext::QWebPageContext()
- : d(0)
-{
-}
-
-QWebPageContext::QWebPageContext(const QWebPageContext &other)
- : d(0)
-{
- if (other.d)
- d = new QWebPageContextPrivate(*other.d);
-}
-
-QWebPageContext &QWebPageContext::operator=(const QWebPageContext &other)
-{
- if (this != &other) {
- if (other.d) {
- if (!d)
- d = new QWebPageContextPrivate;
- *d = *other.d;
- } else {
- delete d;
- d = 0;
- }
- }
- return *this;
-}
-
-QWebPageContext::~QWebPageContext()
-{
- delete d;
-}
-
-QPoint QWebPageContext::pos() const
-{
- if (!d)
- return QPoint();
- return d->pos;
-}
+/*!
+ \fn void QWebPage::loadStarted()
-QString QWebPageContext::text() const
-{
- if (!d)
- return QString();
- return d->text;
-}
+ This signal is emitted when a new load of the page is started.
-QUrl QWebPageContext::linkUrl() const
-{
- if (!d)
- return QUrl();
- return d->linkUrl;
-}
+ \sa loadFinished()
+*/
-QUrl QWebPageContext::imageUrl() const
-{
- if (!d)
- return QUrl();
- return d->linkUrl;
-}
+/*!
+ \fn void QWebPage::loadProgress(int progress)
-QPixmap QWebPageContext::image() const
-{
- if (!d)
- return QPixmap();
- return d->image;
-}
+ This signal is emitted when the global progress status changes.
+ The current value is provided by \a progress and scales from 0 to 100,
+ which is the default range of QProgressBar.
+ It accumulates changes from all the child frames.
-QWebFrame *QWebPageContext::targetFrame() const
-{
- if (!d)
- return 0;
- return d->targetFrame;
-}
+ \sa bytesReceived()
+*/
/*!
- \fn void QWebPage::loadProgressChanged(int progress)
+ \fn void QWebPage::loadFinished(bool ok)
- This signal is emitted when the global progress status changes.
- The current value is provided by \a progress in percent.
- It accumulates changes from all the child frames.
+ This signal is emitted when a load of the page is finished.
+ \a ok will indicate whether the load was successful or any error occurred.
+
+ \sa loadStarted()
*/
/*!
- \fn void QWebPage::hoveringOverLink(const QString &link, const QString &title, const QString &textContent)
+ \fn void QWebPage::linkHovered(const QString &link, const QString &title, const QString &textContent)
This signal is emitted when the mouse is hovering over a link.
The first parameter is the \a link url, the second is the link \a title
if any, and third \a textContent is the text content. Method is emitter with both
empty parameters when the mouse isn't hovering over any link element.
+
+ \sa linkClicked()
*/
/*!
- \fn void QWebPage::statusBarTextChanged(const QString& text)
+ \fn void QWebPage::statusBarMessage(const QString& text)
This signal is emitted when the statusbar \a text is changed by the page.
*/
@@ -1567,27 +2422,122 @@ QWebFrame *QWebPageContext::targetFrame() const
\fn void QWebPage::selectionChanged()
This signal is emitted whenever the selection changes.
+
+ \sa selectedText()
*/
/*!
- \fn void QWebPage::geometryChangeRequest(const QRect& geom)
+ \fn void QWebPage::contentsChanged()
+
+ This signal is emitted whenever the content changes during editing.
+
+ \sa selectedText()
+*/
+
+/*!
+ \fn void QWebPage::geometryChangeRequested(const QRect& geom)
This signal is emitted whenever the document wants to change the position and size of the
page to \a geom. This can happen for example through JavaScript.
*/
/*!
- \fn void QWebPage::handleUnsupportedContent(QNetworkReply *reply)
+ \fn void QWebPage::repaintRequested(const QRect& dirtyRect)
+
+ This signal is emitted whenever this QWebPage should be updated and no view was set.
+ \a dirtyRect contains the area that needs to be updated. To paint the QWebPage get
+ the mainFrame() and call the render(QPainter*, const QRegion&) method with the
+ \a dirtyRect as the second parameter.
+
+ \sa mainFrame()
+ \sa view()
+*/
+
+/*!
+ \fn void QWebPage::scrollRequested(int dx, int dy, const QRect& rectToScroll)
+
+ This signal is emitted whenever the content given by \a rectToScroll needs
+ to be scrolled \a dx and \a dy downwards and no view was set.
+
+ \sa view()
+*/
+
+/*!
+ \fn void QWebPage::windowCloseRequested()
+
+ This signal is emitted whenever the page requests the web browser window to be closed,
+ for example through the JavaScript \c{window.close()} call.
+*/
+
+/*!
+ \fn void QWebPage::printRequested(QWebFrame *frame)
+
+ This signal is emitted whenever the page requests the web browser to print \a frame,
+ for example through the JavaScript \c{window.print()} call.
+
+ \sa QWebFrame::print(), QPrintPreviewDialog
+*/
+
+/*!
+ \fn void QWebPage::unsupportedContent(QNetworkReply *reply)
This signals is emitted when webkit cannot handle a link the user navigated to.
- At signal emissions time the meta data of the QNetworkReply is available.
+ At signal emissions time the meta data of the QNetworkReply \a reply is available.
+
+ \note This signal is only emitted if the forwardUnsupportedContent property is set to true.
+
+ \sa downloadRequested()
+*/
+
+/*!
+ \fn void QWebPage::downloadRequested(const QNetworkRequest &request)
+
+ This signal is emitted when the user decides to download a link. The url of
+ the link as well as additional meta-information is contained in \a request.
+
+ \sa unsupportedContent()
+*/
+
+/*!
+ \fn void QWebPage::microFocusChanged()
+
+ This signal is emitted when for example the position of the cursor in an editable form
+ element changes. It is used inform input methods about the new on-screen position where
+ the user is able to enter text. This signal is usually connected to QWidget's updateMicroFocus()
+ slot.
+*/
+
+/*!
+ \fn void QWebPage::linkClicked(const QUrl &url)
+
+ This signal is emitted whenever the user clicks on a link and the page's linkDelegationPolicy
+ property is set to delegate the link handling for the specified \a url.
+
+ By default no links are delegated and are handled by QWebPage instead.
+
+ \sa linkHovered()
+*/
+
+/*!
+ \fn void QWebPage::toolBarVisibilityChangeRequested(bool visible)
+
+ This signal is emitted whenever the visibility of the toolbar in a web browser
+ window that hosts QWebPage should be changed to \a visible.
+*/
+
+/*!
+ \fn void QWebPage::statusBarVisibilityChangeRequested(bool visible)
+
+ This signal is emitted whenever the visibility of the statusbar in a web browser
+ window that hosts QWebPage should be changed to \a visible.
*/
/*!
- \fn void QWebPage::download(const QNetworkRequest &request)
+ \fn void QWebPage::menuBarVisibilityChangeRequested(bool visible)
- This signals is emitted when the user decides to download a link.
+ This signal is emitted whenever the visibility of the menubar in a web browser
+ window that hosts QWebPage should be changed to \a visible.
*/
#include "moc_qwebpage.cpp"
diff --git a/WebKit/qt/Api/qwebpage.h b/WebKit/qt/Api/qwebpage.h
index e76f935..5b978d8 100644
--- a/WebKit/qt/Api/qwebpage.h
+++ b/WebKit/qt/Api/qwebpage.h
@@ -1,5 +1,5 @@
/*
- Copyright (C) 2007 Trolltech ASA
+ Copyright (C) 2008 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
@@ -16,9 +16,6 @@
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.
-
- This class provides all functionality needed for loading images, style sheets and html
- pages from the web. It has a memory cache for these objects.
*/
#ifndef QWEBPAGE_H
@@ -29,19 +26,26 @@
#include <QtCore/qobject.h>
#include <QtGui/qwidget.h>
+
+QT_BEGIN_NAMESPACE
class QNetworkProxy;
class QUndoStack;
class QUrl;
-class QWebFrame;
-class QWebNetworkRequest;
+class QMenu;
class QNetworkRequest;
class QNetworkReply;
class QNetworkAccessManager;
+QT_END_NAMESPACE
+
+class QWebFrame;
+class QWebNetworkRequest;
class QWebHistory;
class QWebPagePrivate;
class QWebFrameData;
class QWebNetworkInterface;
+class QWebPluginFactory;
+class QWebHitTestResult;
namespace WebCore {
class ChromeClientQt;
@@ -60,16 +64,16 @@ class QWEBKIT_EXPORT QWebPage : public QObject
Q_PROPERTY(bool modified READ isModified)
Q_PROPERTY(QString selectedText READ selectedText)
Q_PROPERTY(QSize viewportSize READ viewportSize WRITE setViewportSize)
+ Q_PROPERTY(bool forwardUnsupportedContent READ forwardUnsupportedContent WRITE setForwardUnsupportedContent)
+ Q_PROPERTY(LinkDelegationPolicy linkDelegationPolicy READ linkDelegationPolicy WRITE setLinkDelegationPolicy)
+ Q_PROPERTY(QPalette palette READ palette WRITE setPalette)
+ Q_PROPERTY(bool editable READ isEditable WRITE setEditable)
+ Q_ENUMS(LinkDelegationPolicy NavigationType WebAction)
public:
- enum NavigationRequestResponse {
- AcceptNavigationRequest,
- IgnoreNavigationRequest
- };
-
enum NavigationType {
NavigationTypeLinkClicked,
NavigationTypeFormSubmitted,
- NavigationTypeBackForward,
+ NavigationTypeBackOrForward,
NavigationTypeReload,
NavigationTypeFormResubmitted,
NavigationTypeOther
@@ -90,8 +94,8 @@ public:
DownloadImageToDisk,
CopyImageToClipboard,
- GoBack, // ###GoBackward instead?
- GoForward,
+ Back,
+ Forward,
Stop,
Reload,
@@ -138,9 +142,29 @@ public:
InspectElement,
+ InsertParagraphSeparator,
+ InsertLineSeparator,
+
WebActionCount
};
+ enum FindFlag {
+ FindBackward = 1,
+ FindCaseSensitively = 2,
+ FindWrapsAroundDocument = 4
+ };
+ Q_DECLARE_FLAGS(FindFlags, FindFlag)
+
+ enum LinkDelegationPolicy {
+ DontDelegateLinks,
+ DelegateExternalLinks,
+ DelegateAllLinks
+ };
+
+ enum WebWindowType {
+ WebBrowserWindow,
+ WebModalDialog
+ };
explicit QWebPage(QObject *parent = 0);
~QWebPage();
@@ -149,16 +173,17 @@ public:
QWebFrame *currentFrame() const;
QWebHistory *history() const;
-
- QWebSettings *settings();
+ QWebSettings *settings() const;
void setView(QWidget *view);
QWidget *view() const;
bool isModified() const;
+#ifndef QT_NO_UNDOSTACK
QUndoStack *undoStack() const;
+#endif
-#if QT_VERSION < 0x040400
+#if QT_VERSION < 0x040400 && !defined(qdoc)
void setNetworkInterface(QWebNetworkInterface *interface);
QWebNetworkInterface *networkInterface() const;
@@ -173,6 +198,9 @@ public:
QNetworkAccessManager *networkAccessManager() const;
#endif
+ void setPluginFactory(QWebPluginFactory *factory);
+ QWebPluginFactory *pluginFactory() const;
+
quint64 totalBytes() const;
quint64 bytesReceived() const;
@@ -185,58 +213,100 @@ public:
void setViewportSize(const QSize &size) const;
virtual bool event(QEvent*);
- virtual bool focusNextPrevChild(bool next);
+ bool focusNextPrevChild(bool next);
+
+ QVariant inputMethodQuery(Qt::InputMethodQuery property) const;
+
+ bool findText(const QString &subString, FindFlags options = 0);
+
+ void setForwardUnsupportedContent(bool forward);
+ bool forwardUnsupportedContent() const;
+
+ void setLinkDelegationPolicy(LinkDelegationPolicy policy);
+ LinkDelegationPolicy linkDelegationPolicy() const;
+
+ void setPalette(const QPalette &palette);
+ QPalette palette() const;
+
+ void setEditable(bool editable);
+ bool isEditable() const;
+
+#ifndef QT_NO_CONTEXTMENU
+ bool swallowContextMenuEvent(QContextMenuEvent *event);
+#endif
+ void updatePositionDependentActions(const QPoint &pos);
+
+ QMenu *createStandardContextMenu();
+
+ enum Extension {
+ };
+ class ExtensionOption
+ {};
+ class ExtensionReturn
+ {};
+ virtual bool extension(Extension extension, const ExtensionOption *option = 0, ExtensionReturn *output = 0);
+ virtual bool supportsExtension(Extension extension) const;
Q_SIGNALS:
- void loadProgressChanged(int progress);
- void hoveringOverLink(const QString &link, const QString &title, const QString &textContent = QString());
- void statusBarTextChanged(const QString& text);
+ void loadStarted();
+ void loadProgress(int progress);
+ void loadFinished(bool ok);
+
+ void linkHovered(const QString &link, const QString &title, const QString &textContent);
+ void statusBarMessage(const QString& text);
void selectionChanged();
void frameCreated(QWebFrame *frame);
- void geometryChangeRequest(const QRect& geom);
+ void geometryChangeRequested(const QRect& geom);
+ void repaintRequested(const QRect& dirtyRect);
+ void scrollRequested(int dx, int dy, const QRect& scrollViewRect);
+ void windowCloseRequested();
+ void printRequested(QWebFrame *frame);
+ void linkClicked(const QUrl &url);
+
+ void toolBarVisibilityChangeRequested(bool visible);
+ void statusBarVisibilityChangeRequested(bool visible);
+ void menuBarVisibilityChangeRequested(bool visible);
#if QT_VERSION >= 0x040400
- void handleUnsupportedContent(QNetworkReply *reply);
- void download(const QNetworkRequest &request);
+ void unsupportedContent(QNetworkReply *reply);
+ void downloadRequested(const QNetworkRequest &request);
#endif
- //void addEmbeddableWidget(QWidget *widget);
- //void addEmbeddableWidget(const QString &classid, QWidget *widget);
- //void removeEmbeddableWidget(QWidget *widget);
- //QHash<QString, QWidget *> embeddableWidgets() const;
- //void clearEmbeddableWidgets();
+ void microFocusChanged();
+ void contentsChanged();
protected:
- virtual QWebPage *createWindow();
- virtual QWebPage *createModalDialog();
+ virtual QWebPage *createWindow(WebWindowType type);
virtual QObject *createPlugin(const QString &classid, const QUrl &url, const QStringList &paramNames, const QStringList &paramValues);
-#if QT_VERSION < 0x040400
- virtual NavigationRequestResponse navigationRequested(QWebFrame *frame, const QWebNetworkRequest &request, NavigationType type);
+#if QT_VERSION >= 0x040400
+ virtual bool acceptNavigationRequest(QWebFrame *frame, const QNetworkRequest &request, NavigationType type);
#else
- virtual NavigationRequestResponse navigationRequested(QWebFrame *frame, const QNetworkRequest &request, NavigationType type);
+ virtual bool acceptNavigationRequest(QWebFrame *frame, const QWebNetworkRequest &request, NavigationType type);
#endif
virtual QString chooseFile(QWebFrame *originatingFrame, const QString& oldFile);
virtual void javaScriptAlert(QWebFrame *originatingFrame, const QString& msg);
virtual bool javaScriptConfirm(QWebFrame *originatingFrame, const QString& msg);
virtual bool javaScriptPrompt(QWebFrame *originatingFrame, const QString& msg, const QString& defaultValue, QString* result);
- virtual void javaScriptConsoleMessage(const QString& message, unsigned int lineNumber, const QString& sourceID);
+ virtual void javaScriptConsoleMessage(const QString& message, int lineNumber, const QString& sourceID);
- virtual QString userAgentFor(const QUrl& url) const;
+ virtual QString userAgentForUrl(const QUrl& url) const;
private:
Q_PRIVATE_SLOT(d, void _q_onLoadProgressChanged(int))
- Q_PRIVATE_SLOT(d, void _q_webActionTriggered(bool checked));
+ Q_PRIVATE_SLOT(d, void _q_webActionTriggered(bool checked))
+ QWebPagePrivate *d;
+
friend class QWebFrame;
friend class QWebPagePrivate;
+ friend class QWebView;
friend class WebCore::ChromeClientQt;
friend class WebCore::EditorClientQt;
friend class WebCore::FrameLoaderClientQt;
friend class WebCore::InspectorClientQt;
friend class WebCore::ResourceHandle;
- QWebPagePrivate *d;
};
-
+Q_DECLARE_OPERATORS_FOR_FLAGS(QWebPage::FindFlags)
#endif
diff --git a/WebKit/qt/Api/qwebpage_p.h b/WebKit/qt/Api/qwebpage_p.h
index 80b1e29..8fae81c 100644
--- a/WebKit/qt/Api/qwebpage_p.h
+++ b/WebKit/qt/Api/qwebpage_p.h
@@ -1,5 +1,6 @@
/*
- Copyright (C) 2007 Trolltech ASA
+ Copyright (C) 2008 Nokia Corporation and/or its subsidiary(-ies)
+ Copyright (C) 2008 Holger Hans Peter Freyther
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Library General Public
@@ -15,15 +16,15 @@
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.
-
- This class provides all functionality needed for loading images, style sheets and html
- pages from the web. It has a memory cache for these objects.
*/
+
#ifndef QWEBPAGE_P_H
#define QWEBPAGE_P_H
+#include <qbasictimer.h>
#include <qnetworkproxy.h>
#include <qpointer.h>
+#include <qevent.h>
#include "qwebpage.h"
#include "qwebhistory.h"
@@ -44,47 +45,25 @@ namespace WebCore
class Element;
class Node;
class Page;
+
+#ifndef QT_NO_CURSOR
+ class SetCursorEvent : public QEvent {
+ public:
+ static const int EventType = 724;
+ SetCursorEvent(const QCursor&);
+
+ QCursor cursor() const;
+ private:
+ QCursor m_cursor;
+ };
+#endif
}
+QT_BEGIN_NAMESPACE
class QUndoStack;
class QMenu;
-
-class QWebPageContextPrivate
-{
-public:
- QPoint pos;
- QString text;
- QUrl linkUrl;
- QUrl imageUrl;
- QPixmap image;
- QPointer<QWebFrame> targetFrame;
- RefPtr<WebCore::Node> innerNonSharedNode;
-};
-
-class QWebPageContext
-{
-public:
- QWebPageContext();
- QWebPageContext(const QWebPageContext &other);
- QWebPageContext &operator=(const QWebPageContext &other);
- ~QWebPageContext();
-
- QPoint pos() const;
- QString text() const;
- QUrl linkUrl() const;
- QUrl imageUrl() const;
- // ### we have a pixmap internally, should this be called pixmap() instead?
- QPixmap image() const;
-
- QWebFrame *targetFrame() const;
-
-private:
- QWebPageContext(const WebCore::HitTestResult &hitTest);
- QWebPageContextPrivate *d;
-
- friend class QWebPage;
- friend class QWebPagePrivate;
-};
+class QBitArray;
+QT_END_NAMESPACE
class QWebPagePrivate
{
@@ -92,7 +71,9 @@ public:
QWebPagePrivate(QWebPage *);
~QWebPagePrivate();
void createMainFrame();
- QMenu *createContextMenu(const WebCore::ContextMenu *webcoreMenu, const QList<WebCore::ContextMenuItem> *items);
+#ifndef QT_NO_CONTEXTMENU
+ QMenu *createContextMenu(const WebCore::ContextMenu *webcoreMenu, const QList<WebCore::ContextMenuItem> *items, QBitArray *visitedWebActions);
+#endif
QWebFrame *frameAt(const QPoint &pos) const;
@@ -102,12 +83,19 @@ public:
void updateNavigationActions();
void updateEditorActions();
+ void timerEvent(QTimerEvent*);
+
void mouseMoveEvent(QMouseEvent*);
void mousePressEvent(QMouseEvent*);
void mouseDoubleClickEvent(QMouseEvent*);
+ void mouseTripleClickEvent(QMouseEvent*);
void mouseReleaseEvent(QMouseEvent*);
+#ifndef QT_NO_CONTEXTMENU
void contextMenuEvent(QContextMenuEvent*);
+#endif
+#ifndef QT_NO_WHEELEVENT
void wheelEvent(QWheelEvent*);
+#endif
void keyPressEvent(QKeyEvent*);
void keyReleaseEvent(QKeyEvent*);
void focusInEvent(QFocusEvent*);
@@ -118,6 +106,11 @@ public:
void dragMoveEvent(QDragMoveEvent *);
void dropEvent(QDropEvent *);
+ void inputMethodEvent(QInputMethodEvent*);
+
+ void shortcutOverrideEvent(QKeyEvent*);
+ void leaveEvent(QEvent *);
+ bool handleScrolling(QKeyEvent*);
WebCore::ChromeClientQt *chromeClient;
WebCore::ContextMenuClientQt *contextMenuClient;
@@ -127,17 +120,20 @@ public:
QPointer<QWebFrame> mainFrame;
QWebPage *q;
+#ifndef QT_NO_UNDOSTACK
QUndoStack *undoStack;
+#endif
QWidget *view;
- bool modified;
-
bool insideOpenCall;
quint64 m_totalBytes;
quint64 m_bytesReceived;
+ QPoint tripleClick;
+ QBasicTimer tripleClickTimer;
+
#if QT_VERSION < 0x040400
- QWebPage::NavigationRequestResponse navigationRequested(QWebFrame *frame, const QWebNetworkRequest &request, QWebPage::NavigationType type);
+ bool acceptNavigationRequest(QWebFrame *frame, const QWebNetworkRequest &request, QWebPage::NavigationType type);
QWebNetworkInterface *networkInterface;
#ifndef QT_NO_NETWORKPROXY
@@ -145,15 +141,26 @@ public:
#endif
#else
- QWebPage::NavigationRequestResponse navigationRequested(QWebFrame *frame, const QNetworkRequest &request, QWebPage::NavigationType type);
+ bool acceptNavigationRequest(QWebFrame *frame, const QNetworkRequest &request, QWebPage::NavigationType type);
QNetworkAccessManager *networkManager;
#endif
+ bool forwardUnsupportedContent;
+ QWebPage::LinkDelegationPolicy linkPolicy;
+
+ QSize viewportSize;
QWebHistory history;
- QWebPageContext currentContext;
+ QWebHitTestResult hitTestResult;
+#ifndef QT_NO_CONTEXTMENU
+ QPointer<QMenu> currentContextMenu;
+#endif
QWebSettings *settings;
+ QPalette palette;
+ bool editable;
QAction *actions[QWebPage::WebActionCount];
+
+ QWebPluginFactory *pluginFactory;
};
#endif
diff --git a/WebKit/qt/Api/qwebpluginfactory.cpp b/WebKit/qt/Api/qwebpluginfactory.cpp
new file mode 100644
index 0000000..0d2390c
--- /dev/null
+++ b/WebKit/qt/Api/qwebpluginfactory.cpp
@@ -0,0 +1,216 @@
+/*
+ Copyright (C) 2008 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 "qwebpluginfactory.h"
+
+/*!
+ \class QWebPluginFactory
+ \since 4.4
+ \brief The QWebPluginFactory class creates plugins to be embedded into web
+ pages.
+
+ QWebPluginFactory is a factory for creating plugins for QWebPage. A plugin
+ factory can be installed on a QWebPage using QWebPage::setPluginFactory().
+
+ \note The plugin factory is only used if plugins are enabled through QWebSettings.
+
+ You can provide a QWebPluginFactory by implementing the plugins() and the
+ create() method. For plugins() it is necessary to describe the plugins the
+ factory can create, including a description and the supported MIME types.
+ The MIME types each plugin can handle should match the ones specified in
+ in the HTML \c{<object>} tag.
+
+ The create() method is called if the requested MIME type is supported. The
+ implementation has to return a new instance of the plugin requested for the
+ given MIME type and the specified URL.
+*/
+
+
+/*!
+ \class QWebPluginFactory::Plugin
+ \since 4.4
+ \brief the QWebPluginFactory::Plugin structure describes the properties of a plugin a QWebPluginFactory can create.
+*/
+
+/*!
+ \variable QWebPluginFactory::Plugin::name
+ The name of the plugin.
+*/
+
+/*!
+ \variable QWebPluginFactory::Plugin::description
+ The description of the plugin.
+*/
+
+/*!
+ \variable QWebPluginFactory::Plugin::mimeTypes
+ The list of mime types supported by the plugin.
+*/
+
+/*!
+ \class QWebPluginFactory::MimeType
+ \since 4.4
+ \brief The QWebPluginFactory::MimeType structure describes a mime type supported by a plugin.
+*/
+
+/*!
+ \variable QWebPluginFactory::MimeType::name
+
+ The full name of the MIME type; e.g., \c{text/plain} or \c{image/png}.
+*/
+
+/*!
+ \variable QWebPluginFactory::MimeType::description
+ The description of the mime type.
+*/
+
+/*!
+ \variable QWebPluginFactory::MimeType::fileExtensions
+ The list of file extensions that are used by this mime type.
+
+ For example, a mime type for PDF documents would return "pdf" as its file extension.
+*/
+
+/*!
+ Constructs a QWebPluginFactory with parent \a parent.
+*/
+QWebPluginFactory::QWebPluginFactory(QObject *parent)
+ : QObject(parent)
+{
+}
+
+/*!
+ Destructor.
+*/
+QWebPluginFactory::~QWebPluginFactory()
+{
+}
+
+/*!
+ \fn QList<Plugin> QWebPluginFactory::plugins() const = 0
+
+ This function is reimplemented in subclasses to return a list of
+ supported plugins the factory can create.
+
+ \note Currently, this function is only called when JavaScript programs
+ access the global \c plugins or \c mimetypes objects.
+*/
+
+/*!
+ This function is called to refresh the list of supported plugins. It may be called after a new plugin
+ has been installed in the system.
+*/
+void QWebPluginFactory::refreshPlugins()
+{
+}
+
+/*!
+ \fn QObject *QWebPluginFactory::create(const QString &mimeType, const QUrl &url,
+ const QStringList &argumentNames, const QStringList &argumentValues) const = 0
+
+ Implemented in subclasses to create a new plugin that can display content of
+ the MIME type given by \a mimeType. The URL of the content is provided in \a url.
+ The returned object should be a QWidget.
+
+ The HTML object element can provide parameters through the \c{<param>} tag.
+ The name and the value attributes of these tags are specified by the
+ \a argumentNames and \a argumentValues string lists.
+
+ For example:
+
+ \code
+ <object type="application/x-pdf" data="http://www.trolltech.com/document.pdf" width="500" height="400">
+ <param name="showTableOfContents" value="true" />
+ <param name="hideThumbnails" value="false" />
+ </object>
+ \endcode
+
+ The above object element will result in a call to create() with the following arguments:
+ \table
+ \header \o Parameter
+ \o Value
+ \row \o mimeType
+ \o "application/x-pdf"
+ \row \o url
+ \o "http://www.trolltech.com/document.pdf"
+ \row \o argumentNames
+ \o "showTableOfContents" "hideThumbnails"
+ \row \o argumentVaues
+ \o "true" "false"
+ \endtable
+
+ \note Ownership of the returned object will be transferred to the caller.
+*/
+
+/*!
+ \enum QWebPluginFactory::Extension
+
+ This enum describes the types of extensions that the plugin factory can support. Before using these extensions, you
+ should verify that the extension is supported by calling supportsExtension().
+
+ Currently there are no extensions.
+*/
+
+/*!
+ \class QWebPluginFactory::ExtensionOption
+ \since 4.4
+ \brief The ExtensionOption class provides an extended input argument to QWebPluginFactory's extension support.
+
+ \sa QWebPluginFactory::extension()
+*/
+
+/*!
+ \class QWebPluginFactory::ExtensionReturn
+ \since 4.4
+ \brief The ExtensionOption class provides an extended output argument to QWebPluginFactory's extension support.
+
+ \sa QWebPluginFactory::extension()
+*/
+
+/*!
+ This virtual function can be reimplemented in a QWebPluginFactory subclass to provide support for extensions. The \a option
+ argument is provided as input to the extension; the output results can be stored in \a output.
+
+ The behaviour of this function is determined by \a extension.
+
+ You can call supportsExtension() to check if an extension is supported by the factory.
+
+ By default, no extensions are supported, and this function returns false.
+
+ \sa supportsExtension(), Extension
+*/
+bool QWebPluginFactory::extension(Extension extension, const ExtensionOption *option, ExtensionReturn *output)
+{
+ Q_UNUSED(extension)
+ Q_UNUSED(option)
+ Q_UNUSED(output)
+ return false;
+}
+
+/*!
+ This virtual function returns true if the plugin factory supports \a extension; otherwise false is returned.
+
+ \sa extension()
+*/
+bool QWebPluginFactory::supportsExtension(Extension extension) const
+{
+ Q_UNUSED(extension)
+ return false;
+}
diff --git a/WebKit/qt/Api/qwebpluginfactory.h b/WebKit/qt/Api/qwebpluginfactory.h
new file mode 100644
index 0000000..3531b06
--- /dev/null
+++ b/WebKit/qt/Api/qwebpluginfactory.h
@@ -0,0 +1,74 @@
+/*
+ Copyright (C) 2008 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 QWEBPLUGINFACTORY_H
+#define QWEBPLUGINFACTORY_H
+
+#include "qwebkitglobal.h"
+
+#include <QtCore/qobject.h>
+#include <QtCore/qstringlist.h>
+
+QT_BEGIN_NAMESPACE
+class QUrl;
+class QString;
+QT_END_NAMESPACE
+class QWebPluginFactoryPrivate;
+
+class QWEBKIT_EXPORT QWebPluginFactory : public QObject
+{
+ Q_OBJECT
+public:
+ struct MimeType {
+ QString name;
+ QString description;
+ QStringList fileExtensions;
+ };
+
+ struct Plugin {
+ QString name;
+ QString description;
+ QList<MimeType> mimeTypes;
+ };
+
+ 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;
+
+ enum Extension {
+ };
+ class ExtensionOption
+ {};
+ class ExtensionReturn
+ {};
+ virtual bool extension(Extension extension, const ExtensionOption *option = 0, ExtensionReturn *output = 0);
+ virtual bool supportsExtension(Extension extension) const;
+
+private:
+ QWebPluginFactoryPrivate *d;
+};
+
+#endif
diff --git a/WebKit/qt/Api/qwebsettings.cpp b/WebKit/qt/Api/qwebsettings.cpp
index 8109de1..132eb0c 100644
--- a/WebKit/qt/Api/qwebsettings.cpp
+++ b/WebKit/qt/Api/qwebsettings.cpp
@@ -1,5 +1,5 @@
/*
- Copyright (C) 2007 Trolltech ASA
+ Copyright (C) 2008 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
@@ -15,9 +15,6 @@
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.
-
- This class provides all functionality needed for loading images, style sheets and html
- pages from the web. It has a memory cache for these objects.
*/
#include "config.h"
@@ -26,11 +23,15 @@
#include "qwebpage.h"
#include "qwebpage_p.h"
+#include "Cache.h"
#include "Page.h"
+#include "PageCache.h"
#include "Settings.h"
#include "KURL.h"
#include "PlatformString.h"
#include "IconDatabase.h"
+#include "Image.h"
+#include "IntSize.h"
#include <QHash>
#include <QSharedData>
@@ -55,14 +56,30 @@ public:
};
typedef QHash<int, QPixmap> WebGraphicHash;
-Q_GLOBAL_STATIC(WebGraphicHash, graphics)
+Q_GLOBAL_STATIC(WebGraphicHash, _graphics)
+
+static WebGraphicHash* graphics()
+{
+ WebGraphicHash* hash = _graphics();
+
+ if (hash->isEmpty()) {
+ hash->insert(QWebSettings::MissingImageGraphic, QPixmap(QLatin1String(":webkit/resources/missingImage.png")));
+ hash->insert(QWebSettings::MissingPluginGraphic, QPixmap(QLatin1String(":webkit/resources/nullPlugin.png")));
+ hash->insert(QWebSettings::DefaultFrameIconGraphic, QPixmap(QLatin1String(":webkit/resources/urlIcon.png")));
+ hash->insert(QWebSettings::TextAreaSizeGripCornerGraphic, QPixmap(QLatin1String(":webkit/resources/textAreaResizeCorner.png")));
+ }
+
+ return hash;
+}
Q_GLOBAL_STATIC(QList<QWebSettingsPrivate *>, allSettings);
void QWebSettingsPrivate::apply()
{
if (settings) {
- QWebSettingsPrivate *global = QWebSettings::defaultSettings()->d;
+ settings->setTextAreasAreResizable(true);
+
+ QWebSettingsPrivate *global = QWebSettings::globalSettings()->d;
QString family = fontFamilies.value(QWebSettings::StandardFont,
global->fontFamilies.value(QWebSettings::StandardFont));
@@ -138,6 +155,10 @@ void QWebSettingsPrivate::apply()
QUrl location = !userStyleSheetLocation.isEmpty() ? userStyleSheetLocation : global->userStyleSheetLocation;
settings->setUserStyleSheetLocation(WebCore::KURL(location));
+
+ value = attributes.value(QWebSettings::ZoomTextOnly,
+ global->attributes.value(QWebSettings::ZoomTextOnly));
+ settings->setZoomsTextOnly(value);
} else {
QList<QWebSettingsPrivate *> settings = *::allSettings();
for (int i = 0; i < settings.count(); ++i)
@@ -146,12 +167,12 @@ void QWebSettingsPrivate::apply()
}
/*!
- Returns the global default settings object.
+ Returns the global settings object.
Any setting changed on the default object is automatically applied to all
QWebPage instances where the particular setting is not overriden already.
*/
-QWebSettings *QWebSettings::defaultSettings()
+QWebSettings *QWebSettings::globalSettings()
{
static QWebSettings *global = 0;
if (!global)
@@ -160,6 +181,94 @@ QWebSettings *QWebSettings::defaultSettings()
}
/*!
+ \class QWebSettings
+ \since 4.4
+ \brief The QWebSettings class provides an object to store the settings used
+ by QWebPage and QWebFrame.
+
+ 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().
+
+ 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 also configures global properties such as the web page memory
+ cache and the web page icon database.
+
+ \sa QWebPage::settings(), QWebView::settings(), {Browser}
+*/
+
+/*!
+ \enum QWebSettings::FontFamily
+
+ This enum describes the generic font families defined by CSS 2.
+ For more information see the
+ \l{http://www.w3.org/TR/REC-CSS2/fonts.html#generic-font-families}{CSS standard}.
+
+ \value StandardFont
+ \value FixedFont
+ \value SerifFont
+ \value SansSerifFont
+ \value CursiveFont
+ \value FantasyFont
+*/
+
+/*!
+ \enum QWebSettings::FontSize
+
+ This enum describes the font sizes configurable through QWebSettings.
+
+ \value MinimumFontSize The hard minimum font size.
+ \value MinimumLogicalFontSize The minimum logical font size that is applied
+ after zooming with QWebFrame's textSizeMultiplier().
+ \value DefaultFontSize The default font size for regular text.
+ \value DefaultFixedFontSize The default font size for fixed-pitch text.
+*/
+
+/*!
+ \enum QWebSettings::WebGraphic
+
+ This enums describes the standard graphical elements used in webpages.
+
+ \value MissingImageGraphic The replacement graphic shown when an image could not be loaded.
+ \value MissingPluginGraphic The replacement graphic shown when a plugin could not be loaded.
+ \value DefaultFrameIconGraphic The default icon for QWebFrame::icon().
+ \value TextAreaSizeGripCornerGraphic The graphic shown for the size grip of text areas.
+*/
+
+/*!
+ \enum QWebSettings::WebAttribute
+
+ This enum describes various attributes that are configurable through QWebSettings.
+
+ \value AutoLoadImages Specifies whether images are automatically loaded in
+ web pages.
+ \value JavascriptEnabled Enables or disables the running of JavaScript
+ programs.
+ \value JavaEnabled Enables or disables Java applets.
+ Currently Java applets are not supported.
+ \value PluginsEnabled Enables or disables plugins in web pages.
+ Currently Flash and other plugins are not supported.
+ \value PrivateBrowsingEnabled Private browsing prevents WebKit from
+ recording visited pages in the history and storing web page icons.
+ \value JavascriptCanOpenWindows Specifies whether JavaScript programs
+ can open new windows.
+ \value JavascriptCanAccessClipboard Specifies whether JavaScript programs
+ can read or write to the clipboard.
+ \value DeveloperExtrasEnabled Enables extra tools for Web developers.
+ Currently this enables the "Inspect" element in the context menu,
+ which shows the WebKit WebInspector for web site debugging.
+ \value LinksIncludedInFocusChain Specifies whether hyperlinks should be
+ included in the keyboard focus chain.
+ \value ZoomTextOnly Specifies whether the zoom factor on a frame applies to
+ only the text or all content.
+*/
+
+/*!
\internal
*/
QWebSettings::QWebSettings()
@@ -181,6 +290,7 @@ QWebSettings::QWebSettings()
d->attributes.insert(QWebSettings::AutoLoadImages, true);
d->attributes.insert(QWebSettings::JavascriptEnabled, true);
d->attributes.insert(QWebSettings::LinksIncludedInFocusChain, true);
+ d->attributes.insert(QWebSettings::ZoomTextOnly, false);
}
/*!
@@ -221,16 +331,17 @@ int QWebSettings::fontSize(FontSize type) const
{
int defaultValue = 0;
if (d->settings) {
- QWebSettingsPrivate *global = QWebSettings::defaultSettings()->d;
+ QWebSettingsPrivate *global = QWebSettings::globalSettings()->d;
defaultValue = global->fontSizes.value(type);
}
return d->fontSizes.value(type, defaultValue);
}
/*!
- Resets the font size for \a type to the size specified in the default settings object.
+ Resets the font size for \a type to the size specified in the global
+ settings object.
- This function has not effect on the default QWebSettings instance.
+ This function has no effect on the global QWebSettings instance.
*/
void QWebSettings::resetFontSize(FontSize type)
{
@@ -243,11 +354,11 @@ void QWebSettings::resetFontSize(FontSize type)
/*!
Specifies the location of a user stylesheet to load with every web page.
- The location can be a URL as well as a path on the local filesystem.
+ The \a location can be a URL or a path on the local filesystem.
- \sa userStyleSheetLocation
+ \sa userStyleSheetUrl()
*/
-void QWebSettings::setUserStyleSheetLocation(const QUrl &location)
+void QWebSettings::setUserStyleSheetUrl(const QUrl &location)
{
d->userStyleSheetLocation = location;
d->apply();
@@ -256,44 +367,92 @@ void QWebSettings::setUserStyleSheetLocation(const QUrl &location)
/*!
Returns the location of the user stylesheet.
- \sa setUserStyleSheetLocation
+ \sa setUserStyleSheetUrl()
*/
-QUrl QWebSettings::userStyleSheetLocation() const
+QUrl QWebSettings::userStyleSheetUrl() const
{
return d->userStyleSheetLocation;
}
/*!
- Enables or disables the icon database. The icon database is used to store favicons
- associated with web sites.
+ Sets the path of the icon database to \a path. The icon database is used
+ to store "favicons" associated with web sites.
+
+ \a path must point to an existing directory where the icons are stored.
- If \a enabled is true then \a location must be specified and point to an existing directory
- where the icons are stored.
+ Setting an empty path disables the icon database.
*/
-void QWebSettings::setIconDatabaseEnabled(bool enabled, const QString &location)
+void QWebSettings::setIconDatabasePath(const QString &path)
{
- WebCore::iconDatabase()->setEnabled(enabled);
- if (enabled) {
- QFileInfo info(location);
+ WebCore::iconDatabase()->delayDatabaseCleanup();
+
+ if (!path.isEmpty()) {
+ WebCore::iconDatabase()->setEnabled(true);
+ QFileInfo info(path);
if (info.isDir() && info.isWritable())
- WebCore::iconDatabase()->open(location);
+ WebCore::iconDatabase()->open(path);
} else {
+ WebCore::iconDatabase()->setEnabled(false);
WebCore::iconDatabase()->close();
}
}
/*!
- Returns whether the icon database is enabled or not.
+ Returns the path of the icon database or an empty string if the icon
+ database is disabled.
+
+ \sa setIconDatabasePath(), clearIconDatabase()
+*/
+QString QWebSettings::iconDatabasePath()
+{
+ if (WebCore::iconDatabase()->isEnabled() && WebCore::iconDatabase()->isOpen()) {
+ return WebCore::iconDatabase()->databasePath();
+ } else {
+ return QString();
+ }
+}
+
+/*!
+ Clears the icon database.
+*/
+void QWebSettings::clearIconDatabase()
+{
+ if (WebCore::iconDatabase()->isEnabled() && WebCore::iconDatabase()->isOpen())
+ WebCore::iconDatabase()->removeAllIcons();
+}
+
+/*!
+ Returns the web site's icon for \a url.
+
+ If the web site does not specify an icon, or the icon is not in the
+ database, a null QIcon is returned.
+
+ \note The returned icon's size is arbitrary.
- \sa setIconDatabaseEnabled
+ \sa setIconDatabasePath()
*/
-bool QWebSettings::iconDatabaseEnabled()
+QIcon QWebSettings::iconForUrl(const QUrl &url)
{
- return WebCore::iconDatabase()->isEnabled() && WebCore::iconDatabase()->isOpen();
+ WebCore::Image* image = WebCore::iconDatabase()->iconForPageURL(WebCore::KURL(url).string(),
+ WebCore::IntSize(16, 16));
+ if (!image) {
+ return QPixmap();
+ }
+ QPixmap *icon = image->nativeImageForCurrentFrame();
+ if (!icon) {
+ return QPixmap();
+ }
+ return *icon;
}
/*!
- Sets \a graphic to be drawn when QtWebKit needs to drawn an image of the given \a type.
+ Sets \a graphic to be drawn when QtWebKit needs to draw an image of the
+ given \a type.
+
+ For example, when an image cannot be loaded the pixmap specified by
+ \l{QWebSettings::WebGraphic}{MissingImageGraphic} is drawn instead.
+
+ \sa webGraphic()
*/
void QWebSettings::setWebGraphic(WebGraphic type, const QPixmap &graphic)
{
@@ -305,7 +464,13 @@ void QWebSettings::setWebGraphic(WebGraphic type, const QPixmap &graphic)
}
/*!
- Returns a previously set pixmap that is used to draw replacement graphics of the specified \a type.
+ Returns a previously set pixmap used to draw replacement graphics of the
+ specified \a type.
+
+ For example, when an image cannot be loaded the pixmap specified by
+ \l{QWebSettings::WebGraphic}{MissingImageGraphic} is drawn instead.
+
+ \sa setWebGraphic()
*/
QPixmap QWebSettings::webGraphic(WebGraphic type)
{
@@ -313,42 +478,90 @@ QPixmap QWebSettings::webGraphic(WebGraphic type)
}
/*!
- Sets the default font family to \a family for the specified \a type of font.
+ Sets the maximum number of pages to hold in the memory cache to \a pages.
+*/
+void QWebSettings::setMaximumPagesInCache(int pages)
+{
+ WebCore::pageCache()->setCapacity(qMax(0, pages));
+}
+
+/*!
+ Returns the maximum number of web pages that are kept in the memory cache.
+*/
+int QWebSettings::maximumPagesInCache()
+{
+ return WebCore::pageCache()->capacity();
+}
+
+/*!
+ Specifies the capacities for the memory cache for dead objects such as
+ stylesheets or scripts.
+
+ 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.
+
+ \a totalCapacity specifies the \e maximum number of bytes that the cache
+ should consume \bold overall.
+
+ The cache is enabled by default. Calling setObjectCacheCapacities(0, 0, 0)
+ will disable the cache. Calling it with one non-zero enables it again.
+*/
+void QWebSettings::setObjectCacheCapacities(int cacheMinDeadCapacity, int cacheMaxDead, int totalCapacity)
+{
+ bool disableCache = cacheMinDeadCapacity == 0 && cacheMaxDead == 0 && totalCapacity == 0;
+ WebCore::cache()->setDisabled(disableCache);
+
+ WebCore::cache()->setCapacities(qMax(0, cacheMinDeadCapacity),
+ qMax(0, cacheMaxDead),
+ qMax(0, totalCapacity));
+}
+
+/*!
+ Sets the actual font family to \a family for the specified generic family,
+ \a which.
*/
-void QWebSettings::setFontFamily(FontType type, const QString &family)
+void QWebSettings::setFontFamily(FontFamily which, const QString &family)
{
- d->fontFamilies.insert(type, family);
+ d->fontFamilies.insert(which, family);
d->apply();
}
/*!
- Returns the default font family to \a family for the specified \a type of font.
+ Returns the actual font family for the specified generic font family,
+ \a which.
*/
-QString QWebSettings::fontFamily(FontType type) const
+QString QWebSettings::fontFamily(FontFamily which) const
{
QString defaultValue;
if (d->settings) {
- QWebSettingsPrivate *global = QWebSettings::defaultSettings()->d;
- defaultValue = global->fontFamilies.value(type);
+ QWebSettingsPrivate *global = QWebSettings::globalSettings()->d;
+ defaultValue = global->fontFamilies.value(which);
}
- return d->fontFamilies.value(type, defaultValue);
+ return d->fontFamilies.value(which, defaultValue);
}
/*!
- Resets the font family for specified \a type of fonts in a web page to the default.
+ Resets the actual font family to the default font family, specified by
+ \a which.
- This function has not effect on the default QWebSettings instance.
+ This function has no effect on the global QWebSettings instance.
*/
-void QWebSettings::resetFontFamily(FontType type)
+void QWebSettings::resetFontFamily(FontFamily which)
{
if (d->settings) {
- d->fontFamilies.remove(type);
+ d->fontFamilies.remove(which);
d->apply();
}
}
/*!
- Enables or disables the specified \a attr feature depending on the value of \a on.
+ \fn void QWebSettings::setAttribute(WebAttribute attribute, bool on)
+
+ Enables or disables the specified \a attribute feature depending on the
+ value of \a on.
*/
void QWebSettings::setAttribute(WebAttribute attr, bool on)
{
@@ -357,24 +570,29 @@ void QWebSettings::setAttribute(WebAttribute attr, bool on)
}
/*!
- Returns true if \a attr is enabled; false otherwise.
+ \fn bool QWebSettings::testAttribute(WebAttribute attribute) const
+
+ Returns true if \a attribute is enabled; otherwise returns false.
*/
bool QWebSettings::testAttribute(WebAttribute attr) const
{
bool defaultValue = false;
if (d->settings) {
- QWebSettingsPrivate *global = QWebSettings::defaultSettings()->d;
+ QWebSettingsPrivate *global = QWebSettings::globalSettings()->d;
defaultValue = global->attributes.value(attr);
}
return d->attributes.value(attr, defaultValue);
}
/*!
- Clears the setting of \a attr. The global default for \a attr will be used instead.
+ \fn void QWebSettings::resetAttribute(WebAttribute attribute)
+
+ Resets the setting of \a attribute.
+ This function has no effect on the global QWebSettings instance.
- This function has not effect on the default QWebSettings instance.
+ \sa globalSettings()
*/
-void QWebSettings::clearAttribute(WebAttribute attr)
+void QWebSettings::resetAttribute(WebAttribute attr)
{
if (d->settings) {
d->attributes.remove(attr);
diff --git a/WebKit/qt/Api/qwebsettings.h b/WebKit/qt/Api/qwebsettings.h
index c071e51..9a75dbf 100644
--- a/WebKit/qt/Api/qwebsettings.h
+++ b/WebKit/qt/Api/qwebsettings.h
@@ -1,5 +1,5 @@
/*
- Copyright (C) 2007 Trolltech ASA
+ Copyright (C) 2008 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
@@ -15,33 +15,33 @@
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.
-
- This class provides all functionality needed for loading images, style sheets and html
- pages from the web. It has a memory cache for these objects.
*/
#ifndef QWEBSETTINGS_H
#define QWEBSETTINGS_H
-#include <qwebkitglobal.h>
+#include "qwebkitglobal.h"
#include <QtCore/qstring.h>
#include <QtGui/qpixmap.h>
+#include <QtGui/qicon.h>
#include <QtCore/qshareddata.h>
namespace WebCore
{
class Settings;
-};
+}
class QWebPage;
class QWebSettingsPrivate;
+QT_BEGIN_NAMESPACE
class QUrl;
+QT_END_NAMESPACE
class QWEBKIT_EXPORT QWebSettings
{
public:
- enum FontType {
+ enum FontFamily {
StandardFont,
FixedFont,
SerifFont,
@@ -58,13 +58,14 @@ public:
JavascriptCanOpenWindows,
JavascriptCanAccessClipboard,
DeveloperExtrasEnabled,
- LinksIncludedInFocusChain
+ LinksIncludedInFocusChain,
+ ZoomTextOnly
};
enum WebGraphic {
MissingImageGraphic,
MissingPluginGraphic,
- DefaultFaviconGraphic,
- TextAreaResizeCornerGraphic
+ DefaultFrameIconGraphic,
+ TextAreaSizeGripCornerGraphic
};
enum FontSize {
MinimumFontSize,
@@ -73,29 +74,35 @@ public:
DefaultFixedFontSize
};
- static QWebSettings *defaultSettings();
+ static QWebSettings *globalSettings();
- void setFontFamily(FontType type, const QString &family);
- QString fontFamily(FontType type) const;
- void resetFontFamily(FontType type);
+ void setFontFamily(FontFamily which, const QString &family);
+ QString fontFamily(FontFamily which) const;
+ void resetFontFamily(FontFamily which);
void setFontSize(FontSize type, int size);
int fontSize(FontSize type) const;
void resetFontSize(FontSize type);
- void setAttribute(WebAttribute attr, bool on = true);
+ void setAttribute(WebAttribute attr, bool on);
bool testAttribute(WebAttribute attr) const;
- void clearAttribute(WebAttribute attr);
+ void resetAttribute(WebAttribute attr);
- void setUserStyleSheetLocation(const QUrl &location);
- QUrl userStyleSheetLocation() const;
+ void setUserStyleSheetUrl(const QUrl &location);
+ QUrl userStyleSheetUrl() const;
- static void setIconDatabaseEnabled(bool enabled, const QString &location = QString());
- static bool iconDatabaseEnabled();
+ static void setIconDatabasePath(const QString &location);
+ static QString iconDatabasePath();
+ static void clearIconDatabase();
+ static QIcon iconForUrl(const QUrl &url);
static void setWebGraphic(WebGraphic type, const QPixmap &graphic);
static QPixmap webGraphic(WebGraphic type);
+ static void setMaximumPagesInCache(int pages);
+ static int maximumPagesInCache();
+ static void setObjectCacheCapacities(int cacheMinDeadCapacity, int cacheMaxDead, int totalCapacity);
+
private:
friend class QWebPagePrivate;
friend class QWebSettingsPrivate;
diff --git a/WebKit/qt/Api/qwebview.cpp b/WebKit/qt/Api/qwebview.cpp
index 3d67437..ad0b12a 100644
--- a/WebKit/qt/Api/qwebview.cpp
+++ b/WebKit/qt/Api/qwebview.cpp
@@ -1,5 +1,6 @@
/*
- Copyright (C) 2007 Trolltech ASA
+ Copyright (C) 2008 Nokia Corporation and/or its subsidiary(-ies)
+ Copyright (C) 2008 Holger Hans Peter Freyther
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Library General Public
@@ -20,36 +21,148 @@
#include "config.h"
#include "qwebview.h"
#include "qwebframe.h"
+#include "qwebpage_p.h"
+
+#include "qbitmap.h"
#include "qevent.h"
#include "qpainter.h"
+#include "qprinter.h"
class QWebViewPrivate
{
public:
+ QWebViewPrivate(QWebView *view)
+ : view(view)
+ , page(0)
+#ifndef QT_NO_CURSOR
+ , cursorSetByWebCore(false)
+ , usesWebCoreCursor(true)
+#endif
+ {}
+
+ QWebView *view;
QWebPage *page;
+
+
+#ifndef QT_NO_CURSOR
+ /*
+ * We keep track of if we have called setCursor and if the CursorChange
+ * event is sent due our setCursor call and if we currently use the WebCore
+ * Cursor and use it to decide if we can update to another WebCore Cursor.
+ */
+ bool cursorSetByWebCore;
+ bool usesWebCoreCursor;
+
+ void setCursor(const QCursor& newCursor)
+ {
+ webCoreCursor = newCursor;
+
+ if (usesWebCoreCursor) {
+ cursorSetByWebCore = true;
+ view->setCursor(webCoreCursor);
+ }
+ }
+
+ QCursor webCoreCursor;
+#endif
};
/*!
\class QWebView
\since 4.4
- \brief The QWebView class provides a widget that is used to view and edit web documents.
+ \brief The QWebView class provides a widget that is used to view and edit
+ web documents.
+ \ingroup advanced
QWebView is the main widget component of the QtWebKit web browsing module.
+ It can be used in various applications to display web content live from the
+ Internet.
+
+ The image below shows QWebView previewed in \QD with the Trolltech website.
+
+ \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
+ QWebView. The snippet below illustrates this:
+
+ \snippet doc/src/snippets/webkit/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.
+
+ The loadStarted() signal is emitted when the view begins loading. The
+ loadProgress() signal, on the other hand, is emitted whenever an element of
+ the web view completes loading, such as an embedded image, a script, etc.
+ Finally, the loadFinished() signal is emitted when the view has loaded
+ completely. It's argument - either \c true or \c false - indicates
+ load success or failure.
+
+ The page() function returns a pointer to the web page object. See
+ \l{Elements of QWebView} for an explanation of how the web page
+ is related to the view. To modify your web view's settings, you can access
+ the QWebSettings object with the settings() function. With QWebSettings,
+ you can change the default fonts, enable or disable features such as
+ JavaScript and plugins.
+
+ The title of an HTML document can be accessed with the title() property.
+ Additionally, a web site may also specify an icon, which can be accessed
+ using the icon() property. If the title or the icon changes, the corresponding
+ titleChanged() and iconChanged() signals will be emitted. The
+ textSizeMultiplier() property can be used to change the overall size of
+ the text displayed in the web view.
+
+ If you require a custom context menu, you can implement it by reimplementing
+ \l{QWidget::}{contextMenuEvent()} and populating your QMenu with the actions
+ obtained from pageAction(). More functionality such as reloading the view,
+ copying selected text to the clipboard, or pasting into the view, is also
+ encapsulated within the QAction objects returned by pageAction(). These
+ actions can be programmatically triggered using triggerPageAction().
+ Alternatively, the actions can be added to a toolbar or a menu directly.
+ QWebView maintains the state of the returned actions but allows
+ modification of action properties such as \l{QAction::}{text} or
+ \l{QAction::}{icon}.
+
+ A QWebView can be printed onto a QPrinter using the print() function.
+ This function is marked as a slot and can be conveniently connected to
+ \l{QPrintPreviewDialog}'s \l{QPrintPreviewDialog::}{paintRequested()}
+ signal.
+
+ If you want to provide support for web sites that allow the user to open
+ new windows, such as pop-up windows, you can subclass QWebView and
+ reimplement the createWindow() function.
+
+ \section1 Elements of QWebView
+
+ QWebView consists of other objects such as QWebFrame and QWebPage. The
+ flowchart below shows these elements are related.
+
+ \image qwebview-diagram.png
+
+ \note It is possible to use QWebPage and QWebFrame, without using QWebView,
+ 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}
*/
/*!
Constructs an empty QWebView with parent \a parent.
+
+ \sa load()
*/
QWebView::QWebView(QWidget *parent)
: QWidget(parent)
{
- d = new QWebViewPrivate;
- d->page = 0;
+ d = new QWebViewPrivate(this);
QPalette pal = palette();
pal.setBrush(QPalette::Background, Qt::white);
setAttribute(Qt::WA_OpaquePaintEvent);
+#if !defined(Q_WS_QWS)
+ setAttribute(Qt::WA_InputMethodEnabled);
+#endif
setPalette(pal);
setAcceptDrops(true);
@@ -59,10 +172,13 @@ QWebView::QWebView(QWidget *parent)
}
/*!
- Destructor.
+ Destroys the web view.
*/
QWebView::~QWebView()
{
+ if (d->page)
+ d->page->d->view = 0;
+
if (d->page && d->page->parent() == this)
delete d->page;
delete d;
@@ -87,7 +203,7 @@ QWebPage *QWebView::page() const
The parent QObject of the provided page remains the owner
of the object. If the current document is a child of the web
- view, then it is deleted.
+ view, it will be deleted.
\sa page()
*/
@@ -105,36 +221,58 @@ void QWebView::setPage(QWebPage *page)
d->page = page;
if (d->page) {
d->page->setView(this);
+ d->page->setPalette(palette());
// #### connect signals
QWebFrame *mainFrame = d->page->mainFrame();
- connect(mainFrame, SIGNAL(loadStarted()),
- this, SIGNAL(loadStarted()));
- connect(mainFrame, SIGNAL(loadFinished()),
- this, SIGNAL(loadFinished()));
connect(mainFrame, SIGNAL(titleChanged(const QString&)),
this, SIGNAL(titleChanged(const QString&)));
- connect(mainFrame, SIGNAL(iconLoaded()),
- this, SIGNAL(iconLoaded()));
+ connect(mainFrame, SIGNAL(iconChanged()),
+ this, SIGNAL(iconChanged()));
connect(mainFrame, SIGNAL(urlChanged(const QUrl &)),
this, SIGNAL(urlChanged(const QUrl &)));
- connect(d->page, SIGNAL(loadProgressChanged(int)),
- this, SIGNAL(loadProgressChanged(int)));
- connect(d->page, SIGNAL(statusBarTextChanged(const QString &)),
- this, SIGNAL(statusBarTextChanged(const QString &)));
+ connect(d->page, SIGNAL(loadStarted()),
+ this, SIGNAL(loadStarted()));
+ connect(d->page, SIGNAL(loadProgress(int)),
+ this, SIGNAL(loadProgress(int)));
+ connect(d->page, SIGNAL(loadFinished(bool)),
+ this, SIGNAL(loadFinished(bool)));
+ connect(d->page, SIGNAL(statusBarMessage(const QString &)),
+ this, SIGNAL(statusBarMessage(const QString &)));
+ connect(d->page, SIGNAL(linkClicked(const QUrl &)),
+ this, SIGNAL(linkClicked(const QUrl &)));
+
+ connect(d->page, SIGNAL(microFocusChanged()),
+ this, SLOT(updateMicroFocus()));
}
update();
}
/*!
- Downloads the specified \a url and displays it.
+ 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()
*/
void QWebView::load(const QUrl &url)
{
page()->mainFrame()->load(url);
}
-#if QT_VERSION < 0x040400
+/*!
+ \fn void QWebView::load(const QNetworkRequest &request, QNetworkAccessManager::Operation operation, const QByteArray &body)
+
+ Loads a network request, \a request, using the method specified in \a operation.
+
+ \a body is optional and is only used for POST operations.
+
+ \note The view remains the same until enough data has arrived to display the new url.
+
+ \sa url(), urlChanged()
+*/
+
+#if QT_VERSION < 0x040400 && !defined(qdoc)
void QWebView::load(const QWebNetworkRequest &request)
#else
void QWebView::load(const QNetworkRequest &request,
@@ -152,28 +290,30 @@ void QWebView::load(const QNetworkRequest &request,
/*!
Sets the content of the web view to the specified \a html.
- External objects referenced in the HTML document are located relative to \a baseUrl.
-*/
-void QWebView::setHtml(const QString &html, const QUrl &baseUrl)
-{
- page()->mainFrame()->setHtml(html, baseUrl);
-}
+ External objects referenced in the HTML document are located relative to
+ \a baseUrl.
-/*!
- Sets the content of the web view to the specified \a html.
+ 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. Alternatively, the
+ encoding can also be specified by the web server.
- External objects referenced in the HTML document are located relative to \a baseUrl.
+ \sa load(), setContent(), QWebFrame::toHtml()
*/
-void QWebView::setHtml(const QByteArray &html, const QUrl &baseUrl)
+void QWebView::setHtml(const QString &html, const QUrl &baseUrl)
{
page()->mainFrame()->setHtml(html, baseUrl);
}
/*!
Sets the content of the web view to the specified content \a data. If the \a mimeType argument
- is empty it is assumed that the content is HTML.
+ is empty it is currently assumed that the content is HTML but in future versions we may introduce
+ auto-detection.
- External objects referenced in the HTML document are located relative to \a baseUrl.
+ External objects referenced in the content are located relative to \a baseUrl.
+
+ \sa load(), setHtml(), QWebFrame::toHtml()
*/
void QWebView::setContent(const QByteArray &data, const QString &mimeType, const QUrl &baseUrl)
{
@@ -185,7 +325,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 doc/src/snippets/code/src_3rdparty_webkit_WebKit_qt_Api_qwebview.cpp 0
*/
QWebHistory *QWebView::history() const
{
@@ -197,7 +337,9 @@ QWebHistory *QWebView::history() const
It is equivalent to
- \snippet doc/src/snippets/code/src.3rdparty.webkit.WebKit.qt.Api.qwebview.cpp 1
+ \snippet doc/src/snippets/code/src_3rdparty_webkit_WebKit_qt_Api_qwebview.cpp 1
+
+ \sa QWebSettings::globalSettings()
*/
QWebSettings *QWebView::settings() const
{
@@ -205,8 +347,12 @@ QWebSettings *QWebView::settings() const
}
/*!
- \property QWebView::title
- \brief the title of the web page currently viewed.
+ \property QWebView::title
+ \brief the title of the web page currently viewed
+
+ By default, this property contains an empty string.
+
+ \sa titleChanged()
*/
QString QWebView::title() const
{
@@ -217,8 +363,20 @@ QString QWebView::title() const
/*!
\property QWebView::url
- \brief the url of the web page currently viewed.
+ \brief the url of the web page currently viewed
+
+ Setting this property clears the view and loads the URL.
+
+ By default, this property contains an empty, invalid URL.
+
+ \sa load(), urlChanged()
*/
+
+void QWebView::setUrl(const QUrl &url)
+{
+ page()->mainFrame()->setUrl(url);
+}
+
QUrl QWebView::url() const
{
if (d->page)
@@ -228,18 +386,26 @@ QUrl QWebView::url() const
/*!
\property QWebView::icon
- \brief the icon associated with the web page currently viewed.
+ \brief the icon associated with the web page currently viewed
+
+ By default, this property contains a null icon.
+
+ \sa iconChanged(), QWebSettings::iconForUrl()
*/
-QPixmap QWebView::icon() const
+QIcon QWebView::icon() const
{
if (d->page)
return d->page->mainFrame()->icon();
- return QPixmap();
+ return QIcon();
}
/*!
\property QWebView::selectedText
- \brief the text currently selected.
+ \brief the text currently selected
+
+ By default, this property contains an empty string.
+
+ \sa findText(), selectionChanged()
*/
QString QWebView::selectedText() const
{
@@ -251,19 +417,23 @@ QString QWebView::selectedText() const
/*!
Returns a pointer to a QAction that encapsulates the specified web action \a action.
*/
-QAction *QWebView::action(QWebPage::WebAction action) const
+QAction *QWebView::pageAction(QWebPage::WebAction action) const
{
return page()->action(action);
}
/*!
- Triggers the specified \a action. If it is a checkable action the specified \a checked state is assumed.
+ Triggers the specified \a action. If it is a checkable action the specified
+ \a checked state is assumed.
+
+ The following example triggers the copy action and therefore copies any
+ selected text to the clipboard.
- 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 doc/src/snippets/code/src.3rdparty.webkit.WebKit.qt.Api.qwebview.cpp 2
+ \sa pageAction()
*/
-void QWebView::triggerAction(QWebPage::WebAction action, bool checked)
+void QWebView::triggerPageAction(QWebPage::WebAction action, bool checked)
{
page()->triggerAction(action, checked);
}
@@ -272,8 +442,10 @@ void QWebView::triggerAction(QWebPage::WebAction action, bool checked)
\property QWebView::modified
\brief whether the document was modified by the user
- Parts of HTML documents can be editable for example through the \c{contenteditable} attribute on
- HTML elements.
+ Parts of HTML documents can be editable for example through the
+ \c{contenteditable} attribute on HTML elements.
+
+ By default, this property is false.
*/
bool QWebView::isModified() const
{
@@ -282,24 +454,28 @@ bool QWebView::isModified() const
return false;
}
+/*
Qt::TextInteractionFlags QWebView::textInteractionFlags() const
{
// ### FIXME (add to page)
return Qt::TextInteractionFlags();
}
+*/
-/*!
+/*
\property QWebView::textInteractionFlags
\brief how the view should handle user input
Specifies how the user can interact with the text on the page.
*/
+/*
void QWebView::setTextInteractionFlags(Qt::TextInteractionFlags flags)
{
Q_UNUSED(flags)
// ### FIXME (add to page)
}
+*/
/*!
\reimp
@@ -310,11 +486,120 @@ QSize QWebView::sizeHint() const
}
/*!
+ \property QWebView::zoomFactor
+ \since 4.5
+ \brief the zoom factor for the view
+*/
+
+void QWebView::setZoomFactor(qreal factor)
+{
+ page()->mainFrame()->setZoomFactor(factor);
+}
+
+qreal QWebView::zoomFactor() const
+{
+ return page()->mainFrame()->zoomFactor();
+}
+
+/*!
+ \property QWebView::textSizeMultiplier
+ \brief the scaling factor for all text in the frame
+ \obsolete
+
+ Use setZoomFactor instead, in combination with the
+ ZoomTextOnly attribute in QWebSettings.
+
+ \note Setting this property also enables the
+ ZoomTextOnly attribute in QWebSettings.
+
+ By default, this property contains a value of 1.0.
+*/
+
+void QWebView::setTextSizeMultiplier(qreal factor)
+{
+ page()->mainFrame()->setTextSizeMultiplier(factor);
+}
+
+qreal QWebView::textSizeMultiplier() const
+{
+ return page()->mainFrame()->textSizeMultiplier();
+}
+
+/*!
+ 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.
+
+ \sa selectedText(), selectionChanged()
+*/
+bool QWebView::findText(const QString &subString, QWebPage::FindFlags options)
+{
+ if (d->page)
+ return d->page->findText(subString, options);
+ return false;
+}
+
+/*! \reimp
+*/
+bool QWebView::event(QEvent *e)
+{
+ if (d->page) {
+#ifndef QT_NO_CONTEXTMENU
+ if (e->type() == QEvent::ContextMenu) {
+ QContextMenuEvent *event = static_cast<QContextMenuEvent *>(e);
+ if (d->page->swallowContextMenuEvent(event)) {
+ e->accept();
+ return true;
+ }
+ d->page->updatePositionDependentActions(event->pos());
+ } else
+#endif // QT_NO_CONTEXTMENU
+ if (e->type() == QEvent::ShortcutOverride) {
+ d->page->event(e);
+#ifndef QT_NO_CURSOR
+ } else if (e->type() == static_cast<QEvent::Type>(WebCore::SetCursorEvent::EventType)) {
+ d->setCursor(static_cast<WebCore::SetCursorEvent*>(e)->cursor());
+#if QT_VERSION >= 0x040400
+ } else if (e->type() == QEvent::CursorChange) {
+ // Okay we might use the WebCore Cursor now.
+ d->usesWebCoreCursor = d->cursorSetByWebCore;
+ d->cursorSetByWebCore = false;
+
+ // Go back to the WebCore Cursor. QWidget::unsetCursor is appromixated with this
+ if (!d->usesWebCoreCursor && cursor().shape() == Qt::ArrowCursor) {
+ d->usesWebCoreCursor = true;
+ d->setCursor(d->webCoreCursor);
+ }
+#endif
+#endif
+ } else if (e->type() == QEvent::Leave) {
+ d->page->event(e);
+ }
+ }
+
+ return QWidget::event(e);
+}
+
+/*!
+ Prints the main frame to the given \a printer.
+
+ \sa QWebFrame::print(), QPrintPreviewDialog
+*/
+void QWebView::print(QPrinter *printer) const
+{
+#ifndef QT_NO_PRINTER
+ page()->mainFrame()->print(printer);
+#endif
+}
+
+/*!
Convenience slot that stops loading the document.
It is equivalent to
- \snippet doc/src/snippets/code/src.3rdparty.webkit.WebKit.qt.Api.qwebview.cpp 3
+ \snippet doc/src/snippets/code/src_3rdparty_webkit_WebKit_qt_Api_qwebview.cpp 3
+
+ \sa reload(), pageAction(), loadFinished()
*/
void QWebView::stop()
{
@@ -323,37 +608,41 @@ void QWebView::stop()
}
/*!
- Convenience slot that loads the previous document in the list of
- documents built by navigating links. Does nothing if there is no
- previous document.
+ Convenience slot that loads the previous document in the list of documents
+ built by navigating links. Does nothing if there is no previous document.
It is equivalent to
- \snippet doc/src/snippets/code/src.3rdparty.webkit.WebKit.qt.Api.qwebview.cpp 4
+ \snippet doc/src/snippets/code/src_3rdparty_webkit_WebKit_qt_Api_qwebview.cpp 4
+
+ \sa forward(), pageAction()
*/
-void QWebView::backward()
+void QWebView::back()
{
if (d->page)
- d->page->triggerAction(QWebPage::GoBack);
+ d->page->triggerAction(QWebPage::Back);
}
/*!
- Convenience slot that loads the next document in the list of
- documents built by navigating links. Does nothing if there is no
- next document.
+ Convenience slot that loads the next document in the list of documents
+ built by navigating links. Does nothing if there is no next document.
It is equivalent to
- \snippet doc/src/snippets/code/src.3rdparty.webkit.WebKit.qt.Api.qwebview.cpp 5
+ \snippet doc/src/snippets/code/src_3rdparty_webkit_WebKit_qt_Api_qwebview.cpp 5
+
+ \sa back(), pageAction()
*/
void QWebView::forward()
{
if (d->page)
- d->page->triggerAction(QWebPage::GoForward);
+ d->page->triggerAction(QWebPage::Forward);
}
/*!
Reloads the current document.
+
+ \sa stop(), pageAction(), loadStarted()
*/
void QWebView::reload()
{
@@ -392,11 +681,14 @@ void QWebView::paintEvent(QPaintEvent *ev)
}
/*!
- This function is called whenever WebKit wants to create a new window, for example as a result of
+ This function is called whenever WebKit wants to create a new window of the given \a type, for example as a result of
a JavaScript request to open a document in a new window.
+
+ \sa QWebPage::createWindow()
*/
-QWebView *QWebView::createWindow()
+QWebView *QWebView::createWindow(QWebPage::WebWindowType type)
{
+ Q_UNUSED(type)
return 0;
}
@@ -404,52 +696,71 @@ QWebView *QWebView::createWindow()
*/
void QWebView::mouseMoveEvent(QMouseEvent* ev)
{
- if (d->page)
+ if (d->page) {
+ const bool accepted = ev->isAccepted();
d->page->event(ev);
+ ev->setAccepted(accepted);
+ }
}
/*! \reimp
*/
void QWebView::mousePressEvent(QMouseEvent* ev)
{
- if (d->page)
+ if (d->page) {
+ const bool accepted = ev->isAccepted();
d->page->event(ev);
+ ev->setAccepted(accepted);
+ }
}
/*! \reimp
*/
void QWebView::mouseDoubleClickEvent(QMouseEvent* ev)
{
- if (d->page)
+ if (d->page) {
+ const bool accepted = ev->isAccepted();
d->page->event(ev);
+ ev->setAccepted(accepted);
+ }
}
/*! \reimp
*/
void QWebView::mouseReleaseEvent(QMouseEvent* ev)
{
- if (d->page)
+ if (d->page) {
+ const bool accepted = ev->isAccepted();
d->page->event(ev);
+ ev->setAccepted(accepted);
+ }
}
+#ifndef QT_NO_CONTEXTMENU
/*! \reimp
*/
void QWebView::contextMenuEvent(QContextMenuEvent* ev)
{
- if (d->page)
+ if (d->page) {
+ const bool accepted = ev->isAccepted();
d->page->event(ev);
+ ev->setAccepted(accepted);
+ }
}
+#endif // QT_NO_CONTEXTMENU
+#ifndef QT_NO_WHEELEVENT
/*! \reimp
*/
void QWebView::wheelEvent(QWheelEvent* ev)
{
- if (d->page)
+ if (d->page) {
+ const bool accepted = ev->isAccepted();
d->page->event(ev);
-
- if (!ev->isAccepted())
- return QWidget::wheelEvent(ev);
+ ev->setAccepted(accepted);
+ }
}
+#endif // QT_NO_WHEELEVENT
/*! \reimp
*/
@@ -477,16 +788,18 @@ void QWebView::focusInEvent(QFocusEvent* ev)
{
if (d->page)
d->page->event(ev);
- QWidget::focusInEvent(ev);
+ else
+ QWidget::focusInEvent(ev);
}
/*! \reimp
*/
void QWebView::focusOutEvent(QFocusEvent* ev)
{
- QWidget::focusOutEvent(ev);
if (d->page)
d->page->event(ev);
+ else
+ QWidget::focusOutEvent(ev);
}
/*! \reimp
@@ -538,56 +851,107 @@ bool QWebView::focusNextPrevChild(bool next)
return QWidget::focusNextPrevChild(next);
}
+/*!\reimp
+*/
+QVariant QWebView::inputMethodQuery(Qt::InputMethodQuery property) const
+{
+ if (d->page)
+ return d->page->inputMethodQuery(property);
+ return QVariant();
+}
+
+/*!\reimp
+*/
+void QWebView::inputMethodEvent(QInputMethodEvent *e)
+{
+ if (d->page)
+ d->page->event(e);
+}
+
+/*!\reimp
+*/
+void QWebView::changeEvent(QEvent *e)
+{
+ if (d->page && e->type() == QEvent::PaletteChange) {
+ d->page->setPalette(palette());
+ }
+ QWidget::changeEvent(e);
+}
+
/*!
- \fn void QWebView::titleChanged(const QString &title)
+ \fn void QWebView::titleChanged(const QString &title)
- This signal is emitted whenever the \a title of the main frame changes.
+ This signal is emitted whenever the \a title of the main frame changes.
- \sa title()
+ \sa title()
*/
/*!
- \fn void QWebView::urlChanged(const QUrl &url)
+ \fn void QWebView::urlChanged(const QUrl &url)
- This signal is emitted whenever the \a url of the main frame changes.
+ This signal is emitted when the \a url of the view changes.
- \sa url()
+ \sa url(), load()
*/
/*!
- \fn void QWebView::statusBarTextChanged(const QString& text)
+ \fn void QWebView::statusBarMessage(const QString& text)
This signal is emitted when the statusbar \a text is changed by the page.
*/
/*!
- \fn void QWebView::iconLoaded()
+ \fn void QWebView::iconChanged()
This signal is emitted whenever the icon of the page is loaded or changes.
+
+ \sa icon()
*/
/*!
\fn void QWebView::loadStarted()
- This signal is emitted when a new load of the frame is started.
+ This signal is emitted when a new load of the page is started.
+
+ \sa loadProgress(), loadFinished()
*/
/*!
- \fn void QWebView::loadFinished()
+ \fn void QWebView::loadFinished(bool ok)
- This signal is emitted when a load of the frame is finished.
+ This signal is emitted when a load of the page is finished.
+ \a ok will indicate whether the load was successful or any error occurred.
+
+ \sa loadStarted()
*/
/*!
\fn void QWebView::selectionChanged()
This signal is emitted whenever the selection changes.
+
+ \sa selectedText()
+*/
+
+/*!
+ \fn void QWebView::loadProgress(int progress)
+
+ This signal is emitted every time an element in the web page
+ completes loading and the overall loading progress advances.
+
+ This signal tracks the progress of all child frames.
+
+ The current value is provided by \a progress and scales from 0 to 100,
+ which is the default range of QProgressBar.
+
+ \sa loadStarted(), loadFinished()
*/
/*!
- \fn void QWebView::loadProgressChanged(int progress)
+ \fn void QWebView::linkClicked(const QUrl &url)
+
+ This signal is emitted whenever the user clicks on a link and the page's linkDelegationPolicy
+ property is set to delegate the link handling for the specified \a url.
- This signal is emitted when the global progress status changes.
- The current value is provided by \a progress in percent.
- It accumulates changes from all the child frames.
+ \sa QWebPage::linkDelegationPolicy()
*/
diff --git a/WebKit/qt/Api/qwebview.h b/WebKit/qt/Api/qwebview.h
index 53043ae..1172f39 100644
--- a/WebKit/qt/Api/qwebview.h
+++ b/WebKit/qt/Api/qwebview.h
@@ -1,5 +1,5 @@
/*
- Copyright (C) 2007 Trolltech ASA
+ Copyright (C) 2008 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
@@ -17,31 +17,39 @@
the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
Boston, MA 02110-1301, USA.
*/
+
#ifndef QWEBVIEW_H
#define QWEBVIEW_H
#include "qwebkitglobal.h"
#include "qwebpage.h"
#include <QtGui/qwidget.h>
+#include <QtGui/qicon.h>
#include <QtCore/qurl.h>
#if QT_VERSION >= 0x040400
#include <QtNetwork/qnetworkaccessmanager.h>
#endif
+QT_BEGIN_NAMESPACE
+class QNetworkRequest;
+class QPrinter;
+QT_END_NAMESPACE
+
class QWebPage;
class QWebViewPrivate;
-class QNetworkRequest;
class QWebNetworkRequest;
class QWEBKIT_EXPORT QWebView : public QWidget
{
Q_OBJECT
Q_PROPERTY(QString title READ title)
- Q_PROPERTY(QUrl url READ url WRITE load)
- Q_PROPERTY(QPixmap icon READ icon)
+ Q_PROPERTY(QUrl url READ url WRITE setUrl)
+ Q_PROPERTY(QIcon icon READ icon)
Q_PROPERTY(QString selectedText READ selectedText)
Q_PROPERTY(bool modified READ isModified)
- Q_PROPERTY(Qt::TextInteractionFlags textInteractionFlags READ textInteractionFlags WRITE setTextInteractionFlags)
+ //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)
public:
explicit QWebView(QWidget *parent = 0);
virtual ~QWebView();
@@ -50,7 +58,7 @@ public:
void setPage(QWebPage *page);
void load(const QUrl &url);
-#if QT_VERSION < 0x040400
+#if QT_VERSION < 0x040400 && !defined(qdoc)
void load(const QWebNetworkRequest &request);
#else
void load(const QNetworkRequest &request,
@@ -58,64 +66,79 @@ public:
const QByteArray &body = QByteArray());
#endif
void setHtml(const QString &html, const QUrl &baseUrl = QUrl());
- void setHtml(const QByteArray &html, const QUrl &baseUrl = QUrl());
void setContent(const QByteArray &data, const QString &mimeType = QString(), const QUrl &baseUrl = QUrl());
QWebHistory *history() const;
QWebSettings *settings() const;
QString title() const;
+ void setUrl(const QUrl &url);
QUrl url() const;
- QPixmap icon() const;
+ QIcon icon() const;
QString selectedText() const;
- QAction *action(QWebPage::WebAction action) const;
- void triggerAction(QWebPage::WebAction action, bool checked = false);
+ QAction *pageAction(QWebPage::WebAction action) const;
+ void triggerPageAction(QWebPage::WebAction action, bool checked = false);
bool isModified() const;
+ /*
Qt::TextInteractionFlags textInteractionFlags() const;
void setTextInteractionFlags(Qt::TextInteractionFlags flags);
-
- /* #### QTextBrowser compatibility?
- bool openLinks() const;
- void setOpenLinks(bool open);
-
- bool openExternalLinks() const;
- void setOpenExternalLinks(bool open);
+ void setTextInteractionFlag(Qt::TextInteractionFlag flag);
*/
+ QVariant inputMethodQuery(Qt::InputMethodQuery property) const;
+
QSize sizeHint() const;
+
+ qreal zoomFactor() const;
+ void setZoomFactor(qreal factor);
+
+ void setTextSizeMultiplier(qreal factor);
+ qreal textSizeMultiplier() const;
+
+ bool findText(const QString &subString, QWebPage::FindFlags options = 0);
+
+ virtual bool event(QEvent *);
+
public Q_SLOTS:
void stop();
- void backward();
+ void back();
void forward();
void reload();
+ void print(QPrinter *printer) const;
+
Q_SIGNALS:
void loadStarted();
- void loadProgressChanged(int progress);
- void loadFinished();
+ void loadProgress(int progress);
+ void loadFinished(bool);
void titleChanged(const QString& title);
- void statusBarTextChanged(const QString& text);
+ void statusBarMessage(const QString& text);
void linkClicked(const QUrl &url);
void selectionChanged();
- void iconLoaded();
+ void iconChanged();
void urlChanged(const QUrl &url);
protected:
void resizeEvent(QResizeEvent *e);
void paintEvent(QPaintEvent *ev);
- virtual QWebView *createWindow();
+ virtual QWebView *createWindow(QWebPage::WebWindowType type);
+ virtual void changeEvent(QEvent*);
virtual void mouseMoveEvent(QMouseEvent*);
virtual void mousePressEvent(QMouseEvent*);
virtual void mouseDoubleClickEvent(QMouseEvent*);
virtual void mouseReleaseEvent(QMouseEvent*);
+#ifndef QT_NO_CONTEXTMENU
virtual void contextMenuEvent(QContextMenuEvent*);
+#endif
+#ifndef QT_NO_WHEELEVENT
virtual void wheelEvent(QWheelEvent*);
+#endif
virtual void keyPressEvent(QKeyEvent*);
virtual void keyReleaseEvent(QKeyEvent*);
virtual void dragEnterEvent(QDragEnterEvent *);
@@ -124,6 +147,7 @@ protected:
virtual void dropEvent(QDropEvent *);
virtual void focusInEvent(QFocusEvent*);
virtual void focusOutEvent(QFocusEvent*);
+ virtual void inputMethodEvent(QInputMethodEvent*);
virtual bool focusNextPrevChild(bool next);