summaryrefslogtreecommitdiffstats
path: root/src/plugins/platforms/android/qandroidinputcontext.cpp
Commit message (Collapse)AuthorAgeFilesLines
* Revert "QAndroidPlatformInputContext: send composition text and cursor jointly"Axel Spoerl2024-03-051-7/+15
| | | | | | | | | | | This reverts commit be3b9b2ab12f664c196d649e8c4247d70805d667. Reason for revert: Caused QTBUG-121561 Fixes: QTBUG-121561 Pick-to: 6.7 6.6 6.5 6.2 Change-Id: I4b59d97ede6c50d2575a7d7cebbe2291983dd19f Reviewed-by: Tor Arne Vestbø <tor.arne.vestbo@qt.io>
* Android: QtEditText support for full-screen soft keyboardRami Potinkara2024-02-151-1/+39
| | | | | | | | | | | | Full-screen soft keyboard support added. Including functionality for copy-cut-paste and line change. Future TODO QTBUG-121522 Task-number: QTBUG-109367 Pick-to: 6.7 6.6 6.5 6.2 Change-Id: Ia5632cacc910c7ebde0e40608c2abd027b8f953a Reviewed-by: Assam Boudjelthia <assam.boudjelthia@qt.io>
* Android: Bail early in showInputPanel() when focusWindow is not nativeAndy Nichols2024-01-151-0/+3
| | | | | | | | | | | | | | QAndroidInputContext::showInputPanel() assumes that any window with focus must be a native window, but sometimes the focus window will be an offscreen window, like in the case of using OpenXR where there is no native window to be focused. In that case the 2D input method overlay doesn't even make sense, since there is no window space to even map back to. This patch prevents crashes when trying to focus on text in Android VR/XR applications. Change-Id: I16ac1a07f0a86ec9786f09a2f416387c1885bde0 Reviewed-by: Assam Boudjelthia <assam.boudjelthia@qt.io> Reviewed-by: Laszlo Agocs <laszlo.agocs@qt.io>
* Android: Hide text handle when it is out or coveredBartlomiej Moskal2023-11-021-1/+9
| | | | | | | | | | | | The text handle should not be visible in case when it is out of the text-object, or when it is hidden by other object. That is why we should call updateSelectionHandles() method after touch only in case when cursor position fits to clipped input item rectangle. Fixes: QTBUG-115005 Pick-to: 6.6 6.5 Change-Id: I35c083acd8fd4d5240e3bb15afa1afbec4ea0b26 Reviewed-by: Assam Boudjelthia <assam.boudjelthia@qt.io>
* Android: Fix for hiding cursor handlesBartlomiej Moskal2023-10-241-3/+7
| | | | | | | | | | | | | | | | | | After c80f262258b7846bf199887bcfdbb6dcfda6ad6f commit (which fixed selection for read-only texts), checking if m_handleMode is Hidden was removed. Because of that hidding cursor handle stopped work correctly. This commit brings back check if m_handleMode is Hidden. Also when only one handle is visible, it should be hidden within the next 5 seconds regardless for keyboard visibility. That is how it is handled in pure Android apps. Pick-to: 6.6 6.5 Fixes: QTBUG-117367 Change-Id: I0400f9604234bfad7fe17d74673ae9a93088bab4 Reviewed-by: Assam Boudjelthia <assam.boudjelthia@qt.io> Reviewed-by: Rami Potinkara <rami.potinkara@qt.io>
* Android: Handle ImhNoTextHandles flag from InputMethodHintsBartlomiej Moskal2023-09-151-0/+13
| | | | | | | | | | | | | | | | [0]Qt::InputMethodHints has a flag ImhNoTextHandles that was not handled. This flag should be considered when QAndroidInputContext is updating Text handles position. What is more, this flag can be used to fix the problem with visible text cursor out of the text object. [0]https://doc.qt.io/qt-6/qt.html#InputMethodHint-enum Task-number: QTBUG-115005 Pick-to: 6.6 6.5 Change-Id: Ie50b77d7afbadfebe73f10137f09da9560aea1ba Reviewed-by: Assam Boudjelthia <assam.boudjelthia@qt.io> Reviewed-by: Rami Potinkara <rami.potinkara@qt.io>
* QAndroidPlatformInputContext: send composition text and cursor jointlyAxel Spoerl2023-08-141-15/+7
| | | | | | | | | | | | | | | | | | | | | | | | | | QAndroidPlatformInputContext::focusObjectStopComposing() sends an input event for each character newly added by the Android virtual keyboard. It then sends a second input event to notify that the cursor has advanced to the position after the new character. The implicit assumption is, that the receiver of the input event does not change the text. If e.g. QLineEdit::setText() is called in the QLineEdit::textEdited slot, the text does change. If the change implies a cursor change, QLineEdit notifies the platform input context about it. However, by sending the second input event, QAndroidPlatformContent returns the cursor back to the position after the last character added by the virtual keyboard. This patch joins the composed text and the cursor position into one single input method event. A new cursor position, set by the receiver of the input method event, is no longer overridden. The patch adds test functionality to tst_QLineEdit::setText(). Fixes: QTBUG-115756 Pick-to: 6.6 6.5 6.2 Change-Id: I85ffac5d6bab93ccb144be0f5b8083258a270550 Reviewed-by: Tor Arne Vestbø <tor.arne.vestbo@qt.io>
* Android: use logging category for im debugLiang Qi2023-06-191-57/+19
| | | | | | | Pick-to: 6.6 6.5 Change-Id: I78e84313841f83416dee6b6b2970b402acce5060 Reviewed-by: Tor Arne Vestbø <tor.arne.vestbo@qt.io> Reviewed-by: Assam Boudjelthia <assam.boudjelthia@qt.io>
* Android input context: don't connect to non-existing signalVolker Hilsheimer2022-12-201-1/+3
| | | | | | | | | | | | Not all focus objects have a cursorPositionChanged signal, so don't connect unless there is one. The code should perhaps not show the software keyboard at all unless the focus object responds to the input method query with cursor positions, but that's for a different patch. Pick-to: 6.5 Change-Id: I0e01da42e96eb579d260b9158f005ad3215d0c26 Reviewed-by: Assam Boudjelthia <assam.boudjelthia@qt.io> Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org>
* Android: Fix the offset of the EditPopupMenuPekka Gehör2022-06-291-3/+14
| | | | | | | | | | Fix the offset of the EditPopupMenu on application window. Issue caused by a5bb7b3ca510c301baf84e1dd46d5aeeb4986eb2 Fixes: QTBUG-71900 Pick-to: 6.2 6.3 6.4 Change-Id: Ib95e1544fe91c273bc5317bd338a50a74fb1090a Reviewed-by: Assam Boudjelthia <assam.boudjelthia@qt.io>
* Use SPDX license identifiersLucie Gérard2022-05-161-40/+4
| | | | | | | | | | | | | Replace the current license disclaimer in files by a SPDX-License-Identifier. Files that have to be modified by hand are modified. License files are organized under LICENSES directory. Task-number: QTBUG-67283 Change-Id: Id880c92784c40f3bbde861c0d93f58151c18b9f1 Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org> Reviewed-by: Lars Knoll <lars.knoll@qt.io> Reviewed-by: Jörg Bornemann <joerg.bornemann@qt.io>
* Remove noop calls to QPlatformInputContext base classTor Arne Vestbø2022-04-291-1/+0
| | | | | | | | | | | | | | Like most QPlatformFoo base classes the default implementations are empty, or have default behavior that should be completely replaced by subclasses. By making it consistent across all the platform plugins when we call base class methods, we avoid confusion of whether a base class call is needed or not. Change-Id: Idd8e4a6fa0e24a1dffd21b63471c9b1c2348691f Reviewed-by: Doris Verria <doris.verria@qt.io> Reviewed-by: Volker Hilsheimer <volker.hilsheimer@qt.io>
* Android: stop using QLatin1Char constructor for creating char literalsSona Kurazyan2022-04-141-3/+3
| | | | | | | | | | | Required for porting away from QLatin1Char/QLatin1String in scope of QTBUG-98434. As a drive-by, fix qsizetype -> int narrowing conversion warnings for the touched lines. Change-Id: Iebcbdbd7cecac09d0a7039e3ef6a4509d33039ba Reviewed-by: Assam Boudjelthia <assam.boudjelthia@qt.io>
* Android: guard against potential null pointer accessAssam Boudjelthia2022-03-151-16/+20
| | | | | | | | | | | | androidPlatformIntegration might be called before setAndroidPlatformIntegration() is called, and also all other uses of androidPlatformIntegration is already guarded in our code. Pick-to: 6.2 6.3 Task-number: QTBUG-100470 Change-Id: Ifd7d36ba7f2f3b55652466825d7fd84c87ec5e19 Reviewed-by: Ville Voutilainen <ville.voutilainen@qt.io>
* android: Fix typo in source code commentJonas Kvinge2021-12-021-1/+1
| | | | | Change-Id: Ieeab35d51588cf247c3d9626d0291e2983720873 Reviewed-by: Kai Koehne <kai.koehne@qt.io>
* Revert "Android: Place cursor correctly on screen when editing"Rami Potinkara2021-10-261-44/+6
| | | | | | | | | | | | | | | 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 <andreas.buhr@qt.io> Reviewed-by: Assam Boudjelthia <assam.boudjelthia@qt.io>
* Android: Fix handling of cursor position when stop composingAndreas Buhr2021-10-141-7/+15
| | | | | | | | | | | | | | | | | | | | | | This is a workaround for a problem in TextEdit. The symptom is that when the user places the cursor inside of a word and hits backspace, the last letter of the word is removed instead of the letter just before the cursor. The reason is as follows. When stopping composing, the current cursor position has to be maintained. To that end, QAndroidInputContext sends an event containing the text to be committed and the cursor position to the editor. But the resulting cursor position is wrong. This patch adapts QAndroidInputContext to send two events: One to commit the text, the second to place the cursor. A real fix would fix the editor to correctly handle the event containing both the committed text and the cursor position. Fixes: QTBUG-97491 Pick-to: 6.2 5.15 Change-Id: Idd00e5afcbfe29c9cb77356f9add2e881c51b9bb Reviewed-by: Paul Olav Tvete <paul.tvete@qt.io>
* Revert "[Android] Remove signal and slot mechanism to listen states in editor's"Andreas Buhr2021-10-131-36/+7
| | | | | | | | | | | | | | | | | This reverts commit a40a512dec0f34e84eb63812af556608f03713ff. It caused UI freezes and cursor position inconsistencies. See the linked bugs. Pick-to: 6.2 6.2.1 5.15 Task-number: QTBUG-58013 Task-number: QTBUG-93414 Task-number: QTBUG-95669 Task-number: QTBUG-96671 Task-number: QTBUG-96675 Task-number: QTBUG-96769 Change-Id: Ie8100538609a1460713ca9115cdbe329654d0772 Reviewed-by: Paul Olav Tvete <paul.tvete@qt.io> Reviewed-by: Assam Boudjelthia <assam.boudjelthia@qt.io>
* Android: Fix select handles misplacement on QDialogPekka Gehör2021-05-251-8/+37
| | | | | | | | | | Get select handles {Left, Right}Point from a mapToGlobal with a cursorRectangleof anchorRectangle of the selected word/text. Task-number: QTBUG-90799 Change-Id: I4fed19a1d3bb2247656b052306307e6980074405 Reviewed-by: Rami Potinkara <rami.potinkara@qt.io> Reviewed-by: Ville Voutilainen <ville.voutilainen@qt.io>
* [Android] Remove signal and slot mechanism to listen states in editor'sTapio Oksa2021-04-221-7/+36
| | | | | | | Task-number: QTBUG-58013 Change-Id: Ib589f1b69e2e82026d27fbc7519d10e18ae21f59 Reviewed-by: Rami Potinkara <rami.potinkara@qt.io> Reviewed-by: Ville Voutilainen <ville.voutilainen@qt.io>
* Android: Add select and copy capability to read-only text widgetsPiotr Mikolajczyk2021-03-301-14/+17
| | | | | | | | | | | | | | | | In case of a read-only text editing widget it was imposibble to copy text from it. In QtWidgets you could not even see the selection handless. Text selection in QtWidgets module was filtered depending on readOnly property of the widget. Additionally, in InputMethod the read-only state was translated into disabled. Patch also makes the edit menu to be aware of the read-only status of the control - the menu items are different for rw and ro controls. Task-number: QTBUG-91417 Change-Id: Ic7b27f78678eeaa87a38607af787f254db1383b8 Reviewed-by: Rami Potinkara <rami.potinkara@qt.io> Reviewed-by: Ville Voutilainen <ville.voutilainen@qt.io>
* Android: Fix constant resize of a large TextEdit on clickPiotr Mikolajczyk2021-03-101-4/+5
| | | | | | | | | | | | | If there is a large (3/5 of the screen in portrait or 2/3 in landscape) TextEdit on the screen, and it gets focus on click, it will be shrank to fit the screen. Next click on this TextEdit will restore its normal height, the next will shrink. Pick-to: 5.15 Fixes: QTBUG-91056 Change-Id: I3dbf085cbfdc2739d537a304c16e28c58a6e01ce Reviewed-by: Rami Potinkara <rami.potinkara@qt.io> Reviewed-by: Ville Voutilainen <ville.voutilainen@qt.io>
* Android: Place cursor correctly on screen when editingPiotr Mikolajczyk2021-03-051-3/+41
| | | | | | | | | | | | When editing text the cursor is not placed correctly. So this has been achieved by tricking Android into thinking that the input area is only the line where the cursor is, so it is forced to keep it on screen. Fixes: QTBUG-91073 Pick-to: 5.15 Change-Id: Icc2e8315deb76ca1a84819d3fdceaa7b027b1174 Reviewed-by: Ville Voutilainen <ville.voutilainen@qt.io>
* Android: Use new QPlatformInputContext geometry APIMorten Sørvig2021-02-041-51/+17
| | | | | | | | | | | | | | | | | | This simplifies the Android platform plugin code, since it no longer has to make QHighDpi scaling calls. QPlatformInputContext returns geometry in the native window coordinates. These can be used directly, or in some cases be mapped further to native global (screen) coordinates. Note that this mapping now happens after High-dpi scaling, so we must use QPlatformWindow::mapToGlobal() instead of QWindow::mapToGlobal() The inputItemTransform() is applied by QPlatformInputContext when needed, these calls can also be removed. Change-Id: I179d44d148dded43683df5e97ad506940894c423 Reviewed-by: Tor Arne Vestbø <tor.arne.vestbo@qt.io>
* Android: fix compiler warnings for Android inputAssam Boudjelthia2021-02-031-3/+3
| | | | | | | | | | QPointingDevice requires using the constructor to set its settings in Qt 6. Replace + with | operator and return QKeyCombination instead of int. Change-Id: Id3da469cc13b34ec7b55afa751dbc04601880df6 Reviewed-by: Volker Hilsheimer <volker.hilsheimer@qt.io>
* Make setSelectionOnFocusObject() take native pixelsMorten Sørvig2021-02-021-6/+1
| | | | | | | | | | | | Change the setSelectionOnFocusObject() to take geometry arguments in native pixels, in order to be consistent with other QPlatformInputContext API. Calling code which pass non-native geometry must be updated (in practice only the Android platform plugin). Change-Id: I1c61b8cf583afe607567d6056ca7ff23cc3de3f3 Reviewed-by: Tor Arne Vestbø <tor.arne.vestbo@qt.io>
* Add geometry accessors to QPlatformInputContextMorten Johan Sørvig2021-02-011-4/+4
| | | | | | | | | | | | | | | | | | | | | | | | | Currently the platform plugins use the public QInputMethod API when querying geometry. However, QInputMethod returns geometry in device independent pixels, while the platform plugins require geometry in native pixels. Add new API to QPlatformInputContext which returns input geometry in the native window coordinate system: QRectF inputItemRectangle() QRectF inputItemClipRectangle() QRectF cursorRectangle() QRectF anchorRectangle() QRectF keyboardRectangle() These make the relevant QHighDpi calls internally, and such calls can then be moved out of the platform plugins. Disambiguate inputItemRectangle() in qandroidinputcontext.cpp by renaming it to screenInputItemRectangle(). Change-Id: I561745b64fb197d64e3dfddcf0751528bb8d0605 Reviewed-by: Richard Moe Gustavsen <richard.gustavsen@qt.io>
* Make QJniObject and QJniEnvironment public APIAssam Boudjelthia2021-01-271-15/+13
| | | | | | | | | | | | | | | | | | | | As part of Qt 6 restructring for the extras modules, this change exposes the Jni APIs which are very important for Android platform. This patch adds the APIs QJniObject, QJniEnvironment, QJniExceptionCleaner based from private QtCore and QtAndroidExtras. The Jni interface is cross-platform which justifies the name, but currently, this API is used mainly for Android, and the naming comes generic without Android keyword to avoid any future limitation on supporting other platforms. [ChangeLog][QtCore] Add new QJniObject, QJniEnvironment and QJniExceptionCleaner APIs. Task-number: QTBUG-89482 Fixes: QTBUG-89633 Change-Id: I4382dd53a225375759b9d042f6035a4a9810572b Reviewed-by: Ville Voutilainen <ville.voutilainen@qt.io>
* [Android] Fix Text select handle misplaced on fields inside QDialog issuesPekka Gehör2021-01-201-2/+2
| | | | | | | | | | | Get cursorPoint from a mapToGlobal with a cursorRectangle of the selected inputMethod Fixes: QTBUG-65229 Fixes: QTBUG-58503 Pick-to: 6.0 5.15 Change-Id: I89b056fa91c59d260f02164c9bd6672b5ada64d6 Reviewed-by: Rami Potinkara <rami.potinkara@qt.io> Reviewed-by: Ville Voutilainen <ville.voutilainen@qt.io>
* Disable copying and assigning of QEventVolker Hilsheimer2020-11-191-9/+11
| | | | | | | | | | | | | | Polymorphic classes should not be copied. However, we do rely on event copying in our propagation logic. So, make the members protected, don't delete them, using a dedicated macro. This way, QMutable*Event classes can be used to make copies. Remove some last usage of copying of QInputMethod(Query)Events. Change-Id: Ia0a8ae4ca9de97dcd7788ca3c6ed930b6460c43a Reviewed-by: Lars Knoll <lars.knoll@qt.io>
* [Android] Request cursor to be in proper positionTapio Oksa2020-10-291-4/+13
| | | | | | | | | | | Cursor were set to incorrect position (-1) causing first character overwrite in password field, fixed by setting position to '0' for the first character Fixes: QTBUG-85090 Pick-to: 5.15 Change-Id: Ia2333803d5fe8f274f1ad1a643e4ff5aa8556b81 Reviewed-by: Rami Potinkara <rami.potinkara@qt.io> Reviewed-by: Assam Boudjelthia <assam.boudjelthia@qt.io>
* Another round of replacing 0 with nullptrAllan Sandfeld Jensen2020-10-071-1/+1
| | | | | | | | | This time based on grepping to also include documentation, tests and examples previously missed by the automatic tool. Change-Id: Ied1703f4bcc470fbc275f759ed5b7c588a5c4e9f Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org> Reviewed-by: Friedemann Kleint <Friedemann.Kleint@qt.io>
* Android: rename Android's package name for Qt 6Assam Boudjelthia2020-10-031-3/+3
| | | | | | | | | | Rename Android package name org.qtproject.qt5.android to org.qtproject.qt.android to avoid inconsistency with Qt 6 name. Also, we include the major version number in the jar target. Task-number: QTBUG-86969 Change-Id: Ibb68947289be1079911b34ea157bf089cc52c47f Reviewed-by: Alexandru Croitor <alexandru.croitor@qt.io>
* Add ; to Q_UNUSEDLars Schmertmann2020-07-071-2/+2
| | | | | | | | This is required to remove the ; from the macro with Qt 6. Task-number: QTBUG-82978 Change-Id: I3f0b6717956ca8fa486bed9817b89dfa19f5e0e1 Reviewed-by: Friedemann Kleint <Friedemann.Kleint@qt.io>
* Use qsizetype in QListLars Knoll2020-07-061-2/+2
| | | | | | | | | | | | | | | | | | | | The change creates a slight source incompatibility. The main things to take care of are * code using printf statements on list.size(). Using qsizetype in printf statements will always require a cast to work on both 32 and 64 bit. * A few places where overloads now get ambiguous. One example is QRandomGenerator::bounded() that has overloads for int, uint and double, but not int64. * Streaming list.size() to a QDataStream will change the format depending on the architecture. [ChangeLog][QtCore][QList] QList now uses qsizetype to index into elements. Change-Id: Iaff562a4d072b97f458417b670f95971bd47cbc6 Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
* Port platform plugins to QStringViewLars Knoll2020-06-151-4/+4
| | | | | | Task-number: QTBUG-84319 Change-Id: If409ba1c99f30c7ab32c7cc826c7f303ccf18c1d Reviewed-by: Lars Knoll <lars.knoll@qt.io>
* Revert "Release left button before showing the popup context menu"Eskil Abrahamsen Blomfeldt2019-10-211-3/+0
| | | | | | | | | | | | | | | | This partially reverts commit 5e8b16f0e4247cc978b08480450526cfa3b25029. Releasing the mouse button synthetically made it impossible to use tap and hold gestures. When investigating, it seems that other changes have fixed the original issue that 5e8b16f0e4247cc978b08480450526cfa3b25029 was meant to address, so this is no longer needed. [ChangeLog][Android] Fixed regression that made it impossible for an application to use the tap-and-hold gesture. Fixes: QTBUG-72408 Change-Id: I53f687d047a4ad0fdf3c8c96a00ed1b11d09f047 Reviewed-by: BogDan Vatra <bogdan@kdab.com>
* QAndroidInputContext: Generate a QInputMethodEvent in reset()Vova Mshanetskiy2019-06-281-0/+1
| | | | | | | | | | | | | Although QPlatformInputContext::reset() documentation says that reset() should not send any QInputMethodEvents, implementations on Windows, macOS and iOS do send a QInputMethodEvent which clears preedit text in their reimplementations of reset(). Text editing controls depend on that and may not clear preedit text if such event is not sent. Change-Id: I75ab73946cb06e93e5fc5e98e0cc503a7de5c2e0 Reviewed-by: BogDan Vatra <bogdan@kdab.com>
* QAndroidInputContext: Do not stop composing when user taps the cursorVova Mshanetskiy2019-06-281-1/+19
| | | | | | | | | | | | | | | There is no need to tell the editor to stop composing if user taps so close to the cursor position that the cursor will not move anyway. If we do stop composing in such case, then since there will be no cursor position change notification, we will never start composing again (before the cursor is actually moved), and the current composing region will remain being displayed as normal text instead of being displayed as composing text. Change-Id: I4ebe6442e1ba8c365d6754c1a8487235d177c732 Reviewed-by: BogDan Vatra <bogdan@kdab.com>
* QAndroidInputContext: Consider preedit text in getCursorCapsMode()Vova Mshanetskiy2019-06-281-2/+7
| | | | | | | | | | Fixes auto-capitalization in AnySoftKeyboard. It was typing the whole first word in a sentence in upper case. Change-Id: I605a1aee39d432a3474c0bf706445d354562285f Reviewed-by: BogDan Vatra <bogdan@kdab.com>
* QAndroidInputContext: Improve compatibility with virtual keyboardsVova Mshanetskiy2019-06-051-200/+426
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | This commit improves QAndroidInputContext's conformance to Android's InputConnection interface and/or consistency of it's behavior with Android's native EditText control. * Composing region is now completely independent from cursor and selection, as required by InputConnection documentation. Also, Qt will now never clear composing region (i.e. call finishComposingText()) without receiving a command to do so from the keyboard. This is important for the following reasons: - Some keyboards misbehave if we change composing region without receiving a command from them. Notably, Samsung Keyboard does (QTBUG-68822). - Due to asynchronous nature of interaction between QAndroidInputContext and the keyboard, when user drags cursor handle quickly, the keyboard may call setComposingRegion() to mark a word, which is no longer under the cursor. This was causing text corruption (QTBUG-43156, QTBUG-59958). Also SwiftKey makes such calls when user presses Enter key (QTBUG-57819). - For similar reasons selecting a word with a double-tap could cause text corruption. The keyboard may call setComposingRegion() in response to the first tap after the second tap has been processed and the word has already been already selected. This is achieved by keeping track of start and end of composing region independently from the editor. Whenever possible (i.e. when there is no selection and the cursor is inside composing region), the composing text is represented as preedit text inside editor. And whenever that is imposible, the editor is told to commit, but QAndroidInputContext keeps information about composing region internally to be able to correctly interract with the keyboard. * deleteSurroundingText() has been re-written to work correctly when there are selection and/or composing region. Some keyboards (e.g Ginger Keyboard) do call deleteSurroundingText() when there is non-empty composing region. * All operations are now performed inside a batch edit (i.e. QAndroidInputContext now calls beginBatchEdit() and endBatchEdit() on itself) to ensure that an intermediate state is never reported to the keyboard, whenever an operation requires more than one QInputMethodEvent. BatchEditLock helper class was added to call begin/endBatchEdit() in RAII style. m_blockUpdateSelection has been removed because m_batchEditNestingLevel is now used instead of it. * Selection start and end positions are now reported to the keyboard so that start <= end. Some keyboards can not handle start > end. * getTextBefore/AfterCursor() now exclude selected text from their return values. While Android docs say "text before/after cursor", what they really mean is "text before/after selection" because "the cursor and the selection are one and the same thing". Some keyboards (e.g. Gboard) were behaving incorrectly when selected text was being returned. * getExtractedText() now tries to obtain and return the whole text from the editor. This is to fix compatibility with some buggy keyboards (e.g. Samsung Keyboard, Minuum) that ignore startOffset field and assume that selectionStart and selectionEnd are absolute values. Then they issue commands with wrong indexes in some cases. Fixes: QTBUG-43156 Fixes: QTBUG-59958 Fixes: QTBUG-57819 Fixes: QTBUG-68822 Change-Id: I7e71f3bcfbb2c32248d653a4197293db03579a79 Reviewed-by: BogDan Vatra <bogdan@kdab.com>
* QAndroidInputContext: Don't allow clearing selection by dragging handlesVova Mshanetskiy2019-06-051-39/+27
| | | | | | | | | Android's native text editing controls do not allow user to clear selection by dragging selection handles. Qt apps should behave in the same way. Change-Id: I9a7c3a2aafa484eed8ff2bbd46dd48c705195291 Reviewed-by: BogDan Vatra <bogdan@kdab.com>
* QAndroidInputContext: Fix unneeded preedit commits when dragging handlesVova Mshanetskiy2019-06-051-11/+52
| | | | | | | | | | | | | | | | | | | If the cursor handle was dragged by only a few pixels, position of the cursor did not actually change, but finishComposingText() was called anyway. So the keyboard was thinking that nothing changed and a word is still being composed, but the app was thinking that there is no preedit string. This was resulting in invalid handling of following key presses. This commit essentially inlines QPlatformInputContext::setSelectionOnFocusObject() into QAndroidInputContext::handleLocationChanged(). This allows us to call finishComposingText() and to send a QInputMethodEvent only when position of the cursur actually changes. This also allows us to add a QInputMethodEvent::Cursor attribute into the event for consistency with QAndroidInputContext::longPress(). Change-Id: I2fc82f138f717991f34024cdf521236845dc0adf Reviewed-by: BogDan Vatra <bogdan@kdab.com>
* QAndroidInputContext: Fix getTextBefore/AfterCursor() in mid. of preeditVova Mshanetskiy2019-05-081-30/+47
| | | | | | | | | | | | | getTextBeforeCursor() and getTextAfterCursor() were not properly handling the case when the cursor is in the middle of preedit string (just as TODO comments inside these functions were saying). This was causing problems with Gboard when the user focuses a text editor by tapping in the middle of a word. Fixes: QTBUG-58063 Change-Id: I4a580a74d79965816557bfb342337975348d1c45 Reviewed-by: Andy Shaw <andy.shaw@qt.io>
* QAndroidInputContext: Fix most "Input method out of sync" warningsVova Mshanetskiy2019-05-131-0/+2
| | | | | | | | | | | | | | | | According to Android docs start == end in a call to setComposingRegion() means finish composing. But this case was not being handled properly: m_composingText was being assigned an empty string, but m_composingTextStart was being assigned the value of start, which is never -1. There is one other possible cause of "Input method out of sync" warnings, but it is tightly coupled with another bug, so it will be fixed by a separate commit. Change-Id: Ie475df84f330453ce4fc623e8b631b435d7d0042 Reviewed-by: Andy Shaw <andy.shaw@qt.io>
* QAndroidInputContext: Fix start value of Cursor attribute in longPress()Vova Mshanetskiy2019-05-101-1/+1
| | | | | | | | | | | | The value of start for a QInputMethodEvent::Cursor attribute must be specified relative to the start of preedit string, but longPress() was specifying it relative to start of surrounding text. This was causing QQuickTextInput to return wrong values of cursor and anchor rectangles. And this was causing invalid positioning of cursor selection handles after a long press. Change-Id: Ief67e86dd90b09ebf2ba191a2b0311ff803afdd9 Reviewed-by: BogDan Vatra <bogdan@kdab.com>
* Android: Fix deleting of new lines when using backspaceAndy Shaw2019-05-031-4/+22
| | | | | | | | | | | | With some keyboards (ASOP, SwiftKey) it was not deleting any new lines when using backspace. So this ensures that it is correctly deleting at these points. Tested with the Samsung, Gboard and SwiftKey keyboards. Fixes: QTBUG-74824 Fixes: QTBUG-57798 Change-Id: Id2e4f96c18c3fec0e7f444b55dd3db2653625fd0 Done-with: Vova Mshanetskiy <vovams163@gmail.com> Reviewed-by: Paul Olav Tvete <paul.tvete@qt.io>
* Android: If there is no surrounding text then don't try to delete itAndy Shaw2019-01-281-0/+4
| | | | | | | | | | | If there is no surrounding text then we can save time by not sending an event to delete it as there is nothing to be deleted. This prevents the underlying widget from being confused as to where the cursor and anchor is later on when entering in new text. Fixes: QTBUG-65584 Change-Id: Ic6325c119327048dffd2baa68520871fb56370d5 Reviewed-by: BogDan Vatra <bogdan@kdab.com>
* Use jint instead of jboolean where applicable and initialize variablesAndy Shaw2019-01-081-14/+14
| | | | | | | | | | | This amends change c6af7cf666d43c68c90ad829c3a55d84ee8e4a3e which had incorrectly used jboolean to store the result of getCursorCapsMode() and thus lost the information it was passing. The variables are also initialized in case there is a lock problem when calling runOnQtThread. Fixes: QTBUG-72783 Change-Id: Ibdc21e348c25ee4fdff242d14b3722c6551b042c Reviewed-by: BogDan Vatra <bogdan@kdab.com>
* Use the AndroidDeadlockProtector when using a blockingqueued connectionAndy Shaw2019-01-041-6/+4
| | | | | | | | | | | | This amends 2afe4a1a074096a3a6476aae21e732c418717da7 to account for cases where it was crashing when it was using the QueuedConnection. The problem came from the fact it was blocking while waiting for a surface update which was pending to come later on, but the Android thread was already blocked which prevented it from being processed. Fixes: QTBUG-72101 Change-Id: I43e355cf1a7792599f23827903d065b1b1298902 Reviewed-by: BogDan Vatra <bogdan@kdab.com>