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

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

Issue 2777203006: Added auto-scan, made some small changes to how prefs are stored, refactored. (Closed)
Patch Set: Responding to comments. Refactored tree_walker. Removed testable_tree_walker. Created 3 years, 9 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/auto_scan_manager.js
diff --git a/chrome/browser/resources/chromeos/switch_access/auto_scan_manager.js b/chrome/browser/resources/chromeos/switch_access/auto_scan_manager.js
new file mode 100644
index 0000000000000000000000000000000000000000..f709547f620a5107b822ddc1d2d5499856b0c8a6
--- /dev/null
+++ b/chrome/browser/resources/chromeos/switch_access/auto_scan_manager.js
@@ -0,0 +1,102 @@
+// Copyright 2017 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+/**
+ * Class to handle changes to auto-scan.
+ *
+ * @constructor
+ * @param {SwitchAccessInterface} switchAccess
+ */
+function AutoScanManager(switchAccess) {
+ /**
+ * SwitchAccess reference.
+ * @private {SwitchAccessInterface}
+ */
+ this.switchAccess_ = switchAccess;
+
+ /**
+ * Auto-scan interval ID.
+ *
+ * @private {number|undefined}
+ */
+ this.intervalID_;
+
+ /**
+ * Length of auto-scan interval in milliseconds.
+ *
+ * @private {number}
+ */
+ this.scanTime_ = switchAccess.switchAccessPrefs.getNumberPref('autoScanTime');
+
+ let enabled = switchAccess.switchAccessPrefs.getBooleanPref('enableAutoScan');
+ if (enabled)
+ this.start_();
+};
+
+AutoScanManager.prototype = {
+ /**
+ * Stop the window from moving to the next node at a fixed interval.
+ *
+ * @private
+ */
+ stop_: function() {
+ window.clearInterval(this.intervalID_);
+ this.intervalID_ = undefined;
+ },
+
+ /**
+ * Set the window to move to the next node at an interval in milliseconds
+ * equal to this.scanTime_.
+ *
+ * @private
+ */
+ start_: function() {
+ this.intervalID_ = window.setInterval(
+ this.switchAccess_.moveToNode.bind(this.switchAccess_, true),
+ this.scanTime_);
+ },
+
+ /**
+ * Return true if auto-scan is currently running. Otherwise return false.
+ *
+ * @return {boolean}
+ */
+ isRunning: function() {
+ return this.intervalID_ !== undefined;
+ },
+
+ /**
+ * Restart auto-scan under the current settings.
+ */
+ restart: function() {
+ this.stop_();
+ this.start_();
+ },
+
+ /**
+ * Stop auto-scan if it is currently running. Then, if |enabled| is true,
+ * turn on auto-scan. Otherwise leave it off.
+ *
+ * @param {boolean} enabled
+ */
+ setEnabled: function(enabled) {
+ if (this.isRunning())
+ this.stop_();
+ if (enabled)
+ this.start_();
+ },
+
+ /**
+ * Update this.scanTime_ to |scanTime|. Then, if auto-scan is currently
+ * running, restart it.
+ *
+ * @param {number} scanTime Auto-scan interval time in milliseconds.
+ */
+ setScanTime: function(scanTime) {
+ this.scanTime_ = scanTime;
+ if (this.isRunning()) {
+ this.restart();
+ }
+ },
+};

Powered by Google App Engine
This is Rietveld 408576698