Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(277)

Unified Diff: chrome/browser/resources/chromeos/switch_access/prefs.js

Issue 2939133004: Added to options page to let users change keyboard mappings. (Closed)
Patch Set: Fixed merge conflict and formatting error Created 3 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
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
*/

Powered by Google App Engine
This is Rietveld 408576698