| OLD | NEW |
| (Empty) |
| 1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. | |
| 2 // Use of this source code is governed by a BSD-style license that can be | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 function insertText(text) { | |
| 6 chrome.send('insertText', [ text ]); | |
| 7 } | |
| 8 | |
| 9 function sendKeyEvent(event) { | |
| 10 chrome.send('sendKeyEvent', [ event ]); | |
| 11 } | |
| 12 | |
| 13 function hideKeyboard() { | |
| 14 chrome.send('hideKeyboard'); | |
| 15 } | |
| 16 | |
| 17 function keyboardLoaded() { | |
| 18 chrome.send('keyboardLoaded'); | |
| 19 } | |
| 20 | |
| 21 (function(exports) { | |
| 22 /** | |
| 23 * An array to save callbacks of each request. | |
| 24 * @type {Array.<function(Object)>} | |
| 25 */ | |
| 26 var requestIdCallbackMap = []; | |
| 27 | |
| 28 /** | |
| 29 * An incremental integer that represents a unique requestId. | |
| 30 * @type {number} | |
| 31 */ | |
| 32 var requestId = 0; | |
| 33 | |
| 34 /** | |
| 35 * Called when a text input box gets focus. | |
| 36 * @param {object} inputContext Describes an input context. It only contains | |
| 37 * the type of text input box at present and only "password", "number" and | |
| 38 * "text" are supported. | |
| 39 */ | |
| 40 function OnTextInputBoxFocused(inputContext) { | |
| 41 // Do not want to use the system keyboard for passwords in webui. | |
| 42 if (inputContext.type == 'password') | |
| 43 inputContext.type = 'text'; | |
| 44 keyboard.inputTypeValue = inputContext.type; | |
| 45 } | |
| 46 | |
| 47 /** | |
| 48 * Gets the context of the focused input field. The context is returned as a | |
| 49 * paramter in the |callback|. | |
| 50 * @param {function(Object)} callback The callback function after the webui | |
| 51 * function finished. | |
| 52 * @return {number} The ID of the new request. | |
| 53 */ | |
| 54 function GetInputContext(callback) { | |
| 55 var id = requestId; | |
| 56 requestIdCallbackMap[id] = callback; | |
| 57 chrome.send('getInputContext', [ id ]); | |
| 58 requestId++; | |
| 59 return id; | |
| 60 } | |
| 61 | |
| 62 /** | |
| 63 * Cancel the callback specified by requestId. | |
| 64 * @param {number} requestId The requestId of the callback that about to | |
| 65 * cancel. | |
| 66 */ | |
| 67 function CancelRequest(requestId) { | |
| 68 requestIdCallbackMap[requestId] = undefined; | |
| 69 } | |
| 70 | |
| 71 /** | |
| 72 * Webui function callback. Any call to chrome.send('getInputContext', [id]) | |
| 73 * should trigger this function being called with the parameter | |
| 74 * inputContext.requestId == id. | |
| 75 * @param {Object} inputContext The context of focused input field. Note we | |
| 76 * only have type(input box type) and requestId fields now. | |
| 77 */ | |
| 78 function GetInputContextCallback(inputContext) { | |
| 79 var requestId = inputContext.requestId; | |
| 80 if (!requestIdCallbackMap[requestId]) | |
| 81 return; | |
| 82 requestIdCallbackMap[requestId](inputContext); | |
| 83 } | |
| 84 | |
| 85 exports.OnTextInputBoxFocused = OnTextInputBoxFocused; | |
| 86 exports.getInputContext = GetInputContext; | |
| 87 exports.cancelRequest = CancelRequest; | |
| 88 exports.GetInputContextCallback = GetInputContextCallback; | |
| 89 })(this); | |
| OLD | NEW |