Android: Do not modify Touch Event position in JAVA code
In QtWindow class, the Touch Event coordinates were increased by Layout position. That allows to move to global coordinates. In the same time, in 15674f4ce9ea455b47f68d8871d5676d7a731630 commit, we started mapping coordinates of Touch Event to Global position. That cause the issue with incorrectly handled touches for example with QDialogs. To avoid this issue, we will stop modify Touch Event position in JAVA code. We will send only localPosition to not make transformation twice. With this change, all events received from JAVA have local position of their window. Pick-to: 6.9 6.8 Fixes: QTBUG-130576 Fixes: QTBUG-127925 Change-Id: I6b58e0369959840f869e31a3d96425c64507b39d Reviewed-by: Tinja Paavoseppä <tinja.paavoseppa@qt.io>
This commit is contained in:
parent
01d25533b4
commit
23fd2cfb01
@ -140,7 +140,6 @@ class QtWindow extends QtLayout implements QtSurfaceInterface {
|
||||
if (m_editText != null && m_inputConnectionListener != null)
|
||||
m_inputConnectionListener.onEditTextChanged(m_editText);
|
||||
|
||||
event.setLocation(event.getX() + getX(), event.getY() + getY());
|
||||
QtInputDelegate.sendTouchEvent(event, getId());
|
||||
m_gestureDetector.onTouchEvent(event);
|
||||
return true;
|
||||
|
@ -168,23 +168,23 @@ namespace QtAndroidInput
|
||||
if (m_ignoreMouseEvents)
|
||||
return;
|
||||
|
||||
const QPoint globalPos(x,y);
|
||||
const QPoint localPos(x,y);
|
||||
QWindow *window = windowFromId(winId);
|
||||
m_mouseGrabber = window;
|
||||
const QPoint localPos = window && window->handle() ?
|
||||
window->handle()->mapFromGlobal(globalPos) : globalPos;
|
||||
const QPoint globalPos = window && window->handle() ?
|
||||
window->handle()->mapToGlobal(localPos) : localPos;
|
||||
sendMouseButtonEvents(window, localPos, globalPos, mouseButtonState, QEvent::MouseButtonPress);
|
||||
}
|
||||
|
||||
static void mouseUp(JNIEnv */*env*/, jobject /*thiz*/, jint winId, jint x, jint y, jint mouseButtonState)
|
||||
{
|
||||
const QPoint globalPos(x,y);
|
||||
const QPoint localPos(x,y);
|
||||
QWindow *window = m_mouseGrabber.data();
|
||||
if (!window)
|
||||
window = windowFromId(winId);
|
||||
|
||||
const QPoint localPos = window && window->handle() ?
|
||||
window->handle()->mapFromGlobal(globalPos) : globalPos;
|
||||
const QPoint globalPos = window && window->handle() ?
|
||||
window->handle()->mapToGlobal(localPos) : localPos;
|
||||
|
||||
sendMouseButtonEvents(window, localPos, globalPos, mouseButtonState, QEvent::MouseButtonRelease);
|
||||
m_ignoreMouseEvents = false;
|
||||
@ -196,12 +196,12 @@ namespace QtAndroidInput
|
||||
if (m_ignoreMouseEvents)
|
||||
return;
|
||||
|
||||
const QPoint globalPos(x,y);
|
||||
const QPoint localPos(x,y);
|
||||
QWindow *window = m_mouseGrabber.data();
|
||||
if (!window)
|
||||
window = windowFromId(winId);
|
||||
const QPoint localPos = window && window->handle() ?
|
||||
window->handle()->mapFromGlobal(globalPos) : globalPos;
|
||||
const QPoint globalPos = window && window->handle() ?
|
||||
window->handle()->mapToGlobal(localPos) : localPos;
|
||||
sendMouseButtonEvents(window, localPos, globalPos, mouseButtonState, QEvent::MouseMove);
|
||||
}
|
||||
|
||||
@ -210,12 +210,12 @@ namespace QtAndroidInput
|
||||
if (m_ignoreMouseEvents)
|
||||
return;
|
||||
|
||||
const QPoint globalPos(x,y);
|
||||
const QPoint localPos(x,y);
|
||||
QWindow *window = m_mouseGrabber.data();
|
||||
if (!window)
|
||||
window = windowFromId(winId);
|
||||
const QPoint localPos = window && window->handle() ?
|
||||
window->handle()->mapFromGlobal(globalPos) : globalPos;
|
||||
const QPoint globalPos = window && window->handle() ?
|
||||
window->handle()->mapToGlobal(localPos) : localPos;
|
||||
const QPoint angleDelta(hdelta * 120, vdelta * 120);
|
||||
|
||||
QWindowSystemInterface::handleWheelEvent(window,
|
||||
@ -228,18 +228,21 @@ namespace QtAndroidInput
|
||||
static void longPress(JNIEnv */*env*/, jobject /*thiz*/, jint winId, jint x, jint y)
|
||||
{
|
||||
QAndroidInputContext *inputContext = QAndroidInputContext::androidInputContext();
|
||||
|
||||
const QPoint globalPos(x,y);
|
||||
QWindow *window = windowFromId(winId);
|
||||
const QPoint localPos = window && window->handle() ?
|
||||
window->handle()->mapFromGlobal(globalPos) : globalPos;
|
||||
|
||||
if (inputContext && qGuiApp)
|
||||
QMetaObject::invokeMethod(inputContext, "longPress", Q_ARG(int, x), Q_ARG(int, y));
|
||||
QMetaObject::invokeMethod(inputContext, "longPress", Q_ARG(int, globalPos.x()), Q_ARG(int, globalPos.y()));
|
||||
|
||||
//### TODO: add proper API for Qt 5.2
|
||||
static bool rightMouseFromLongPress = qEnvironmentVariableIntValue("QT_ANDROID_ENABLE_RIGHT_MOUSE_FROM_LONG_PRESS");
|
||||
if (!rightMouseFromLongPress)
|
||||
return;
|
||||
m_ignoreMouseEvents = true;
|
||||
const QPoint globalPos(x,y);
|
||||
QWindow *window = windowFromId(winId);
|
||||
const QPoint localPos = window && window->handle() ?
|
||||
window->handle()->mapFromGlobal(globalPos) : globalPos;
|
||||
|
||||
|
||||
// Click right button if no other button is already pressed.
|
||||
if (!m_mouseGrabber) {
|
||||
@ -312,7 +315,7 @@ namespace QtAndroidInput
|
||||
if (state == QEventPoint::State::Pressed) {
|
||||
QAndroidInputContext *inputContext = QAndroidInputContext::androidInputContext();
|
||||
if (inputContext && qGuiApp)
|
||||
QMetaObject::invokeMethod(inputContext, "touchDown", Q_ARG(int, x), Q_ARG(int, y));
|
||||
QMetaObject::invokeMethod(inputContext, "touchDown", Q_ARG(int, mappedTouchPoint.x()), Q_ARG(int, mappedTouchPoint.y()));
|
||||
}
|
||||
}
|
||||
|
||||
@ -384,10 +387,10 @@ namespace QtAndroidInput
|
||||
jint pointerType, jint buttonState, jfloat x, jfloat y, jfloat pressure)
|
||||
{
|
||||
#if QT_CONFIG(tabletevent)
|
||||
const QPointF globalPosF(x, y);
|
||||
const QPointF localPos(x, y);
|
||||
QWindow *window = windowFromId(winId);
|
||||
const QPointF localPos = window && window->handle() ?
|
||||
window->handle()->mapFromGlobalF(globalPosF) : globalPosF;
|
||||
const QPointF globalPosF = window && window->handle() ?
|
||||
window->handle()->mapFromGlobalF(localPos) : localPos;
|
||||
|
||||
// Galaxy Note with plain Android:
|
||||
// 0 1 0 stylus press
|
||||
|
Loading…
x
Reference in New Issue
Block a user