Skip to content
This repository has been archived by the owner on Nov 3, 2021. It is now read-only.

Commit

Permalink
Merge pull request #20121 from timdream/keyboard-hide-lock
Browse files Browse the repository at this point in the history
Bug 1018335 - removeFocus() when the screen is locked, r=rudyl
Conflicts:
	apps/system/js/keyboard_manager.js
	apps/system/test/unit/keyboard_manager_test.js
  • Loading branch information
timdream committed Jun 13, 2014
1 parent 0539be8 commit fe6d683
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 0 deletions.
9 changes: 9 additions & 0 deletions apps/system/js/keyboard_manager.js
Expand Up @@ -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) {
Expand Down Expand Up @@ -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;
}
},

Expand Down
23 changes: 23 additions & 0 deletions apps/system/test/unit/keyboard_manager_test.js
Expand Up @@ -86,14 +86,21 @@ suite('KeyboardManager', function() {
mocksHelperForKeyboardManager.attachTestHelpers();

var realMozSettings = null;
var realKeyboard = null;

suiteSetup(function() {
document.body.innerHTML += '<div id="run-container"></div>';
navigator.mozSettings = MockNavigatorSettings;

realKeyboard = window.navigator.mozInputMethod;
window.navigator.mozInputMethod = {
removeFocus: function() {}
};
});

suiteTeardown(function() {
navigator.mozSettings = realMozSettings;
window.navigator.mozInputMethod = realKeyboard;
});

setup(function() {
Expand Down Expand Up @@ -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() {
Expand Down

0 comments on commit fe6d683

Please sign in to comment.