Index: chrome/browser/resources/chromeos/switch_access/prefs.js |
diff --git a/chrome/browser/resources/chromeos/switch_access/prefs.js b/chrome/browser/resources/chromeos/switch_access/prefs.js |
index 15ae9dd93f15c24e56ad68428bb157850a4b1504..9be570a7723b16a10dab0b1f5ff5ade579a37b2c 100644 |
--- a/chrome/browser/resources/chromeos/switch_access/prefs.js |
+++ b/chrome/browser/resources/chromeos/switch_access/prefs.js |
@@ -13,7 +13,8 @@ function SwitchAccessPrefs() { |
* |
* @private |
*/ |
- this.prefs_ = Object.assign({}, this.DEFAULT_PREFS); |
+ this.prefs_ = Object.assign( |
+ {}, this.DEFAULT_COMMAND_KEYCODE_MAP, this.DEFAULT_OTHER_PREFS); |
this.loadPrefs_(); |
chrome.storage.onChanged.addListener(this.handleStorageChange_.bind(this)); |
@@ -28,7 +29,7 @@ SwitchAccessPrefs.prototype = { |
* @private |
*/ |
loadPrefs_: function() { |
- let defaultKeys = Object.keys(this.DEFAULT_PREFS); |
+ let defaultKeys = Object.keys(this.prefs_); |
chrome.storage.sync.get(defaultKeys, function(loadedPrefs) { |
let updatedPrefs = {}; |
for (let key of Object.keys(loadedPrefs)) { |
@@ -126,12 +127,52 @@ SwitchAccessPrefs.prototype = { |
}, |
/** |
- * The default value of all preferences. All preferences should be primitives |
- * to prevent changes to default values. |
+ * Get a list of the commands that can be run using a keyboard key. |
+ * |
+ * @return {!Array<string>} |
+ */ |
+ getCommands: function() { |
+ return Object.keys(this.DEFAULT_COMMAND_KEYCODE_MAP); |
+ }, |
+ |
+ /** |
+ * Returns true if |keyCode| is already used to run a command from the |
+ * keyboard. |
+ * |
+ * @param {number} keyCode |
+ * @return {boolean} |
+ */ |
+ keyCodeIsUsed: function(keyCode) { |
+ for (let command of this.getCommands()) { |
+ if (keyCode === this.prefs_[command]) |
+ return true; |
+ } |
+ return false; |
+ }, |
+ |
+ /** |
+ * The default mapping between commands and key codes. |
+ * |
+ * @const |
+ */ |
+ DEFAULT_COMMAND_KEYCODE_MAP: { |
+ 'next': 49, |
+ 'previous': 50, |
+ 'select': 51, |
+ 'options': 52, |
+ 'debugNext': 54, |
+ 'debugPrevious': 55, |
+ 'debugChild': 56, |
+ 'debugParent': 57 |
+ }, |
+ |
+ /** |
+ * The default value of all other preferences. All preferences should be |
+ * primitives to prevent changes to default values. |
* |
* @const |
*/ |
- DEFAULT_PREFS: { |
+ DEFAULT_OTHER_PREFS: { |
'enableAutoScan': false, |
'autoScanTime': 800 |
} |