| Index: chrome/browser/resources/chromeos/switch_access/options.js
|
| diff --git a/chrome/browser/resources/chromeos/switch_access/options.js b/chrome/browser/resources/chromeos/switch_access/options.js
|
| index 0f935e8efb7ee6c3651fea30685700eac621a7e3..606dcccbfc109e491c3ace49131986caba51ef5e 100644
|
| --- a/chrome/browser/resources/chromeos/switch_access/options.js
|
| +++ b/chrome/browser/resources/chromeos/switch_access/options.js
|
| @@ -23,9 +23,9 @@ function SwitchAccessOptions() {
|
| /**
|
| * User preferences.
|
| *
|
| - * @type {SwitchAccessPrefs}
|
| + * @private {SwitchAccessPrefs}
|
| */
|
| - this.switchAccessPrefs_ = background.switchAccess.switchAccessPrefs;
|
| + this.prefs_ = background.switchAccess.switchAccessPrefs;
|
|
|
| this.init_();
|
| document.addEventListener('change', this.handleInputChange_.bind(this));
|
| @@ -42,9 +42,14 @@ SwitchAccessOptions.prototype = {
|
| */
|
| init_: function() {
|
| $('enableAutoScan').checked =
|
| - this.switchAccessPrefs_.getBooleanPref('enableAutoScan');
|
| + this.prefs_.getBooleanPref('enableAutoScan');
|
| $('autoScanTime').value =
|
| - this.switchAccessPrefs_.getNumberPref('autoScanTime') / 1000;
|
| + this.prefs_.getNumberPref('autoScanTime') / 1000;
|
| +
|
| + for (let command of this.prefs_.getCommands()) {
|
| + $(command).value = String.fromCharCode(
|
| + this.prefs_.getNumberPref(command));
|
| + }
|
| },
|
|
|
| /**
|
| @@ -57,20 +62,44 @@ SwitchAccessOptions.prototype = {
|
| let input = event.target;
|
| switch (input.id) {
|
| case 'enableAutoScan':
|
| - this.switchAccessPrefs_.setPref(input.id, input.checked);
|
| + this.prefs_.setPref(input.id, input.checked);
|
| break;
|
| case 'autoScanTime':
|
| - let oldVal = this.switchAccessPrefs_.getNumberPref(input.id);
|
| + let oldVal = this.prefs_.getNumberPref(input.id);
|
| let val = Number(input.value) * 1000;
|
| let min = Number(input.min) * 1000;
|
| - if (this.isValidInput_(val, oldVal, min)) {
|
| + if (this.isValidScanTimeInput_(val, oldVal, min)) {
|
| input.value = Number(input.value);
|
| - this.switchAccessPrefs_.setPref(input.id, val);
|
| + this.prefs_.setPref(input.id, val);
|
| } else {
|
| input.value = oldVal;
|
| }
|
| break;
|
| - }
|
| + default:
|
| + if (this.prefs_.getCommands().includes(input.id)) {
|
| + let keyCode = input.value.toUpperCase().charCodeAt(0);
|
| + if (this.isValidKeyCode_(keyCode)) {
|
| + input.value = input.value.toUpperCase();
|
| + this.prefs_.setPref(input.id, keyCode);
|
| + } else {
|
| + let oldKeyCode = this.prefs_.getNumberPref(input.id);
|
| + input.value = String.fromCharCode(oldKeyCode);
|
| + }
|
| + }
|
| + }
|
| + },
|
| +
|
| + /**
|
| + * Return true if |keyCode| is a letter or number, and if it is not already
|
| + * being used.
|
| + *
|
| + * @param {number} keyCode
|
| + * @return {boolean}
|
| + */
|
| + isValidKeyCode_: function(keyCode) {
|
| + return ((keyCode >= '0'.charCodeAt(0) && keyCode <= '9'.charCodeAt(0))
|
| + || (keyCode >= 'A'.charCodeAt(0) && keyCode <= 'Z'.charCodeAt(0)))
|
| + && !this.prefs_.keyCodeIsUsed(keyCode);
|
| },
|
|
|
| /**
|
| @@ -82,7 +111,7 @@ SwitchAccessOptions.prototype = {
|
| * @param {number} min
|
| * @return {boolean}
|
| */
|
| - isValidInput_: function(value, oldValue, min) {
|
| + isValidScanTimeInput_: function(value, oldValue, min) {
|
| return (value !== oldValue) && (value >= min);
|
| },
|
|
|
| @@ -102,6 +131,9 @@ SwitchAccessOptions.prototype = {
|
| case 'autoScanTime':
|
| $(key).value = updatedPrefs[key] / 1000;
|
| break;
|
| + default:
|
| + if (this.prefs_.getCommands().includes(key))
|
| + $(key).value = String.fromCharCode(updatedPrefs[key]);
|
| }
|
| }
|
| }
|
|
|