From 84a9a39debc520f04f1c501df570828db5c70642 Mon Sep 17 00:00:00 2001
From: Pavel Tumakaev
Date: Tue, 1 Mar 2022 19:05:44 +0300
Subject: [PATCH] [qtmozembed] Switch toolbar appearance control from gecko
scroll events to qt touch events. Contributes to JB#57776
This allows to control the visibility of the toolbar when the vertical size
of the page is larger than the visible area but less than or equal to the
size of the window.
---
src/qmozview_p.cpp | 51 ++++++++++++++++++++++++++++++++++------------
src/qmozview_p.h | 2 ++
2 files changed, 40 insertions(+), 13 deletions(-)
diff --git a/src/qmozview_p.cpp b/src/qmozview_p.cpp
index 71f86fd..9110ebf 100644
--- a/src/qmozview_p.cpp
+++ b/src/qmozview_p.cpp
@@ -45,6 +45,10 @@
#define MOZVIEW_FLICK_THRESHOLD 200
#endif
+#ifndef MOZVIEW_TOOLBAR_THRESHOLD
+#define MOZVIEW_TOOLBAR_THRESHOLD 5.0
+#endif
+
#ifndef MOZVIEW_FLICK_STOP_TIMEOUT
#define MOZVIEW_FLICK_STOP_TIMEOUT 500
#endif
@@ -137,6 +141,7 @@ QMozViewPrivate::QMozViewPrivate(IMozQViewIface *aViewIface, QObject *publicPtr)
, mContentRect(0.0, 0.0, 0.0, 0.0)
, mScrollableSize(0.0, 0.0)
, mScrollableOffset(0, 0)
+ , mScrollable(false)
, mAtXBeginning(false)
, mAtXEnd(false)
, mAtYBeginning(false)
@@ -244,19 +249,6 @@ void QMozViewPrivate::updateScrollArea(unsigned int aWidth, unsigned int aHeight
mDragStartY = offset;
}
- if (currentDelta > mChromeGestureThreshold) {
- qCDebug(lcEmbedLiteExt) << "currentDelta > mChromeGestureThreshold:" << mChrome;
- if (mChrome) {
- mChrome = false;
- mViewIface->chromeChanged();
- }
- } else if (currentDelta < -mChromeGestureThreshold) {
- qCDebug(lcEmbedLiteExt) << "currentDelta < -mChromeGestureThreshold:" << mChrome;
- if (!mChrome) {
- mChrome = true;
- mViewIface->chromeChanged();
- }
- }
mMoveDelta = qAbs(currentDelta);
}
}
@@ -286,6 +278,13 @@ void QMozViewPrivate::updateScrollArea(unsigned int aWidth, unsigned int aHeight
if (widthChanged || heightChanged) {
mViewIface->scrollableSizeChanged();
}
+
+ scrollableUpdate();
+}
+
+void QMozViewPrivate::scrollableUpdate()
+{
+ mScrollable = mScrollableSize.height() > (mContentResolution * mContentRect.height() - mDynamicToolbarHeight);
}
void QMozViewPrivate::testFlickingMode(QTouchEvent *event)
@@ -928,6 +927,7 @@ void QMozViewPrivate::setDynamicToolbarHeight(const int height)
} else {
mDirtyState |= DirtyDynamicToolbarHeight;
}
+ scrollableUpdate();
}
}
@@ -1377,6 +1377,8 @@ void QMozViewPrivate::touchEvent(QTouchEvent *event)
return;
}
+ qreal yDelta = 0.0;
+
QList pressedIds, moveIds, endIds;
QHash idHash;
for (int i = 0; i < touchPointsCount; ++i) {
@@ -1395,6 +1397,10 @@ void QMozViewPrivate::touchEvent(QTouchEvent *event)
}
case Qt::TouchPointMoved:
case Qt::TouchPointStationary: {
+ QMap::const_iterator i = mActiveTouchPoints.find(pt.id());
+ if (i != mActiveTouchPoints.end()) {
+ yDelta -= pt.pos().y() - i.value().y();
+ }
mActiveTouchPoints.insert(pt.id(), pt.pos());
moveIds.append(pt.id());
break;
@@ -1404,6 +1410,25 @@ void QMozViewPrivate::touchEvent(QTouchEvent *event)
}
}
+ if (moveIds.size()) {
+ static qreal yDeltaBuffer = 0.0;
+ yDeltaBuffer += yDelta / moveIds.size();
+
+ if (yDeltaBuffer > MOZVIEW_TOOLBAR_THRESHOLD) {
+ if (mChrome && mScrollable) {
+ mChrome = false;
+ mViewIface->chromeChanged();
+ }
+ yDeltaBuffer = MOZVIEW_TOOLBAR_THRESHOLD;
+ } else if (yDeltaBuffer < -MOZVIEW_TOOLBAR_THRESHOLD) {
+ if (!mChrome) {
+ mChrome = true;
+ mViewIface->chromeChanged();
+ }
+ yDeltaBuffer = -MOZVIEW_TOOLBAR_THRESHOLD;
+ }
+ }
+
// We should append previous touches to start event in order
// to make Gecko recognize it as new added touches to existing session
// and not evict it here http://hg.mozilla.org/mozilla-central/annotate/1d9c510b3742/layout/base/nsPresShell.cpp#l6135
diff --git a/src/qmozview_p.h b/src/qmozview_p.h
index 88afe20..87059ad 100644
--- a/src/qmozview_p.h
+++ b/src/qmozview_p.h
@@ -93,6 +93,7 @@ class QMozViewPrivate : public QObject,
void setDesktopMode(bool aDesktopMode);
void setThrottlePainting(bool aThrottle);
void updateScrollArea(unsigned int aWidth, unsigned int aHeight, float aPosX, float aPosY);
+ void scrollableUpdate();
void testFlickingMode(QTouchEvent *event);
void handleTouchEnd(bool &draggingChanged, bool &pinchingChanged);
void resetTouchState();
@@ -217,6 +218,7 @@ public Q_SLOTS:
QRectF mContentRect;
QSizeF mScrollableSize;
QPointF mScrollableOffset;
+ bool mScrollable;
bool mAtXBeginning;
bool mAtXEnd;
bool mAtYBeginning;