qgraphicswebview.cpp [plain text]
#include "config.h"
#include "qgraphicswebview.h"
#include "qwebframe.h"
#include "qwebframe_p.h"
#include "qwebpage.h"
#include "qwebpage_p.h"
#include "QWebPageClient.h"
#include "FrameView.h"
#include "GraphicsContext.h"
#include "IntRect.h"
#include "TiledBackingStore.h"
#include <QtCore/qmetaobject.h>
#include <QtCore/qsharedpointer.h>
#include <QtCore/qtimer.h>
#include <QtGui/qapplication.h>
#include <QtGui/qgraphicsscene.h>
#include <QtGui/qgraphicssceneevent.h>
#include <QtGui/qgraphicsview.h>
#include <QtGui/qpixmapcache.h>
#include <QtGui/qscrollbar.h>
#include <QtGui/qstyleoption.h>
#include <QtGui/qinputcontext.h>
#if defined(Q_WS_X11)
#include <QX11Info>
#endif
#include <Settings.h>
class QGraphicsWebViewOverlay : public QGraphicsItem {
public:
QGraphicsWebViewOverlay(QGraphicsWebView* view)
:QGraphicsItem(view)
, q(view)
{
setPos(0, 0);
#if QT_VERSION >= QT_VERSION_CHECK(4, 6, 0)
setFlag(QGraphicsItem::ItemUsesExtendedStyleOption, true);
#endif
setCacheMode(QGraphicsItem::DeviceCoordinateCache);
}
QRectF boundingRect() const
{
return q->boundingRect();
}
void paint(QPainter* painter, const QStyleOptionGraphicsItem* options, QWidget*)
{
q->page()->mainFrame()->render(painter, static_cast<QWebFrame::RenderLayer>(QWebFrame::AllLayers&(~QWebFrame::ContentsLayer)), options->exposedRect.toRect());
}
friend class QGraphicsWebView;
QGraphicsWebView* q;
};
class QGraphicsWebViewPrivate : public QWebPageClient {
public:
QGraphicsWebViewPrivate(QGraphicsWebView* parent)
: q(parent)
, page(0)
, resizesToContents(false)
#if USE(ACCELERATED_COMPOSITING)
, rootGraphicsLayer(0)
, shouldSync(false)
#endif
{
#if USE(ACCELERATED_COMPOSITING)
q->setFlag(QGraphicsItem::ItemUsesExtendedStyleOption);
syncMetaMethod = q->metaObject()->method(q->metaObject()->indexOfMethod("syncLayers()"));
#endif
}
virtual ~QGraphicsWebViewPrivate();
virtual void scroll(int dx, int dy, const QRect&);
virtual void update(const QRect& dirtyRect);
virtual void setInputMethodEnabled(bool enable);
virtual bool inputMethodEnabled() const;
#if QT_VERSION >= 0x040600
virtual void setInputMethodHint(Qt::InputMethodHint hint, bool enable);
#endif
#ifndef QT_NO_CURSOR
virtual QCursor cursor() const;
virtual void updateCursor(const QCursor& cursor);
#endif
virtual QPalette palette() const;
virtual int screenNumber() const;
virtual QWidget* ownerWidget() const;
virtual QRect geometryRelativeToOwnerWidget() const;
virtual QObject* pluginParent() const;
virtual QStyle* style() const;
#if USE(ACCELERATED_COMPOSITING)
virtual void setRootGraphicsLayer(QGraphicsItem* layer);
virtual void markForSync(bool scheduleSync);
void updateCompositingScrollPosition();
virtual bool allowsAcceleratedCompositing() const { return true; }
#endif
void updateResizesToContentsForPage();
QRectF graphicsItemVisibleRect() const;
#if ENABLE(TILED_BACKING_STORE)
void updateTiledBackingStoreScale();
#endif
void createOrDeleteOverlay();
void syncLayers();
void unsetPageIfExists();
void _q_doLoadFinished(bool success);
void _q_contentsSizeChanged(const QSize&);
void _q_scaleChanged();
void _q_updateMicroFocus();
void _q_pageDestroyed();
QGraphicsWebView* q;
QWebPage* page;
bool resizesToContents;
QSharedPointer<QGraphicsWebViewOverlay> overlay;
enum { RootGraphicsLayerZValue, OverlayZValue };
#if USE(ACCELERATED_COMPOSITING)
QGraphicsItem* rootGraphicsLayer;
bool shouldSync;
QMetaMethod syncMetaMethod;
#endif
};
QGraphicsWebViewPrivate::~QGraphicsWebViewPrivate()
{
#if USE(ACCELERATED_COMPOSITING)
if (rootGraphicsLayer) {
rootGraphicsLayer->setParentItem(0);
q->scene()->removeItem(rootGraphicsLayer);
}
#endif
}
void QGraphicsWebViewPrivate::createOrDeleteOverlay()
{
bool useOverlay = false;
if (!resizesToContents) {
#if USE(ACCELERATED_COMPOSITING)
useOverlay = useOverlay || rootGraphicsLayer;
#endif
#if ENABLE(TILED_BACKING_STORE)
useOverlay = useOverlay || QWebFramePrivate::core(q->page()->mainFrame())->tiledBackingStore();
#endif
}
if (useOverlay == !!overlay)
return;
if (useOverlay) {
overlay = QSharedPointer<QGraphicsWebViewOverlay>(new QGraphicsWebViewOverlay(q));
overlay->setZValue(OverlayZValue);
} else
overlay.clear();
}
#if USE(ACCELERATED_COMPOSITING)
void QGraphicsWebViewPrivate::setRootGraphicsLayer(QGraphicsItem* layer)
{
if (rootGraphicsLayer) {
rootGraphicsLayer->setParentItem(0);
q->scene()->removeItem(rootGraphicsLayer);
QWebFramePrivate::core(q->page()->mainFrame())->view()->syncCompositingStateRecursive();
}
rootGraphicsLayer = layer;
if (layer) {
layer->setFlag(QGraphicsItem::ItemClipsChildrenToShape, true);
layer->setParentItem(q);
layer->setZValue(RootGraphicsLayerZValue);
updateCompositingScrollPosition();
}
createOrDeleteOverlay();
}
void QGraphicsWebViewPrivate::markForSync(bool scheduleSync)
{
shouldSync = true;
if (scheduleSync)
syncMetaMethod.invoke(q, Qt::QueuedConnection);
}
void QGraphicsWebViewPrivate::updateCompositingScrollPosition()
{
if (rootGraphicsLayer && q->page() && q->page()->mainFrame()) {
const QPoint scrollPosition = q->page()->mainFrame()->scrollPosition();
rootGraphicsLayer->setPos(-scrollPosition);
}
}
#endif
void QGraphicsWebViewPrivate::syncLayers()
{
#if USE(ACCELERATED_COMPOSITING)
if (shouldSync) {
QWebFramePrivate::core(q->page()->mainFrame())->view()->syncCompositingStateRecursive();
shouldSync = false;
}
#endif
}
void QGraphicsWebViewPrivate::_q_doLoadFinished(bool success)
{
if (q->title().isEmpty())
emit q->urlChanged(q->url());
emit q->loadFinished(success);
}
void QGraphicsWebViewPrivate::_q_updateMicroFocus()
{
#if !defined(QT_NO_IM) && (defined(Q_WS_X11) || defined(Q_WS_QWS) || defined(Q_OS_SYMBIAN))
QList<QGraphicsView*> views = q->scene()->views();
for (int c = 0; c < views.size(); ++c) {
QInputContext* ic = views.at(c)->inputContext();
if (ic)
ic->update();
}
#endif
}
void QGraphicsWebViewPrivate::_q_pageDestroyed()
{
page = 0;
q->setPage(0);
}
void QGraphicsWebViewPrivate::scroll(int dx, int dy, const QRect& rectToScroll)
{
q->scroll(qreal(dx), qreal(dy), QRectF(rectToScroll));
#if USE(ACCELERATED_COMPOSITING)
updateCompositingScrollPosition();
#endif
}
void QGraphicsWebViewPrivate::update(const QRect & dirtyRect)
{
q->update(QRectF(dirtyRect));
createOrDeleteOverlay();
if (overlay)
overlay->update(QRectF(dirtyRect));
#if USE(ACCELERATED_COMPOSITING)
updateCompositingScrollPosition();
syncLayers();
#endif
}
void QGraphicsWebViewPrivate::setInputMethodEnabled(bool enable)
{
#if QT_VERSION >= QT_VERSION_CHECK(4, 6, 0)
q->setFlag(QGraphicsItem::ItemAcceptsInputMethod, enable);
#endif
}
bool QGraphicsWebViewPrivate::inputMethodEnabled() const
{
#if QT_VERSION >= QT_VERSION_CHECK(4, 6, 0)
return q->flags() & QGraphicsItem::ItemAcceptsInputMethod;
#else
return false;
#endif
}
#if QT_VERSION >= 0x040600
void QGraphicsWebViewPrivate::setInputMethodHint(Qt::InputMethodHint hint, bool enable)
{
if (enable)
q->setInputMethodHints(q->inputMethodHints() | hint);
else
q->setInputMethodHints(q->inputMethodHints() & ~hint);
}
#endif
#ifndef QT_NO_CURSOR
QCursor QGraphicsWebViewPrivate::cursor() const
{
return q->cursor();
}
void QGraphicsWebViewPrivate::updateCursor(const QCursor& cursor)
{
q->setCursor(cursor);
}
#endif
QPalette QGraphicsWebViewPrivate::palette() const
{
return q->palette();
}
int QGraphicsWebViewPrivate::screenNumber() const
{
#if defined(Q_WS_X11)
if (QGraphicsScene* scene = q->scene()) {
const QList<QGraphicsView*> views = scene->views();
if (!views.isEmpty())
return views.at(0)->x11Info().screen();
}
#endif
return 0;
}
QWidget* QGraphicsWebViewPrivate::ownerWidget() const
{
if (QGraphicsScene* scene = q->scene()) {
const QList<QGraphicsView*> views = scene->views();
return views.value(0);
}
return 0;
}
QRect QGraphicsWebViewPrivate::geometryRelativeToOwnerWidget() const
{
if (!q->scene())
return QRect();
QList<QGraphicsView*> views = q->scene()->views();
if (views.isEmpty())
return QRect();
QGraphicsView* view = views.at(0);
return view->mapFromScene(q->boundingRect()).boundingRect();
}
QObject* QGraphicsWebViewPrivate::pluginParent() const
{
return q;
}
QStyle* QGraphicsWebViewPrivate::style() const
{
return q->style();
}
void QGraphicsWebViewPrivate::updateResizesToContentsForPage()
{
ASSERT(page);
if (resizesToContents) {
if (!page->preferredContentsSize().isValid())
page->setPreferredContentsSize(QSize(960, 800));
#if QT_VERSION >= QT_VERSION_CHECK(4, 6, 0)
QObject::connect(page->mainFrame(), SIGNAL(contentsSizeChanged(QSize)),
q, SLOT(_q_contentsSizeChanged(const QSize&)), Qt::UniqueConnection);
#else
QObject::connect(page->mainFrame(), SIGNAL(contentsSizeChanged(QSize)),
q, SLOT(_q_contentsSizeChanged(const QSize&)));
#endif
} else {
QObject::disconnect(page->mainFrame(), SIGNAL(contentsSizeChanged(QSize)),
q, SLOT(_q_contentsSizeChanged(const QSize&)));
}
}
void QGraphicsWebViewPrivate::_q_contentsSizeChanged(const QSize& size)
{
if (!resizesToContents)
return;
q->setGeometry(QRectF(q->geometry().topLeft(), size));
}
void QGraphicsWebViewPrivate::_q_scaleChanged()
{
#if ENABLE(TILED_BACKING_STORE)
updateTiledBackingStoreScale();
#endif
}
QRectF QGraphicsWebViewPrivate::graphicsItemVisibleRect() const
{
if (!q->scene())
return QRectF();
QList<QGraphicsView*> views = q->scene()->views();
if (views.size() > 1) {
#ifndef QT_NO_DEBUG_STREAM
qDebug() << "QGraphicsWebView is in more than one graphics views, unable to compute the visible rect";
#endif
return QRectF();
}
if (views.size() < 1)
return QRectF();
int xPosition = views[0]->horizontalScrollBar()->value();
int yPosition = views[0]->verticalScrollBar()->value();
return q->mapRectFromScene(QRectF(QPoint(xPosition, yPosition), views[0]->viewport()->size()));
}
#if ENABLE(TILED_BACKING_STORE)
void QGraphicsWebViewPrivate::updateTiledBackingStoreScale()
{
WebCore::TiledBackingStore* backingStore = QWebFramePrivate::core(page->mainFrame())->tiledBackingStore();
if (!backingStore)
return;
backingStore->setContentsScale(q->scale());
}
#endif
QGraphicsWebView::QGraphicsWebView(QGraphicsItem* parent)
: QGraphicsWidget(parent)
, d(new QGraphicsWebViewPrivate(this))
{
#if QT_VERSION >= 0x040600
setFlag(QGraphicsItem::ItemUsesExtendedStyleOption, true);
#endif
setAcceptDrops(true);
setAcceptHoverEvents(true);
#if QT_VERSION >= QT_VERSION_CHECK(4, 6, 0)
setAcceptTouchEvents(true);
#endif
setFocusPolicy(Qt::StrongFocus);
setFlag(QGraphicsItem::ItemClipsChildrenToShape, true);
#if ENABLE(TILED_BACKING_STORE)
QObject::connect(this, SIGNAL(scaleChanged()), this, SLOT(_q_scaleChanged()));
#endif
}
QGraphicsWebView::~QGraphicsWebView()
{
if (d->page) {
#if QT_VERSION >= 0x040600
d->page->d->view.clear();
#else
d->page->d->view = 0;
#endif
d->page->d->client = 0; }
if (d->page && d->page->parent() == this)
delete d->page;
delete d;
}
QWebPage* QGraphicsWebView::page() const
{
if (!d->page) {
QGraphicsWebView* that = const_cast<QGraphicsWebView*>(this);
QWebPage* page = new QWebPage(that);
QPalette palette = QApplication::palette();
palette.setBrush(QPalette::Base, QColor::fromRgbF(0, 0, 0, 0));
page->setPalette(palette);
that->setPage(page);
}
return d->page;
}
void QGraphicsWebView::paint(QPainter* painter, const QStyleOptionGraphicsItem* option, QWidget*)
{
#if ENABLE(TILED_BACKING_STORE)
if (WebCore::TiledBackingStore* backingStore = QWebFramePrivate::core(page()->mainFrame())->tiledBackingStore()) {
if (d->resizesToContents)
backingStore->viewportChanged(WebCore::IntRect(d->graphicsItemVisibleRect()));
else {
QRectF visibleRect(d->page->mainFrame()->scrollPosition(), d->page->mainFrame()->geometry().size());
backingStore->viewportChanged(WebCore::IntRect(visibleRect));
}
WebCore::GraphicsContext context(painter);
page()->mainFrame()->d->renderFromTiledBackingStore(&context, option->exposedRect.toAlignedRect());
return;
}
#endif
#if USE(ACCELERATED_COMPOSITING)
page()->mainFrame()->render(painter, d->overlay ? QWebFrame::ContentsLayer : QWebFrame::AllLayers, option->exposedRect.toAlignedRect());
#else
page()->mainFrame()->render(painter, QWebFrame::AllLayers, option->exposedRect.toRect());
#endif
}
bool QGraphicsWebView::sceneEvent(QEvent* event)
{
#if QT_VERSION >= QT_VERSION_CHECK(4, 6, 0)
if (d->page && (event->type() == QEvent::TouchBegin
|| event->type() == QEvent::TouchEnd
|| event->type() == QEvent::TouchUpdate)) {
d->page->event(event);
if (event->isAccepted())
return true;
}
#endif
return QGraphicsWidget::sceneEvent(event);
}
QVariant QGraphicsWebView::itemChange(GraphicsItemChange change, const QVariant& value)
{
switch (change) {
case ItemCursorChange:
return value;
case ItemCursorHasChanged: {
QEvent event(QEvent::CursorChange);
QApplication::sendEvent(this, &event);
return value;
}
default:
break;
}
return QGraphicsWidget::itemChange(change, value);
}
QSizeF QGraphicsWebView::sizeHint(Qt::SizeHint which, const QSizeF& constraint) const
{
if (which == Qt::PreferredSize)
return QSizeF(800, 600); return QGraphicsWidget::sizeHint(which, constraint);
}
QVariant QGraphicsWebView::inputMethodQuery(Qt::InputMethodQuery query) const
{
if (d->page)
return d->page->inputMethodQuery(query);
return QVariant();
}
bool QGraphicsWebView::event(QEvent* event)
{
if (d->page) {
#ifndef QT_NO_CONTEXTMENU
if (event->type() == QEvent::GraphicsSceneContextMenu) {
if (!isEnabled())
return false;
QGraphicsSceneContextMenuEvent* ev = static_cast<QGraphicsSceneContextMenuEvent*>(event);
QContextMenuEvent fakeEvent(QContextMenuEvent::Reason(ev->reason()), ev->pos().toPoint());
if (d->page->swallowContextMenuEvent(&fakeEvent)) {
event->accept();
return true;
}
d->page->updatePositionDependentActions(fakeEvent.pos());
} else
#endif // QT_NO_CONTEXTMENU
{
#ifndef QT_NO_CURSOR
if (event->type() == QEvent::CursorChange) {
if (cursor().shape() == Qt::ArrowCursor)
d->resetCursor();
}
#endif
}
}
return QGraphicsWidget::event(event);
}
void QGraphicsWebViewPrivate::unsetPageIfExists()
{
if (!page)
return;
if (page->d->client && page->d->client->isQWidgetClient())
delete page->d->client;
page->d->client = 0;
if (page->parent() == q)
delete page;
else
page->disconnect(q);
}
void QGraphicsWebView::setPage(QWebPage* page)
{
if (d->page == page)
return;
d->unsetPageIfExists();
d->page = page;
if (!d->page)
return;
d->page->d->client = d;
if (d->overlay)
d->overlay->prepareGeometryChange();
QSize size = geometry().size().toSize();
page->setViewportSize(size);
if (d->resizesToContents)
d->updateResizesToContentsForPage();
QWebFrame* mainFrame = d->page->mainFrame();
connect(mainFrame, SIGNAL(titleChanged(QString)),
this, SIGNAL(titleChanged(QString)));
connect(mainFrame, SIGNAL(iconChanged()),
this, SIGNAL(iconChanged()));
connect(mainFrame, SIGNAL(urlChanged(QUrl)),
this, SIGNAL(urlChanged(QUrl)));
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, SLOT(_q_doLoadFinished(bool)));
connect(d->page, SIGNAL(statusBarMessage(QString)),
this, SIGNAL(statusBarMessage(QString)));
connect(d->page, SIGNAL(linkClicked(QUrl)),
this, SIGNAL(linkClicked(QUrl)));
connect(d->page, SIGNAL(microFocusChanged()),
this, SLOT(_q_updateMicroFocus()));
connect(d->page, SIGNAL(destroyed()),
this, SLOT(_q_pageDestroyed()));
}
void QGraphicsWebView::setUrl(const QUrl &url)
{
page()->mainFrame()->setUrl(url);
}
QUrl QGraphicsWebView::url() const
{
if (d->page)
return d->page->mainFrame()->url();
return QUrl();
}
QString QGraphicsWebView::title() const
{
if (d->page)
return d->page->mainFrame()->title();
return QString();
}
QIcon QGraphicsWebView::icon() const
{
if (d->page)
return d->page->mainFrame()->icon();
return QIcon();
}
void QGraphicsWebView::setZoomFactor(qreal factor)
{
if (factor == page()->mainFrame()->zoomFactor())
return;
page()->mainFrame()->setZoomFactor(factor);
}
qreal QGraphicsWebView::zoomFactor() const
{
return page()->mainFrame()->zoomFactor();
}
void QGraphicsWebView::updateGeometry()
{
if (d->overlay)
d->overlay->prepareGeometryChange();
QGraphicsWidget::updateGeometry();
if (!d->page)
return;
QSize size = geometry().size().toSize();
d->page->setViewportSize(size);
}
void QGraphicsWebView::setGeometry(const QRectF& rect)
{
QGraphicsWidget::setGeometry(rect);
if (d->overlay)
d->overlay->prepareGeometryChange();
if (!d->page)
return;
QSize size = geometry().size().toSize();
d->page->setViewportSize(size);
}
void QGraphicsWebView::stop()
{
if (d->page)
d->page->triggerAction(QWebPage::Stop);
}
void QGraphicsWebView::back()
{
if (d->page)
d->page->triggerAction(QWebPage::Back);
}
void QGraphicsWebView::forward()
{
if (d->page)
d->page->triggerAction(QWebPage::Forward);
}
void QGraphicsWebView::reload()
{
if (d->page)
d->page->triggerAction(QWebPage::Reload);
}
void QGraphicsWebView::load(const QUrl& url)
{
page()->mainFrame()->load(url);
}
void QGraphicsWebView::load(const QNetworkRequest& request,
QNetworkAccessManager::Operation operation,
const QByteArray& body)
{
page()->mainFrame()->load(request, operation, body);
}
void QGraphicsWebView::setHtml(const QString& html, const QUrl& baseUrl)
{
page()->mainFrame()->setHtml(html, baseUrl);
}
void QGraphicsWebView::setContent(const QByteArray& data, const QString& mimeType, const QUrl& baseUrl)
{
page()->mainFrame()->setContent(data, mimeType, baseUrl);
}
QWebHistory* QGraphicsWebView::history() const
{
return page()->history();
}
bool QGraphicsWebView::isModified() const
{
if (d->page)
return d->page->isModified();
return false;
}
QWebSettings* QGraphicsWebView::settings() const
{
return page()->settings();
}
QAction *QGraphicsWebView::pageAction(QWebPage::WebAction action) const
{
#ifdef QT_NO_ACTION
Q_UNUSED(action)
return 0;
#else
return page()->action(action);
#endif
}
void QGraphicsWebView::triggerPageAction(QWebPage::WebAction action, bool checked)
{
page()->triggerAction(action, checked);
}
bool QGraphicsWebView::findText(const QString &subString, QWebPage::FindFlags options)
{
if (d->page)
return d->page->findText(subString, options);
return false;
}
void QGraphicsWebView::setResizesToContents(bool enabled)
{
if (d->resizesToContents == enabled)
return;
d->resizesToContents = enabled;
if (d->page)
d->updateResizesToContentsForPage();
}
bool QGraphicsWebView::resizesToContents() const
{
return d->resizesToContents;
}
bool QGraphicsWebView::isTiledBackingStoreFrozen() const
{
#if ENABLE(TILED_BACKING_STORE)
WebCore::TiledBackingStore* backingStore = QWebFramePrivate::core(page()->mainFrame())->tiledBackingStore();
if (!backingStore)
return false;
return backingStore->contentsFrozen();
#else
return false;
#endif
}
void QGraphicsWebView::setTiledBackingStoreFrozen(bool frozen)
{
#if ENABLE(TILED_BACKING_STORE)
WebCore::TiledBackingStore* backingStore = QWebFramePrivate::core(page()->mainFrame())->tiledBackingStore();
if (!backingStore)
return;
backingStore->setContentsFrozen(frozen);
#else
UNUSED_PARAM(frozen);
#endif
}
void QGraphicsWebView::hoverMoveEvent(QGraphicsSceneHoverEvent* ev)
{
if (d->page) {
const bool accepted = ev->isAccepted();
QMouseEvent me = QMouseEvent(QEvent::MouseMove,
ev->pos().toPoint(), Qt::NoButton,
Qt::NoButton, Qt::NoModifier);
d->page->event(&me);
ev->setAccepted(accepted);
}
if (!ev->isAccepted())
QGraphicsItem::hoverMoveEvent(ev);
}
void QGraphicsWebView::hoverLeaveEvent(QGraphicsSceneHoverEvent* ev)
{
Q_UNUSED(ev);
}
void QGraphicsWebView::mouseMoveEvent(QGraphicsSceneMouseEvent* ev)
{
if (d->page) {
const bool accepted = ev->isAccepted();
d->page->event(ev);
ev->setAccepted(accepted);
}
if (!ev->isAccepted())
QGraphicsItem::mouseMoveEvent(ev);
}
void QGraphicsWebView::mousePressEvent(QGraphicsSceneMouseEvent* ev)
{
if (d->page) {
const bool accepted = ev->isAccepted();
d->page->event(ev);
ev->setAccepted(accepted);
}
if (!ev->isAccepted())
QGraphicsItem::mousePressEvent(ev);
}
void QGraphicsWebView::mouseReleaseEvent(QGraphicsSceneMouseEvent* ev)
{
if (d->page) {
const bool accepted = ev->isAccepted();
d->page->event(ev);
ev->setAccepted(accepted);
}
if (!ev->isAccepted())
QGraphicsItem::mouseReleaseEvent(ev);
}
void QGraphicsWebView::mouseDoubleClickEvent(QGraphicsSceneMouseEvent* ev)
{
if (d->page) {
const bool accepted = ev->isAccepted();
d->page->event(ev);
ev->setAccepted(accepted);
}
if (!ev->isAccepted())
QGraphicsItem::mouseDoubleClickEvent(ev);
}
void QGraphicsWebView::keyPressEvent(QKeyEvent* ev)
{
if (d->page)
d->page->event(ev);
if (!ev->isAccepted())
QGraphicsItem::keyPressEvent(ev);
}
void QGraphicsWebView::keyReleaseEvent(QKeyEvent* ev)
{
if (d->page)
d->page->event(ev);
if (!ev->isAccepted())
QGraphicsItem::keyReleaseEvent(ev);
}
void QGraphicsWebView::focusInEvent(QFocusEvent* ev)
{
if (d->page)
d->page->event(ev);
else
QGraphicsItem::focusInEvent(ev);
}
void QGraphicsWebView::focusOutEvent(QFocusEvent* ev)
{
if (d->page)
d->page->event(ev);
else
QGraphicsItem::focusOutEvent(ev);
}
bool QGraphicsWebView::focusNextPrevChild(bool next)
{
if (d->page)
return d->page->focusNextPrevChild(next);
return QGraphicsWidget::focusNextPrevChild(next);
}
void QGraphicsWebView::dragEnterEvent(QGraphicsSceneDragDropEvent* ev)
{
#ifndef QT_NO_DRAGANDDROP
if (d->page)
d->page->event(ev);
#else
Q_UNUSED(ev);
#endif
}
void QGraphicsWebView::dragLeaveEvent(QGraphicsSceneDragDropEvent* ev)
{
#ifndef QT_NO_DRAGANDDROP
if (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
}
void QGraphicsWebView::dragMoveEvent(QGraphicsSceneDragDropEvent* ev)
{
#ifndef QT_NO_DRAGANDDROP
if (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
}
void QGraphicsWebView::dropEvent(QGraphicsSceneDragDropEvent* ev)
{
#ifndef QT_NO_DRAGANDDROP
if (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
void QGraphicsWebView::contextMenuEvent(QGraphicsSceneContextMenuEvent* ev)
{
if (d->page) {
const bool accepted = ev->isAccepted();
d->page->event(ev);
ev->setAccepted(accepted);
}
}
#endif // QT_NO_CONTEXTMENU
#ifndef QT_NO_WHEELEVENT
void QGraphicsWebView::wheelEvent(QGraphicsSceneWheelEvent* ev)
{
if (d->page) {
const bool accepted = ev->isAccepted();
d->page->event(ev);
ev->setAccepted(accepted);
}
if (!ev->isAccepted())
QGraphicsItem::wheelEvent(ev);
}
#endif // QT_NO_WHEELEVENT
void QGraphicsWebView::inputMethodEvent(QInputMethodEvent* ev)
{
if (d->page)
d->page->event(ev);
if (!ev->isAccepted())
QGraphicsItem::inputMethodEvent(ev);
}
#include "moc_qgraphicswebview.cpp"