Skip to content

Commit

Permalink
[qtwebkit] Add pinching property to the experimental API
Browse files Browse the repository at this point in the history
  • Loading branch information
Raine Makelainen committed Aug 8, 2014
1 parent 940abe6 commit a671446
Show file tree
Hide file tree
Showing 5 changed files with 34 additions and 1 deletion.
16 changes: 16 additions & 0 deletions qtwebkit/Source/WebKit2/UIProcess/API/qt/qquickwebview.cpp
Expand Up @@ -349,6 +349,7 @@ void QQuickWebViewPrivate::initialize(WKContextRef contextRef, WKPageGroupRef pa
cookieManagerProxy = toImpl(context->context())->supplement<WebCookieManagerProxy>();

pageEventHandler.reset(new QtWebPageEventHandler(webPage.get(), pageView.data(), q_ptr));
QObject::connect(pageEventHandler.data(), SIGNAL(pinching(bool)), q_ptr, SLOT(_q_onPinchingChanged(bool)));

{
WKPageFindClient findClient;
Expand Down Expand Up @@ -701,6 +702,15 @@ void QQuickWebViewPrivate::_q_onIconChangedForPageURL(const QString& pageUrl)
updateIcon();
}

void QQuickWebViewPrivate::_q_onPinchingChanged(bool pinching)
{
if (pinching == m_pinching)
return;

m_pinching = pinching;
emit experimental->pinchingChanged();
}

/* Called either when the url changes, or when the icon for the current page changes */
void QQuickWebViewPrivate::updateIcon()
{
Expand Down Expand Up @@ -1649,6 +1659,12 @@ void QQuickWebViewExperimental::setOverview(bool enabled)
}
}

bool QQuickWebViewExperimental::pinching() const
{
Q_D(const QQuickWebView);
return d->m_pinching;
}

/*!
\internal
Expand Down
6 changes: 6 additions & 0 deletions qtwebkit/Source/WebKit2/UIProcess/API/qt/qquickwebview_p.h
Expand Up @@ -217,6 +217,7 @@ public Q_SLOTS:
Q_PRIVATE_SLOT(d_func(), void _q_onUrlChanged());
Q_PRIVATE_SLOT(d_func(), void _q_onReceivedResponseFromDownload(QWebDownloadItem*));
Q_PRIVATE_SLOT(d_func(), void _q_onIconChangedForPageURL(const QString&));
Q_PRIVATE_SLOT(d_func(), void _q_onPinchingChanged(bool));

// Hides QObject::d_ptr allowing us to use the convenience macros.
QScopedPointer<QQuickWebViewPrivate> d_ptr;
Expand Down Expand Up @@ -262,6 +263,7 @@ class QWEBKIT_EXPORT QQuickWebViewExperimental : public QObject {
Q_PROPERTY(int deviceHeight WRITE setDeviceHeight READ deviceHeight NOTIFY deviceHeightChanged)
Q_PROPERTY(int customLayoutWidth WRITE setCustomLayoutWidth READ customLayoutWidth NOTIFY customLayoutWidthChanged)
Q_PROPERTY(bool overview WRITE setOverview READ overview NOTIFY overviewChanged FINAL)
Q_PROPERTY(bool pinching READ pinching NOTIFY pinchingChanged FINAL)

Q_PROPERTY(bool autoCorrect WRITE setAutoCorrect READ autoCorrect NOTIFY autoCorrectChanged)
Q_PROPERTY(bool temporaryCookies WRITE setTemporaryCookies READ temporaryCookies NOTIFY temporaryCookiesChanged FINAL)
Expand Down Expand Up @@ -371,6 +373,8 @@ class QWEBKIT_EXPORT QQuickWebViewExperimental : public QObject {
bool overview() const;
void setOverview(bool enabled);

bool pinching() const;

bool autoCorrect() const;
void setAutoCorrect(bool autoCorrect);

Expand Down Expand Up @@ -427,6 +431,8 @@ public Q_SLOTS:
void autoCorrectChanged();
void customLayoutWidthChanged();
void overviewChanged();
void pinchingChanged();

void temporaryCookiesChanged();
void textFound(int matchCount);
void offlineChanged();
Expand Down
2 changes: 2 additions & 0 deletions qtwebkit/Source/WebKit2/UIProcess/API/qt/qquickwebview_p_p.h
Expand Up @@ -104,6 +104,7 @@ class QQuickWebViewPrivate {
void _q_onUrlChanged();
void _q_onReceivedResponseFromDownload(QWebDownloadItem*);
void _q_onIconChangedForPageURL(const QString&);
void _q_onPinchingChanged(bool);

void chooseFiles(WKOpenPanelResultListenerRef, const QStringList& selectedFileNames, WebKit::QtWebPageUIClient::FileChooserType);
quint64 exceededDatabaseQuota(const QString& databaseName, const QString& displayName, WKSecurityOriginRef securityOrigin, quint64 currentQuota, quint64 currentOriginUsage, quint64 currentDatabaseUsage, quint64 expectedUsage);
Expand Down Expand Up @@ -240,6 +241,7 @@ class QQuickWebViewPrivate {
QUrl m_iconUrl;
int m_loadProgress;
QString m_currentUrl;
bool m_pinching;
};

class QQuickWebViewLegacyPrivate : public QQuickWebViewPrivate {
Expand Down
Expand Up @@ -489,8 +489,10 @@ void QtWebPageEventHandler::handleInputEvent(const QInputEvent* event)

// If the scale animation is active we don't pass the event to the recognizers. In the future
// we would want to queue the event here and repost then when the animation ends.
if (m_viewportController->scaleAnimationActive())
if (m_viewportController->scaleAnimationActive()) {
emit pinching(false);
return;
}
}

bool isMouseEvent = false;
Expand All @@ -510,6 +512,7 @@ void QtWebPageEventHandler::handleInputEvent(const QInputEvent* event)
m_isMouseButtonPressed = false;
break;
case QEvent::MouseButtonDblClick:
emit pinching(false);
return;
default:
break;
Expand Down Expand Up @@ -564,16 +567,19 @@ void QtWebPageEventHandler::handleInputEvent(const QInputEvent* event)
m_pinchGestureRecognizer.finish();

// Early return since this was a touch-end event.
emit pinching(false);
return;
} else if (activeTouchPointCount == 1) {
// If the pinch gesture recognizer was previously in active state the content might
// be out of valid zoom boundaries, thus we need to finish the pinch gesture here.
// This will resume the content to valid zoom levels before the pan gesture is started.
m_pinchGestureRecognizer.finish();
m_panGestureRecognizer.update(activeTouchPoints.first(), eventTimestampMillis);
emit pinching(false);
} else if (activeTouchPointCount == 2) {
m_panGestureRecognizer.cancel();
m_pinchGestureRecognizer.update(activeTouchPoints.first(), activeTouchPoints.last());
emit pinching(true);
}

if (m_panGestureRecognizer.isRecognized() || m_pinchGestureRecognizer.isRecognized() || m_webView->isMoving())
Expand Down
3 changes: 3 additions & 0 deletions qtwebkit/Source/WebKit2/UIProcess/qt/QtWebPageEventHandler.h
Expand Up @@ -96,6 +96,9 @@ class QtWebPageEventHandler : public QObject {

void startDrag(const WebCore::DragData&, PassRefPtr<ShareableBitmap> dragImage);

Q_SIGNALS:
void pinching(bool enabled);

protected:
WebPageProxy* m_webPageProxy;
PageViewportControllerClientQt* m_viewportController;
Expand Down

0 comments on commit a671446

Please sign in to comment.