From 865ef951077a641768093ed56950eb39d6b59e63 Mon Sep 17 00:00:00 2001 From: Richard Moe Gustavsen Date: Fri, 31 Jan 2014 15:28:07 +0100 Subject: [PATCH] iOS: be more specific about IM callbacks to iOS MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit No need to call textWillChange all the time if the text is really not changing. And report that selectionWillChange when Qt reports that it has changed. Change-Id: I7bd9f540cd9302c37888926a6152b803cc871ccb Reviewed-by: Tor Arne Vestbø --- .../platforms/ios/quiview_textinput.mm | 27 +++++++++++-------- 1 file changed, 16 insertions(+), 11 deletions(-) diff --git a/src/plugins/platforms/ios/quiview_textinput.mm b/src/plugins/platforms/ios/quiview_textinput.mm index ff037b5647..64e93be7f2 100644 --- a/src/plugins/platforms/ios/quiview_textinput.mm +++ b/src/plugins/platforms/ios/quiview_textinput.mm @@ -154,27 +154,32 @@ Q_GLOBAL_STATIC(StaticVariables, staticVariables); - (void)updateInputMethodWithQuery:(Qt::InputMethodQueries)query { - // TODO: check what changed, and perhaps update delegate if the text was - // changed from somewhere other than this plugin.... - - // Note: This function is called both when as a result of the application changing the - // input, but also (and most commonly) as a response to us sending QInputMethodQueryEvents. - // Because of the latter, we cannot call textWill/DidChange here, as that will confuse - // iOS IM handling, and e.g stop spellchecking from working. Q_UNUSED(query); QObject *focusObject = QGuiApplication::focusObject(); if (!focusObject) return; - if (!m_inSendEventToFocusObject) - [self.inputDelegate textWillChange:id(self)]; + if (!m_inSendEventToFocusObject) { + if (query & (Qt::ImCursorPosition | Qt::ImAnchorPosition)) + [self.inputDelegate selectionWillChange:id(self)]; + if (query & Qt::ImSurroundingText) + [self.inputDelegate textWillChange:id(self)]; + } + // Note that we ignore \a query, and instead update using Qt::ImQueryInput. This enables us to just + // store the event without copying out the result from the event each time. Besides, we seem to be + // called with Qt::ImQueryInput when only changing selection, and always if typing text. So there would + // not be any performance gain by only updating \a query. staticVariables()->inputMethodQueryEvent = QInputMethodQueryEvent(Qt::ImQueryInput); QCoreApplication::sendEvent(focusObject, &staticVariables()->inputMethodQueryEvent); - if (!m_inSendEventToFocusObject) - [self.inputDelegate textDidChange:id(self)]; + if (!m_inSendEventToFocusObject) { + if (query & (Qt::ImCursorPosition | Qt::ImAnchorPosition)) + [self.inputDelegate selectionDidChange:id(self)]; + if (query & Qt::ImSurroundingText) + [self.inputDelegate textDidChange:id(self)]; + } } - (void)sendEventToFocusObject:(QEvent &)e