Bug 912951 - Implement supportsSwitching in inputMethod based on content events from gaia. r=yxl

This commit is contained in:
Jan Jongboom 2013-09-12 13:02:36 -04:00
parent 86f71f5e75
commit 691da12877
3 changed files with 42 additions and 1 deletions

View File

@ -700,6 +700,9 @@ var CustomEventManager = {
case 'captive-portal-login-cancel': case 'captive-portal-login-cancel':
CaptivePortalLoginHelper.handleEvent(detail); CaptivePortalLoginHelper.handleEvent(detail);
break; break;
case 'inputmethod-update-layouts':
KeyboardHelper.handleEvent(detail);
break;
} }
} }
} }
@ -1052,6 +1055,14 @@ let RemoteDebugger = {
} }
} }
let KeyboardHelper = {
handleEvent: function keyboard_handleEvent(aMessage) {
let data = aMessage.data;
Keyboard.setLayouts(data.layouts);
}
};
// This is the backend for Gaia's screenshot feature. Gaia requests a // This is the backend for Gaia's screenshot feature. Gaia requests a
// screenshot by sending a mozContentEvent with detail.type set to // screenshot by sending a mozContentEvent with detail.type set to
// 'take-screenshot'. Then we take a screenshot and send a // 'take-screenshot'. Then we take a screenshot and send a

View File

@ -238,6 +238,10 @@ let Keyboard = {
}, },
getContext: function keyboardGetContext(msg) { getContext: function keyboardGetContext(msg) {
if (this._layouts) {
ppmm.broadcastAsyncMessage('Keyboard:LayoutsChange', this._layouts);
}
this.sendAsyncMessage('Forms:GetContext', msg.data); this.sendAsyncMessage('Forms:GetContext', msg.data);
}, },
@ -247,6 +251,19 @@ let Keyboard = {
endComposition: function keyboardEndComposition(msg) { endComposition: function keyboardEndComposition(msg) {
this.sendAsyncMessage('Forms:EndComposition', msg.data); this.sendAsyncMessage('Forms:EndComposition', msg.data);
},
/**
* Get the number of keyboard layouts active from keyboard_manager
*/
_layouts: null,
setLayouts: function keyboardSetLayoutCount(layouts) {
// The input method plugins may not have loaded yet,
// cache the layouts so on init we can respond immediately instead
// of going back and forth between keyboard_manager
this._layouts = layouts;
ppmm.broadcastAsyncMessage('Keyboard:LayoutsChange', layouts);
} }
}; };

View File

@ -207,6 +207,8 @@ MozKeyboard.prototype = {
function MozInputMethodManager() { } function MozInputMethodManager() { }
MozInputMethodManager.prototype = { MozInputMethodManager.prototype = {
_supportsSwitching: false,
classID: Components.ID("{7e9d7280-ef86-11e2-b778-0800200c9a66}"), classID: Components.ID("{7e9d7280-ef86-11e2-b778-0800200c9a66}"),
QueryInterface: XPCOMUtils.generateQI([ QueryInterface: XPCOMUtils.generateQI([
@ -230,7 +232,7 @@ MozInputMethodManager.prototype = {
}, },
supportsSwitching: function() { supportsSwitching: function() {
return true; return this._supportsSwitching;
}, },
hide: function() { hide: function() {
@ -247,6 +249,7 @@ function MozInputMethod() { }
MozInputMethod.prototype = { MozInputMethod.prototype = {
_inputcontext: null, _inputcontext: null,
_layouts: {},
classID: Components.ID("{4607330d-e7d2-40a4-9eb8-43967eae0142}"), classID: Components.ID("{4607330d-e7d2-40a4-9eb8-43967eae0142}"),
@ -284,6 +287,7 @@ MozInputMethod.prototype = {
cpmm.addMessageListener('Keyboard:FocusChange', this); cpmm.addMessageListener('Keyboard:FocusChange', this);
cpmm.addMessageListener('Keyboard:SelectionChange', this); cpmm.addMessageListener('Keyboard:SelectionChange', this);
cpmm.addMessageListener('Keyboard:GetContext:Result:OK', this); cpmm.addMessageListener('Keyboard:GetContext:Result:OK', this);
cpmm.addMessageListener('Keyboard:LayoutsChange', this);
// If there already is an active context, then this will trigger // If there already is an active context, then this will trigger
// a GetContext:Result:OK event, and we can initialize ourselves. // a GetContext:Result:OK event, and we can initialize ourselves.
@ -296,6 +300,7 @@ MozInputMethod.prototype = {
cpmm.removeMessageListener('Keyboard:FocusChange', this); cpmm.removeMessageListener('Keyboard:FocusChange', this);
cpmm.removeMessageListener('Keyboard:SelectionChange', this); cpmm.removeMessageListener('Keyboard:SelectionChange', this);
cpmm.removeMessageListener('Keyboard:GetContext:Result:OK', this); cpmm.removeMessageListener('Keyboard:GetContext:Result:OK', this);
cpmm.removeMessageListener('Keyboard:LayoutsChange', this);
this._window = null; this._window = null;
this._mgmt = null; this._mgmt = null;
@ -320,6 +325,9 @@ MozInputMethod.prototype = {
case 'Keyboard:GetContext:Result:OK': case 'Keyboard:GetContext:Result:OK':
this.setInputContext(json); this.setInputContext(json);
break; break;
case 'Keyboard:LayoutsChange':
this._layouts = json;
break;
} }
}, },
@ -349,9 +357,14 @@ MozInputMethod.prototype = {
if (this._inputcontext) { if (this._inputcontext) {
this._inputcontext.destroy(); this._inputcontext.destroy();
this._inputcontext = null; this._inputcontext = null;
this._mgmt._supportsSwitching = false;
} }
if (data) { if (data) {
this._mgmt._supportsSwitching = this._layouts[data.type] ?
this._layouts[data.type] > 1 :
false;
this._inputcontext = new MozInputContext(data); this._inputcontext = new MozInputContext(data);
this._inputcontext.init(this._window); this._inputcontext.init(this._window);
} }