iOS: ensure we don't break UIKit IM state when sending key events

We need to be careful about calling textDidChange on the input
delegate, since that will reset the internal IM state in UIKit
and stop any ongoing text composition or spell checking.

For that reason we set m_inSendEventToFocusObject to true whenever
we send an IM event to Qt, to not call the abovementioned method when
callbacks from UIKit is the reason for changing the text.

But until now we never applied the same protection for key events.
This lead to ligatures not working correctly (e.g when using Korean
IM), since UIKit composes ligatures by first selecting the characters
that can be truncated, then do a deleteBackwards, then insert the ligature.
And deleteBackwards leads us to send backspace key events, which
ends up in a textDidChange call, which confuses UIKit.

This patch will ensure we don't call textDidChange as a result of
sending key events.

Task-number: QTBUG-52486
Change-Id: Ida268edae517f55a5b5f975340a5d3821f7b8f52
Reviewed-by: Tor Arne Vestbø <tor.arne.vestbo@theqtcompany.com>
This commit is contained in:
Richard Moe Gustavsen 2016-05-23 15:35:17 +02:00
parent b092f681cf
commit 17a4384d12

View File

@ -353,6 +353,7 @@
- (void)sendKeyPressRelease:(Qt::Key)key modifiers:(Qt::KeyboardModifiers)modifiers - (void)sendKeyPressRelease:(Qt::Key)key modifiers:(Qt::KeyboardModifiers)modifiers
{ {
QScopedValueRollback<BOOL> rollback(m_inSendEventToFocusObject, true);
QWindowSystemInterface::handleKeyEvent(qApp->focusWindow(), QEvent::KeyPress, key, modifiers); QWindowSystemInterface::handleKeyEvent(qApp->focusWindow(), QEvent::KeyPress, key, modifiers);
QWindowSystemInterface::handleKeyEvent(qApp->focusWindow(), QEvent::KeyRelease, key, modifiers); QWindowSystemInterface::handleKeyEvent(qApp->focusWindow(), QEvent::KeyRelease, key, modifiers);
QWindowSystemInterface::flushWindowSystemEvents(); QWindowSystemInterface::flushWindowSystemEvents();