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 6dbfda6b9454f848dd55059ed8cec0a6a69b8cbb..7ca9e04395bb2ecba2d2d603e2901d000856c55b 100644 |
--- a/chrome/browser/resources/chromeos/switch_access/prefs.js |
+++ b/chrome/browser/resources/chromeos/switch_access/prefs.js |
@@ -6,14 +6,24 @@ |
* Class to manage user preferences. |
* |
* @constructor |
+ * @param {SwitchAccessInterface} switchAccess |
*/ |
-function SwitchAccessPrefs() { |
+function SwitchAccessPrefs(switchAccess) { |
+ /** |
+ * SwitchAccess reference. |
+ * |
+ * @private {SwitchAccessInterface} |
+ */ |
+ this.switchAccess_ = switchAccess; |
+ |
/** |
* User preferences, initially set to the default preference values. |
* |
* @private |
*/ |
this.prefs_ = Object.assign({}, this.DEFAULT_PREFS); |
+ for (let command of this.switchAccess_.getCommands()) |
+ this.prefs_[command] = this.switchAccess_.getDefaultKeyCodeFor(command); |
this.loadPrefs_(); |
chrome.storage.onChanged.addListener(this.handleStorageChange_.bind(this)); |
@@ -28,7 +38,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,8 +136,23 @@ SwitchAccessPrefs.prototype = { |
}, |
/** |
- * The default value of all preferences. All preferences should be primitives |
- * to prevent changes to default values. |
+ * 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.switchAccess_.getCommands()) { |
+ if (keyCode === this.prefs_[command]) |
+ return true; |
+ } |
+ return false; |
+ }, |
+ |
+ /** |
+ * The default value of all preferences besides command keyboard bindings. |
+ * All preferences should be primitives to prevent changes to default values. |
* |
* @const |
*/ |