[Android] Fix select handles misplacement on QDialog

Get select handles {Left, Right}Point from a mapToGlobal with a cursorRectangle of anchorRectangle of the selected word/text

Change-Id: I3425104c90f0efe6a1e4337328cf06dc93685b6f
Task-number: QTBUG-90799
Reviewed-by: Rami Potinkara <rami.potinkara@qt.io>
Reviewed-by: Ville Voutilainen <ville.voutilainen@qt.io>
(cherry picked from commit 56b54743e001c4af196c1e4786118d88b1d2cd2f)
Reviewed-by: Qt Cherry-pick Bot <cherrypick_bot@qt-project.org>
This commit is contained in:
Pekka Gehör 2021-02-26 12:26:51 +02:00 committed by Qt Cherry-pick Bot
parent 3081731b02
commit 906da939f3

View File

@ -94,6 +94,7 @@ private:
static QAndroidInputContext *m_androidInputContext = nullptr;
static char const *const QtNativeInputConnectionClassName = "org/qtproject/qt/android/QtNativeInputConnection";
static char const *const QtExtractedTextClassName = "org/qtproject/qt/android/QtExtractedText";
static char const *const QtObjectType = "QDialog";
static jclass m_extractedTextClass = 0;
static jmethodID m_classConstructorMethodID = 0;
static jfieldID m_partialEndOffsetFieldID = 0;
@ -645,7 +646,7 @@ void QAndroidInputContext::updateSelectionHandles()
}
auto curRect = im->cursorRectangle();
QPoint cursorPoint = qGuiApp->focusWindow()->mapToGlobal(QPoint(curRect.x() + (curRect.width() / 2), curRect.y() + curRect.height()));
QPoint cursorPoint(window->mapToGlobal(QPoint(curRect.x() + (curRect.width() / 2), curRect.y() + curRect.height())));
QPoint editMenuPoint(cursorPoint.x(), cursorPoint.y());
m_handleMode &= ShowEditPopup;
m_handleMode |= ShowCursor;
@ -665,10 +666,12 @@ void QAndroidInputContext::updateSelectionHandles()
if (cpos > anchor)
std::swap(leftRect, rightRect);
QPoint leftPoint(leftRect.bottomLeft().toPoint() * pixelDensity);
QPoint righPoint(rightRect.bottomRight().toPoint() * pixelDensity);
QPoint editPoint(leftRect.united(rightRect).topLeft().toPoint() * pixelDensity);
QtAndroidInput::updateHandles(m_handleMode, editPoint, EditContext::AllButtons, leftPoint, righPoint,
QPoint leftPoint(window->mapToGlobal(leftRect.bottomLeft().toPoint()));
QPoint righPoint(window->mapToGlobal(rightRect.bottomRight().toPoint()));
QPoint editPoint(window->mapToGlobal(leftRect.united(rightRect)
.topLeft().toPoint()));
QtAndroidInput::updateHandles(m_handleMode, editPoint * pixelDensity, EditContext::AllButtons,
leftPoint * pixelDensity, righPoint * pixelDensity,
query.value(Qt::ImCurrentSelection).toString().isRightToLeft());
m_hideCursorHandleTimer.stop();
}
@ -692,7 +695,17 @@ void QAndroidInputContext::handleLocationChanged(int handleId, int x, int y)
double pixelDensity = window
? QHighDpiScaling::factor(window)
: QHighDpiScaling::factor(QtAndroid::androidPlatformIntegration()->screen());
QPointF point(x / pixelDensity, y / pixelDensity);
auto object = m_focusObject->parent();
int dialogMoveX = 0;
while (object) {
if (QString::compare(object->metaObject()->className(),
QtObjectType, Qt::CaseInsensitive) == 0) {
dialogMoveX += object->property("x").toInt();
}
object = object->parent();
};
QPointF point((x / pixelDensity) - dialogMoveX, y / pixelDensity);
point.setY(point.y() - leftRect.width() / 2);
QInputMethodQueryEvent query(Qt::ImCursorPosition | Qt::ImAnchorPosition