Release left button before showing the popup context menu

If we release the left button after the popup context menu
is visible, the left button will hide the menu immediately.

Change-Id: Ie6edf85beb683fd83247e90e7edb4faa5aff6d35
Reviewed-by: Eskil Abrahamsen Blomfeldt <eskil.abrahamsen-blomfeldt@qt.io>
bb10
BogDan Vatra 2017-12-15 14:45:17 +02:00
parent 8379186009
commit 5e8b16f0e4
3 changed files with 23 additions and 0 deletions

View File

@ -196,6 +196,20 @@ namespace QtAndroidInput
angleDelta);
}
void releaseMouse(int x, int y)
{
m_ignoreMouseEvents = true;
QPoint globalPos(x,y);
QWindow *tlw = topLevelWindowAt(globalPos);
QPoint localPos = tlw ? (globalPos-tlw->position()) : globalPos;
// Release left button
QWindowSystemInterface::handleMouseEvent(tlw,
localPos,
globalPos,
Qt::MouseButtons(Qt::NoButton));
}
static void longPress(JNIEnv */*env*/, jobject /*thiz*/, jint /*winId*/, jint x, jint y)
{
QAndroidInputContext *inputContext = QAndroidInputContext::androidInputContext();

View File

@ -61,6 +61,8 @@ namespace QtAndroidInput
void updateHandles(int handleCount, QPoint editMenuPos = QPoint(), uint32_t editButtons = 0, QPoint cursor = QPoint(), QPoint anchor = QPoint(), bool rtl = false);
bool registerNatives(JNIEnv *env);
void releaseMouse(int x, int y);
}
QT_END_NAMESPACE

View File

@ -715,7 +715,14 @@ void QAndroidInputContext::touchDown(int x, int y)
void QAndroidInputContext::longPress(int x, int y)
{
static bool noHandles = qEnvironmentVariableIntValue("QT_QPA_NO_TEXT_HANDLES");
if (noHandles)
return;
if (m_focusObject && inputItemRectangle().contains(x, y)) {
// Release left button, otherwise the following events will cancel the menu popup
QtAndroidInput::releaseMouse(x, y);
handleLocationChanged(1, x, y);
ScopedValueChangeBack<bool> svcb(m_blockUpdateSelection, true);