diff options
author | Friedemann Kleint <Friedemann.Kleint@qt.io> | 2018-01-19 16:54:34 +0100 |
---|---|---|
committer | Friedemann Kleint <Friedemann.Kleint@qt.io> | 2018-09-29 19:45:35 +0000 |
commit | 97f4366202d170f8c64df2a9f92d457c69b565cc (patch) | |
tree | b47cdb03972f84d400d282a6df6f306c78de6c63 /src/gui/kernel/qinputmethod.cpp | |
parent | a34054c75e18326d10328baa9e39fc9eab0cbfc9 (diff) |
QLineEdit: Disable input methods for password unless IME supports hidden text
Move the checking logic from QGuiApplicationPrivate::_q_updateFocusObject()
to QInputMethodPrivate::objectAcceptsInputMethod(), which is also called
from QWidget::updateMicroFocus() via QInputMethod::update().
Fixes: QTBUG-56767
Change-Id: Ia4cce5e7e766008df891537048d5daf739c010ff
Reviewed-by: Alex Blasche <alexander.blasche@qt.io>
Diffstat (limited to 'src/gui/kernel/qinputmethod.cpp')
-rw-r--r-- | src/gui/kernel/qinputmethod.cpp | 18 |
1 files changed, 16 insertions, 2 deletions
diff --git a/src/gui/kernel/qinputmethod.cpp b/src/gui/kernel/qinputmethod.cpp index 365b088840..a319529442 100644 --- a/src/gui/kernel/qinputmethod.cpp +++ b/src/gui/kernel/qinputmethod.cpp @@ -390,15 +390,29 @@ void QInputMethod::invokeAction(Action a, int cursorPosition) ic->invokeAction(a, cursorPosition); } +static inline bool platformSupportsHiddenText() +{ + const QPlatformInputContext *inputContext = QGuiApplicationPrivate::platformIntegration()->inputContext(); + return inputContext && inputContext->hasCapability(QPlatformInputContext::HiddenTextCapability); +} + bool QInputMethodPrivate::objectAcceptsInputMethod(QObject *object) { bool enabled = false; if (object) { - QInputMethodQueryEvent query(Qt::ImEnabled); + // If the platform does not support hidden text, query the hints + // in addition and disable in case of ImhHiddenText. + static const bool supportsHiddenText = platformSupportsHiddenText(); + QInputMethodQueryEvent query(supportsHiddenText + ? Qt::InputMethodQueries(Qt::ImEnabled) + : Qt::InputMethodQueries(Qt::ImEnabled | Qt::ImHints)); QGuiApplication::sendEvent(object, &query); enabled = query.value(Qt::ImEnabled).toBool(); + if (enabled && !supportsHiddenText + && Qt::InputMethodHints(query.value(Qt::ImHints).toInt()).testFlag(Qt::ImhHiddenText)) { + enabled = false; + } } - return enabled; } |