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

Side by Side 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, 8 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 unified diff | Download patch
OLDNEW
(Empty)
1 // Copyright 2017 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 /**
6 * Class to handle changes to auto-scan.
7 *
8 * @constructor
9 * @param {SwitchAccessInterface} switchAccess
10 */
11 function AutoScanManager(switchAccess) {
12 /**
13 * SwitchAccess reference.
14 * @private {SwitchAccessInterface}
15 */
16 this.switchAccess_ = switchAccess;
17
18 /**
19 * Auto-scan interval ID.
20 *
21 * @private {number|undefined}
22 */
23 this.intervalID_;
24
25 /**
26 * Length of auto-scan interval in milliseconds.
27 *
28 * @private {number}
29 */
30 this.scanTime_ = switchAccess.switchAccessPrefs.getNumberPref('autoScanTime');
31
32 let enabled = switchAccess.switchAccessPrefs.getBooleanPref('enableAutoScan');
33 if (enabled)
34 this.start_();
35 };
36
37 AutoScanManager.prototype = {
38 /**
39 * Stop the window from moving to the next node at a fixed interval.
40 *
41 * @private
42 */
43 stop_: function() {
44 window.clearInterval(this.intervalID_);
45 this.intervalID_ = undefined;
46 },
47
48 /**
49 * Set the window to move to the next node at an interval in milliseconds
50 * equal to this.scanTime_.
51 *
52 * @private
53 */
54 start_: function() {
55 this.intervalID_ = window.setInterval(
56 this.switchAccess_.moveToNode.bind(this.switchAccess_, true),
57 this.scanTime_);
58 },
59
60 /**
61 * Return true if auto-scan is currently running. Otherwise return false.
62 *
63 * @return {boolean}
64 */
65 isRunning: function() {
66 return this.intervalID_ !== undefined;
67 },
68
69 /**
70 * Restart auto-scan under the current settings.
71 */
72 restart: function() {
73 this.stop_();
74 this.start_();
75 },
76
77 /**
78 * Stop auto-scan if it is currently running. Then, if |enabled| is true,
79 * turn on auto-scan. Otherwise leave it off.
80 *
81 * @param {boolean} enabled
82 */
83 setEnabled: function(enabled) {
84 if (this.isRunning())
85 this.stop_();
86 if (enabled)
87 this.start_();
88 },
89
90 /**
91 * Update this.scanTime_ to |scanTime|. Then, if auto-scan is currently
92 * running, restart it.
93 *
94 * @param {number} scanTime Auto-scan interval time in milliseconds.
95 */
96 setScanTime: function(scanTime) {
97 this.scanTime_ = scanTime;
98 if (this.isRunning()) {
99 this.restart();
100 }
101 },
102 };
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698