mozilla-b2g/gaia — pull request #12945 by bmac (2013-10-18 20:55:08+00:00)
Title: Bug 927744 - [Keyboard] Keyboard app loses "inputContext" object when sw...

...itching layouts

It looks like `navigator.mozInputMethod.mgmt.next()` call in the `switchToNextIME` function ends up triggering `switchToNext` in `apps/system/keyboard_manager.js`.

This calls `frame.setInputMethodActive(true)` on the frame for the new keyboard layout which briefly causes the inputContext to be set to null.

To fix the "Cannot get inputContext" errors from appearing in the logs we return early from the `showKeyboard` function when `inputContext` is null.

To solve the issue blocking https://bugzilla.mozilla.org/show_bug.cgi?id=906617 we can call the `inputMethod .deactivate` method before calling `navigator.mozInputMethod.mgmt.next()`. This gives the inputMethod object a chance to call `endComposition ` on `navigator.mozInputMethod.inputContext` before it gets set to null.