Chromium Code Reviews| 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 75 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 86 * @private {number} | 86 * @private {number} |
| 87 */ | 87 */ |
| 88 accumulated_: 0, | 88 accumulated_: 0, |
| 89 | 89 |
| 90 /** | 90 /** |
| 91 * Maps key codes on a standard keyboard to the correspodning dots. | 91 * 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. | 92 * 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. | 93 * Note that the mapping below is arranged like the dots in a braille cell. |
| 94 * Only 6 dot input is supported. | 94 * Only 6 dot input is supported. |
| 95 * @private | 95 * @private |
| 96 * @const {Object.<string, string>} | 96 * @const {Object.<string, number>} |
| 97 */ | 97 */ |
| 98 CODE_TO_DOT_: {'KeyF': 0x01, 'KeyJ': 0x08, | 98 CODE_TO_DOT_: {'KeyF': 0x01, 'KeyJ': 0x08, |
| 99 'KeyD': 0x02, 'KeyK': 0x10, | 99 'KeyD': 0x02, 'KeyK': 0x10, |
| 100 'KeyS': 0x04, 'KeyL': 0x20 }, | 100 'KeyS': 0x04, 'KeyL': 0x20 , |
|
David Tseng
2014/05/07 18:05:54
nit: extra space before comma
| |
| 101 'Space': 0}, | |
|
David Tseng
2014/05/07 18:05:54
nit: space before }
| |
| 101 | 102 |
| 102 /** | 103 /** |
| 103 * The current engine ID as set by {@code onActivate}, or the empty string if | 104 * The current engine ID as set by {@code onActivate}, or the empty string if |
| 104 * the IME is not active. | 105 * the IME is not active. |
| 105 * @type {string} | 106 * @type {string} |
| 106 * @private | 107 * @private |
| 107 */ | 108 */ |
| 108 engineID_: '', | 109 engineID_: '', |
| 109 | 110 |
| 110 /** | 111 /** |
| (...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 194 /** | 195 /** |
| 195 * Called by the system when this IME is active and a key event is generated. | 196 * Called by the system when this IME is active and a key event is generated. |
| 196 * @param {string} engineID Engine ID, should be 'braille'. | 197 * @param {string} engineID Engine ID, should be 'braille'. |
| 197 * @param {!ChromeKeyboardEvent} event The keyboard event. | 198 * @param {!ChromeKeyboardEvent} event The keyboard event. |
| 198 * @return {boolean} Whether the event was handled by this IME (true) or | 199 * @return {boolean} Whether the event was handled by this IME (true) or |
| 199 * should be allowed to propagate. | 200 * should be allowed to propagate. |
| 200 * @private | 201 * @private |
| 201 */ | 202 */ |
| 202 onKeyEvent_: function(engineID, event) { | 203 onKeyEvent_: function(engineID, event) { |
| 203 this.log_('onKeyEvent', engineID + ', ' + JSON.stringify(event)); | 204 this.log_('onKeyEvent', engineID + ', ' + JSON.stringify(event)); |
| 204 return this.processKey_(event.code, event.type); | 205 return this.processKey_(event); |
| 205 }, | 206 }, |
| 206 | 207 |
| 207 /** | 208 /** |
| 208 * Called when chrome ends the current text input session. | 209 * Called when chrome ends the current text input session. |
| 209 * @param {string} engineID Engine ID, should be 'braille'. | 210 * @param {string} engineID Engine ID, should be 'braille'. |
| 210 * @private | 211 * @private |
| 211 */ | 212 */ |
| 212 onReset_: function(engineID) { | 213 onReset_: function(engineID) { |
| 213 this.log_('onReset', engineID); | 214 this.log_('onReset', engineID); |
| 214 this.engineID_ = engineID; | 215 this.engineID_ = engineID; |
| (...skipping 30 matching lines...) Expand all Loading... | |
| 245 log_: function(func, message) { | 246 log_: function(func, message) { |
| 246 if (func === 'onKeyEvent') { | 247 if (func === 'onKeyEvent') { |
| 247 return; | 248 return; |
| 248 } | 249 } |
| 249 if (this.DEBUG) { | 250 if (this.DEBUG) { |
| 250 console.log('BrailleIme.' + func + ': ' + message); | 251 console.log('BrailleIme.' + func + ': ' + message); |
| 251 } | 252 } |
| 252 }, | 253 }, |
| 253 | 254 |
| 254 /** | 255 /** |
| 255 * Handles a querty key on the home row as a braille key. | 256 * Handles a querty key on the home row as a braille key. |
|
David Tseng
2014/05/07 18:05:54
nit: I think it's "qwerty"
| |
| 256 * @param {string} code Key code. | 257 * @param {!ChromeKeyboardEvent} event Keyboard event. |
| 257 * @param {string} type Type of key event. | |
| 258 * @return {boolean} Whether the key event was handled or not. | 258 * @return {boolean} Whether the key event was handled or not. |
| 259 * @private | 259 * @private |
| 260 */ | 260 */ |
| 261 processKey_: function(code, type) { | 261 processKey_: function(event) { |
| 262 if (!this.useStandardKeyboard_) { | 262 if (!this.useStandardKeyboard_) { |
| 263 return false; | 263 return false; |
| 264 } | 264 } |
| 265 var dot = this.CODE_TO_DOT_[code]; | 265 var dot = this.CODE_TO_DOT_[event.code]; |
| 266 if (!dot) { | 266 if (dot === undefined || event.altKey || event.ctrlKey || event.shiftKey || |
| 267 event.capsLock) { | |
| 267 this.pressed_ = 0; | 268 this.pressed_ = 0; |
| 268 this.accumulated_ = 0; | 269 this.accumulated_ = 0; |
| 269 return false; | 270 return false; |
| 270 } | 271 } |
| 271 if (type === 'keydown') { | 272 if (event.type === 'keydown') { |
| 272 this.pressed_ |= dot; | 273 if (dot !== 0) { |
| 273 this.accumulated_ |= this.pressed_; | 274 this.pressed_ |= dot; |
| 275 this.accumulated_ |= this.pressed_; | |
| 276 } else { | |
| 277 // Space cancels other dots. | |
|
David Tseng
2014/05/07 18:05:54
Just wondering about the behavior here. If I hold
| |
| 278 this.pressed_ = this.accumulated_ = 0; | |
| 279 } | |
| 274 return true; | 280 return true; |
| 275 } else if (type == 'keyup') { | 281 } else if (event.type === 'keyup') { |
| 276 this.pressed_ &= ~dot; | 282 this.pressed_ &= ~dot; |
| 277 if (this.pressed_ == 0 && this.accumulated_ != 0) { | 283 if (this.pressed_ === 0 && (this.accumulated_ !== 0 || dot === 0)) { |
| 278 this.sendToChromeVox_({type: 'brailleDots', dots: this.accumulated_}); | 284 this.sendToChromeVox_({type: 'brailleDots', dots: this.accumulated_}); |
| 279 this.accumulated_ = 0; | 285 this.accumulated_ = 0; |
| 280 } | 286 } |
| 281 return true; | 287 return true; |
| 282 } | 288 } |
| 283 return false; | 289 return false; |
| 284 }, | 290 }, |
| 285 | 291 |
| 286 /** | 292 /** |
| 287 * Connects to the ChromeVox extension for message passing. | 293 * Connects to the ChromeVox extension for message passing. |
| (...skipping 116 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 404 label: 'Use standard keyboard for braille', | 410 label: 'Use standard keyboard for braille', |
| 405 style: 'check', | 411 style: 'check', |
| 406 visible: true, | 412 visible: true, |
| 407 checked: this.useStandardKeyboard_, | 413 checked: this.useStandardKeyboard_, |
| 408 enabled: true | 414 enabled: true |
| 409 } | 415 } |
| 410 ] | 416 ] |
| 411 }); | 417 }); |
| 412 } | 418 } |
| 413 }; | 419 }; |
| OLD | NEW |