• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1// Copyright 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/**
6 * Queries the document for an element with a matching id.
7 * @param {string} id is a case-sensitive string representing the unique ID of
8 *     the element being sought.
9 * @return {?Element} The element with that id.
10 */
11var $ = function(id) {
12  return document.getElementById(id);
13}
14
15function logIfError() {
16  if (chrome.runtime.lastError) {
17    console.log(chrome.runtime.lastError);
18  }
19}
20
21function insertText(text) {
22  chrome.virtualKeyboardPrivate.insertText(text, logIfError);
23}
24
25function MoveCursor(swipe_direction, swipe_flags) {
26  chrome.virtualKeyboardPrivate.moveCursor(swipe_direction, swipe_flags);
27}
28
29function sendKeyEvent(event) {
30  chrome.virtualKeyboardPrivate.sendKeyEvent(event, logIfError);
31}
32
33(function(scope) {
34  var keyboardLocked_ = false;
35
36  /**
37   * Check the lock state of virtual keyboard.
38   * @return {boolean} True if virtual keyboard is locked.
39   */
40  function keyboardLocked() {
41    return keyboardLocked_;
42  }
43
44  /**
45   * Lock or unlock virtual keyboard.
46   * @param {boolean} lock Whether or not to lock the virtual keyboard.
47   */
48  function lockKeyboard(lock) {
49    keyboardLocked_ = lock;
50    chrome.virtualKeyboardPrivate.lockKeyboard(lock);
51  }
52
53  scope.keyboardLocked = keyboardLocked;
54  scope.lockKeyboard = lockKeyboard;
55})(this);
56
57function hideKeyboard() {
58  lockKeyboard(false);
59  chrome.virtualKeyboardPrivate.hideKeyboard(logIfError);
60}
61
62function keyboardLoaded() {
63  chrome.virtualKeyboardPrivate.keyboardLoaded(logIfError);
64}
65
66function getKeyboardConfig(callback) {
67  chrome.virtualKeyboardPrivate.getKeyboardConfig(function (config) {
68    callback(config);
69  });
70}
71
72chrome.virtualKeyboardPrivate.onTextInputBoxFocused.addListener(
73  function (inputContext) {
74    $('keyboard').inputTypeValue = inputContext.type;
75  }
76);
77