diff options
author | Simon Hausmann <simon.hausmann@nokia.com> | 2012-05-25 15:09:11 +0200 |
---|---|---|
committer | Simon Hausmann <simon.hausmann@nokia.com> | 2012-05-25 15:09:11 +0200 |
commit | a89b2ebb8e192c5e8cea21079bda2ee2c0c7dddd (patch) | |
tree | b7abd9f49ae1d4d2e426a5883bfccd42b8e2ee12 /Source/WebKit2/UIProcess/API/qt/qquickwebview.cpp | |
parent | 8d473cf9743f1d30a16a27114e93bd5af5648d23 (diff) | |
download | qtwebkit-a89b2ebb8e192c5e8cea21079bda2ee2c0c7dddd.tar.gz |
Imported WebKit commit eb5c1b8fe4d4b1b90b5137433fc58a91da0e6878 (http://svn.webkit.org/repository/webkit/trunk@118516)
Diffstat (limited to 'Source/WebKit2/UIProcess/API/qt/qquickwebview.cpp')
-rw-r--r-- | Source/WebKit2/UIProcess/API/qt/qquickwebview.cpp | 136 |
1 files changed, 74 insertions, 62 deletions
diff --git a/Source/WebKit2/UIProcess/API/qt/qquickwebview.cpp b/Source/WebKit2/UIProcess/API/qt/qquickwebview.cpp index 935842146..9d77171cc 100644 --- a/Source/WebKit2/UIProcess/API/qt/qquickwebview.cpp +++ b/Source/WebKit2/UIProcess/API/qt/qquickwebview.cpp @@ -324,31 +324,33 @@ bool QQuickWebViewPrivate::transparentBackground() const return webPageProxy->drawsTransparentBackground(); } -QPointF QQuickWebViewPrivate::pageItemPos() -{ - ASSERT(pageView); - return pageView->pos(); -} - /*! \qmlsignal WebView::loadingChanged(WebLoadRequest request) */ -void QQuickWebViewPrivate::provisionalLoadDidStart(const QUrl& url) +void QQuickWebViewPrivate::provisionalLoadDidStart(const WTF::String& url) { Q_Q(QQuickWebView); - QWebLoadRequest loadRequest(url, QQuickWebView::LoadStartedStatus); + q->emitUrlChangeIfNeeded(); + + QWebLoadRequest loadRequest(QString(url), QQuickWebView::LoadStartedStatus); emit q->loadingChanged(&loadRequest); } +void QQuickWebViewPrivate::didReceiveServerRedirectForProvisionalLoad(const WTF::String&) +{ + Q_Q(QQuickWebView); + + q->emitUrlChangeIfNeeded(); +} + void QQuickWebViewPrivate::loadDidCommit() { Q_Q(QQuickWebView); ASSERT(q->loading()); emit q->navigationHistoryChanged(); - emit q->urlChanged(); emit q->titleChanged(); } @@ -356,8 +358,8 @@ void QQuickWebViewPrivate::didSameDocumentNavigation() { Q_Q(QQuickWebView); + q->emitUrlChangeIfNeeded(); emit q->navigationHistoryChanged(); - emit q->urlChanged(); } void QQuickWebViewPrivate::titleDidChange() @@ -419,6 +421,7 @@ void QQuickWebViewPrivate::setNeedsDisplay() void QQuickWebViewPrivate::_q_onIconChangedForPageURL(const QUrl& pageURL, const QUrl& iconURL) { Q_Q(QQuickWebView); + if (q->url() != pageURL) return; @@ -644,6 +647,9 @@ void QQuickWebViewPrivate::setIcon(const QUrl& iconURL) if (m_iconURL == iconURL) return; + if (!webPageProxy->mainFrame()) + return; + String oldPageURL = QUrl::fromPercentEncoding(m_iconURL.encodedFragment()); String newPageURL = webPageProxy->mainFrame()->url(); @@ -798,34 +804,6 @@ void QQuickWebViewFlickablePrivate::initialize(WKContextRef contextRef, WKPageGr webPageProxy->setUseFixedLayout(true); } -QPointF QQuickWebViewFlickablePrivate::pageItemPos() -{ - Q_Q(QQuickWebView); - // Flickable moves its contentItem so we need to take that position into account, - // as well as the potential displacement of the page on the contentItem because - // of additional QML items. - qreal xPos = q->contentItem()->x() + pageView->x(); - qreal yPos = q->contentItem()->y() + pageView->y(); - return QPointF(xPos, yPos); -} - -void QQuickWebViewFlickablePrivate::updateContentsSize(const QSizeF& size) -{ - Q_Q(QQuickWebView); - - // Make sure that the contentItem is sized to the page - // if the user did not add other flickable items in QML. - // If the user adds items in QML he has to make sure to - // disable the default content item size property on the WebView - // and bind the contentWidth and contentHeight accordingly. - // This is in accordance with normal QML Flickable behaviour. - if (!m_useDefaultContentItemSize) - return; - - q->setContentWidth(size.width()); - q->setContentHeight(size.height()); -} - void QQuickWebViewFlickablePrivate::onComponentComplete() { Q_Q(QQuickWebView); @@ -835,7 +813,7 @@ void QQuickWebViewFlickablePrivate::onComponentComplete() QObject::connect(interactionEngine.data(), SIGNAL(contentSuspendRequested()), q, SLOT(_q_suspend())); QObject::connect(interactionEngine.data(), SIGNAL(contentResumeRequested()), q, SLOT(_q_resume())); - QObject::connect(interactionEngine.data(), SIGNAL(contentViewportChanged(QPointF)), q, SLOT(_q_contentViewportChanged(QPointF))); + QObject::connect(interactionEngine.data(), SIGNAL(informVisibleContentChange(QPointF)), q, SLOT(_q_onInformVisibleContentChange(QPointF))); _q_resume(); @@ -868,7 +846,7 @@ void QQuickWebViewFlickablePrivate::didChangeViewportProperties(const WebCore::V // If the web app successively changes the viewport on purpose // it wants to be in control and we should disable animations. - interactionEngine->ensureContentWithinViewportBoundary(/*immediate*/ true); + interactionEngine->setItemRectVisible(interactionEngine->nearestValidBounds()); } void QQuickWebViewFlickablePrivate::updateViewportSize() @@ -887,10 +865,10 @@ void QQuickWebViewFlickablePrivate::updateViewportSize() // it can resize the content accordingly. webPageProxy->setViewportSize(viewportSize); - _q_contentViewportChanged(QPointF()); + _q_onInformVisibleContentChange(QPointF()); } -void QQuickWebViewFlickablePrivate::_q_contentViewportChanged(const QPointF& trajectoryVector) +void QQuickWebViewFlickablePrivate::_q_onInformVisibleContentChange(const QPointF& trajectoryVector) { Q_Q(QQuickWebView); @@ -925,7 +903,7 @@ void QQuickWebViewFlickablePrivate::_q_resume() pageIsSuspended = false; webPageProxy->resumeActiveDOMObjectsAndAnimations(); - _q_contentViewportChanged(QPointF()); + _q_onInformVisibleContentChange(QPointF()); } void QQuickWebViewFlickablePrivate::pageDidRequestScroll(const QPoint& pos) @@ -942,15 +920,26 @@ void QQuickWebViewFlickablePrivate::didChangeContentsSize(const QSize& newSize) float minimumScale = WebCore::computeMinimumScaleFactorForContentContained(attributes, viewportSize, newSize); + bool scaleCommitNotified = false; + if (!qFuzzyCompare(minimumScale, attributes.minimumScale)) { interactionEngine->setCSSScaleBounds(minimumScale, attributes.maximumScale); emit q->experimental()->test()->viewportChanged(); - if (!interactionEngine->hadUserInteraction() && !pageIsSuspended) + if (!interactionEngine->hadUserInteraction() && !pageIsSuspended) { + // Emits contentsScaleCommitted(); + scaleCommitNotified = true; interactionEngine->setCSSScale(minimumScale); + } } + + // Emit for testing purposes, so that it can be verified that + // we didn't do scale adjustment. + if (!scaleCommitNotified) + emit q->experimental()->test()->contentsScaleCommitted(); } + /*! \qmlsignal WebView::onNavigationRequested(WebNavigationRequest request) @@ -1452,6 +1441,19 @@ void QQuickWebView::stop() void QQuickWebView::reload() { Q_D(QQuickWebView); + + WebFrameProxy* mainFrame = d->webPageProxy->mainFrame(); + if (mainFrame && !mainFrame->unreachableURL().isEmpty() && mainFrame->url() != blankURL()) { + // We are aware of the unreachable url on the UI process side, but since we haven't + // loaded alternative/subsitute data for it (an error page eg.) WebCore doesn't know + // about the unreachable url yet. If we just do a reload at this point WebCore will try to + // reload the currently committed url instead of the unrachable url. To work around this + // we override the reload here by doing a manual load. + d->webPageProxy->loadURL(mainFrame->unreachableURL()); + // FIXME: We should make WebCore aware of the unreachable url regardless of substitute-loads + return; + } + const bool reloadFromOrigin = true; d->webPageProxy->reload(reloadFromOrigin); } @@ -1459,10 +1461,11 @@ void QQuickWebView::reload() QUrl QQuickWebView::url() const { Q_D(const QQuickWebView); - RefPtr<WebFrameProxy> mainFrame = d->webPageProxy->mainFrame(); - if (!mainFrame) - return QUrl(); - return QUrl(QString(mainFrame->url())); + + // FIXME: Enable once we are sure this should not trigger + // Q_ASSERT(d->m_currentUrl == d->webPageProxy->activeURL()); + + return QUrl(d->m_currentUrl); } void QQuickWebView::setUrl(const QUrl& url) @@ -1473,6 +1476,19 @@ void QQuickWebView::setUrl(const QUrl& url) return; d->webPageProxy->loadURL(url.toString()); + emitUrlChangeIfNeeded(); +} + +// Make sure we don't emit urlChanged unless it actually changed +void QQuickWebView::emitUrlChangeIfNeeded() +{ + Q_D(QQuickWebView); + + WTF::String activeUrl = d->webPageProxy->activeURL(); + if (activeUrl != d->m_currentUrl) { + d->m_currentUrl = activeUrl; + emit urlChanged(); + } } QUrl QQuickWebView::icon() const @@ -1708,6 +1724,7 @@ void QQuickWebView::mouseDoubleClickEvent(QMouseEvent* event) { Q_D(QQuickWebView); + forceActiveFocus(); // If a MouseButtonDblClick was received then we got a MouseButtonPress before // handleMousePressEvent will take care of double clicks. d->pageView->eventHandler()->handleMousePressEvent(event); @@ -1819,24 +1836,19 @@ void QQuickWebView::handleFlickableMouseRelease(const QPointF& position, qint64 External objects such as stylesheets or images referenced in the HTML document are located relative to \a baseUrl. + If an \a unreachableUrl is passed it is used as the url for the loaded + content. This is typically used to display error pages for a failed + load. + \sa WebView::url */ -void QQuickWebView::loadHtml(const QString& html, const QUrl& baseUrl) -{ - Q_D(QQuickWebView); - d->webPageProxy->loadHTMLString(html, baseUrl.toString()); -} - -QPointF QQuickWebView::pageItemPos() -{ - Q_D(QQuickWebView); - return d->pageItemPos(); -} - -void QQuickWebView::updateContentsSize(const QSizeF& size) +void QQuickWebView::loadHtml(const QString& html, const QUrl& baseUrl, const QUrl& unreachableUrl) { Q_D(QQuickWebView); - d->updateContentsSize(size); + if (unreachableUrl.isValid()) + d->webPageProxy->loadAlternateHTMLString(html, baseUrl.toString(), unreachableUrl.toString()); + else + d->webPageProxy->loadHTMLString(html, baseUrl.toString()); } qreal QQuickWebView::zoomFactor() const |