Windows QPA: Handle key event sequences of surrogates

Emoji characters as input by the virtual keyboard are received
as a sequence of surrogates. Store state internally when a high
surrogate is received and send off the sequence when the matching
low surrogate is received via input method.

Task-number: QTBUG-50617
Change-Id: I91e763ec3e0747d6852f7c5c2057a67b0c24e0f5
Reviewed-by: Eskil Abrahamsen Blomfeldt <eskil.abrahamsen-blomfeldt@qt.io>
This commit is contained in:
Friedemann Kleint 2016-08-01 16:15:13 +02:00
parent 9b1db44c2a
commit dbb5c95f4d
2 changed files with 17 additions and 0 deletions

View File

@ -37,6 +37,7 @@
#include "qwindowswindow.h"
#include "qwindowsinputcontext.h"
#include <QtGui/QGuiApplication>
#include <QtGui/QWindow>
#include <qpa/qwindowsysteminterface.h>
#include <private/qguiapplication_p.h>
@ -1072,6 +1073,21 @@ bool QWindowsKeyMapper::translateKeyEventInternal(QWindow *window, const MSG &ms
if (PeekMessage(&wm_char, 0, charType, charType, PM_REMOVE)) {
// Found a ?_CHAR
uch = QChar(ushort(wm_char.wParam));
if (uch.isHighSurrogate()) {
m_lastHighSurrogate = uch;
return true;
} else if (uch.isLowSurrogate() && !m_lastHighSurrogate.isNull()) {
if (QObject *focusObject = QGuiApplication::focusObject()) {
const QChar chars[2] = {m_lastHighSurrogate, uch};
QInputMethodEvent event;
event.setCommitString(QString(chars, 2));
QCoreApplication::sendEvent(focusObject, &event);
}
m_lastHighSurrogate = QChar();
return true;
} else {
m_lastHighSurrogate = QChar();
}
if (msgType == WM_SYSKEYDOWN && uch.isLetter() && (msg.lParam & KF_ALTDOWN))
uch = uch.toLower(); // (See doc of WM_SYSCHAR) Alt-letter
if (!code && !uch.row())

View File

@ -97,6 +97,7 @@ private:
void deleteLayouts();
QWindow *m_keyGrabber;
QChar m_lastHighSurrogate;
static const size_t NumKeyboardLayoutItems = 256;
KeyboardLayoutItem keyLayout[NumKeyboardLayoutItems];
};