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>
This commit is contained in:
Friedemann Kleint 2018-01-19 16:54:34 +01:00
parent a34054c75e
commit 97f4366202
3 changed files with 19 additions and 15 deletions

View File

@ -84,6 +84,7 @@
#include "private/qcursor_p.h"
#include "private/qopenglcontext_p.h"
#include "private/qinputdevicemanager_p.h"
#include "private/qinputmethod_p.h"
#include "private/qtouchdevice_p.h"
#include <qpa/qplatformthemefactory_p.h>
@ -4030,18 +4031,7 @@ void QGuiApplicationPrivate::_q_updateFocusObject(QObject *object)
Q_Q(QGuiApplication);
QPlatformInputContext *inputContext = platformIntegration()->inputContext();
bool enabled = false;
if (object && inputContext) {
QInputMethodQueryEvent query(Qt::ImEnabled | Qt::ImHints);
QGuiApplication::sendEvent(object, &query);
enabled = query.value(Qt::ImEnabled).toBool();
if (enabled) {
static const bool supportsHiddenText = inputContext->hasCapability(QPlatformInputContext::HiddenTextCapability);
const Qt::InputMethodHints hints = static_cast<Qt::InputMethodHints>(query.value(Qt::ImHints).toInt());
if ((hints & Qt::ImhHiddenText) && !supportsHiddenText)
enabled = false;
}
}
const bool enabled = inputContext && QInputMethodPrivate::objectAcceptsInputMethod(object);
QPlatformInputContextPrivate::setInputMethodAccepted(enabled);
if (inputContext)

View File

@ -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;
}

View File

@ -80,7 +80,7 @@ public:
void _q_connectFocusObject();
void _q_checkFocusObject(QObject *object);
bool objectAcceptsInputMethod(QObject *object);
static bool objectAcceptsInputMethod(QObject *object);
QTransform inputItemTransform;
QRectF inputRectangle;