Skip to content

Commit

Permalink
[qtmozembed] Switch toolbar appearance control from gecko scroll even…
Browse files Browse the repository at this point in the history
…ts 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.
  • Loading branch information
paveltkv committed Mar 17, 2022
1 parent 5c671a5 commit 84a9a39
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 13 deletions.
51 changes: 38 additions & 13 deletions src/qmozview_p.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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);
}
}
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -928,6 +927,7 @@ void QMozViewPrivate::setDynamicToolbarHeight(const int height)
} else {
mDirtyState |= DirtyDynamicToolbarHeight;
}
scrollableUpdate();
}
}

Expand Down Expand Up @@ -1377,6 +1377,8 @@ void QMozViewPrivate::touchEvent(QTouchEvent *event)
return;
}

qreal yDelta = 0.0;

QList<int> pressedIds, moveIds, endIds;
QHash<int, int> idHash;
for (int i = 0; i < touchPointsCount; ++i) {
Expand All @@ -1395,6 +1397,10 @@ void QMozViewPrivate::touchEvent(QTouchEvent *event)
}
case Qt::TouchPointMoved:
case Qt::TouchPointStationary: {
QMap<int, QPointF>::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;
Expand All @@ -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
Expand Down
2 changes: 2 additions & 0 deletions src/qmozview_p.h
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down Expand Up @@ -217,6 +218,7 @@ public Q_SLOTS:
QRectF mContentRect;
QSizeF mScrollableSize;
QPointF mScrollableOffset;
bool mScrollable;
bool mAtXBeginning;
bool mAtXEnd;
bool mAtYBeginning;
Expand Down

0 comments on commit 84a9a39

Please sign in to comment.