diff options
author | Richard Moe Gustavsen <richard.gustavsen@qt.io> | 2021-10-11 14:26:38 +0200 |
---|---|---|
committer | Richard Moe Gustavsen <richard.gustavsen@qt.io> | 2021-11-11 22:24:30 +0200 |
commit | 30276cec3d47f4f4fa847fea90214ec5c28d54ed (patch) | |
tree | 258e2dbd8c20da2bdf2717a53506cc8c721d0563 /src/plugins | |
parent | aae4d52cbb79c61161271473ab5c3a1ba1086e01 (diff) |
QIOSTextInputOverlay: listen for selection changes, also for Qt::ImReadOnly
The focus object can emit selection updates (e.g from mouse drag), and
accept modifying it through IM when dragging on the handles, even if it
doesn't accept text input and IM in general (and hence return false from
inputMethodAccepted()). This is typically the case for read-only text fields.
So we should listen for selection changes and enable handles also for
this case (unless the IM hints tells us explicitly not to use handles/edit menu).
Fixes: QTBUG-91545
Change-Id: I2855505fc229e954b2c43f5e11374e64bba7eb4e
Reviewed-by: Tor Arne Vestbø <tor.arne.vestbo@qt.io>
Diffstat (limited to 'src/plugins')
-rw-r--r-- | src/plugins/platforms/ios/qiostextinputoverlay.mm | 32 |
1 files changed, 28 insertions, 4 deletions
diff --git a/src/plugins/platforms/ios/qiostextinputoverlay.mm b/src/plugins/platforms/ios/qiostextinputoverlay.mm index 2ab732df7a..c72d8dc596 100644 --- a/src/plugins/platforms/ios/qiostextinputoverlay.mm +++ b/src/plugins/platforms/ios/qiostextinputoverlay.mm @@ -1048,15 +1048,39 @@ void QIOSTextInputOverlay::updateFocusObject() s_editMenu = nullptr; } - if (platformInputContext()->inputMethodAccepted()) { - s_editMenu = [QIOSEditMenu new]; - m_cursorRecognizer = [QIOSCursorRecognizer new]; + const QVariant hintsVariant = QGuiApplication::inputMethod()->queryFocusObject(Qt::ImHints, QVariant()); + const Qt::InputMethodHints hints = Qt::InputMethodHints(hintsVariant.toUInt()); + if (hints & Qt::ImhNoTextHandles) + return; + + // The focus object can emit selection updates (e.g from mouse drag), and + // accept modifying it through IM when dragging on the handles, even if it + // doesn't accept text input and IM in general (and hence return false from + // inputMethodAccepted()). This is the case for read-only text fields. + // Therefore, listen for selection changes also when the focus object + // reports that it's ImReadOnly (which we take as a hint that it's actually + // a text field, and that selections therefore might happen). But since + // we have no guarantee that the focus object can actually accept new selections + // through IM (and since we also need to respect if the input accepts selections + // in the first place), we only support selections started by the text field (e.g from + // mouse drag), even if we in theory could also start selections from a loupe. + + const bool inputAccepted = platformInputContext()->inputMethodAccepted(); + const bool readOnly = QGuiApplication::inputMethod()->queryFocusObject(Qt::ImReadOnly, QVariant()).toBool(); + + if (inputAccepted || readOnly) { + if (!(hints & Qt::ImhNoEditMenu)) + s_editMenu = [QIOSEditMenu new]; m_selectionRecognizer = [QIOSSelectionRecognizer new]; m_openMenuOnTapRecognizer = [QIOSTapRecognizer new]; - m_cursorRecognizer.enabled = YES; m_selectionRecognizer.enabled = YES; m_openMenuOnTapRecognizer.enabled = YES; } + + if (inputAccepted) { + m_cursorRecognizer = [QIOSCursorRecognizer new]; + m_cursorRecognizer.enabled = YES; + } } QT_END_NAMESPACE |