diff --git a/apps/system/js/keyboard_manager.js b/apps/system/js/keyboard_manager.js index e4a95f3368d4..35b84285eaa1 100644 --- a/apps/system/js/keyboard_manager.js +++ b/apps/system/js/keyboard_manager.js @@ -138,6 +138,7 @@ var KeyboardManager = { window.addEventListener('mozbrowsererror', this); window.addEventListener('applicationsetupdialogshow', this); window.addEventListener('mozmemorypressure', this); + window.addEventListener('lock', this); // To handle keyboard layout switching window.addEventListener('mozChromeEvent', function(evt) { @@ -457,6 +458,14 @@ var KeyboardManager = { this._debug('mozmemorypressure event; keyboard removed'); } break; + + case 'lock': + if (this.hasActiveKeyboard) { + // Instead of hideKeyboard(), we should removeFocus() here. + // (and, removing the focus cause Gecko to ask us to hideKeyboard()) + navigator.mozInputMethod.removeFocus(); + } + break; } }, diff --git a/apps/system/test/unit/keyboard_manager_test.js b/apps/system/test/unit/keyboard_manager_test.js index cfdfc3b09fc0..5609d33f6176 100644 --- a/apps/system/test/unit/keyboard_manager_test.js +++ b/apps/system/test/unit/keyboard_manager_test.js @@ -86,14 +86,21 @@ suite('KeyboardManager', function() { mocksHelperForKeyboardManager.attachTestHelpers(); var realMozSettings = null; + var realKeyboard = null; suiteSetup(function() { document.body.innerHTML += '
'; navigator.mozSettings = MockNavigatorSettings; + + realKeyboard = window.navigator.mozInputMethod; + window.navigator.mozInputMethod = { + removeFocus: function() {} + }; }); suiteTeardown(function() { navigator.mozSettings = realMozSettings; + window.navigator.mozInputMethod = realKeyboard; }); setup(function() { @@ -488,6 +495,22 @@ suite('KeyboardManager', function() { trigger('applicationsetupdialogshow'); assert.ok(hideKeyboardImmediately.called); }); + + test('lock event: do nothing if no keyboard', function() { + var spy = this.sinon.spy(navigator.mozInputMethod, 'removeFocus'); + trigger('lock'); + assert.ok(spy.notCalled); + }); + + test('lock event: hide keyboard if needed', function() { + var realActive = KeyboardManager.hasActiveKeyboard; + KeyboardManager.hasActiveKeyboard = true; + var spy = this.sinon.spy(navigator.mozInputMethod, 'removeFocus'); + trigger('lock'); + sinon.assert.calledOnce(spy); + + KeyboardManager.hasActiveKeyboard = realActive; + }); }); suite('Hide Keyboard', function() {