'use strict'; (function(exports) { /** * InputFrameManager manages all the iframe-related operations that * has to do with keyboard layouts. It receives a layout from KeyboardManager * and performs operations on the iframe associated with the layout, such that * KeyboardManager does not have to be concerned about the inner mechanisms * of a keyboard iframe. */ var InputFrameManager = function(keyboardManager) { this._keyboardManager = keyboardManager; // The set of running keyboards. // This is a map from keyboard manifestURL to an object like this: // 'keyboard.gaiamobile.org/manifest.webapp' : { // 'English': aIframe // } this.runningLayouts = {}; this._onDebug = false; this._activeFrame = null; }; InputFrameManager.prototype._debug = function ifm__debug(msg) { if (this._onDebug) { console.log('[InputFrameManager] ' + msg); } }; InputFrameManager.prototype.start = function ifm_start() { }; InputFrameManager.prototype.stop = function ifm_stop() { }; InputFrameManager.prototype.handleEvent = function ifm_handleEvent(evt) { this._keyboardManager.resizeKeyboard(evt); }; InputFrameManager.prototype.setupFrame = function ifm_setupFrame(layout) { var frame = this.runningLayouts[layout.manifestURL][layout.id]; frame.classList.remove('hide'); this._setFrameActive(frame, true); frame.addEventListener('mozbrowserresize', this, true); }; InputFrameManager.prototype.resetFrame = function ifm_resetFrame(layout) { if (!layout) { return; } var frame = this.runningLayouts[layout.manifestURL][layout.id]; if (!frame) { return; } frame.classList.add('hide'); this._setFrameActive(frame, false); frame.removeEventListener('mozbrowserresize', this, true); }; InputFrameManager.prototype.pauseTemporarily = function ifm_pauseTemporarily(value) { // This method is to deactivate the currently-active input frame for a while // without dismissing the whole keyboard app. It's designed for the remote // control input function to grant system app the ability to become another // input frame temporarily. if (this._activeFrame) { this._activeFrame.setInputMethodActive(!value); } }; InputFrameManager.prototype._setFrameActive = function ifm_setFrameActive(frame, active) { this._debug('setFrameActive: ' + frame.dataset.frameManifestURL + frame.dataset.framePath + ', active: ' + active); if (frame.setVisible) { frame.setVisible(active); } if (frame.setInputMethodActive) { frame.setInputMethodActive(active); this._activeFrame = active ? frame : null; } this._keyboardManager.setHasActiveKeyboard(active); }; InputFrameManager.prototype.launchFrame = function ifm_launchFrame(layout, keepInactive) { if (this._isRunningLayout(layout)) { this._debug('this layout is running'); return; } var frame = null; // The layout is in a keyboard app that has been launched. if (this._isRunningKeyboard(layout)) { // Re-use the iframe by changing its src. frame = this._getFrameFromExistingKeyboard(layout); } // Can't reuse, so create a new frame to load this new layout. if (!frame) { frame = this._loadKeyboardLayoutToFrame(layout, keepInactive); frame.dataset.frameManifestURL = layout.manifestURL; } frame.dataset.frameName = layout.id; frame.dataset.framePath = layout.path; this._insertFrameRef(layout, frame); }; InputFrameManager.prototype._loadKeyboardLayoutToFrame = function ifm__loadKeyboardLayoutToFrame(layout, keepInactive) { var frame = this._constructFrame(layout); this._keyboardManager.keyboardFrameContainer.appendChild(frame); if (keepInactive) { frame.setVisible(false); frame.classList.add('hide'); } return frame; }; InputFrameManager.prototype._constructFrame = function ifm__constructFrame(layout) { // Generate a