.: [Qt] Add the alternative QtLauncher (based on QGraphicsView) to the build.
authorkenneth@webkit.org <kenneth@webkit.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Wed, 9 Sep 2009 20:15:18 +0000 (20:15 +0000)
committerkenneth@webkit.org <kenneth@webkit.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Wed, 9 Sep 2009 20:15:18 +0000 (20:15 +0000)
Patch by Kenneth Rohde Christiansen <kenneth@webkit.org> on 2009-09-09
Reviewed by Simon Hausmann.

https://bugs.webkit.org/show_bug.cgi?id=28862

* WebKit.pro:

WebCore: Add the qwebgraphicsitem.cpp to the build system.

Patch by Kenneth Rohde Christiansen <kenneth@webkit.org> on 2009-09-09
Reviewed by Simon Hausmann.

https://bugs.webkit.org/show_bug.cgi?id=28862

* WebCore.pro:

WebKit/qt: Add a new QGraphicsWidget based version of the "QWebView"
under the name "QWebGraphicsItem".

Patch by Kenneth Rohde Christiansen  <kenneth@webkit.org>, Antonio Gomes <antonio.gomes@openbossa.org> on 2009-09-09
Reviewed by Simon Hausmann.

https://bugs.webkit.org/show_bug.cgi?id=28862

Includes an alternative Qt launcher using the QGraphicsView.

* Api/headers.pri:
* Api/qwebgraphicsitem.cpp: Added.
* Api/qwebgraphicsitem.h: Added.
* Api/qwebpage.h:
* QGVLauncher/QGVLauncher.pro: Copied from WebKit/qt/QtLauncher/QtLauncher.pro.
* QGVLauncher/main.cpp: Added.
* WebCoreSupport/ChromeClientQt.cpp:
(WebCore::ChromeClientQt::repaint):
(WebCore::ChromeClientQt::scroll):

git-svn-id: https://svn.webkit.org/repository/webkit/trunk@48219 268f45cc-cd09-0410-ab3c-d52691b4dbfc

12 files changed:
ChangeLog
WebCore/ChangeLog
WebCore/WebCore.pro
WebKit.pro
WebKit/qt/Api/headers.pri
WebKit/qt/Api/qwebgraphicsitem.cpp [new file with mode: 0644]
WebKit/qt/Api/qwebgraphicsitem.h [new file with mode: 0644]
WebKit/qt/Api/qwebpage.h
WebKit/qt/ChangeLog
WebKit/qt/QGVLauncher/QGVLauncher.pro [new file with mode: 0644]
WebKit/qt/QGVLauncher/main.cpp [new file with mode: 0644]
WebKit/qt/WebCoreSupport/ChromeClientQt.cpp

index 1305a37..d7574da 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,13 @@
+2009-09-09  Kenneth Rohde Christiansen  <kenneth@webkit.org>
+
+        Reviewed by Simon Hausmann.
+
+        [Qt] Add the alternative QtLauncher (based on QGraphicsView) to the build.
+
+        https://bugs.webkit.org/show_bug.cgi?id=28862
+
+        * WebKit.pro:
+
 2009-09-07  Xan Lopez  <xlopez@igalia.com>
 
         Rubber-stamped by Gustavo Noronha.
index 6617456..c21592d 100644 (file)
@@ -1,3 +1,13 @@
+2009-09-09  Kenneth Rohde Christiansen  <kenneth@webkit.org>
+
+        Reviewed by Simon Hausmann.
+
+        Add the qwebgraphicsitem.cpp to the build system.
+
+        https://bugs.webkit.org/show_bug.cgi?id=28862
+
+        * WebCore.pro:
+
 2009-09-08  Kevin Watters  <kevinwatters@gmail.com>
 
         Reviewed by Kevin Ollivier.
index 1f6769a..4fe1393 100644 (file)
@@ -2379,6 +2379,7 @@ SOURCES += \
     ../WebKit/qt/WebCoreSupport/FrameLoaderClientQt.cpp \
     ../WebKit/qt/WebCoreSupport/InspectorClientQt.cpp \
     ../WebKit/qt/Api/qwebframe.cpp \
+    ../WebKit/qt/Api/qwebgraphicsitem.cpp \
     ../WebKit/qt/Api/qwebpage.cpp \
     ../WebKit/qt/Api/qwebview.cpp \
     ../WebKit/qt/Api/qwebelement.cpp \
index 0ba14e4..866bb9b 100644 (file)
@@ -5,6 +5,7 @@ SUBDIRS += \
         WebCore \
         JavaScriptCore/jsc.pro \
         WebKit/qt/QtLauncher \
