From 97f4366202d170f8c64df2a9f92d457c69b565cc Mon Sep 17 00:00:00 2001 From: Friedemann Kleint Date: Fri, 19 Jan 2018 16:54:34 +0100 Subject: 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 --- src/gui/kernel/qinputmethod.cpp | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) (limited to 'src/gui/kernel/qinputmethod.cpp') 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; } -- cgit v1.2.3