diff options
author | Richard Moe Gustavsen <richard.gustavsen@digia.com> | 2014-01-29 17:45:25 +0100 |
---|---|---|
committer | The Qt Project <gerrit-noreply@qt-project.org> | 2014-02-06 14:19:53 +0100 |
commit | 35dc77f8dbca0528bdab9ad7e4e1baa0769f5639 (patch) | |
tree | 2713e06f0f627a265d53ad57879d906c68201ddf | |
parent | 60fe9fb018fda423754941e41be17186fd98fa85 (diff) |
iOS: send IM events instead of fake key events
Sending faked key events is not such a good idea, since:
1. We don't get key events on iOS, but text events
2. We cannot determine correct key code or modifiers, nor
do we want to fake modifer press/release etc.
3. Android uses IM for all text input
So it seems that the correct solution is to avoid sending
key events in the first place. This will also bring the iOS
port on par with the Android port.
Change-Id: Ibac1d335184e62eb4185cfd4218a0ec73dffb2c4
Reviewed-by: Tor Arne Vestbø <tor.arne.vestbo@digia.com>
-rw-r--r-- | src/plugins/platforms/ios/quiview_textinput.mm | 21 |
1 files changed, 9 insertions, 12 deletions
diff --git a/src/plugins/platforms/ios/quiview_textinput.mm b/src/plugins/platforms/ios/quiview_textinput.mm index 21ef93c4ed..46c63402a0 100644 --- a/src/plugins/platforms/ios/quiview_textinput.mm +++ b/src/plugins/platforms/ios/quiview_textinput.mm @@ -453,19 +453,16 @@ Q_GLOBAL_STATIC(StaticVariables, staticVariables); - (void)insertText:(NSString *)text { - QString string = QString::fromUtf8([text UTF8String]); - int key = 0; - if ([text isEqualToString:@"\n"]) { - key = (int)Qt::Key_Return; - if (self.returnKeyType == UIReturnKeyDone) - [self resignFirstResponder]; - } + QObject *focusObject = QGuiApplication::focusObject(); + if (!focusObject) + return; - // Send key event to window system interface - QWindowSystemInterface::handleKeyEvent( - 0, QEvent::KeyPress, key, Qt::NoModifier, string, false, int(string.length())); - QWindowSystemInterface::handleKeyEvent( - 0, QEvent::KeyRelease, key, Qt::NoModifier, string, false, int(string.length())); + if ([text isEqualToString:@"\n"] && self.returnKeyType == UIReturnKeyDone) + [self resignFirstResponder]; + + QInputMethodEvent e; + e.setCommitString(QString::fromNSString(text)); + [self sendEventToFocusObject:e]; } - (void)deleteBackward |