From 35dc77f8dbca0528bdab9ad7e4e1baa0769f5639 Mon Sep 17 00:00:00 2001 From: Richard Moe Gustavsen Date: Wed, 29 Jan 2014 17:45:25 +0100 Subject: [PATCH] iOS: send IM events instead of fake key events MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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ø --- .../platforms/ios/quiview_textinput.mm | 21 ++++++++----------- 1 file 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