+        WebKit/qt/QGVLauncher \
         WebKit/qt/tests
 
 !win32:!symbian {
index 92a120d..30a36ef 100644 (file)
@@ -1,4 +1,5 @@
 WEBKIT_API_HEADERS = $$PWD/qwebframe.h \
+                     $$PWD/qwebgraphicsitem.h \
                      $$PWD/qwebkitglobal.h \
                      $$PWD/qwebpage.h \
                      $$PWD/qwebview.h \
diff --git a/WebKit/qt/Api/qwebgraphicsitem.cpp b/WebKit/qt/Api/qwebgraphicsitem.cpp
new file mode 100644 (file)
index 0000000..1f61673
--- /dev/null
@@ -0,0 +1,740 @@
+/*
+    Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies)
+
+    This library is free software; you can redistribute it and/or
+    modify it under the terms of the GNU Library General Public
+    License as published by the Free Software Foundation; either
+    version 2 of the License, or (at your option) any later version.
+
+    This library is distributed in the hope that it will be useful,
+    but WITHOUT ANY WARRANTY; without even the implied warranty of
+    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+    Library General Public License for more details.
+
+    You should have received a copy of the GNU Library General Public License
+    along with this library; see the file COPYING.LIB.  If not, write to
+    the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+    Boston, MA 02110-1301, USA.
+*/
+
+#include "config.h"
+#include "qwebgraphicsitem.h"
+
+#include "qwebframe.h"
+#include "qwebpage.h"
+#include "qwebpage_p.h"
+#include <Qt/qstyleoption.h>
+#include <QtGui/QGraphicsScene>
+#include <QtGui/QGraphicsView>
+#include <QtGui/qapplication.h>
+#include <QtGui/qgraphicssceneevent.h>
+
+class QWebGraphicsItemPrivate {
+public:
+    QWebGraphicsItemPrivate(QWebGraphicsItem* parent)
+        : q(parent)
+        , page(0)
+        , interactive(true)
+        , progress(1.0)
+    {}
+
+    void _q_doScroll(int dx, int dy, const QRect&);
+    void _q_doLoadProgress(int progress);
+    void _q_doLoadFinished(bool success);
+    void _q_doUpdate(const QRect& dirtyRect);
+    void _q_setStatusBarMessage(const QString& message);
+
+    QWebGraphicsItem* q;
+    QWebPage* page;
+
+    QString statusBarMessage;
+    bool interactive;
+    qreal progress;
+};
+
+void QWebGraphicsItemPrivate::_q_doLoadProgress(int progress)
+{
+    if (qFuzzyCompare(this->progress, progress / 100.))
+        return;
+
+    this->progress = progress / 100.;
+
+    emit q->progressChanged(this->progress);
+}
+
+void QWebGraphicsItemPrivate::_q_doLoadFinished(bool success)
+{
+    // If the page had no title, still make sure it gets the signal
+    if (q->title().isEmpty())
+        emit q->urlChanged(q->url());
+
+    if (success)
+        emit q->loadFinished();
+    else
+        emit q->loadFailed();
+}
+
+void QWebGraphicsItemPrivate::_q_doScroll(int dx, int dy, const QRect& rectToScroll)
+{
+    q->scroll(qreal(dx), qreal(dy), QRectF(rectToScroll));
+}
+
+void QWebGraphicsItemPrivate::_q_doUpdate(const QRect & dirtyRect)
+{
+    q->update(QRectF(dirtyRect));
+}
+
+void QWebGraphicsItemPrivate::_q_setStatusBarMessage(const QString& s)
+{
+    statusBarMessage = s;
+    q->emit statusChanged();
+}
+
+/*!
+    \brief QWebGrahicsItem allows web content to be added to a canvas.
+    \inherits QGraphicsWidget.
+    \since 4.6
+
+    A WebGraphicsItem renders web content based on a URL or set data.
+
+    If the width and height of the item is not set, they will
+    dynamically adjust to a size appropriate for the content.
+    This width may be large (eg. 980) for typical online web pages.
+*/
+
+/*!
+    Constructs an empty QWebGraphicsItem with parent \a parent/
+
+    \sa load()
+*/
+QWebGraphicsItem::QWebGraphicsItem(QGraphicsItem* parent)
+    : QGraphicsWidget(parent)
+    , d(new QWebGraphicsItemPrivate(this))
+{
+#if QT_VERSION >= 0x040600
+    setFlag(QGraphicsItem::ItemUsesExtendedStyleOption, true);
+#endif
+    setAcceptHoverEvents(true);
+    setFocusPolicy(Qt::StrongFocus);
+}
+
+/*!
+    Destroys the web graphicsitem.
+*/
+QWebGraphicsItem::~QWebGraphicsItem()
+{
+    if (d->page)
+        d->page->d->view = 0;
+
+    if (d->page && d->page->parent() == this)
+        delete d->page;
+
+    delete d;
+}
+
+/*!
+    Returns a pointer to the underlying web page.
+
+    \sa setPage()
+*/
+QWebPage* QWebGraphicsItem::page() const
+{
+    if (!d->page) {
+        QWebGraphicsItem* that = const_cast<QWebGraphicsItem*>(this);
+        QWebPage* page = new QWebPage(that);
+
+        // Default to not having a background, in the case
+        // the page doesn't provide one.
+        QPalette palette = QApplication::palette();
+        palette.setBrush(QPalette::Base, QColor::fromRgbF(0, 0, 0, 0));
+        page->setPalette(palette);
+
+        that->setPage(page);
+    }
+
+    return d->page;
+}
+
+/*! \reimp
+*/
+void QWebGraphicsItem::paint(QPainter* painter, const QStyleOptionGraphicsItem* option, QWidget*)
+{
+    d->page->mainFrame()->render(painter, option->exposedRect.toRect());
+}
+
+/*!
+    Makes \a page the new web page of the web graphicsitem.
+
+    The parent QObject of the provided page remains the owner
+    of the object. If the current document is a child of the web
+    view, it will be deleted.
+
+    \sa page()
+*/
+void QWebGraphicsItem::setPage(QWebPage* page)
+{
+    if (d->page == page)
+        return;
+
+    if (d->page) {
+        if (d->page->parent() == this)
+            delete d->page;
+        else
+            d->page->disconnect(this);
+    }
+
+    d->page = page;
+    if (!d->page)
+        return;
+
+    QSize size = geometry().size().toSize();
+    page->setViewportSize(size);
+
+    QWebFrame* mainFrame = d->page->mainFrame();
+
+    connect(mainFrame, SIGNAL(titleChanged(const QString&)),
+            this, SIGNAL(titleChanged(const QString&)));
+    connect(mainFrame, SIGNAL(iconChanged()),
+            this, SIGNAL(iconChanged()));
+    connect(mainFrame, SIGNAL(urlChanged(const QUrl&)),
+            this, SIGNAL(urlChanged(const QUrl&)));
+    connect(d->page, SIGNAL(loadStarted()),
+            this, SIGNAL(loadStarted()));
+    connect(d->page, SIGNAL(loadProgress(int)),
+            this, SLOT(_q_doLoadProgress(int)));
+    connect(d->page, SIGNAL(loadFinished(bool)),
+            this, SLOT(_q_doLoadFinished(bool)));
+    connect(d->page, SIGNAL(repaintRequested(QRect)),
+            this, SLOT(_q_doUpdate(const QRect&)));
+    connect(d->page, SIGNAL(scrollRequested(int, int, const QRect&)),
+            this, SLOT(_q_doScroll(int, int, const QRect&)));
+    connect(d->page, SIGNAL(statusBarMessage(const QString&)),
+            this, SLOT(_q_setStatusBarMessage(const QString&)));
+}
+
+/*!
+    \property QWebGraphicsItem::url
+    \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 QWebGraphicsItem::setUrl(const QUrl &url)
+{
+    if (!d->page || d->page->mainFrame()->url() == url)
+        return;
+
+    d->page->mainFrame()->setUrl(url);
+}
+
+QUrl QWebGraphicsItem::url() const
+{
+    if (d->page)
+        return d->page->mainFrame()->url();
+
+    return QUrl();
+}
+
+/*!
+    \property QWebGraphicsItem::title
+    \brief the title of the web page currently viewed
+
+    By default, this property contains an empty string.
+
+    \sa titleChanged()
+*/
+QString QWebGraphicsItem::title() const
+{
+    if (d->page)
+        return d->page->mainFrame()->title();
+
+    return QString();
+}
+
+/*!
+    \property QWebGraphicsItem::icon
+    \brief the icon associated with the web page currently viewed
+
+    By default, this property contains a null icon.
+
+    \sa iconChanged(), QWebSettings::iconForUrl()
+*/
+QIcon QWebGraphicsItem::icon() const
+{
+    return d->page->mainFrame()->icon();
+}
+
+/*!
+    \property QWebGraphicsItem::zoomFactor
+    \since 4.5
+    \brief the zoom factor for the view
+*/
+
+void QWebGraphicsItem::setZoomFactor(qreal factor)
+{
+    if (factor == d->page->mainFrame()->zoomFactor())
+        return;
+
+    d->page->mainFrame()->setZoomFactor(factor);
+
+    emit zoomFactorChanged();
+}
+
+qreal QWebGraphicsItem::zoomFactor() const
+{
+    return d->page->mainFrame()->zoomFactor();
+}
+
+/*! \reimp
+*/
+void QWebGraphicsItem::updateGeometry()
+{
+    QGraphicsWidget::updateGeometry();
+    QSize size = geometry().size().toSize();
+    d->page->setViewportSize(size);
+}
+
+/*! \reimp
+*/
+void QWebGraphicsItem::setGeometry(const QRectF& rect)
+{
+    QGraphicsWidget::setGeometry(rect);
+    // NOTE: call geometry() as setGeometry ensures that
+    // the geometry is within legal bounds (minimumSize, maximumSize)
+    QSize size = geometry().size().toSize();
+    d->page->setViewportSize(size);
+}
+
+/*!
+    \brief The load status message associated to the web graphicsitem
+
+    Provides the latest status message set during the load of a URL.
+    Commonly shown by Status Bar widgets.
+
+    \sa statusChanged()
+*/
+
+QString QWebGraphicsItem::status() const
+{
+    return d->statusBarMessage;
+}
+
+/*!
+    Convenience slot that stops loading the document.
+
+    \sa reload(), pageAction(), loadFinished()
+*/
+void QWebGraphicsItem::stop()
+{
+    if (d->page)
+        d->page->triggerAction(QWebPage::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.
+
+    \sa forward(), pageAction()
+*/
+void QWebGraphicsItem::back()
+{
+    if (d->page)
+        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.
+
+    \sa back(), pageAction()
+*/
+void QWebGraphicsItem::forward()
+{
+    if (d->page)
+        d->page->triggerAction(QWebPage::Forward);
+}
+
+/*!
+    Reloads the current document.
+
+    \sa stop(), pageAction(), loadStarted()
+*/
+void QWebGraphicsItem::reload()
+{
+    if (d->page)
+        d->page->triggerAction(QWebPage::Reload);
+}
+
+/*!
+    \property QWebGraphicsItem::progress
+    \brief the progress of loading the current URL, from 0 to 1.
+*/
+qreal QWebGraphicsItem::progress() const
+{
+    return d->progress;
+}
+
+/*!
+    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 QWebGraphicsItem::load(const QUrl& url)
+{
+    d->page->mainFrame()->load(url);
+}
+
+/*!
+    \fn void QWebGraphicsItem::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()
+*/
+
+void QWebGraphicsItem::load(const QNetworkRequest& request,
+                    QNetworkAccessManager::Operation operation,
+                    const QByteArray& body)
+{
+    d->page->mainFrame()->load(request, operation, body);
+}
+
+/*!
+    Sets the content of the web graphicsitem to the specified \a html.
+
+    External objects such as stylesheets or images referenced in the HTML
+    document are located relative to \a baseUrl.
+
+    The \a html is loaded immediately; external objects are loaded asynchronously.
+
+    When using this method, WebKit assumes that external resources such as
+    JavaScript programs or style sheets are encoded in UTF-8 unless otherwise
+    specified. For example, the encoding of an external script can be specified
+    through the charset attribute of the HTML script tag. Alternatively, the
+    encoding can also be specified by the web server.
+
+    \sa load(), setContent(), QWebFrame::toHtml()
+*/
+void QWebGraphicsItem::setHtml(const QString& html, const QUrl& baseUrl)
+{
+    d->page->mainFrame()->setHtml(html, baseUrl);
+}
+
+QString QWebGraphicsItem::toHtml() const
+{
+    return d->page->mainFrame()->toHtml();
+}
+
+/*!
+    Sets the content of the web graphicsitem 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.
+
+    External objects referenced in the content are located relative to \a baseUrl.
+
+    The \a data is loaded immediately; external objects are loaded asynchronously.
+
+    \sa load(), setHtml(), QWebFrame::toHtml()
+*/
+void QWebGraphicsItem::setContent(const QByteArray& data, const QString& mimeType, const QUrl& baseUrl)
+{
+    d->page->mainFrame()->setContent(data, mimeType, baseUrl);
+}
+
+/*!
+    Returns a pointer to the view's history of navigated web pages.
+
+    It is equivalent to
+
+    \snippet webkitsnippets/qtwebkit_qwebview_snippet.cpp 0
+*/
+QWebHistory* QWebGraphicsItem::history() const
+{
+    return d->page->history();
+}
+
+/*!
+  \property QWebGraphicsItem::interactive
+  \brief controls whether the item responds to mouse and key events.
+*/
+
+bool QWebGraphicsItem::isInteractive() const
+{
+    return d->interactive;
+}
+
+void QWebGraphicsItem::setInteractive(bool allowed)
+{
+    if (d->interactive == allowed)
+        return;
+
+    d->interactive = allowed;
+    emit interactivityChanged();
+}
+
+/*!
+    Returns a pointer to the view/page specific settings object.
+
+    It is equivalent to
+
+    \snippet webkitsnippets/qtwebkit_qwebview_snippet.cpp 1
+
+    \sa QWebSettings::globalSettings()
+*/
+QWebSettings* QWebGraphicsItem::settings() const
+{
+    return d->page->settings();
+}
+
+/*! \reimp
+*/
+void QWebGraphicsItem::hoverMoveEvent(QGraphicsSceneHoverEvent* ev)
+{
+    if (d->interactive && d->page) {
+        const bool accepted = ev->isAccepted();
+        QMouseEvent me = QMouseEvent(QEvent::MouseMove,
+                ev->pos().toPoint(), Qt::NoButton,
+                Qt::NoButton, Qt::NoModifier);
+        d->page->setView(ev->widget());
+        d->page->event(&me);
+        ev->setAccepted(accepted);
+    }
+
+    if (!ev->isAccepted())
+        QGraphicsItem::hoverMoveEvent(ev);
+}
+
+/*! \reimp
+*/
+void QWebGraphicsItem::hoverLeaveEvent(QGraphicsSceneHoverEvent* ev)
+{
+    Q_UNUSED(ev);
+}
+
+/*! \reimp
+*/
+void QWebGraphicsItem::mouseMoveEvent(QGraphicsSceneMouseEvent* ev)
+{
+    if (d->interactive && d->page) {
+        const bool accepted = ev->isAccepted();
+        d->page->event(ev);
+        ev->setAccepted(accepted);
+    }
+
+    if (!ev->isAccepted())
+        QGraphicsItem::mouseMoveEvent(ev);
+}
+
+/*! \reimp
+*/
+void QWebGraphicsItem::mousePressEvent(QGraphicsSceneMouseEvent* ev)
+{
+    if (d->interactive && d->page) {
+        const bool accepted = ev->isAccepted();
+        d->page->event(ev);
+        ev->setAccepted(accepted);
+    }
+
+    if (!ev->isAccepted())
+        QGraphicsItem::mousePressEvent(ev);
+}
+
+/*! \reimp
+*/
+void QWebGraphicsItem::mouseReleaseEvent(QGraphicsSceneMouseEvent* ev)
+{
+    if (d->interactive && d->page) {
+        const bool accepted = ev->isAccepted();
+        d->page->event(ev);
+        ev->setAccepted(accepted);
+    }
+
+    if (!ev->isAccepted())
+        QGraphicsItem::mouseReleaseEvent(ev);
+}
+
+/*! \reimp
+*/
+void QWebGraphicsItem::mouseDoubleClickEvent(QGraphicsSceneMouseEvent* ev)
+{
+    if (d->interactive && d->page) {
+        const bool accepted = ev->isAccepted();
+        d->page->event(ev);
+        ev->setAccepted(accepted);
+    }
+
+    if (!ev->isAccepted())
+        QGraphicsItem::mouseDoubleClickEvent(ev);
+}
+
+/*! \reimp
+*/
+void QWebGraphicsItem::keyPressEvent(QKeyEvent* ev)
+{
+    if (d->interactive && d->page)
+        d->page->event(ev);
+
+    if (!ev->isAccepted())
+        QGraphicsItem::keyPressEvent(ev);
+}
+
+/*! \reimp
+*/
+void QWebGraphicsItem::keyReleaseEvent(QKeyEvent* ev)
+{
+    if (d->interactive && d->page)
+        d->page->event(ev);
+
+    if (!ev->isAccepted())
+        QGraphicsItem::keyReleaseEvent(ev);
+}
+
+/*! \reimp
+*/
+void QWebGraphicsItem::focusInEvent(QFocusEvent* ev)
+{
+    if (d->page)
+        d->page->event(ev);
+    else
+        QGraphicsItem::focusInEvent(ev);
+}
+
+/*! \reimp
+*/
+void QWebGraphicsItem::focusOutEvent(QFocusEvent* ev)
+{
+    if (d->page)
+        d->page->event(ev);
+    else
+        QGraphicsItem::focusOutEvent(ev);
+}
+
+/*! \reimp
+*/
+bool QWebGraphicsItem::focusNextPrevChild(bool next)
+{
+    if (d->page)
+        return d->page->focusNextPrevChild(next);
+
+    return QGraphicsWidget::focusNextPrevChild(next);
+}
+
+/*! \reimp
+*/
+void QWebGraphicsItem::dragEnterEvent(QGraphicsSceneDragDropEvent* ev)
+{
+#ifndef QT_NO_DRAGANDDROP
+    //if (d->page)
+    //    d->page->event(ev);
+    //Just remove this line below when the code above is working
+    Q_UNUSED(ev);
+#else
+    Q_UNUSED(ev);
+#endif
+}
+
+/*! \reimp
+*/
+void QWebGraphicsItem::dragLeaveEvent(QGraphicsSceneDragDropEvent* ev)
+{
+#ifndef QT_NO_DRAGANDDROP
+    if (d->interactive && d->page) {
+        const bool accepted = ev->isAccepted();
+        d->page->event(ev);
+        ev->setAccepted(accepted);
+    }
+
+    if (!ev->isAccepted())
+        QGraphicsWidget::dragLeaveEvent(ev);
+#else
+    Q_UNUSED(ev);
+#endif
+}
+
+/*! \reimp
+*/
+void QWebGraphicsItem::dragMoveEvent(QGraphicsSceneDragDropEvent* ev)
+{
+#ifndef QT_NO_DRAGANDDROP
+    if (d->interactive && d->page) {
+        const bool accepted = ev->isAccepted();
+        d->page->event(ev);
+        ev->setAccepted(accepted);
+    }
+
+    if (!ev->isAccepted())
+        QGraphicsWidget::dragMoveEvent(ev);
+#else
+    Q_UNUSED(ev);
+#endif
+}
+
+/*! \reimp
+*/
+void QWebGraphicsItem::dropEvent(QGraphicsSceneDragDropEvent* ev)
+{
+#ifndef QT_NO_DRAGANDDROP
+    if (d->interactive && d->page) {
+        const bool accepted = ev->isAccepted();
+        d->page->event(ev);
+        ev->setAccepted(accepted);
+    }
+
+    if (!ev->isAccepted())
+        QGraphicsWidget::dropEvent(ev);
+#else
+    Q_UNUSED(ev);
+#endif
+}
+
+#ifndef QT_NO_CONTEXTMENU
+/*! \reimp
+*/
+void QWebGraphicsItem::contextMenuEvent(QContextMenuEvent* ev)
+{
+    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 QWebGraphicsItem::wheelEvent(QGraphicsSceneWheelEvent* ev)
+{
+    if (d->interactive && d->page) {
+        const bool accepted = ev->isAccepted();
+        d->page->event(ev);
+        ev->setAccepted(accepted);
+    }
+
+    if (!ev->isAccepted())
+        QGraphicsItem::wheelEvent(ev);
+}
+#endif // QT_NO_WHEELEVENT
+
+/*! \reimp
+*/
+void QWebGraphicsItem::inputMethodEvent(QInputMethodEvent* ev)
+{
+    if (d->interactive && d->page)
+        d->page->event(ev);
+
+    if (!ev->isAccepted())
+        QGraphicsItem::inputMethodEvent(ev);
+}
+
+#include "moc_qwebgraphicsitem.cpp"
diff --git a/WebKit/qt/Api/qwebgraphicsitem.h b/WebKit/qt/Api/qwebgraphicsitem.h
new file mode 100644 (file)
index 0000000..d41f552
--- /dev/null
@@ -0,0 +1,143 @@
+/*
+    Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies)
+
+    This library is free software; you can redistribute it and/or
+    modify it under the terms of the GNU Library General Public
+    License as published by the Free Software Foundation; either
+    version 2 of the License, or (at your option) any later version.
+
+    This library is distributed in the hope that it will be useful,
+    but WITHOUT ANY WARRANTY; without even the implied warranty of
+    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+    Library General Public License for more details.
+
+    You should have received a copy of the GNU Library General Public License
+    along with this library; see the file COPYING.LIB.  If not, write to
+    the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+    Boston, MA 02110-1301, USA.
+*/
+
+#ifndef QWebGraphicsItem_h
+#define QWebGraphicsItem_h
+
+#include "qwebkitglobal.h"
+#include <Qt/qevent.h>
+#include <QtCore/qurl.h>
+#include <QtGui/qgraphicswidget.h>
+#include <QtGui/qicon.h>
+#include <QtGui/qpainter.h>
+#include <QtNetwork/qnetworkaccessmanager.h>
+
+class QWebPage;
+class QWebHistory;
+class QWebSettings;
+
+class QWebGraphicsItemPrivate;
+
+class QWEBKIT_EXPORT QWebGraphicsItem : public QGraphicsWidget {
+    Q_OBJECT
+
+    Q_PROPERTY(QString title READ title NOTIFY titleChanged)
+    Q_PROPERTY(QIcon icon READ icon NOTIFY iconChanged)
+    Q_PROPERTY(qreal zoomFactor READ zoomFactor WRITE setZoomFactor NOTIFY zoomFactorChanged)
+    Q_PROPERTY(QString status READ status NOTIFY statusChanged)
+
+    Q_PROPERTY(QString html READ toHtml WRITE setHtml)
+    Q_PROPERTY(QUrl url READ url WRITE setUrl NOTIFY urlChanged)
+    Q_PROPERTY(qreal progress READ progress NOTIFY progressChanged)
+
+    Q_PROPERTY(bool interactive READ isInteractive WRITE setInteractive NOTIFY interactivityChanged)
+
+public:
+    QWebGraphicsItem(QGraphicsItem* parent = 0);
+    ~QWebGraphicsItem();
+
+    QWebPage* page() const;
+    void setPage(QWebPage*);
+
+    QUrl url() const;
+    void setUrl(const QUrl&);
+
+    QString title() const;
+    QIcon icon() const;
+
+    qreal zoomFactor() const;
+    void setZoomFactor(qreal);
+
+    bool isInteractive() const;
+    void setInteractive(bool);
+
+    qreal progress() const;
+
+    void load(const QUrl &url);
+    void load(const QNetworkRequest& request, QNetworkAccessManager::Operation operation = QNetworkAccessManager::GetOperation, const QByteArray& body = QByteArray());
+
+    QString toHtml() const;
+    void setHtml(const QString& html, const QUrl& baseUrl = QUrl());
+    // FIXME: Consider rename to setHtml?
+    void setContent(const QByteArray& data, const QString& mimeType = QString(), const QUrl& baseUrl = QUrl());
+
+    QWebHistory* history() const;
+    QWebSettings* settings() const;
+
+    QString status() const;
+
+    virtual void setGeometry(const QRectF& rect);
+    virtual void updateGeometry();
+    virtual void paint(QPainter*, const QStyleOptionGraphicsItem* options, QWidget* widget = 0);
+
+public Q_SLOTS:
+    void stop();
+    void back();
+    void forward();
+    void reload();
+
+Q_SIGNALS:
+    void loadStarted();
+    void loadFinished();
+    void loadFailed();
+
+    void progressChanged(qreal);
+    void interactivityChanged();
+    void urlChanged(const QUrl&);
+    void titleChanged(const QString&);
+    void iconChanged();
+    void statusChanged();
+    void zoomFactorChanged();
+
+protected:
+    virtual void mousePressEvent(QGraphicsSceneMouseEvent*);
+    virtual void mouseDoubleClickEvent(QGraphicsSceneMouseEvent*);
+    virtual void mouseReleaseEvent(QGraphicsSceneMouseEvent*);
+    virtual void mouseMoveEvent(QGraphicsSceneMouseEvent*);
+    virtual void hoverMoveEvent(QGraphicsSceneHoverEvent*);
+    virtual void hoverLeaveEvent(QGraphicsSceneHoverEvent*);
+#ifndef QT_NO_WHEELEVENT
+    virtual void wheelEvent(QGraphicsSceneWheelEvent*);
+#endif
+    virtual void keyPressEvent(QKeyEvent*);
+    virtual void keyReleaseEvent(QKeyEvent*);
+#ifndef QT_NO_CONTEXTMENU
+    virtual void contextMenuEvent(QContextMenuEvent*);
+#endif
+    virtual void dragEnterEvent(QGraphicsSceneDragDropEvent*);
+    virtual void dragLeaveEvent(QGraphicsSceneDragDropEvent*);
+    virtual void dragMoveEvent(QGraphicsSceneDragDropEvent*);
+    virtual void dropEvent(QGraphicsSceneDragDropEvent*);
+    virtual void focusInEvent(QFocusEvent*);
+    virtual void focusOutEvent(QFocusEvent*);
+    virtual void inputMethodEvent(QInputMethodEvent*);
+    virtual bool focusNextPrevChild(bool next);
+
+private:
+    Q_PRIVATE_SLOT(d, void _q_doScroll(int dx, int dy, const QRect&))
+    Q_PRIVATE_SLOT(d, void _q_doLoadProgress(int progress))
+    Q_PRIVATE_SLOT(d, void _q_doLoadFinished(bool success))
+    Q_PRIVATE_SLOT(d, void _q_doUpdate(const QRect& dirtyRect))
+    Q_PRIVATE_SLOT(d, void _q_setStatusBarMessage(const QString& message))
+
+    QWebGraphicsItemPrivate* const d;
+    friend class QWebGraphicsItemPrivate;
+};
+
+#endif // QWebGraphicsItem_h
index 24741a1..10c7938 100644 (file)
@@ -351,6 +351,7 @@ private:
     friend class QWebFrame;
     friend class QWebPagePrivate;
     friend class QWebView;
+    friend class QWebGraphicsItem;
     friend class WebCore::ChromeClientQt;
     friend class WebCore::EditorClientQt;
     friend class WebCore::FrameLoaderClientQt;
index d11907f..9717d96 100644 (file)
@@ -1,3 +1,24 @@
+2009-09-09  Kenneth Rohde Christiansen  <kenneth@webkit.org>, Antonio Gomes  <antonio.gomes@openbossa.org>
+
+        Reviewed by Simon Hausmann.
+
+        Add a new QGraphicsWidget based version of the "QWebView"
+        under the name "QWebGraphicsItem".
+
+        https://bugs.webkit.org/show_bug.cgi?id=28862
+
+        Includes an alternative Qt launcher using the QGraphicsView.
+
+        * Api/headers.pri:
+        * Api/qwebgraphicsitem.cpp: Added.
+        * Api/qwebgraphicsitem.h: Added.
+        * Api/qwebpage.h:
+        * QGVLauncher/QGVLauncher.pro: Copied from WebKit/qt/QtLauncher/QtLauncher.pro.
+        * QGVLauncher/main.cpp: Added.
+        * WebCoreSupport/ChromeClientQt.cpp:
+        (WebCore::ChromeClientQt::repaint):
+        (WebCore::ChromeClientQt::scroll):
+
 2009-09-08  Kenneth Rohde Christiansen  <kenneth@webkit.org>
 
         Unreviewed build fix.
diff --git a/WebKit/qt/QGVLauncher/QGVLauncher.pro b/WebKit/qt/QGVLauncher/QGVLauncher.pro
new file mode 100644 (file)
index 0000000..b883b52
--- /dev/null
@@ -0,0 +1,13 @@
+TEMPLATE = app
+SOURCES += main.cpp
+CONFIG -= app_bundle
+CONFIG += uitools
+DESTDIR = ../../../bin
+
+include(../../../WebKit.pri)
+
+QT += network
+macx:QT+=xml
+QMAKE_RPATHDIR = $$OUTPUT_DIR/lib $$QMAKE_RPATHDIR
+
+symbian:TARGET.UID3 = 0x200267D0
diff --git a/WebKit/qt/QGVLauncher/main.cpp b/WebKit/qt/QGVLauncher/main.cpp
new file mode 100644 (file)
index 0000000..4e2c45a
--- /dev/null
@@ -0,0 +1,297 @@
+/*
+ * Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies)
+ * Copyright (C) 2006 George Staikos <staikos@kde.org>
+ * Copyright (C) 2006 Dirk Mueller <mueller@kde.org>
+ * Copyright (C) 2006 Zack Rusin <zack@kde.org>
+ * Copyright (C) 2006 Simon Hausmann <hausmann@kde.org>
+ * Copyright (C) 2009 Kenneth Christiansen <kenneth@webkit.org>
+ * Copyright (C) 2009 Antonio Gomes <antonio.gomes@openbossa.org>
+ *
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY APPLE COMPUTER, INC. ``AS IS'' AND ANY
+ * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL APPLE COMPUTER, INC. OR
+ * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
+ * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
+ * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
+ * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
+ * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#include <QDebug>
+#include <QFile>
+#include <QGraphicsScene>
+#include <QGraphicsView>
+#include <QGraphicsWidget>
+#include <QNetworkRequest>
+#include <QTextStream>
+#include <QVector>
+#include <QtGui>
+#include <QtNetwork/QNetworkProxy>
+#include <cstdio>
+#include <qwebelement.h>
+#include <qwebframe.h>
+#include <qwebgraphicsitem.h>
+#include <qwebpage.h>
+#include <qwebsettings.h>
+#include <qwebview.h>
+
+class WebPage : public QWebPage {
+    Q_OBJECT
+
+public:
+    WebPage(QWidget* parent = 0) : QWebPage(parent)
+    {
+        applyProxy();
+    }
+    virtual QWebPage* createWindow(QWebPage::WebWindowType);
+
+private:
+    void applyProxy();
+};
+
+class MainView : public QGraphicsView {
+    Q_OBJECT
+
+public:
+    MainView(QWidget* parent) : QGraphicsView(parent), m_mainWidget(0)
+    {
+        setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
+        setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
+    }
+
+    void setMainWidget(QGraphicsWidget* widget)
+    {
+        QRectF rect(QRect(QPoint(0, 0), size()));
+        widget->setGeometry(rect);
+        m_mainWidget = widget;
+    }
+
+    void resizeEvent(QResizeEvent* event)
+    {
+        QGraphicsView::resizeEvent(event);
+        QRectF rect(QRect(QPoint(0, 0), event->size()));
+        if (!m_mainWidget)
+            return;
+        m_mainWidget->setGeometry(rect);
+    }
+
+private:
+    QGraphicsWidget* m_mainWidget;
+};
+
+class SharedScene : public QSharedData {
+public:
+    SharedScene()
+    {
+        m_scene = new QGraphicsScene;
+
+        m_item = new QWebGraphicsItem;
+        m_item->setPage(new WebPage());
+
+        m_scene->addItem(m_item);
+        m_scene->setActiveWindow(m_item);
+    }
+
+    ~SharedScene()
+    {
+        delete m_item;
+        delete m_scene;
+    }
+
+    QGraphicsScene* scene() const { return m_scene; }
+    QWebGraphicsItem* webItem() const { return m_item; }
+
+private:
+    QGraphicsScene* m_scene;
+    QWebGraphicsItem* m_item;
+};
+
+
+class MainWindow : public QMainWindow {
+    Q_OBJECT
+
+public:
+    MainWindow(QExplicitlySharedDataPointer<SharedScene> other)
+        : QMainWindow(), view(new MainView(this)), scene(other)
+    {
+        init();
+    }
+
+    MainWindow()
+        : QMainWindow(), view(new MainView(this)), scene(new SharedScene())
+    {
+        init();
+    }
+
+    void init()
+    {
+        setAttribute(Qt::WA_DeleteOnClose);
+
+        view->setScene(scene->scene());
+        view->setFrameShape(QFrame::NoFrame);
+        view->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding);
+        setCentralWidget(view);
+
+        view->setMainWidget(scene->webItem());
+
+        connect(scene->webItem(), SIGNAL(loadFinished()), this, SLOT(loadFinished()));
+        connect(scene->webItem(), SIGNAL(titleChanged(const QString&)), this, SLOT(setWindowTitle(const QString&)));
+        connect(scene->webItem()->page(), SIGNAL(windowCloseRequested()), this, SLOT(close()));
+
+        resize(640, 480);
+        buildUI();
+    }
+
+    void load(const QString& url)
+    {
+        QUrl deducedUrl = guessUrlFromString(url);
+        if (!deducedUrl.isValid())
+            deducedUrl = QUrl("http://" + url + "/");
+
+        urlEdit->setText(deducedUrl.toEncoded());
+        scene->webItem()->load(deducedUrl);
+        scene->webItem()->setFocus(Qt::OtherFocusReason);
+    }
+
+    QUrl guessUrlFromString(const QString& string)
+    {
+        QString input(string);
+        QFileInfo fi(input);
+        if (fi.exists() && fi.isRelative())
+            input = fi.absoluteFilePath();
+
+        return QWebView::guessUrlFromString(input);
+    }
+
+    QWebPage* page() const
+    {
+        return scene->webItem()->page();
+    }
+
+protected slots:
+    void changeLocation()
+    {
+        load(urlEdit->text());
+    }
+
+    void loadFinished()
+    {
+        QUrl url = scene->webItem()->url();
+        urlEdit->setText(url.toString());
+
+        QUrl::FormattingOptions opts;
+        opts |= QUrl::RemoveScheme;
+        opts |= QUrl::RemoveUserInfo;
+        opts |= QUrl::StripTrailingSlash;
+        QString s = url.toString(opts);
+        s = s.mid(2);
+        if (s.isEmpty())
+            return;
+        //FIXME: something missing here
+    }
+
+public slots:
+    void newWindow(const QString &url = QString())
+    {
+        MainWindow* mw = new MainWindow();
+        mw->load(url);
+        mw->show();
+    }
+
+    void clone()
+    {
+        MainWindow* mw = new MainWindow(scene);
+        mw->show();
+    }
+
+private:
+    void buildUI()
+    {
+        QWebPage* page = scene->webItem()->page();
+        urlEdit = new QLineEdit(this);
+        urlEdit->setSizePolicy(QSizePolicy::Expanding, urlEdit->sizePolicy().verticalPolicy());
+        connect(urlEdit, SIGNAL(returnPressed()), SLOT(changeLocation()));
+
+        QToolBar* bar = addToolBar("Navigation");
+        bar->addAction(page->action(QWebPage::Back));
+        bar->addAction(page->action(QWebPage::Forward));
+        bar->addAction(page->action(QWebPage::Reload));
+        bar->addAction(page->action(QWebPage::Stop));
+        bar->addWidget(urlEdit);
+
+        QMenu* fileMenu = menuBar()->addMenu("&File");
+        QAction* newWindow = fileMenu->addAction("New Window", this, SLOT(newWindow()));
+        QAction* cloneView = fileMenu->addAction("Clone view", this, SLOT(clone()));
+        fileMenu->addAction("Close", this, SLOT(close()));
+
+        QMenu* viewMenu = menuBar()->addMenu("&View");
+        viewMenu->addAction(page->action(QWebPage::Stop));
+        viewMenu->addAction(page->action(QWebPage::Reload));
+    }
+
+private:
+    MainView* view;
+    QExplicitlySharedDataPointer<SharedScene> scene;
+
+    QLineEdit* urlEdit;
+};
+
+QWebPage* WebPage::createWindow(QWebPage::WebWindowType)
+{
+    MainWindow* mw = new MainWindow;
+    mw->show();
+    return mw->page();
+}
+
+void WebPage::applyProxy()
+{
+    QUrl proxyUrl = QWebView::guessUrlFromString(qgetenv("http_proxy"));
+
+    if (proxyUrl.isValid() && !proxyUrl.host().isEmpty()) {
+        int proxyPort = (proxyUrl.port() > 0) ? proxyUrl.port() : 8080;
+        networkAccessManager()->setProxy(QNetworkProxy(QNetworkProxy::HttpProxy, proxyUrl.host(), proxyPort));
+    }
+}
+
+int main(int argc, char** argv)
+{
+    QApplication app(argc, argv);
+    QString url = QString("file://%1/%2").arg(QDir::homePath()).arg(QLatin1String("index.html"));
+
+    app.setApplicationName("GQVLauncher");
+
+    QWebSettings::setObjectCacheCapacities((16 * 1024 * 1024) / 8, (16 * 1024 * 1024) / 8, 16 * 1024 * 1024);
+    QWebSettings::setMaximumPagesInCache(4);
+    QWebSettings::globalSettings()->setAttribute(QWebSettings::PluginsEnabled, true);
+    QWebSettings::globalSettings()->setAttribute(QWebSettings::DeveloperExtrasEnabled, true);
+    QWebSettings::globalSettings()->setAttribute(QWebSettings::LocalStorageEnabled, true);
+
+    const QStringList args = app.arguments();
+    if (args.count() > 1)
+        url = args.at(1);
+
+    MainWindow* window = new MainWindow;
+    window->load(url);
+
+    for (int i = 2; i < args.count(); i++)
+        window->newWindow(args.at(i));
+
+    window->show();
+    return app.exec();
+}
+
+#include "main.moc"
index d659833..e79ae55 100644 (file)
@@ -45,6 +45,7 @@
 #include "qwebframe_p.h"
 #include "qwebsecurityorigin.h"
 #include "qwebsecurityorigin_p.h"
+#include "qwebview.h"
 
 #include <qtooltip.h>
 #include <qtextdocument.h>
@@ -307,8 +308,8 @@ void ChromeClientQt::repaint(const IntRect& windowRect, bool contentChanged, boo
 {
     // No double buffer, so only update the QWidget if content changed.
     if (contentChanged) {
-        QWidget* view = m_webPage->view();
-        if (view) {
+        // Only do implicit paints for QWebView's
+        if (QWebView* view = qobject_cast<QWebView*>(m_webPage->view())) {
             QRect rect(windowRect);
             rect = rect.intersected(QRect(QPoint(0, 0), m_webPage->viewportSize()));
             if (!rect.isEmpty())
@@ -323,8 +324,8 @@ void ChromeClientQt::repaint(const IntRect& windowRect, bool contentChanged, boo
 
 void ChromeClientQt::scroll(const IntSize& delta, const IntRect& scrollViewRect, const IntRect&)
 {
-    QWidget* view = m_webPage->view();
-    if (view)
+    // Only do implicit paints for QWebView's
+    if (QWebView* view = qobject_cast<QWebView*>(m_webPage->view()))
         view->scroll(delta.width(), delta.height(), scrollViewRect);
     emit m_webPage->scrollRequested(delta.width(), delta.height(), scrollViewRect);
 }