From b1820295e1e8f04634cf9c008a2473d9e2889288 Mon Sep 17 00:00:00 2001 From: Rami Potinkara Date: Fri, 15 Oct 2021 05:52:44 +0000 Subject: Revert "Android: Place cursor correctly on screen when editing" This reverts commit 5c6b10c3cee5737dbc041d0463220898c8120807. It caused a regression such that the main window no longer resized or panned when the VKB is shown, in spite of android:windowSoftInputMode being set. Pick-to: 6.2 5.15 Task-number: QTBUG-95300 Task-number: QTBUG-96117 Task-number: QTBUG-97503 Change-Id: If56e1113eea69a940f6760bdb2ad06a93a0759c1 Reviewed-by: Andreas Buhr Reviewed-by: Assam Boudjelthia --- .../qtproject/qt/android/QtActivityDelegate.java | 15 ++----- .../jar/src/org/qtproject/qt/android/QtNative.java | 17 +------- .../qtproject/qt/android/bindings/QtActivity.java | 11 ++--- src/plugins/platforms/android/androidjniinput.cpp | 16 +------ src/plugins/platforms/android/androidjniinput.h | 4 +- .../platforms/android/qandroidinputcontext.cpp | 50 +++------------------- .../platforms/android/qandroidinputcontext.h | 2 - 7 files changed, 17 insertions(+), 98 deletions(-) (limited to 'src') diff --git a/src/android/jar/src/org/qtproject/qt/android/QtActivityDelegate.java b/src/android/jar/src/org/qtproject/qt/android/QtActivityDelegate.java index 9039f9c4f9..3c387f1f9d 100644 --- a/src/android/jar/src/org/qtproject/qt/android/QtActivityDelegate.java +++ b/src/android/jar/src/org/qtproject/qt/android/QtActivityDelegate.java @@ -285,7 +285,7 @@ public class QtActivityDelegate }, 5); } - public void showSoftwareKeyboard(final int x, final int y, final int width, final int height, final int editorHeight, final int inputHints, final int enterKeyType) + public void showSoftwareKeyboard(final int x, final int y, final int width, final int height, final int inputHints, final int enterKeyType) { if (m_imm == null) return; @@ -307,7 +307,7 @@ public class QtActivityDelegate if (softInputIsHidden) return; } else { - if (editorHeight > visibleHeight) + if (height > visibleHeight) m_activity.getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_UNCHANGED | WindowManager.LayoutParams.SOFT_INPUT_ADJUST_RESIZE); else m_activity.getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_UNCHANGED | WindowManager.LayoutParams.SOFT_INPUT_ADJUST_PAN); @@ -428,12 +428,12 @@ public class QtActivityDelegate if (metrics.widthPixels > metrics.heightPixels) { // landscape if (m_landscapeKeyboardHeight != r.bottom) { m_landscapeKeyboardHeight = r.bottom; - showSoftwareKeyboard(x, y, width, height, editorHeight, inputHints, enterKeyType); + showSoftwareKeyboard(x, y, width, height, inputHints, enterKeyType); } } else { if (m_portraitKeyboardHeight != r.bottom) { m_portraitKeyboardHeight = r.bottom; - showSoftwareKeyboard(x, y, width, height, editorHeight, inputHints, enterKeyType); + showSoftwareKeyboard(x, y, width, height, inputHints, enterKeyType); } } } else { @@ -593,13 +593,6 @@ public class QtActivityDelegate } } - public void updateInputItemRectangle(final int x, final int y, final int w, final int h) - { - if (m_layout == null || m_editText == null || !m_keyboardIsVisible) - return; - m_layout.setLayoutParams(m_editText, new QtLayout.LayoutParams(w, h, x, y), true); - } - public boolean loadApplication(Activity activity, ClassLoader classLoader, Bundle loaderParams) { /// check parameters integrity diff --git a/src/android/jar/src/org/qtproject/qt/android/QtNative.java b/src/android/jar/src/org/qtproject/qt/android/QtNative.java index 61dbaee2a2..11bb0b37ef 100644 --- a/src/android/jar/src/org/qtproject/qt/android/QtNative.java +++ b/src/android/jar/src/org/qtproject/qt/android/QtNative.java @@ -892,25 +892,10 @@ public class QtNative }); } - private static void updateInputItemRectangle(final int x, - final int y, - final int w, - final int h) - { - runAction(new Runnable() { - @Override - public void run() { - m_activityDelegate.updateInputItemRectangle(x, y, w, h); - } - }); - } - - private static void showSoftwareKeyboard(final int x, final int y, final int width, final int height, - final int editorHeight, final int inputHints, final int enterKeyType) { @@ -918,7 +903,7 @@ public class QtNative @Override public void run() { if (m_activityDelegate != null) - m_activityDelegate.showSoftwareKeyboard(x, y, width, height, editorHeight, inputHints, enterKeyType); + m_activityDelegate.showSoftwareKeyboard(x, y, width, height, inputHints, enterKeyType); } }); } diff --git a/src/android/java/src/org/qtproject/qt/android/bindings/QtActivity.java b/src/android/java/src/org/qtproject/qt/android/bindings/QtActivity.java index 3d233f1c90..9bfa8738b6 100644 --- a/src/android/java/src/org/qtproject/qt/android/bindings/QtActivity.java +++ b/src/android/java/src/org/qtproject/qt/android/bindings/QtActivity.java @@ -1090,11 +1090,6 @@ public class QtActivity extends Activity QtNative.activityDelegate().resetSoftwareKeyboard(); } - public void updateInputItemRectangle(final int x, final int y, final int w, final int h) - { - QtNative.activityDelegate().updateInputItemRectangle(x, y, w, h); - } - public boolean setKeyboardVisibility(boolean visibility, long timeStamp) { return QtNative.activityDelegate().setKeyboardVisibility(visibility, timeStamp); @@ -1111,10 +1106,10 @@ public class QtActivity extends Activity } public void showSoftwareKeyboard(final int x, final int y, final int width, - final int height, final int editorHeight, - final int inputHints, final int enterKeyType) + final int height, final int inputHints, + final int enterKeyType) { - QtNative.activityDelegate().showSoftwareKeyboard(x, y, width, height, editorHeight, inputHints, enterKeyType); + QtNative.activityDelegate().showSoftwareKeyboard(x, y, width, height, inputHints, enterKeyType); } public boolean startApplication() diff --git a/src/plugins/platforms/android/androidjniinput.cpp b/src/plugins/platforms/android/androidjniinput.cpp index ebdc18cc07..eb41ec6656 100644 --- a/src/plugins/platforms/android/androidjniinput.cpp +++ b/src/plugins/platforms/android/androidjniinput.cpp @@ -78,16 +78,15 @@ namespace QtAndroidInput candidatesEnd); } - void showSoftwareKeyboard(int left, int top, int width, int height, int editorHeight, int inputHints, int enterKeyType) + void showSoftwareKeyboard(int left, int top, int width, int height, int inputHints, int enterKeyType) { QJniObject::callStaticMethod(applicationClass(), "showSoftwareKeyboard", - "(IIIIIII)V", + "(IIIIII)V", left, top, width, height, - editorHeight, inputHints, enterKeyType); #ifdef QT_DEBUG_ANDROID_IM_PROTOCOL @@ -134,17 +133,6 @@ namespace QtAndroidInput anchor.x(), anchor.y(), rtl); } - void updateInputItemRectangle(int left, int top, int width, int height) - { - QJniObject::callStaticMethod(applicationClass(), - "updateInputItemRectangle", - "(IIII)V", - left, - top, - width, - height); - } - static void mouseDown(JNIEnv */*env*/, jobject /*thiz*/, jint /*winId*/, jint x, jint y) { if (m_ignoreMouseEvents) diff --git a/src/plugins/platforms/android/androidjniinput.h b/src/plugins/platforms/android/androidjniinput.h index ceef2a826c..30c083f51c 100644 --- a/src/plugins/platforms/android/androidjniinput.h +++ b/src/plugins/platforms/android/androidjniinput.h @@ -49,7 +49,7 @@ QT_BEGIN_NAMESPACE namespace QtAndroidInput { // Software keyboard support - void showSoftwareKeyboard(int top, int left, int width, int editorHeight, int height, int inputHints, int enterKeyType); + void showSoftwareKeyboard(int top, int left, int width, int height, int inputHints, int enterKeyType); void resetSoftwareKeyboard(); void hideSoftwareKeyboard(); bool isSoftwareKeyboardVisible(); @@ -57,8 +57,6 @@ namespace QtAndroidInput void updateSelection(int selStart, int selEnd, int candidatesStart, int candidatesEnd); // Software keyboard support - // edit field resize - void updateInputItemRectangle(int left, int top, int width, int height); // cursor/selection handles void updateHandles(int handleCount, QPoint editMenuPos = QPoint(), uint32_t editButtons = 0, QPoint cursor = QPoint(), QPoint anchor = QPoint(), bool rtl = false); diff --git a/src/plugins/platforms/android/qandroidinputcontext.cpp b/src/plugins/platforms/android/qandroidinputcontext.cpp index 37a5191dfc..aac0ba2c89 100644 --- a/src/plugins/platforms/android/qandroidinputcontext.cpp +++ b/src/plugins/platforms/android/qandroidinputcontext.cpp @@ -60,6 +60,7 @@ #include #include #include + QT_BEGIN_NAMESPACE namespace { @@ -492,7 +493,7 @@ QAndroidInputContext::QAndroidInputContext() m_androidInputContext = this; QObject::connect(QGuiApplication::inputMethod(), &QInputMethod::cursorRectangleChanged, - this, &QAndroidInputContext::updateInputItemRectangle); + this, &QAndroidInputContext::updateSelectionHandles); QObject::connect(QGuiApplication::inputMethod(), &QInputMethod::anchorRectangleChanged, this, &QAndroidInputContext::updateSelectionHandles); QObject::connect(QGuiApplication::inputMethod(), &QInputMethod::inputItemClipRectangleChanged, this, [this]{ @@ -921,49 +922,10 @@ void QAndroidInputContext::showInputPanel() else m_updateCursorPosConnection = connect(qGuiApp->focusObject(), SIGNAL(cursorPositionChanged()), this, SLOT(updateCursorPosition())); - QRect rect = cursorRect(); - if (!isInputPanelVisible()) - QtAndroidInput::showSoftwareKeyboard(rect.left(), rect.top(), rect.width(), rect.height(), - screenInputItemRectangle().height(), - query->value(Qt::ImHints).toUInt(), - query->value(Qt::ImEnterKeyType).toUInt()); -} - -QRect QAndroidInputContext::cursorRect() -{ - QSharedPointer query = focusObjectInputMethodQuery(); - // if single line, we do not want to mess with the editor's position, as we do not - // have to follow the cursor in vertical axis - if (query.isNull() - || (query->value(Qt::ImHints).toUInt() & Qt::ImhMultiLine) != Qt::ImhMultiLine) - return {}; - - auto im = qGuiApp->inputMethod(); - if (!im) - return {}; - - const auto cursorRect= im->cursorRectangle().toRect(); - QRect finalRect(inputItemRectangle().toRect()); - const QWindow *window = qGuiApp->focusWindow(); - const double pd = window - ? QHighDpiScaling::factor(window) - : QHighDpiScaling::factor(QtAndroid::androidPlatformIntegration()->screen()); - finalRect.setY(cursorRect.y() * pd); - finalRect.setHeight(cursorRect.height() * pd); - //fiddle a bit with vert margins, so the tracking rectangle is not too tight. - finalRect += QMargins(0, cursorRect.height() / 4, 0, cursorRect.height() / 4); - return finalRect; -} - -void QAndroidInputContext::updateInputItemRectangle() -{ - QRect rect = cursorRect(); - - if (!rect.isValid()) - return; - QtAndroidInput::updateInputItemRectangle(rect.left(), rect.top(), - rect.width(), rect.height()); - updateSelectionHandles(); + QRect rect = screenInputItemRectangle(); + QtAndroidInput::showSoftwareKeyboard(rect.left(), rect.top(), rect.width(), rect.height(), + query->value(Qt::ImHints).toUInt(), + query->value(Qt::ImEnterKeyType).toUInt()); } void QAndroidInputContext::showInputPanelLater(Qt::ApplicationState state) diff --git a/src/plugins/platforms/android/qandroidinputcontext.h b/src/plugins/platforms/android/qandroidinputcontext.h index 02a66c367a..e9bfb98e66 100644 --- a/src/plugins/platforms/android/qandroidinputcontext.h +++ b/src/plugins/platforms/android/qandroidinputcontext.h @@ -138,7 +138,6 @@ public: public slots: void safeCall(const std::function &func, Qt::ConnectionType conType = Qt::BlockingQueuedConnection); void updateCursorPosition(); - void updateInputItemRectangle(); void updateSelectionHandles(); void handleLocationChanged(int handleId, int x, int y); void touchDown(int x, int y); @@ -155,7 +154,6 @@ private: bool focusObjectIsComposing() const; void focusObjectStartComposing(); bool focusObjectStopComposing(); - QRect cursorRect(); private: ExtractedText m_extractedText; -- cgit v1.2.3