From 3c1cb52aae6f7a5bd94c28a0b183e2375526724b Mon Sep 17 00:00:00 2001 From: Simon Hausmann Date: Mon, 10 May 2010 12:45:27 +0200 Subject: Removed dependency of QDeclarativeWebView to private Qt (Declarative) API Exchanged the use of QDeclarativePaintedItem with the use of QGraphicsWebView and its tiled backing store. --- .../webbrowser/content/FlickableWebView.qml | 29 +-- src/imports/webkit/qdeclarativewebview.cpp | 237 ++++++++------------- src/imports/webkit/qdeclarativewebview_p.h | 32 ++- 3 files changed, 113 insertions(+), 185 deletions(-) diff --git a/demos/declarative/webbrowser/content/FlickableWebView.qml b/demos/declarative/webbrowser/content/FlickableWebView.qml index 7efbaa3..32d69d8 100644 --- a/demos/declarative/webbrowser/content/FlickableWebView.qml +++ b/demos/declarative/webbrowser/content/FlickableWebView.qml @@ -12,8 +12,8 @@ Flickable { id: flickable width: parent.width - contentWidth: Math.max(parent.width,webView.width*webView.scale) - contentHeight: Math.max(parent.height,webView.height*webView.scale) + contentWidth: Math.max(parent.width,webView.width) + contentHeight: Math.max(parent.height,webView.height) anchors.top: headerSpace.bottom anchors.bottom: parent.top anchors.left: parent.left @@ -28,7 +28,6 @@ Flickable { WebView { id: webView - pixelCacheSize: 4000000 transformOrigin: Item.TopLeft function fixUrl(url) @@ -48,8 +47,6 @@ Flickable { url: fixUrl(webBrowser.urlString) smooth: false // We don't want smooth scaling, since we only scale during (fast) transitions - smoothCache: true // We do want smooth rendering - fillColor: "white" focus: true zoomFactor: 1 @@ -59,14 +56,13 @@ Flickable { { if (centerX) { var sc = zoom/contentsScale; - scaleAnim.to = sc; + scaleAnim.to = zoom; flickVX.from = flickable.contentX flickVX.to = Math.max(0,Math.min(centerX-flickable.width/2,webView.width*sc-flickable.width)) finalX.value = flickVX.to flickVY.from = flickable.contentY flickVY.to = Math.max(0,Math.min(centerY-flickable.height/2,webView.height*sc-flickable.height)) finalY.value = flickVY.to - finalZoom.value = zoom quickZoom.start() } } @@ -74,8 +70,8 @@ Flickable { Keys.onLeftPressed: webView.contentsScale -= 0.1 Keys.onRightPressed: webView.contentsScale += 0.1 - preferredWidth: flickable.width*zoomFactor - preferredHeight: flickable.height*zoomFactor + preferredWidth: flickable.width + preferredHeight: flickable.height contentsScale: 1/zoomFactor onContentsSizeChanged: { // zoom out @@ -108,9 +104,8 @@ Flickable { NumberAnimation { id: scaleAnim target: webView - property: "scale" - from: 1 - to: 0 // set before calling + property: "contentsScale" + // the to property is set before calling easing.type: Easing.Linear duration: 200 } @@ -133,16 +128,6 @@ Flickable { to: 0 // set before calling } } - PropertyAction { - id: finalZoom - target: webView - property: "contentsScale" - } - PropertyAction { - target: webView - property: "scale" - value: 1.0 - } // Have to set the contentXY, since the above 2 // size changes may have started a correction if // contentsScale < 1.0. diff --git a/src/imports/webkit/qdeclarativewebview.cpp b/src/imports/webkit/qdeclarativewebview.cpp index 9571470..9e24007 100644 --- a/src/imports/webkit/qdeclarativewebview.cpp +++ b/src/imports/webkit/qdeclarativewebview.cpp @@ -42,11 +42,9 @@ #include "qdeclarativewebview_p.h" #include "qdeclarativewebview_p_p.h" -#include - #include #include -#include +#include #include #include @@ -61,29 +59,29 @@ #include #include #include -#include QT_BEGIN_NAMESPACE static const int MAX_DOUBLECLICK_TIME=500; // XXX need better gesture system -class QDeclarativeWebViewPrivate : public QDeclarativePaintedItemPrivate +class QDeclarativeWebViewPrivate { - Q_DECLARE_PUBLIC(QDeclarativeWebView) - public: - QDeclarativeWebViewPrivate() - : QDeclarativePaintedItemPrivate(), page(0), preferredwidth(0), preferredheight(0), + QDeclarativeWebViewPrivate(QDeclarativeWebView* qq) + : q(qq), page(0), preferredwidth(0), preferredheight(0), progress(1.0), status(QDeclarativeWebView::Null), pending(PendingNone), newWindowComponent(0), newWindowParent(0), pressTime(400), rendering(true) { + QObject::connect(q, SIGNAL(focusChanged(bool)), q, SLOT(propagateFocusToWebPage(bool))); } - void focusChanged(bool); + + QDeclarativeWebView *q; QUrl url; // page url might be different if it has not loaded yet QWebPage *page; + QGraphicsWebView* view; int preferredwidth, preferredheight; qreal progress; @@ -101,7 +99,6 @@ public: QPoint pressPoint; int pressTime; // milliseconds before it's a "hold" - static void windowObjects_append(QDeclarativeListProperty *prop, QObject *o) { static_cast(prop->data)->windowObjects.append(o); static_cast(prop->data)->updateWindowObjects(); @@ -169,34 +166,39 @@ public: */ QDeclarativeWebView::QDeclarativeWebView(QDeclarativeItem *parent) - : QDeclarativePaintedItem(*(new QDeclarativeWebViewPrivate), parent) + : QDeclarativeItem(parent) { init(); } QDeclarativeWebView::~QDeclarativeWebView() { - Q_D(QDeclarativeWebView); delete d->page; + delete d; } void QDeclarativeWebView::init() { - Q_D(QDeclarativeWebView); + d = new QDeclarativeWebViewPrivate(this); QWebSettings::enablePersistentStorage(); setAcceptHoverEvents(true); setAcceptedMouseButtons(Qt::LeftButton); - setFlag(QGraphicsItem::ItemHasNoContents, false); + setFlag(QGraphicsItem::ItemHasNoContents, true); + setClip(true); d->page = 0; + d->view = new QGraphicsWebView(this); + d->view->setResizesToContents(true); + d->view->setFlag(QGraphicsItem::ItemStacksBehindParent, true); + connect(d->view, SIGNAL(geometryChanged()), this, SLOT(updateDeclarativeWebViewSize())); + connect(d->view, SIGNAL(scaleChanged()), this, SIGNAL(contentsScaleChanged())); } void QDeclarativeWebView::componentComplete() { - QDeclarativePaintedItem::componentComplete(); - Q_D(QDeclarativeWebView); + QDeclarativeItem::componentComplete(); switch (d->pending) { case QDeclarativeWebViewPrivate::PendingUrl: setUrl(d->pending_url); @@ -216,7 +218,6 @@ void QDeclarativeWebView::componentComplete() QDeclarativeWebView::Status QDeclarativeWebView::status() const { - Q_D(const QDeclarativeWebView); return d->status; } @@ -230,13 +231,11 @@ QDeclarativeWebView::Status QDeclarativeWebView::status() const */ qreal QDeclarativeWebView::progress() const { - Q_D(const QDeclarativeWebView); return d->progress; } void QDeclarativeWebView::doLoadStarted() { - Q_D(QDeclarativeWebView); if (!d->url.isEmpty()) { d->status = Loading; @@ -247,7 +246,6 @@ void QDeclarativeWebView::doLoadStarted() void QDeclarativeWebView::doLoadProgress(int p) { - Q_D(QDeclarativeWebView); if (d->progress == p/100.0) return; d->progress = p/100.0; @@ -256,12 +254,7 @@ void QDeclarativeWebView::doLoadProgress(int p) void QDeclarativeWebView::pageUrlChanged() { - Q_D(QDeclarativeWebView); - - page()->setViewportSize(QSize( - d->preferredwidth>0 ? d->preferredwidth : width(), - d->preferredheight>0 ? d->preferredheight : height())); - expandToWebPage(); + updateContentsSize(); if ((d->url.isEmpty() && page()->mainFrame()->url() != QUrl(QLatin1String("about:blank"))) || (d->url != page()->mainFrame()->url() && !page()->mainFrame()->url().isEmpty())) @@ -275,7 +268,6 @@ void QDeclarativeWebView::pageUrlChanged() void QDeclarativeWebView::doLoadFinished(bool ok) { - Q_D(QDeclarativeWebView); if (title().isEmpty()) pageUrlChanged(); // XXX bug 232556 - pages with no title never get urlChanged() @@ -302,21 +294,17 @@ void QDeclarativeWebView::doLoadFinished(bool ok) */ QUrl QDeclarativeWebView::url() const { - Q_D(const QDeclarativeWebView); return d->url; } void QDeclarativeWebView::setUrl(const QUrl &url) { - Q_D(QDeclarativeWebView); if (url == d->url) return; if (isComponentComplete()) { d->url = url; - page()->setViewportSize(QSize( - d->preferredwidth>0 ? d->preferredwidth : width(), - d->preferredheight>0 ? d->preferredheight : height())); + updateContentsSize(); QUrl seturl = url; if (seturl.isEmpty()) seturl = QUrl(QLatin1String("about:blank")); @@ -338,16 +326,14 @@ void QDeclarativeWebView::setUrl(const QUrl &url) */ int QDeclarativeWebView::preferredWidth() const { - Q_D(const QDeclarativeWebView); return d->preferredwidth; } void QDeclarativeWebView::setPreferredWidth(int iw) { - Q_D(QDeclarativeWebView); if (d->preferredwidth == iw) return; d->preferredwidth = iw; - //expandToWebPage(); + updateContentsSize(); emit preferredWidthChanged(); } @@ -358,14 +344,14 @@ void QDeclarativeWebView::setPreferredWidth(int iw) */ int QDeclarativeWebView::preferredHeight() const { - Q_D(const QDeclarativeWebView); return d->preferredheight; } + void QDeclarativeWebView::setPreferredHeight(int ih) { - Q_D(QDeclarativeWebView); if (d->preferredheight == ih) return; d->preferredheight = ih; + updateContentsSize(); emit preferredHeightChanged(); } @@ -383,55 +369,45 @@ QVariant QDeclarativeWebView::evaluateJavaScript(const QString &scriptSource) return this->page()->mainFrame()->evaluateJavaScript(scriptSource); } -void QDeclarativeWebViewPrivate::focusChanged(bool hasFocus) +void QDeclarativeWebView::propagateFocusToWebPage(bool hasFocus) { - Q_Q(QDeclarativeWebView); QFocusEvent e(hasFocus ? QEvent::FocusIn : QEvent::FocusOut); - q->page()->event(&e); - QDeclarativeItemPrivate::focusChanged(hasFocus); + page()->event(&e); } -void QDeclarativeWebView::initialLayout() +void QDeclarativeWebView::updateDeclarativeWebViewSize() { - // nothing useful to do at this point + QSizeF size = d->view->geometry().size() * contentsScale(); + setImplicitWidth(size.width()); + setImplicitHeight(size.height()); } -void QDeclarativeWebView::noteContentsSizeChanged(const QSize&) +void QDeclarativeWebView::initialLayout() { - expandToWebPage(); + // nothing useful to do at this point } -void QDeclarativeWebView::expandToWebPage() +void QDeclarativeWebView::updateContentsSize() { - Q_D(QDeclarativeWebView); - QSize cs = page()->mainFrame()->contentsSize(); - if (cs.width() < d->preferredwidth) - cs.setWidth(d->preferredwidth); - if (cs.height() < d->preferredheight) - cs.setHeight(d->preferredheight); - if (widthValid()) - cs.setWidth(width()); - if (heightValid()) - cs.setHeight(height()); - if (cs != page()->viewportSize()) { - page()->setViewportSize(cs); - } - if (cs != contentsSize()) - setContentsSize(cs); + if (d->page) + d->page->setPreferredContentsSize(QSize( + d->preferredwidth>0 ? d->preferredwidth : width(), + d->preferredheight>0 ? d->preferredheight : height())); } void QDeclarativeWebView::geometryChanged(const QRectF &newGeometry, const QRectF &oldGeometry) { - if (newGeometry.size() != oldGeometry.size()) - expandToWebPage(); - QDeclarativePaintedItem::geometryChanged(newGeometry, oldGeometry); -} - -void QDeclarativeWebView::paintPage(const QRect& r) -{ - dirtyCache(r); - update(); + if (newGeometry.size() != oldGeometry.size() && d->page) { + QSize cs = d->page->preferredContentsSize(); + if (widthValid()) + cs.setWidth(width()); + if (heightValid()) + cs.setHeight(height()); + if (cs != d->page->preferredContentsSize()) + d->page->setPreferredContentsSize(cs); + } + QDeclarativeItem::geometryChanged(newGeometry, oldGeometry); } /*! @@ -473,7 +449,6 @@ void QDeclarativeWebView::paintPage(const QRect& r) */ QDeclarativeListProperty QDeclarativeWebView::javaScriptWindowObjects() { - Q_D(QDeclarativeWebView); return QDeclarativeListProperty(this, d, &QDeclarativeWebViewPrivate::windowObjects_append); } @@ -484,8 +459,7 @@ QDeclarativeWebViewAttached *QDeclarativeWebView::qmlAttachedProperties(QObject void QDeclarativeWebViewPrivate::updateWindowObjects() { - Q_Q(QDeclarativeWebView); - if (!q->isComponentComplete() || !page) + if (!q->isComponentCompletePublic() || !page) return; for (int ii = 0; ii < windowObjects.count(); ++ii) { @@ -499,29 +473,17 @@ void QDeclarativeWebViewPrivate::updateWindowObjects() bool QDeclarativeWebView::renderingEnabled() const { - Q_D(const QDeclarativeWebView); return d->rendering; } void QDeclarativeWebView::setRenderingEnabled(bool enabled) { - Q_D(QDeclarativeWebView); if (d->rendering == enabled) return; d->rendering = enabled; emit renderingEnabledChanged(); - setCacheFrozen(!enabled); - if (enabled) - clearCache(); -} - - -void QDeclarativeWebView::drawContents(QPainter *p, const QRect &r) -{ - Q_D(QDeclarativeWebView); - if (d->rendering) - page()->mainFrame()->render(p,r); + d->view->setTiledBackingStoreFrozen(!enabled); } QMouseEvent *QDeclarativeWebView::sceneMouseEventToMouseEvent(QGraphicsSceneMouseEvent *e) @@ -556,7 +518,6 @@ QMouseEvent *QDeclarativeWebView::sceneHoverMoveEventToMouseEvent(QGraphicsScene return me; } - /*! \qmlsignal WebView::onDoubleClick(clickx,clicky) @@ -588,7 +549,6 @@ void QDeclarativeWebView::mouseDoubleClickEvent(QGraphicsSceneMouseEvent *event) */ bool QDeclarativeWebView::heuristicZoom(int clickX, int clickY, qreal maxzoom) { - Q_D(QDeclarativeWebView); if (contentsScale() >= maxzoom/zoomFactor()) return false; qreal ozf = contentsScale(); @@ -617,13 +577,11 @@ bool QDeclarativeWebView::heuristicZoom(int clickX, int clickY, qreal maxzoom) */ int QDeclarativeWebView::pressGrabTime() const { - Q_D(const QDeclarativeWebView); return d->pressTime; } void QDeclarativeWebView::setPressGrabTime(int ms) { - Q_D(QDeclarativeWebView); if (d->pressTime == ms) return; d->pressTime = ms; @@ -632,8 +590,6 @@ void QDeclarativeWebView::setPressGrabTime(int ms) void QDeclarativeWebView::mousePressEvent(QGraphicsSceneMouseEvent *event) { - Q_D(QDeclarativeWebView); - setFocus (true); QMouseEvent *me = sceneMouseEventToMouseEvent(event); @@ -661,14 +617,12 @@ void QDeclarativeWebView::mousePressEvent(QGraphicsSceneMouseEvent *event) ); delete me; if (!event->isAccepted()) { - QDeclarativePaintedItem::mousePressEvent(event); + QDeclarativeItem::mousePressEvent(event); } } void QDeclarativeWebView::mouseReleaseEvent(QGraphicsSceneMouseEvent *event) { - Q_D(QDeclarativeWebView); - QMouseEvent *me = sceneMouseEventToMouseEvent(event); page()->event(me); d->pressTimer.stop(); @@ -685,7 +639,7 @@ void QDeclarativeWebView::mouseReleaseEvent(QGraphicsSceneMouseEvent *event) ); delete me; if (!event->isAccepted()) { - QDeclarativePaintedItem::mouseReleaseEvent(event); + QDeclarativeItem::mouseReleaseEvent(event); } setKeepMouseGrab(false); ungrabMouse(); @@ -693,7 +647,6 @@ void QDeclarativeWebView::mouseReleaseEvent(QGraphicsSceneMouseEvent *event) void QDeclarativeWebView::timerEvent(QTimerEvent *event) { - Q_D(QDeclarativeWebView); if (event->timerId() == d->pressTimer.timerId()) { d->pressTimer.stop(); grabMouse(); @@ -703,8 +656,6 @@ void QDeclarativeWebView::timerEvent(QTimerEvent *event) void QDeclarativeWebView::mouseMoveEvent(QGraphicsSceneMouseEvent *event) { - Q_D(QDeclarativeWebView); - QMouseEvent *me = sceneMouseEventToMouseEvent(event); if (d->pressTimer.isActive()) { if ((me->pos() - d->pressPoint).manhattanLength() > QApplication::startDragDistance()) { @@ -728,9 +679,9 @@ void QDeclarativeWebView::mouseMoveEvent(QGraphicsSceneMouseEvent *event) } delete me; if (!event->isAccepted()) - QDeclarativePaintedItem::mouseMoveEvent(event); - + QDeclarativeItem::mouseMoveEvent(event); } + void QDeclarativeWebView::hoverMoveEvent (QGraphicsSceneHoverEvent * event) { QMouseEvent *me = sceneHoverMoveEventToMouseEvent(event); @@ -744,21 +695,7 @@ void QDeclarativeWebView::hoverMoveEvent (QGraphicsSceneHoverEvent * event) ); delete me; if (!event->isAccepted()) - QDeclarativePaintedItem::hoverMoveEvent(event); -} - -void QDeclarativeWebView::keyPressEvent(QKeyEvent* event) -{ - page()->event(event); - if (!event->isAccepted()) - QDeclarativePaintedItem::keyPressEvent(event); -} - -void QDeclarativeWebView::keyReleaseEvent(QKeyEvent* event) -{ - page()->event(event); - if (!event->isAccepted()) - QDeclarativePaintedItem::keyReleaseEvent(event); + QDeclarativeItem::hoverMoveEvent(event); } bool QDeclarativeWebView::sceneEvent(QEvent *event) @@ -773,7 +710,7 @@ bool QDeclarativeWebView::sceneEvent(QEvent *event) } } } - return QDeclarativePaintedItem::sceneEvent(event); + return QDeclarativeItem::sceneEvent(event); } @@ -842,15 +779,11 @@ QPixmap QDeclarativeWebView::icon() const */ void QDeclarativeWebView::setZoomFactor(qreal factor) { - Q_D(QDeclarativeWebView); if (factor == page()->mainFrame()->zoomFactor()) return; page()->mainFrame()->setZoomFactor(factor); - page()->setViewportSize(QSize( - d->preferredwidth>0 ? d->preferredwidth*factor : width()*factor, - d->preferredheight>0 ? d->preferredheight*factor : height()*factor)); - expandToWebPage(); + updateContentsSize(); emit zoomFactorChanged(); } @@ -868,37 +801,27 @@ qreal QDeclarativeWebView::zoomFactor() const */ void QDeclarativeWebView::setStatusText(const QString& s) { - Q_D(QDeclarativeWebView); d->statusText = s; emit statusTextChanged(); } void QDeclarativeWebView::windowObjectCleared() { - Q_D(QDeclarativeWebView); d->updateWindowObjects(); } QString QDeclarativeWebView::statusText() const { - Q_D(const QDeclarativeWebView); return d->statusText; } QWebPage *QDeclarativeWebView::page() const { - Q_D(const QDeclarativeWebView); if (!d->page) { QDeclarativeWebView *self = const_cast(this); QWebPage *wp = new QDeclarativeWebPage(self); - // QML items don't default to having a background, - // even though most we pages will set one anyway. - QPalette pal = QApplication::palette(); - pal.setBrush(QPalette::Base, QColor::fromRgbF(0, 0, 0, 0)); - wp->setPalette(pal); - wp->setNetworkAccessManager(qmlEngine(this)->networkAccessManager()); self->setPage(wp); @@ -954,14 +877,12 @@ QWebPage *QDeclarativeWebView::page() const */ QDeclarativeWebSettings *QDeclarativeWebView::settingsObject() const { - Q_D(const QDeclarativeWebView); d->settings.s = page()->settings(); return &d->settings; } void QDeclarativeWebView::setPage(QWebPage *page) { - Q_D(QDeclarativeWebView); if (d->page == page) return; if (d->page) { @@ -972,18 +893,15 @@ void QDeclarativeWebView::setPage(QWebPage *page) } } d->page = page; - d->page->setViewportSize(QSize( - d->preferredwidth>0 ? d->preferredwidth : width(), - d->preferredheight>0 ? d->preferredheight : height())); + updateContentsSize(); d->page->mainFrame()->setScrollBarPolicy(Qt::Horizontal,Qt::ScrollBarAlwaysOff); d->page->mainFrame()->setScrollBarPolicy(Qt::Vertical,Qt::ScrollBarAlwaysOff); - connect(d->page,SIGNAL(repaintRequested(QRect)),this,SLOT(paintPage(QRect))); connect(d->page->mainFrame(),SIGNAL(urlChanged(QUrl)),this,SLOT(pageUrlChanged())); connect(d->page->mainFrame(), SIGNAL(titleChanged(QString)), this, SIGNAL(titleChanged(QString))); connect(d->page->mainFrame(), SIGNAL(titleChanged(QString)), this, SIGNAL(iconChanged())); connect(d->page->mainFrame(), SIGNAL(iconChanged()), this, SIGNAL(iconChanged())); - connect(d->page->mainFrame(), SIGNAL(contentsSizeChanged(QSize)), this, SLOT(noteContentsSizeChanged(QSize))); connect(d->page->mainFrame(), SIGNAL(initialLayoutCompleted()), this, SLOT(initialLayout())); + connect(d->page->mainFrame(), SIGNAL(contentsSizeChanged(QSize)), this, SIGNAL(contentsSizeChanged(QSize))); connect(d->page,SIGNAL(loadStarted()),this,SLOT(doLoadStarted())); connect(d->page,SIGNAL(loadProgress(int)),this,SLOT(doLoadProgress(int))); @@ -991,6 +909,10 @@ void QDeclarativeWebView::setPage(QWebPage *page) connect(d->page,SIGNAL(statusBarMessage(QString)),this,SLOT(setStatusText(QString))); connect(d->page->mainFrame(),SIGNAL(javaScriptWindowObjectCleared()),this,SLOT(windowObjectCleared())); + + d->page->settings()->setAttribute(QWebSettings::TiledBackingStoreEnabled, true); + + d->view->setPage(page); } /*! @@ -1045,10 +967,7 @@ QString QDeclarativeWebView::html() const */ void QDeclarativeWebView::setHtml(const QString &html, const QUrl &baseUrl) { - Q_D(QDeclarativeWebView); - page()->setViewportSize(QSize( - d->preferredwidth>0 ? d->preferredwidth : width(), - d->preferredheight>0 ? d->preferredheight : height())); + updateContentsSize(); if (isComponentComplete()) page()->mainFrame()->setHtml(html, baseUrl); else { @@ -1061,10 +980,7 @@ void QDeclarativeWebView::setHtml(const QString &html, const QUrl &baseUrl) void QDeclarativeWebView::setContent(const QByteArray &data, const QString &mimeType, const QUrl &baseUrl) { - Q_D(QDeclarativeWebView); - page()->setViewportSize(QSize( - d->preferredwidth>0 ? d->preferredwidth : width(), - d->preferredheight>0 ? d->preferredheight : height())); + updateContentsSize(); if (isComponentComplete()) page()->mainFrame()->setContent(data,mimeType,qmlContext(this)->resolvedUrl(baseUrl)); @@ -1088,7 +1004,6 @@ QWebSettings *QDeclarativeWebView::settings() const QDeclarativeWebView *QDeclarativeWebView::createWindow(QWebPage::WebWindowType type) { - Q_D(QDeclarativeWebView); switch (type) { case QWebPage::WebBrowserWindow: { if (!d->newWindowComponent && d->newWindowParent) @@ -1142,13 +1057,11 @@ QDeclarativeWebView *QDeclarativeWebView::createWindow(QWebPage::WebWindowType t */ QDeclarativeComponent *QDeclarativeWebView::newWindowComponent() const { - Q_D(const QDeclarativeWebView); return d->newWindowComponent; } void QDeclarativeWebView::setNewWindowComponent(QDeclarativeComponent *newWindow) { - Q_D(QDeclarativeWebView); if (newWindow == d->newWindowComponent) return; d->newWindowComponent = newWindow; @@ -1165,13 +1078,11 @@ void QDeclarativeWebView::setNewWindowComponent(QDeclarativeComponent *newWindow */ QDeclarativeItem *QDeclarativeWebView::newWindowParent() const { - Q_D(const QDeclarativeWebView); return d->newWindowParent; } void QDeclarativeWebView::setNewWindowParent(QDeclarativeItem *parent) { - Q_D(QDeclarativeWebView); if (parent == d->newWindowParent) return; if (d->newWindowParent && parent) { @@ -1184,6 +1095,25 @@ void QDeclarativeWebView::setNewWindowParent(QDeclarativeItem *parent) emit newWindowParentChanged(); } +QSize QDeclarativeWebView::contentsSize() const +{ + return d->page->mainFrame()->contentsSize() * contentsScale(); +} + +qreal QDeclarativeWebView::contentsScale() const +{ + return d->view->scale(); +} + +void QDeclarativeWebView::setContentsScale(qreal scale) +{ + if (scale == d->view->scale()) + return; + d->view->setScale(scale); + updateDeclarativeWebViewSize(); + emit contentsScaleChanged(); +} + /*! Returns the area of the largest element at position (\a x,\a y) that is no larger than \a maxwidth by \a maxheight pixels. @@ -1280,3 +1210,4 @@ QWebPage *QDeclarativeWebPage::createWindow(WebWindowType type) } QT_END_NAMESPACE + diff --git a/src/imports/webkit/qdeclarativewebview_p.h b/src/imports/webkit/qdeclarativewebview_p.h index 81581d8..87bd938 100644 --- a/src/imports/webkit/qdeclarativewebview_p.h +++ b/src/imports/webkit/qdeclarativewebview_p.h @@ -42,12 +42,13 @@ #ifndef QDECLARATIVEWEBVIEW_H #define QDECLARATIVEWEBVIEW_H -#include +#include #include #include #include #include +#include QT_BEGIN_HEADER @@ -61,6 +62,7 @@ class QDeclarativeWebSettings; class QDeclarativeWebViewPrivate; class QNetworkRequest; class QDeclarativeWebView; +class QDeclarativeWebViewPrivate; class QDeclarativeWebPage : public QWebPage { @@ -85,7 +87,7 @@ class QDeclarativeWebViewAttached; //### TODO: browser plugins -class QDeclarativeWebView : public QDeclarativePaintedItem +class QDeclarativeWebView : public QDeclarativeItem { Q_OBJECT @@ -120,6 +122,9 @@ class QDeclarativeWebView : public QDeclarativePaintedItem Q_PROPERTY(bool renderingEnabled READ renderingEnabled WRITE setRenderingEnabled NOTIFY renderingEnabledChanged) + Q_PROPERTY(QSize contentsSize READ contentsSize NOTIFY contentsSizeChanged) + Q_PROPERTY(qreal contentsScale READ contentsScale WRITE setContentsScale NOTIFY contentsScaleChanged) + public: QDeclarativeWebView(QDeclarativeItem *parent=0); ~QDeclarativeWebView(); @@ -182,6 +187,13 @@ public: QDeclarativeItem *newWindowParent() const; void setNewWindowParent(QDeclarativeItem *newWindow); + bool isComponentCompletePublic() const { return isComponentComplete(); } + + QSize contentsSize() const; + + void setContentsScale(qreal scale); + qreal contentsScale() const; + Q_SIGNALS: void preferredWidthChanged(); void preferredHeightChanged(); @@ -197,6 +209,8 @@ Q_SIGNALS: void newWindowComponentChanged(); void newWindowParentChanged(); void renderingEnabledChanged(); + void contentsSizeChanged(const QSize&); + void contentsScaleChanged(); void loadStarted(); void loadFinished(); @@ -212,38 +226,36 @@ public Q_SLOTS: QVariant evaluateJavaScript(const QString&); private Q_SLOTS: - void expandToWebPage(); - void paintPage(const QRect&); void doLoadStarted(); void doLoadProgress(int p); void doLoadFinished(bool ok); void setStatusText(const QString&); void windowObjectCleared(); void pageUrlChanged(); - void noteContentsSizeChanged(const QSize&); void initialLayout(); -protected: - void drawContents(QPainter *, const QRect &); + void propagateFocusToWebPage(bool); + void updateDeclarativeWebViewSize(); + +protected: void mousePressEvent(QGraphicsSceneMouseEvent *event); void mouseReleaseEvent(QGraphicsSceneMouseEvent *event); void mouseMoveEvent(QGraphicsSceneMouseEvent *event); void mouseDoubleClickEvent(QGraphicsSceneMouseEvent *event); void timerEvent(QTimerEvent *event); void hoverMoveEvent (QGraphicsSceneHoverEvent * event); - void keyPressEvent(QKeyEvent* event); - void keyReleaseEvent(QKeyEvent* event); virtual void geometryChanged(const QRectF &newGeometry, const QRectF &oldGeometry); virtual bool sceneEvent(QEvent *event); QDeclarativeWebView *createWindow(QWebPage::WebWindowType type); private: + void updateContentsSize(); void init(); virtual void componentComplete(); Q_DISABLE_COPY(QDeclarativeWebView) - Q_DECLARE_PRIVATE_D(QGraphicsItem::d_ptr.data(), QDeclarativeWebView) + QDeclarativeWebViewPrivate* d; QMouseEvent *sceneMouseEventToMouseEvent(QGraphicsSceneMouseEvent *); QMouseEvent *sceneHoverMoveEventToMouseEvent(QGraphicsSceneHoverEvent *); friend class QDeclarativeWebPage; -- cgit v0.12