2 Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies)
3 Copyright (C) 2009 Girish Ramakrishnan <girish@forwardbias.in>
5 This library is free software; you can redistribute it and/or
6 modify it under the terms of the GNU Library General Public
7 License as published by the Free Software Foundation; either
8 version 2 of the License, or (at your option) any later version.
10 This library is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 Library General Public License for more details.
15 You should have received a copy of the GNU Library General Public License
16 along with this library; see the file COPYING.LIB. If not, write to
17 the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
18 Boston, MA 02110-1301, USA.
22 #include "qgraphicswebview.h"
24 #if !defined(QT_NO_GRAPHICSVIEW)
26 #include "qwebframe.h"
27 #include "qwebframe_p.h"
29 #include "qwebpage_p.h"
31 #include "PageClientQt.h"
33 #include "FrameView.h"
34 #include "GraphicsContext.h"
36 #include "TiledBackingStore.h"
37 #include <QtCore/qmetaobject.h>
38 #include <QtCore/qsharedpointer.h>
39 #include <QtCore/qtimer.h>
40 #include <QtGui/qapplication.h>
41 #include <QtGui/qgraphicsscene.h>
42 #include <QtGui/qgraphicssceneevent.h>
43 #include <QtGui/qgraphicsview.h>
44 #include <QtGui/qpixmapcache.h>
45 #include <QtGui/qscrollbar.h>
46 #include <QtGui/qstyleoption.h>
47 #include <QtGui/qinputcontext.h>
53 using namespace WebCore;
55 class QGraphicsWebViewPrivate {
57 QGraphicsWebViewPrivate(QGraphicsWebView* parent)
60 , resizesToContents(false)
61 , renderHints(QPainter::TextAntialiasing | QPainter::SmoothPixmapTransform) {}
63 virtual ~QGraphicsWebViewPrivate();
67 void updateResizesToContentsForPage();
69 void detachCurrentPage();
71 void _q_doLoadFinished(bool success);
72 void _q_contentsSizeChanged(const QSize&);
73 void _q_scaleChanged();
75 void _q_pageDestroyed();
79 bool resizesToContents;
80 QPainter::RenderHints renderHints;
82 QGraphicsItemOverlay* overlay() const
84 if (!page || !page->d->client)
86 return pageClient()->overlay;
89 PageClientQGraphicsWidget* pageClient() const
91 return static_cast<WebCore::PageClientQGraphicsWidget*> (page->d->client.get());
95 QGraphicsWebViewPrivate::~QGraphicsWebViewPrivate()
100 void QGraphicsWebViewPrivate::syncLayers()
102 #if USE(ACCELERATED_COMPOSITING)
103 pageClient()->syncLayers();
107 void QGraphicsWebViewPrivate::_q_doLoadFinished(bool success)
109 // If the page had no title, still make sure it gets the signal
110 if (q->title().isEmpty())
111 emit q->urlChanged(q->url());
113 emit q->loadFinished(success);
116 void QGraphicsWebViewPrivate::_q_pageDestroyed()
122 void QGraphicsWebViewPrivate::updateResizesToContentsForPage()
125 pageClient()->viewResizesToContents = resizesToContents;
126 if (resizesToContents) {
127 // resizes to contents mode requires preferred contents size to be set
128 if (!page->preferredContentsSize().isValid())
129 page->setPreferredContentsSize(QSize(960, 800));
131 QObject::connect(page->mainFrame(), SIGNAL(contentsSizeChanged(QSize)),
132 q, SLOT(_q_contentsSizeChanged(const QSize&)), Qt::UniqueConnection);
134 QObject::disconnect(page->mainFrame(), SIGNAL(contentsSizeChanged(QSize)),
135 q, SLOT(_q_contentsSizeChanged(const QSize&)));
137 page->d->page->mainFrame()->view()->setPaintsEntireContents(resizesToContents);
138 page->d->page->mainFrame()->view()->setDelegatesScrolling(resizesToContents);
141 void QGraphicsWebViewPrivate::_q_contentsSizeChanged(const QSize& size)
143 if (!resizesToContents)
145 q->setGeometry(QRectF(q->geometry().topLeft(), size));
148 void QGraphicsWebViewPrivate::_q_scaleChanged()
150 #if ENABLE(TILED_BACKING_STORE)
153 pageClient()->updateTiledBackingStoreScale();
158 \class QGraphicsWebView
159 \brief The QGraphicsWebView class allows Web content to be added to a GraphicsView.
162 An instance of this class renders Web content from a URL or supplied as data, using
163 features of the QtWebKit module.
165 If the width and height of the item are not set, they will default to 800 and 600,
166 respectively. If the Web page contents is larger than that, scrollbars will be shown
167 if not disabled explicitly.
169 \section1 Browser Features
171 Many of the functions, signals and properties provided by QWebView are also available
172 for this item, making it simple to adapt existing code to use QGraphicsWebView instead
175 The item uses a QWebPage object to perform the rendering of Web content, and this can
176 be obtained with the page() function, enabling the document itself to be accessed and
179 As with QWebView, the item records the browsing history using a QWebHistory object,
180 accessible using the history() function. The QWebSettings object that defines the
181 configuration of the browser can be obtained with the settings() function, enabling
182 features like plugin support to be customized for each item.
184 \sa QWebView, QGraphicsTextItem
188 \fn void QGraphicsWebView::titleChanged(const QString &title)
190 This signal is emitted whenever the \a title of the main frame changes.
196 \fn void QGraphicsWebView::urlChanged(const QUrl &url)
198 This signal is emitted when the \a url of the view changes.
204 \fn void QGraphicsWebView::iconChanged()
206 This signal is emitted whenever the icon of the page is loaded or changes.
208 In order for icons to be loaded, you will need to set an icon database path
209 using QWebSettings::setIconDatabasePath().
211 \sa icon(), QWebSettings::setIconDatabasePath()
215 \fn void QGraphicsWebView::loadStarted()
217 This signal is emitted when a new load of the page is started.
219 \sa loadProgress(), loadFinished()
223 \fn void QGraphicsWebView::loadFinished(bool ok)
225 This signal is emitted when a load of the page is finished.
226 \a ok will indicate whether the load was successful or any error occurred.
232 Constructs an empty QGraphicsWebView with parent \a parent.
236 QGraphicsWebView::QGraphicsWebView(QGraphicsItem* parent)
237 : QGraphicsWidget(parent)
238 , d(new QGraphicsWebViewPrivate(this))
240 setFlag(QGraphicsItem::ItemUsesExtendedStyleOption, true);
241 setAcceptDrops(true);
242 setAcceptHoverEvents(true);
243 setAcceptTouchEvents(true);
244 setFocusPolicy(Qt::StrongFocus);
245 setFlag(QGraphicsItem::ItemClipsChildrenToShape, true);
246 #if ENABLE(TILED_BACKING_STORE)
247 QObject::connect(this, SIGNAL(scaleChanged()), this, SLOT(_q_scaleChanged()));
254 QGraphicsWebView::~QGraphicsWebView()
260 Returns a pointer to the underlying web page.
264 QWebPage* QGraphicsWebView::page() const
267 QGraphicsWebView* that = const_cast<QGraphicsWebView*>(this);
268 QWebPage* page = new QWebPage(that);
270 // Default to not having a background, in the case
271 // the page doesn't provide one.
272 QPalette palette = QApplication::palette();
273 palette.setBrush(QPalette::Base, QColor::fromRgbF(0, 0, 0, 0));
274 page->setPalette(palette);
284 void QGraphicsWebView::paint(QPainter* painter, const QStyleOptionGraphicsItem* option, QWidget*)
286 QPainter::RenderHints oldHints = painter->renderHints();
287 painter->setRenderHints(oldHints | d->renderHints);
288 #if ENABLE(TILED_BACKING_STORE)
289 if (WebCore::TiledBackingStore* backingStore = QWebFramePrivate::core(page()->mainFrame())->tiledBackingStore()) {
290 // FIXME: We should set the backing store viewport earlier than in paint
291 backingStore->adjustVisibleRect();
292 // QWebFrame::render is a public API, bypass it for tiled rendering so behavior does not need to change.
293 WebCore::GraphicsContext context(painter);
294 page()->mainFrame()->d->renderFromTiledBackingStore(&context, option->exposedRect.toAlignedRect());
295 painter->setRenderHints(oldHints);
299 #if USE(ACCELERATED_COMPOSITING) && !USE(TEXTURE_MAPPER)
300 page()->mainFrame()->render(painter, d->overlay() ? QWebFrame::ContentsLayer : QWebFrame::AllLayers, option->exposedRect.toAlignedRect());
302 page()->mainFrame()->render(painter, QWebFrame::AllLayers, option->exposedRect.toRect());
304 painter->setRenderHints(oldHints);
309 bool QGraphicsWebView::sceneEvent(QEvent* event)
311 // Re-implemented in order to allows fixing event-related bugs in patch releases.
313 if (d->page && (event->type() == QEvent::TouchBegin
314 || event->type() == QEvent::TouchEnd
315 || event->type() == QEvent::TouchUpdate)) {
316 d->page->event(event);
318 // Always return true so that we'll receive also TouchUpdate and TouchEnd events
322 return QGraphicsWidget::sceneEvent(event);
327 QVariant QGraphicsWebView::itemChange(GraphicsItemChange change, const QVariant& value)
330 // Differently from QWebView, it is interesting to QGraphicsWebView to handle
331 // post mouse cursor change notifications. Reason: 'ItemCursorChange' is sent
332 // as the first action in QGraphicsItem::setCursor implementation, and at that
333 // item widget's cursor has not been effectively changed yet.
334 // After cursor is properly set (at 'ItemCursorHasChanged' emission time), we
335 // fire 'CursorChange'.
336 case ItemCursorChange:
338 case ItemCursorHasChanged: {
339 QEvent event(QEvent::CursorChange);
340 QApplication::sendEvent(this, &event);
347 return QGraphicsWidget::itemChange(change, value);
352 QSizeF QGraphicsWebView::sizeHint(Qt::SizeHint which, const QSizeF& constraint) const
354 if (which == Qt::PreferredSize)
355 return QSizeF(800, 600); // ###
356 return QGraphicsWidget::sizeHint(which, constraint);
361 QVariant QGraphicsWebView::inputMethodQuery(Qt::InputMethodQuery query) const
364 return d->page->inputMethodQuery(query);
369 \property QGraphicsWebView::renderHints
371 \brief the default render hints for the view
373 These hints are used to initialize QPainter before painting the Web page.
375 QPainter::TextAntialiasing and QPainter::SmoothPixmapTransform are enabled by default and will be
376 used to render the item in addition of what has been set on the painter given by QGraphicsScene.
378 \note This property is not available on Symbian. However, the getter and
379 setter functions can still be used directly.
381 \sa QPainter::renderHints()
386 Returns the render hints used by the view to render content.
388 \sa QPainter::renderHints()
390 QPainter::RenderHints QGraphicsWebView::renderHints() const
392 return d->renderHints;
397 Sets the render hints used by the view to the specified \a hints.
399 \sa QPainter::setRenderHints()
401 void QGraphicsWebView::setRenderHints(QPainter::RenderHints hints)
403 if (hints == d->renderHints)
405 d->renderHints = hints;
411 If \a enabled is true, enables the specified render \a hint; otherwise
414 \sa renderHints, QPainter::renderHints()
416 void QGraphicsWebView::setRenderHint(QPainter::RenderHint hint, bool enabled)
418 QPainter::RenderHints oldHints = d->renderHints;
420 d->renderHints |= hint;
422 d->renderHints &= ~hint;
423 if (oldHints != d->renderHints)
429 bool QGraphicsWebView::event(QEvent* event)
431 // Re-implemented in order to allows fixing event-related bugs in patch releases.
434 if (event->type() == QEvent::PaletteChange)
435 d->page->setPalette(palette());
436 #ifndef QT_NO_CONTEXTMENU
437 if (event->type() == QEvent::GraphicsSceneContextMenu) {
441 QGraphicsSceneContextMenuEvent* ev = static_cast<QGraphicsSceneContextMenuEvent*>(event);
442 QContextMenuEvent fakeEvent(QContextMenuEvent::Reason(ev->reason()), ev->pos().toPoint());
443 if (d->page->swallowContextMenuEvent(&fakeEvent)) {
447 d->page->updatePositionDependentActions(fakeEvent.pos());
449 #endif // QT_NO_CONTEXTMENU
452 if (event->type() == QEvent::CursorChange) {
453 // An unsetCursor will set the cursor to Qt::ArrowCursor.
454 // Thus this cursor change might be a QWidget::unsetCursor()
455 // If this is not the case and it came from WebCore, the
456 // QWebPageClient already has set its cursor internally
457 // to Qt::ArrowCursor, so updating the cursor is always
458 // right, as it falls back to the last cursor set by
460 // FIXME: Add a QEvent::CursorUnset or similar to Qt.
461 if (cursor().shape() == Qt::ArrowCursor)
462 d->page->d->client->resetCursor();
467 return QGraphicsWidget::event(event);
470 void QGraphicsWebViewPrivate::detachCurrentPage()
475 page->d->view.clear();
476 page->d->client = nullptr;
478 // if the page was created by us, we own it and need to
479 // destroy it as well.
481 if (page->parent() == q)
490 Makes \a page the new web page of the web graphicsitem.
492 The parent QObject of the provided page remains the owner
493 of the object. If the current document is a child of the web
494 view, it will be deleted.
498 void QGraphicsWebView::setPage(QWebPage* page)
503 d->detachCurrentPage();
509 d->page->d->client = adoptPtr(new PageClientQGraphicsWidget(this, page));
512 d->overlay()->prepareGraphicsItemGeometryChange();
514 QSize size = geometry().size().toSize();
515 page->setViewportSize(size);
517 if (d->resizesToContents)
518 d->updateResizesToContentsForPage();
520 QWebFrame* mainFrame = d->page->mainFrame();
522 connect(mainFrame, SIGNAL(titleChanged(QString)),
523 this, SIGNAL(titleChanged(QString)));
524 connect(mainFrame, SIGNAL(iconChanged()),
525 this, SIGNAL(iconChanged()));
526 connect(mainFrame, SIGNAL(urlChanged(QUrl)),
527 this, SIGNAL(urlChanged(QUrl)));
528 connect(d->page, SIGNAL(loadStarted()),
529 this, SIGNAL(loadStarted()));
530 connect(d->page, SIGNAL(loadProgress(int)),
531 this, SIGNAL(loadProgress(int)));
532 connect(d->page, SIGNAL(loadFinished(bool)),
533 this, SLOT(_q_doLoadFinished(bool)));
534 connect(d->page, SIGNAL(statusBarMessage(QString)),
535 this, SIGNAL(statusBarMessage(QString)));
536 connect(d->page, SIGNAL(linkClicked(QUrl)),
537 this, SIGNAL(linkClicked(QUrl)));
538 connect(d->page, SIGNAL(destroyed()),
539 this, SLOT(_q_pageDestroyed()));
540 #if !defined(QT_NO_IM) && (defined(Q_WS_X11) || defined(Q_WS_QWS) || defined(Q_OS_SYMBIAN))
541 connect(d->page, SIGNAL(microFocusChanged()),
542 this, SLOT(updateMicroFocus()));
547 \property QGraphicsWebView::url
548 \brief the url of the web page currently viewed
550 Setting this property clears the view and loads the URL.
552 By default, this property contains an empty, invalid URL.
554 \sa load(), urlChanged()
557 void QGraphicsWebView::setUrl(const QUrl &url)
559 page()->mainFrame()->setUrl(url);
562 QUrl QGraphicsWebView::url() const
565 return d->page->mainFrame()->url();
571 \property QGraphicsWebView::title
572 \brief the title of the web page currently viewed
574 By default, this property contains an empty string.
578 QString QGraphicsWebView::title() const
581 return d->page->mainFrame()->title();
587 \property QGraphicsWebView::icon
588 \brief the icon associated with the web page currently viewed
590 By default, this property contains a null icon.
592 \sa iconChanged(), QWebSettings::iconForUrl()
594 QIcon QGraphicsWebView::icon() const
597 return d->page->mainFrame()->icon();
603 \property QGraphicsWebView::zoomFactor
604 \brief the zoom factor for the view
607 void QGraphicsWebView::setZoomFactor(qreal factor)
609 if (factor == page()->mainFrame()->zoomFactor())
612 page()->mainFrame()->setZoomFactor(factor);
615 qreal QGraphicsWebView::zoomFactor() const
617 return page()->mainFrame()->zoomFactor();
622 void QGraphicsWebView::updateGeometry()
625 d->overlay()->prepareGraphicsItemGeometryChange();
627 QGraphicsWidget::updateGeometry();
632 QSize size = geometry().size().toSize();
633 d->page->setViewportSize(size);
638 void QGraphicsWebView::setGeometry(const QRectF& rect)
640 QGraphicsWidget::setGeometry(rect);
643 d->overlay()->prepareGraphicsItemGeometryChange();
648 // NOTE: call geometry() as setGeometry ensures that
649 // the geometry is within legal bounds (minimumSize, maximumSize)
650 QSize size = geometry().size().toSize();
651 d->page->setViewportSize(size);
655 Convenience slot that stops loading the document.
657 \sa reload(), loadFinished()
659 void QGraphicsWebView::stop()
662 d->page->triggerAction(QWebPage::Stop);
666 Convenience slot that loads the previous document in the list of documents
667 built by navigating links. Does nothing if there is no previous document.
671 void QGraphicsWebView::back()
674 d->page->triggerAction(QWebPage::Back);
678 Convenience slot that loads the next document in the list of documents
679 built by navigating links. Does nothing if there is no next document.
683 void QGraphicsWebView::forward()
686 d->page->triggerAction(QWebPage::Forward);
690 Reloads the current document.
692 \sa stop(), loadStarted()
694 void QGraphicsWebView::reload()
697 d->page->triggerAction(QWebPage::Reload);
701 Loads the specified \a url and displays it.
703 \note The view remains the same until enough data has arrived to display the new \a url.
705 \sa setUrl(), url(), urlChanged()
707 void QGraphicsWebView::load(const QUrl& url)
709 page()->mainFrame()->load(url);
713 \fn void QGraphicsWebView::load(const QNetworkRequest &request, QNetworkAccessManager::Operation operation, const QByteArray &body)
715 Loads a network request, \a request, using the method specified in \a operation.
717 \a body is optional and is only used for POST operations.
719 \note The view remains the same until enough data has arrived to display the new url.
721 \sa url(), urlChanged()
724 void QGraphicsWebView::load(const QNetworkRequest& request,
725 QNetworkAccessManager::Operation operation,
726 const QByteArray& body)
728 page()->mainFrame()->load(request, operation, body);
732 Sets the content of the web view to the specified \a html.
734 External objects such as stylesheets or images referenced in the HTML
735 document are located relative to \a baseUrl.
737 The \a html is loaded immediately; external objects are loaded asynchronously.
739 When using this method, WebKit assumes that external resources such as
740 JavaScript programs or style sheets are encoded in UTF-8 unless otherwise
741 specified. For example, the encoding of an external script can be specified
742 through the charset attribute of the HTML script tag. Alternatively, the
743 encoding can also be specified by the web server.
745 This is a convenience function equivalent to setContent(html, "text/html", baseUrl).
747 \warning This function works only for HTML, for other mime types (i.e. XHTML, SVG)
748 setContent() should be used instead.
750 \sa load(), setContent(), QWebFrame::toHtml(), QWebFrame::setContent()
752 void QGraphicsWebView::setHtml(const QString& html, const QUrl& baseUrl)
754 page()->mainFrame()->setHtml(html, baseUrl);
758 Sets the content of the web graphicsitem to the specified content \a data. If the \a mimeType argument
759 is empty it is currently assumed that the content is HTML but in future versions we may introduce
762 External objects referenced in the content are located relative to \a baseUrl.
764 The \a data is loaded immediately; external objects are loaded asynchronously.
766 \sa load(), setHtml(), QWebFrame::toHtml()
768 void QGraphicsWebView::setContent(const QByteArray& data, const QString& mimeType, const QUrl& baseUrl)
770 page()->mainFrame()->setContent(data, mimeType, baseUrl);
774 Returns a pointer to the view's history of navigated web pages.
778 \snippet webkitsnippets/qtwebkit_qwebview_snippet.cpp 0
780 QWebHistory* QGraphicsWebView::history() const
782 return page()->history();
786 \property QGraphicsWebView::modified
787 \brief whether the document was modified by the user
789 Parts of HTML documents can be editable for example through the
790 \c{contenteditable} attribute on HTML elements.
792 By default, this property is false.
794 bool QGraphicsWebView::isModified() const
797 return d->page->isModified();
802 Returns a pointer to the view/page specific settings object.
806 \snippet webkitsnippets/qtwebkit_qwebview_snippet.cpp 1
808 \sa QWebSettings::globalSettings()
810 QWebSettings* QGraphicsWebView::settings() const
812 return page()->settings();
816 Returns a pointer to a QAction that encapsulates the specified web action \a action.
818 QAction *QGraphicsWebView::pageAction(QWebPage::WebAction action) const
824 return page()->action(action);
829 Triggers the specified \a action. If it is a checkable action the specified
830 \a checked state is assumed.
834 void QGraphicsWebView::triggerPageAction(QWebPage::WebAction action, bool checked)
836 page()->triggerAction(action, checked);
840 Finds the specified string, \a subString, in the page, using the given \a options.
842 If the HighlightAllOccurrences flag is passed, the function will highlight all occurrences
843 that exist in the page. All subsequent calls will extend the highlight, rather than
844 replace it, with occurrences of the new string.
846 If the HighlightAllOccurrences flag is not passed, the function will select an occurrence
847 and all subsequent calls will replace the current occurrence with the next one.
849 To clear the selection, just pass an empty string.
851 Returns true if \a subString was found; otherwise returns false.
853 \sa QWebPage::selectedText(), QWebPage::selectionChanged()
855 bool QGraphicsWebView::findText(const QString &subString, QWebPage::FindFlags options)
858 return d->page->findText(subString, options);
863 \property QGraphicsWebView::resizesToContents
864 \brief whether the size of the QGraphicsWebView and its viewport changes to match the contents size
867 If this property is set, the QGraphicsWebView will automatically change its
868 size to match the size of the main frame contents. As a result the top level frame
869 will never have scrollbars. It will also make CSS fixed positioning to behave like absolute positioning
870 with elements positioned relative to the document instead of the viewport.
872 This property should be used in conjunction with the QWebPage::preferredContentsSize property.
873 If not explicitly set, the preferredContentsSize is automatically set to a reasonable value.
875 \sa QWebPage::setPreferredContentsSize()
877 void QGraphicsWebView::setResizesToContents(bool enabled)
879 if (d->resizesToContents == enabled)
881 d->resizesToContents = enabled;
883 d->updateResizesToContentsForPage();
886 bool QGraphicsWebView::resizesToContents() const
888 return d->resizesToContents;
892 \property QGraphicsWebView::tiledBackingStoreFrozen
893 \brief whether the tiled backing store updates its contents
896 If the tiled backing store is enabled using QWebSettings::TiledBackingStoreEnabled attribute, this property
897 can be used to disable backing store updates temporarily. This can be useful for example for running
898 a smooth animation that changes the scale of the QGraphicsWebView.
900 When the backing store is unfrozen, its contents will be automatically updated to match the current
901 state of the document. If the QGraphicsWebView scale was changed, the backing store is also
902 re-rendered using the new scale.
904 If the tiled backing store is not enabled, this property does nothing.
906 \sa QWebSettings::TiledBackingStoreEnabled
907 \sa QGraphicsObject::scale
909 bool QGraphicsWebView::isTiledBackingStoreFrozen() const
911 #if ENABLE(TILED_BACKING_STORE)
912 WebCore::TiledBackingStore* backingStore = QWebFramePrivate::core(page()->mainFrame())->tiledBackingStore();
915 return backingStore->contentsFrozen();
921 void QGraphicsWebView::setTiledBackingStoreFrozen(bool frozen)
923 #if ENABLE(TILED_BACKING_STORE)
924 WebCore::TiledBackingStore* backingStore = QWebFramePrivate::core(page()->mainFrame())->tiledBackingStore();
927 backingStore->setContentsFrozen(frozen);
929 UNUSED_PARAM(frozen);
935 void QGraphicsWebView::hoverMoveEvent(QGraphicsSceneHoverEvent* ev)
938 const bool accepted = ev->isAccepted();
939 QMouseEvent me = QMouseEvent(QEvent::MouseMove,
940 ev->pos().toPoint(), Qt::NoButton,
941 Qt::NoButton, Qt::NoModifier);
943 ev->setAccepted(accepted);
946 if (!ev->isAccepted())
947 QGraphicsItem::hoverMoveEvent(ev);
952 void QGraphicsWebView::hoverLeaveEvent(QGraphicsSceneHoverEvent* ev)
959 void QGraphicsWebView::mouseMoveEvent(QGraphicsSceneMouseEvent* ev)
962 const bool accepted = ev->isAccepted();
964 ev->setAccepted(accepted);
967 if (!ev->isAccepted())
968 QGraphicsItem::mouseMoveEvent(ev);
973 void QGraphicsWebView::mousePressEvent(QGraphicsSceneMouseEvent* ev)
976 const bool accepted = ev->isAccepted();
978 ev->setAccepted(accepted);
981 if (!ev->isAccepted())
982 QGraphicsItem::mousePressEvent(ev);
987 void QGraphicsWebView::mouseReleaseEvent(QGraphicsSceneMouseEvent* ev)
990 const bool accepted = ev->isAccepted();
992 ev->setAccepted(accepted);
995 if (!ev->isAccepted())
996 QGraphicsItem::mouseReleaseEvent(ev);
1001 void QGraphicsWebView::mouseDoubleClickEvent(QGraphicsSceneMouseEvent* ev)
1004 const bool accepted = ev->isAccepted();
1006 ev->setAccepted(accepted);
1009 if (!ev->isAccepted())
1010 QGraphicsItem::mouseDoubleClickEvent(ev);
1015 void QGraphicsWebView::keyPressEvent(QKeyEvent* ev)
1020 if (!ev->isAccepted())
1021 QGraphicsItem::keyPressEvent(ev);
1026 void QGraphicsWebView::keyReleaseEvent(QKeyEvent* ev)
1031 if (!ev->isAccepted())
1032 QGraphicsItem::keyReleaseEvent(ev);
1037 void QGraphicsWebView::focusInEvent(QFocusEvent* ev)
1042 QGraphicsItem::focusInEvent(ev);
1047 void QGraphicsWebView::focusOutEvent(QFocusEvent* ev)
1052 QGraphicsItem::focusOutEvent(ev);
1057 bool QGraphicsWebView::focusNextPrevChild(bool next)
1060 return d->page->focusNextPrevChild(next);
1062 return QGraphicsWidget::focusNextPrevChild(next);
1067 void QGraphicsWebView::dragEnterEvent(QGraphicsSceneDragDropEvent* ev)
1069 #ifndef QT_NO_DRAGANDDROP
1079 void QGraphicsWebView::dragLeaveEvent(QGraphicsSceneDragDropEvent* ev)
1081 #ifndef QT_NO_DRAGANDDROP
1083 const bool accepted = ev->isAccepted();
1085 ev->setAccepted(accepted);
1088 if (!ev->isAccepted())
1089 QGraphicsWidget::dragLeaveEvent(ev);
1097 void QGraphicsWebView::dragMoveEvent(QGraphicsSceneDragDropEvent* ev)
1099 #ifndef QT_NO_DRAGANDDROP
1101 const bool accepted = ev->isAccepted();
1103 ev->setAccepted(accepted);
1106 if (!ev->isAccepted())
1107 QGraphicsWidget::dragMoveEvent(ev);
1115 void QGraphicsWebView::dropEvent(QGraphicsSceneDragDropEvent* ev)
1117 #ifndef QT_NO_DRAGANDDROP
1119 const bool accepted = ev->isAccepted();
1121 ev->setAccepted(accepted);
1124 if (!ev->isAccepted())
1125 QGraphicsWidget::dropEvent(ev);
1131 #ifndef QT_NO_CONTEXTMENU
1134 void QGraphicsWebView::contextMenuEvent(QGraphicsSceneContextMenuEvent* ev)
1137 const bool accepted = ev->isAccepted();
1139 ev->setAccepted(accepted);
1142 #endif // QT_NO_CONTEXTMENU
1144 #ifndef QT_NO_WHEELEVENT
1147 void QGraphicsWebView::wheelEvent(QGraphicsSceneWheelEvent* ev)
1150 const bool accepted = ev->isAccepted();
1152 ev->setAccepted(accepted);
1155 if (!ev->isAccepted())
1156 QGraphicsItem::wheelEvent(ev);
1158 #endif // QT_NO_WHEELEVENT
1162 void QGraphicsWebView::inputMethodEvent(QInputMethodEvent* ev)
1167 if (!ev->isAccepted())
1168 QGraphicsItem::inputMethodEvent(ev);
1172 \fn void QGraphicsWebView::statusBarMessage(const QString& text)
1174 This signal is emitted when the statusbar \a text is changed by the page.
1178 \fn void QGraphicsWebView::loadProgress(int progress)
1180 This signal is emitted every time an element in the web page
1181 completes loading and the overall loading progress advances.
1183 This signal tracks the progress of all child frames.
1185 The current value is provided by \a progress and scales from 0 to 100,
1186 which is the default range of QProgressBar.
1188 \sa loadStarted(), loadFinished()
1192 \fn void QGraphicsWebView::linkClicked(const QUrl &url)
1194 This signal is emitted whenever the user clicks on a link and the page's linkDelegationPolicy
1195 property is set to delegate the link handling for the specified \a url.
1197 \sa QWebPage::linkDelegationPolicy()
1200 #endif // QT_NO_GRAPHICSVIEW
1202 #include "moc_qgraphicswebview.cpp"