Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[qtmozembed] Switch toolbar appearance control from gecko scroll events to qt touch events. Contributes to JB#57777 #44

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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