OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 /** | 5 /** |
6 * @fileoverview A simple virtual keyboard implementation. | 6 * @fileoverview A simple virtual keyboard implementation. |
7 */ | 7 */ |
8 | 8 |
9 var KEY_MODE = 'key'; | 9 var KEY_MODE = 'key'; |
10 var SHIFT_MODE = 'shift'; | 10 var SHIFT_MODE = 'shift'; |
(...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
107 } | 107 } |
108 | 108 |
109 /** | 109 /** |
110 * Transition the mode according to the given transition. | 110 * Transition the mode according to the given transition. |
111 * @param {string} transition The transition to take. | 111 * @param {string} transition The transition to take. |
112 */ | 112 */ |
113 function transitionMode(transition) { | 113 function transitionMode(transition) { |
114 setMode(MODE_TRANSITIONS[currentMode + transition]); | 114 setMode(MODE_TRANSITIONS[currentMode + transition]); |
115 } | 115 } |
116 | 116 |
117 function logIfError() { | |
118 if (chrome.runtime.lastError) { | |
119 console.log(chrome.runtime.lastError); | |
120 } | |
121 } | |
122 | |
123 /** | 117 /** |
124 * Send the given key to chrome, via the experimental extension API. | 118 * Send the given key to chrome, via the experimental extension API. |
125 * @param {string} keyIdentifier The key to send. | 119 * @param {string} keyIdentifier The key to send. |
126 */ | 120 */ |
127 function sendKey(keyIdentifier) { | 121 function sendKey(keyIdentifier) { |
128 // FIXME(bryeung) | |
129 console.log('Typed: ' + keyIdentifier); | |
130 var keyEvent = { | 122 var keyEvent = { |
131 type: 'keydown', | |
132 keyIdentifier: keyIdentifier | 123 keyIdentifier: keyIdentifier |
133 }; | 124 }; |
134 chrome.experimental.input.virtualKeyboard.sendKeyboardEvent(keyEvent, | 125 sendKeyEvent(keyEvent); |
135 logIfError); | |
136 keyEvent.type = 'keyup'; | |
137 chrome.experimental.input.virtualKeyboard.sendKeyboardEvent(keyEvent, | |
138 logIfError); | |
139 | 126 |
140 // Exit shift mode after pressing any key but space. | 127 // Exit shift mode after pressing any key but space. |
141 if (currentMode == SHIFT_MODE && keyIdentifier != 'Spacebar') { | 128 if (currentMode == SHIFT_MODE && keyIdentifier != 'Spacebar') { |
142 transitionMode(SHIFT_MODE); | 129 transitionMode(SHIFT_MODE); |
143 } | 130 } |
144 // Enter shift mode after typing a closing punctuation and then a space for a | 131 // Enter shift mode after typing a closing punctuation and then a space for a |
145 // new sentence. | 132 // new sentence. |
146 if (enterShiftModeOnSpace) { | 133 if (enterShiftModeOnSpace) { |
147 enterShiftModeOnSpace = false; | 134 enterShiftModeOnSpace = false; |
148 if (currentMode != SHIFT_MODE && keyIdentifier == 'Spacebar') { | 135 if (currentMode != SHIFT_MODE && keyIdentifier == 'Spacebar') { |
(...skipping 558 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
707 }, | 694 }, |
708 | 695 |
709 /** | 696 /** |
710 * Returns the size of keys this row contains. | 697 * Returns the size of keys this row contains. |
711 * @return {number} The size of keys. | 698 * @return {number} The size of keys. |
712 */ | 699 */ |
713 get length() { | 700 get length() { |
714 return this.keys_.length; | 701 return this.keys_.length; |
715 } | 702 } |
716 }; | 703 }; |
OLD | NEW |