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:
Friedemann Kleint 2014-11-17 12:26:00 +01:00
parent 421f78a65f
commit c91c05b056
5 changed files with 41 additions and 3 deletions

View File

@ -3400,15 +3400,21 @@ void QGuiApplicationPrivate::_q_updateFocusObject(QObject *object)
{ {
Q_Q(QGuiApplication); Q_Q(QGuiApplication);
QPlatformInputContext *inputContext = platformIntegration()->inputContext();
bool enabled = false; bool enabled = false;
if (object) { if (object && inputContext) {
QInputMethodQueryEvent query(Qt::ImEnabled); QInputMethodQueryEvent query(Qt::ImEnabled | Qt::ImHints);
QGuiApplication::sendEvent(object, &query); QGuiApplication::sendEvent(object, &query);
enabled = query.value(Qt::ImEnabled).toBool(); 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); QPlatformInputContextPrivate::setInputMethodAccepted(enabled);
QPlatformInputContext *inputContext = platformIntegration()->inputContext();
if (inputContext) if (inputContext)
inputContext->setFocusObject(object); inputContext->setFocusObject(object);
emit q->focusObjectChanged(object); emit q->focusObjectChanged(object);

View File

@ -91,6 +91,17 @@ bool QPlatformInputContext::isValid() const
return false; 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(). Method to be called when input method needs to be reset. Called by QInputMethod::reset().
No further QInputMethodEvents should be sent as response. No further QInputMethodEvents should be sent as response.

View File

@ -55,10 +55,15 @@ class Q_GUI_EXPORT QPlatformInputContext : public QObject
Q_DECLARE_PRIVATE(QPlatformInputContext) Q_DECLARE_PRIVATE(QPlatformInputContext)
public: public:
enum Capability {
HiddenTextCapability = 0x1
};
QPlatformInputContext(); QPlatformInputContext();
virtual ~QPlatformInputContext(); virtual ~QPlatformInputContext();
virtual bool isValid() const; virtual bool isValid() const;
virtual bool hasCapability(Capability capability) const;
virtual void reset(); virtual void reset();
virtual void commit(); virtual void commit();

View File

@ -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. \brief Cancels a composition.
*/ */

View File

@ -62,6 +62,7 @@ public:
explicit QWindowsInputContext(); explicit QWindowsInputContext();
~QWindowsInputContext(); ~QWindowsInputContext();
bool hasCapability(Capability capability) const Q_DECL_OVERRIDE;
void reset() Q_DECL_OVERRIDE; void reset() Q_DECL_OVERRIDE;
void update(Qt::InputMethodQueries) Q_DECL_OVERRIDE; void update(Qt::InputMethodQueries) Q_DECL_OVERRIDE;
void invokeAction(QInputMethod::Action, int cursorPosition) Q_DECL_OVERRIDE; void invokeAction(QInputMethod::Action, int cursorPosition) Q_DECL_OVERRIDE;