| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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 'use strict'; | 5 'use strict'; |
| 6 | 6 |
| 7 /** | 7 /** |
| 8 * @fileoverview Braille hardware keyboard input method. | 8 * @fileoverview Braille hardware keyboard input method. |
| 9 * | 9 * |
| 10 * This method is automatically enabled when a braille display is connected | 10 * This method is automatically enabled when a braille display is connected |
| (...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 62 | 62 |
| 63 /** | 63 /** |
| 64 * Identifier for the use standard keyboard option used in the menu and | 64 * Identifier for the use standard keyboard option used in the menu and |
| 65 * {@code localStorage}. This can be switched on to type braille using the | 65 * {@code localStorage}. This can be switched on to type braille using the |
| 66 * standard keyboard, or off (default) for the usual keyboard behaviour. | 66 * standard keyboard, or off (default) for the usual keyboard behaviour. |
| 67 * @const {string} | 67 * @const {string} |
| 68 */ | 68 */ |
| 69 USE_STANDARD_KEYBOARD_ID: 'useStandardKeyboard', | 69 USE_STANDARD_KEYBOARD_ID: 'useStandardKeyboard', |
| 70 | 70 |
| 71 // State related to the support for typing braille using a standrad | 71 // State related to the support for typing braille using a standrad |
| 72 // (querty) keyboard. | 72 // (qwerty) keyboard. |
| 73 | 73 |
| 74 /** @private {boolean} */ | 74 /** @private {boolean} */ |
| 75 useStandardKeyboard_: false, | 75 useStandardKeyboard_: false, |
| 76 | 76 |
| 77 /** | 77 /** |
| 78 * Braille dots for keys that are currently pressed. | 78 * Braille dots for keys that are currently pressed. |
| 79 * @private {number} | 79 * @private {number} |
| 80 */ | 80 */ |
| 81 pressed_: 0, | 81 pressed_: 0, |
| 82 | 82 |
| 83 /** | 83 /** |
| 84 * Dots that have been pressed at some point since {@code pressed_} was last | 84 * Dots that have been pressed at some point since {@code pressed_} was last |
| 85 * {@code 0}. | 85 * {@code 0}. |
| 86 * @private {number} | 86 * @private {number} |
| 87 */ | 87 */ |
| 88 accumulated_: 0, | 88 accumulated_: 0, |
| 89 | 89 |
| 90 /** | 90 /** |
| 91 * Bit in {@code pressed_} and {@code accumulated_} that represent |
| 92 * the space key. |
| 93 * @const {number} |
| 94 */ |
| 95 SPACE: 0x100, |
| 96 |
| 97 /** |
| 91 * Maps key codes on a standard keyboard to the correspodning dots. | 98 * Maps key codes on a standard keyboard to the correspodning dots. |
| 92 * Keys on the 'home row' correspond to the keys on a Perkins-style keyboard. | 99 * Keys on the 'home row' correspond to the keys on a Perkins-style keyboard. |
| 93 * Note that the mapping below is arranged like the dots in a braille cell. | 100 * Note that the mapping below is arranged like the dots in a braille cell. |
| 94 * Only 6 dot input is supported. | 101 * Only 6 dot input is supported. |
| 95 * @private | 102 * @private |
| 96 * @const {Object.<string, string>} | 103 * @const {Object.<string, number>} |
| 97 */ | 104 */ |
| 98 CODE_TO_DOT_: {'KeyF': 0x01, 'KeyJ': 0x08, | 105 CODE_TO_DOT_: {'KeyF': 0x01, 'KeyJ': 0x08, |
| 99 'KeyD': 0x02, 'KeyK': 0x10, | 106 'KeyD': 0x02, 'KeyK': 0x10, |
| 100 'KeyS': 0x04, 'KeyL': 0x20 }, | 107 'KeyS': 0x04, 'KeyL': 0x20, |
| 108 'Space': 0x100 }, |
| 101 | 109 |
| 102 /** | 110 /** |
| 103 * The current engine ID as set by {@code onActivate}, or the empty string if | 111 * The current engine ID as set by {@code onActivate}, or the empty string if |
| 104 * the IME is not active. | 112 * the IME is not active. |
| 105 * @type {string} | 113 * @type {string} |
| 106 * @private | 114 * @private |
| 107 */ | 115 */ |
| 108 engineID_: '', | 116 engineID_: '', |
| 109 | 117 |
| 110 /** | 118 /** |
| (...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 194 /** | 202 /** |
| 195 * Called by the system when this IME is active and a key event is generated. | 203 * Called by the system when this IME is active and a key event is generated. |
| 196 * @param {string} engineID Engine ID, should be 'braille'. | 204 * @param {string} engineID Engine ID, should be 'braille'. |
| 197 * @param {!ChromeKeyboardEvent} event The keyboard event. | 205 * @param {!ChromeKeyboardEvent} event The keyboard event. |
| 198 * @return {boolean} Whether the event was handled by this IME (true) or | 206 * @return {boolean} Whether the event was handled by this IME (true) or |
| 199 * should be allowed to propagate. | 207 * should be allowed to propagate. |
| 200 * @private | 208 * @private |
| 201 */ | 209 */ |
| 202 onKeyEvent_: function(engineID, event) { | 210 onKeyEvent_: function(engineID, event) { |
| 203 this.log_('onKeyEvent', engineID + ', ' + JSON.stringify(event)); | 211 this.log_('onKeyEvent', engineID + ', ' + JSON.stringify(event)); |
| 204 return this.processKey_(event.code, event.type); | 212 return this.processKey_(event); |
| 205 }, | 213 }, |
| 206 | 214 |
| 207 /** | 215 /** |
| 208 * Called when chrome ends the current text input session. | 216 * Called when chrome ends the current text input session. |
| 209 * @param {string} engineID Engine ID, should be 'braille'. | 217 * @param {string} engineID Engine ID, should be 'braille'. |
| 210 * @private | 218 * @private |
| 211 */ | 219 */ |
| 212 onReset_: function(engineID) { | 220 onReset_: function(engineID) { |
| 213 this.log_('onReset', engineID); | 221 this.log_('onReset', engineID); |
| 214 this.engineID_ = engineID; | 222 this.engineID_ = engineID; |
| (...skipping 30 matching lines...) Expand all Loading... |
| 245 log_: function(func, message) { | 253 log_: function(func, message) { |
| 246 if (func === 'onKeyEvent') { | 254 if (func === 'onKeyEvent') { |
| 247 return; | 255 return; |
| 248 } | 256 } |
| 249 if (this.DEBUG) { | 257 if (this.DEBUG) { |
| 250 console.log('BrailleIme.' + func + ': ' + message); | 258 console.log('BrailleIme.' + func + ': ' + message); |
| 251 } | 259 } |
| 252 }, | 260 }, |
| 253 | 261 |
| 254 /** | 262 /** |
| 255 * Handles a querty key on the home row as a braille key. | 263 * Handles a qwerty key on the home row as a braille key. |
| 256 * @param {string} code Key code. | 264 * @param {!ChromeKeyboardEvent} event Keyboard event. |
| 257 * @param {string} type Type of key event. | |
| 258 * @return {boolean} Whether the key event was handled or not. | 265 * @return {boolean} Whether the key event was handled or not. |
| 259 * @private | 266 * @private |
| 260 */ | 267 */ |
| 261 processKey_: function(code, type) { | 268 processKey_: function(event) { |
| 262 if (!this.useStandardKeyboard_) { | 269 if (!this.useStandardKeyboard_) { |
| 263 return false; | 270 return false; |
| 264 } | 271 } |
| 265 var dot = this.CODE_TO_DOT_[code]; | 272 var dot = this.CODE_TO_DOT_[event.code]; |
| 266 if (!dot) { | 273 if (!dot || event.altKey || event.ctrlKey || event.shiftKey || |
| 274 event.capsLock) { |
| 267 this.pressed_ = 0; | 275 this.pressed_ = 0; |
| 268 this.accumulated_ = 0; | 276 this.accumulated_ = 0; |
| 269 return false; | 277 return false; |
| 270 } | 278 } |
| 271 if (type === 'keydown') { | 279 if (event.type === 'keydown') { |
| 272 this.pressed_ |= dot; | 280 this.pressed_ |= dot; |
| 273 this.accumulated_ |= this.pressed_; | 281 this.accumulated_ |= this.pressed_; |
| 274 return true; | 282 return true; |
| 275 } else if (type == 'keyup') { | 283 } else if (event.type === 'keyup') { |
| 276 this.pressed_ &= ~dot; | 284 this.pressed_ &= ~dot; |
| 277 if (this.pressed_ == 0 && this.accumulated_ != 0) { | 285 if (this.pressed_ === 0 && this.accumulated_ !== 0) { |
| 278 this.sendToChromeVox_({type: 'brailleDots', dots: this.accumulated_}); | 286 var dotsToSend = this.accumulated_; |
| 279 this.accumulated_ = 0; | 287 this.accumulated_ = 0; |
| 288 if (dotsToSend & this.SPACE) { |
| 289 if (dotsToSend != this.SPACE) { |
| 290 // Can't combine space and actual dot keys. |
| 291 return true; |
| 292 } |
| 293 // Space is sent as a blank cell. |
| 294 dotsToSend = 0; |
| 295 } |
| 296 this.sendToChromeVox_({type: 'brailleDots', dots: dotsToSend}); |
| 280 } | 297 } |
| 281 return true; | 298 return true; |
| 282 } | 299 } |
| 283 return false; | 300 return false; |
| 284 }, | 301 }, |
| 285 | 302 |
| 286 /** | 303 /** |
| 287 * Connects to the ChromeVox extension for message passing. | 304 * Connects to the ChromeVox extension for message passing. |
| 288 * @private | 305 * @private |
| 289 */ | 306 */ |
| (...skipping 114 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 404 label: 'Use standard keyboard for braille', | 421 label: 'Use standard keyboard for braille', |
| 405 style: 'check', | 422 style: 'check', |
| 406 visible: true, | 423 visible: true, |
| 407 checked: this.useStandardKeyboard_, | 424 checked: this.useStandardKeyboard_, |
| 408 enabled: true | 425 enabled: true |
| 409 } | 426 } |
| 410 ] | 427 ] |
| 411 }); | 428 }); |
| 412 } | 429 } |
| 413 }; | 430 }; |
| OLD | NEW |