Add capabilities to QPlatformInputContext.
Add a capability enumeration to QPlatformInputContext and use that to turn off input methods for hidden text depending on platform support. Disable on Windows. Task-number: QTBUG-40691 Change-Id: I9909005de1f21316ec8f64e2729f1fffcd37c7c3 Reviewed-by: Lars Knoll <lars.knoll@digia.com> Reviewed-by: Björn Breitmeyer <bjoern.breitmeyer@kdab.com> Reviewed-by: Liang Qi <liang.qi@theqtcompany.com>
This commit is contained in:
parent
421f78a65f
commit
c91c05b056
@ -3400,15 +3400,21 @@ void QGuiApplicationPrivate::_q_updateFocusObject(QObject *object)
|
||||
{
|
||||
Q_Q(QGuiApplication);
|
||||
|
||||
QPlatformInputContext *inputContext = platformIntegration()->inputContext();
|
||||
bool enabled = false;
|
||||
if (object) {
|
||||
QInputMethodQueryEvent query(Qt::ImEnabled);
|
||||
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;
|
||||
}
|
||||
}
|
||||
|
||||
QPlatformInputContextPrivate::setInputMethodAccepted(enabled);
|
||||
QPlatformInputContext *inputContext = platformIntegration()->inputContext();
|
||||
if (inputContext)
|
||||
inputContext->setFocusObject(object);
|
||||
emit q->focusObjectChanged(object);
|
||||
|
@ -91,6 +91,17 @@ bool QPlatformInputContext::isValid() const
|
||||
return false;
|
||||
}
|
||||
|
||||
/*!
|
||||
Returns whether the implementation supports \a capability.
|
||||
\internal
|
||||
\since 5.4
|
||||
*/
|
||||
bool QPlatformInputContext::hasCapability(Capability capability) const
|
||||
{
|
||||
Q_UNUSED(capability)
|
||||
return true;
|
||||
}
|
||||
|
||||
/*!
|
||||
Method to be called when input method needs to be reset. Called by QInputMethod::reset().
|
||||
No further QInputMethodEvents should be sent as response.
|
||||
|
@ -55,10 +55,15 @@ class Q_GUI_EXPORT QPlatformInputContext : public QObject
|
||||
Q_DECLARE_PRIVATE(QPlatformInputContext)
|
||||
|
||||
public:
|
||||
enum Capability {
|
||||
HiddenTextCapability = 0x1
|
||||
};
|
||||
|
||||
QPlatformInputContext();
|
||||
virtual ~QPlatformInputContext();
|
||||
|
||||
virtual bool isValid() const;
|
||||
virtual bool hasCapability(Capability capability) const;
|
||||
|
||||
virtual void reset();
|
||||
virtual void commit();
|
||||
|
@ -163,6 +163,21 @@ QWindowsInputContext::~QWindowsInputContext()
|
||||
{
|
||||
}
|
||||
|
||||
bool QWindowsInputContext::hasCapability(Capability capability) const
|
||||
{
|
||||
switch (capability) {
|
||||
case QPlatformInputContext::HiddenTextCapability:
|
||||
#ifndef Q_OS_WINCE
|
||||
return false; // QTBUG-40691, do not show IME on desktop for password entry fields.
|
||||
#else
|
||||
break; // Windows CE: Show software keyboard.
|
||||
#endif
|
||||
default:
|
||||
break;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
/*!
|
||||
\brief Cancels a composition.
|
||||
*/
|
||||
|
@ -62,6 +62,7 @@ public:
|
||||
explicit QWindowsInputContext();
|
||||
~QWindowsInputContext();
|
||||
|
||||
bool hasCapability(Capability capability) const Q_DECL_OVERRIDE;
|
||||
void reset() Q_DECL_OVERRIDE;
|
||||
void update(Qt::InputMethodQueries) Q_DECL_OVERRIDE;
|
||||
void invokeAction(QInputMethod::Action, int cursorPosition) Q_DECL_OVERRIDE;
|
||||
|
Loading…
Reference in New Issue
Block a user