From ac6b9be9b3d207aef6241c59edc7375f6fadabeb Mon Sep 17 00:00:00 2001 From: Roger Maclean Date: Tue, 12 Nov 2013 18:00:09 -0500 Subject: BB10: Clean up IMF session code Be more rigorous about checking if we're in a session before invoking IMF functions. In particular the code would call initEvent if a key was received while no text field had focus leading to a crash. Also closeSession is now always called when a session is terminated rather than just setting sInputSession to 0 and hasSession is always called to check for a valid session. Change-Id: I22ce1c9bcdf8dd130f05ae319c4cc1e01afc4456 Reviewed-by: Kevin Krammer Reviewed-by: Fabian Bumberger Reviewed-by: Bernd Weimer Reviewed-by: Rafael Roquetto --- src/plugins/platforms/qnx/qqnxinputcontext_imf.cpp | 26 +++++++++++++--------- 1 file changed, 16 insertions(+), 10 deletions(-) diff --git a/src/plugins/platforms/qnx/qqnxinputcontext_imf.cpp b/src/plugins/platforms/qnx/qqnxinputcontext_imf.cpp index 7f60fa1822..dd47d37af3 100644 --- a/src/plugins/platforms/qnx/qqnxinputcontext_imf.cpp +++ b/src/plugins/platforms/qnx/qqnxinputcontext_imf.cpp @@ -717,7 +717,7 @@ void QQnxInputContext::update(Qt::InputMethodQueries queries) updateCursorPosition(); // If caret position has changed we need to inform IMF unless this is just due to our own action // such as committing text. - if (!m_isUpdatingText && lastCaret != m_caretPosition) { + if (hasSession() && !m_isUpdatingText && lastCaret != m_caretPosition) { caret_event_t caretEvent; initEvent(&caretEvent.event, sInputSession, EVENT_CARET, CARET_POS_CHANGED, sizeof(caretEvent)); caretEvent.old_pos = lastCaret; @@ -738,6 +738,10 @@ void QQnxInputContext::closeSession() p_ictrl_close_session((input_session_t *)sInputSession); sInputSession = 0; } + // These are likely already in the right state but this depends on the text control + // having called reset or commit. So, just in case, set them to proper values. + m_isComposing = false; + m_composingText.clear(); } bool QQnxInputContext::openSession() @@ -791,7 +795,7 @@ bool QQnxInputContext::dispatchCloseSoftwareInputPanel() */ bool QQnxInputContext::dispatchFocusGainEvent(int inputHints) { - if (sInputSession != 0) + if (hasSession()) dispatchFocusLossEvent(); QObject *input = qGuiApp->focusObject(); @@ -835,13 +839,13 @@ bool QQnxInputContext::dispatchFocusGainEvent(int inputHints) void QQnxInputContext::dispatchFocusLossEvent() { - if (sInputSession != 0) { + if (hasSession()) { qInputContextDebug() << Q_FUNC_INFO << "ictrl_dispatch_event focus lost"; focus_event_t focusEvent; initEvent(&focusEvent.event, sInputSession, EVENT_FOCUS, FOCUS_LOST, sizeof(focusEvent)); p_ictrl_dispatch_event((event_t *)&focusEvent); - sInputSession = 0; + closeSession(); } } @@ -849,7 +853,7 @@ bool QQnxInputContext::handleKeyboardEvent(int flags, int sym, int mod, int scan { Q_UNUSED(scan); - if (!imfAvailable()) + if (!hasSession()) return false; int key = (flags & KEY_SYM_VALID) ? sym : cap; @@ -950,10 +954,12 @@ void QQnxInputContext::endComposition() finishComposingText(); - action_event_t actionEvent; - initEvent(&actionEvent.event, sInputSession, EVENT_ACTION, ACTION_END_COMPOSITION, sizeof(actionEvent)); - qInputContextDebug() << Q_FUNC_INFO << "ictrl_dispatch_even end composition"; - p_ictrl_dispatch_event(&actionEvent.event); + if (hasSession()) { + action_event_t actionEvent; + initEvent(&actionEvent.event, sInputSession, EVENT_ACTION, ACTION_END_COMPOSITION, sizeof(actionEvent)); + qInputContextDebug() << Q_FUNC_INFO << "ictrl_dispatch_even end composition"; + p_ictrl_dispatch_event(&actionEvent.event); + } } void QQnxInputContext::updateComposition(spannable_string_t *text, int32_t new_cursor_position) @@ -1318,7 +1324,7 @@ void QQnxInputContext::setFocusObject(QObject *object) if (!inputMethodAccepted()) { if (m_inputPanelVisible) hideInputPanel(); - if (sInputSession != 0) + if (hasSession()) dispatchFocusLossEvent(); } else { QInputMethodQueryEvent query(Qt::ImHints); -- cgit v1.2.3