From 691da1287711688915728387557f79d99045e317 Mon Sep 17 00:00:00 2001 From: Jan Jongboom Date: Thu, 12 Sep 2013 13:02:36 -0400 Subject: [PATCH] Bug 912951 - Implement supportsSwitching in inputMethod based on content events from gaia. r=yxl --- b2g/chrome/content/shell.js | 11 +++++++++++ b2g/components/Keyboard.jsm | 17 +++++++++++++++++ b2g/components/MozKeyboard.js | 15 ++++++++++++++- 3 files changed, 42 insertions(+), 1 deletion(-) diff --git a/b2g/chrome/content/shell.js b/b2g/chrome/content/shell.js index 8fde9771c13..7598e005d62 100644 --- a/b2g/chrome/content/shell.js +++ b/b2g/chrome/content/shell.js @@ -700,6 +700,9 @@ var CustomEventManager = { case 'captive-portal-login-cancel': CaptivePortalLoginHelper.handleEvent(detail); 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 // screenshot by sending a mozContentEvent with detail.type set to // 'take-screenshot'. Then we take a screenshot and send a diff --git a/b2g/components/Keyboard.jsm b/b2g/components/Keyboard.jsm index 021c6125f58..9b16f457f8b 100644 --- a/b2g/components/Keyboard.jsm +++ b/b2g/components/Keyboard.jsm @@ -238,6 +238,10 @@ let Keyboard = { }, getContext: function keyboardGetContext(msg) { + if (this._layouts) { + ppmm.broadcastAsyncMessage('Keyboard:LayoutsChange', this._layouts); + } + this.sendAsyncMessage('Forms:GetContext', msg.data); }, @@ -247,6 +251,19 @@ let Keyboard = { endComposition: function keyboardEndComposition(msg) { 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); } }; diff --git a/b2g/components/MozKeyboard.js b/b2g/components/MozKeyboard.js index 20b348aee31..11a1cc1b291 100644 --- a/b2g/components/MozKeyboard.js +++ b/b2g/components/MozKeyboard.js @@ -207,6 +207,8 @@ MozKeyboard.prototype = { function MozInputMethodManager() { } MozInputMethodManager.prototype = { + _supportsSwitching: false, + classID: Components.ID("{7e9d7280-ef86-11e2-b778-0800200c9a66}"), QueryInterface: XPCOMUtils.generateQI([ @@ -230,7 +232,7 @@ MozInputMethodManager.prototype = { }, supportsSwitching: function() { - return true; + return this._supportsSwitching; }, hide: function() { @@ -247,6 +249,7 @@ function MozInputMethod() { } MozInputMethod.prototype = { _inputcontext: null, + _layouts: {}, classID: Components.ID("{4607330d-e7d2-40a4-9eb8-43967eae0142}"), @@ -284,6 +287,7 @@ MozInputMethod.prototype = { cpmm.addMessageListener('Keyboard:FocusChange', this); cpmm.addMessageListener('Keyboard:SelectionChange', this); cpmm.addMessageListener('Keyboard:GetContext:Result:OK', this); + cpmm.addMessageListener('Keyboard:LayoutsChange', this); // If there already is an active context, then this will trigger // a GetContext:Result:OK event, and we can initialize ourselves. @@ -296,6 +300,7 @@ MozInputMethod.prototype = { cpmm.removeMessageListener('Keyboard:FocusChange', this); cpmm.removeMessageListener('Keyboard:SelectionChange', this); cpmm.removeMessageListener('Keyboard:GetContext:Result:OK', this); + cpmm.removeMessageListener('Keyboard:LayoutsChange', this); this._window = null; this._mgmt = null; @@ -320,6 +325,9 @@ MozInputMethod.prototype = { case 'Keyboard:GetContext:Result:OK': this.setInputContext(json); break; + case 'Keyboard:LayoutsChange': + this._layouts = json; + break; } }, @@ -349,9 +357,14 @@ MozInputMethod.prototype = { if (this._inputcontext) { this._inputcontext.destroy(); this._inputcontext = null; + this._mgmt._supportsSwitching = false; } if (data) { + this._mgmt._supportsSwitching = this._layouts[data.type] ? + this._layouts[data.type] > 1 : + false; + this._inputcontext = new MozInputContext(data); this._inputcontext.init(this._window); }