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

Side by Side Diff: chrome/browser/resources/options/chromeos/keyboard_overlay.js

Issue 393023006: Add settings for keyboard auto-repeat to options page. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: rebase Created 6 years, 4 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 | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 cr.define('options', function() { 5 cr.define('options', function() {
6 6
7 /** 7 /**
8 * Auto-repeat delays (in ms) for the corresponding slider values, from
9 * long to short. The values were chosen to provide a large range while giving
10 * several options near the defaults.
11 * @type {!Array.<number>}
12 * @const
13 */
14 var AUTO_REPEAT_DELAYS =
15 [2000, 1500, 1000, 500, 300, 200, 150];
16
17 /**
18 * Auto-repeat intervals (in ms) for the corresponding slider values, from
19 * long to short. The slider itself is labeled "rate", the inverse of
20 * interval, and goes from slow (long interval) to fast (short interval).
21 * @type {!Array.<number>}
22 * @const
23 */
24 var AUTO_REPEAT_INTERVALS =
25 [2000, 1000, 500, 300, 200, 100, 50, 30, 20];
26
27 /**
8 * Encapsulated handling of the keyboard overlay. 28 * Encapsulated handling of the keyboard overlay.
9 * @constructor 29 * @constructor
10 */ 30 */
11 function KeyboardOverlay() { 31 function KeyboardOverlay() {
12 options.SettingsDialog.call(this, 'keyboard-overlay', 32 options.SettingsDialog.call(this, 'keyboard-overlay',
13 loadTimeData.getString('keyboardOverlayTitle'), 33 loadTimeData.getString('keyboardOverlayTitle'),
14 'keyboard-overlay', 34 'keyboard-overlay',
15 $('keyboard-confirm'), $('keyboard-cancel')); 35 $('keyboard-confirm'), $('keyboard-cancel'));
16 } 36 }
17 37
18 cr.addSingletonGetter(KeyboardOverlay); 38 cr.addSingletonGetter(KeyboardOverlay);
19 39
20 KeyboardOverlay.prototype = { 40 KeyboardOverlay.prototype = {
21 __proto__: options.SettingsDialog.prototype, 41 __proto__: options.SettingsDialog.prototype,
22 42
23 /** 43 /**
24 * Initializes the page. This method is called in initialize. 44 * Initializes the page. This method is called in initialize.
25 */ 45 */
26 initializePage: function() { 46 initializePage: function() {
27 options.SettingsDialog.prototype.initializePage.call(this); 47 options.SettingsDialog.prototype.initializePage.call(this);
28 48
49 $('enable-auto-repeat').customPrefChangeHandler =
50 this.handleAutoRepeatEnabledPrefChange_.bind(this);
51
52 var autoRepeatDelayRange = $('auto-repeat-delay-range');
53 autoRepeatDelayRange.valueMap = AUTO_REPEAT_DELAYS;
54 autoRepeatDelayRange.max = AUTO_REPEAT_DELAYS.length - 1;
55 autoRepeatDelayRange.customPrefChangeHandler =
56 this.handleAutoRepeatDelayPrefChange_.bind(this);
57
58 var autoRepeatIntervalRange = $('auto-repeat-interval-range');
59 autoRepeatIntervalRange.valueMap = AUTO_REPEAT_INTERVALS;
60 autoRepeatIntervalRange.max = AUTO_REPEAT_INTERVALS.length - 1;
61 autoRepeatIntervalRange.customPrefChangeHandler =
62 this.handleAutoRepeatIntervalPrefChange_.bind(this);
63
29 $('languages-and-input-settings').onclick = function(e) { 64 $('languages-and-input-settings').onclick = function(e) {
30 OptionsPage.navigateToPage('languages'); 65 OptionsPage.navigateToPage('languages');
31 chrome.send('coreOptionsUserMetricsAction', 66 chrome.send('coreOptionsUserMetricsAction',
32 ['Options_KeyboardShowLanguageSettings']); 67 ['Options_KeyboardShowLanguageSettings']);
33 }; 68 };
34 69
35 $('keyboard-shortcuts').onclick = function(e) { 70 $('keyboard-shortcuts').onclick = function(e) {
36 chrome.send('showKeyboardShortcuts'); 71 chrome.send('showKeyboardShortcuts');
37 chrome.send('coreOptionsUserMetricsAction', 72 chrome.send('coreOptionsUserMetricsAction',
38 ['Options_KeyboardShowKeyboardShortcuts']); 73 ['Options_KeyboardShowKeyboardShortcuts']);
39 }; 74 };
40 }, 75 },
41 76
42 /** 77 /**
78 * Handles auto-repeat enabled pref change and allows the event to continue
79 * propagating.
80 * @param {Event} e Change event.
81 * @return {boolean} Whether the event has finished being handled.
82 * @private
83 */
84 handleAutoRepeatEnabledPrefChange_: function(e) {
85 $('auto-repeat-settings-section').classList.toggle('disabled',
86 !e.value.value);
87 $('auto-repeat-delay-range').disabled =
88 $('auto-repeat-interval-range').disabled = !e.value.value;
89 return false;
90 },
91
92 /**
93 * Handles auto-repeat delay pref change and stops the event from
94 * propagating.
95 * @param {Event} e Change event.
96 * @return {boolean} Whether the event has finished being handled.
97 * @private
98 */
99 handleAutoRepeatDelayPrefChange_: function(e) {
100 this.updateSliderFromValue_('auto-repeat-delay-range',
101 e.value.value,
102 AUTO_REPEAT_DELAYS);
103 return true;
104 },
105
106 /**
107 * Handles auto-repeat interval pref change and stops the event from
108 * propagating.
109 * @param {Event} e Change event.
110 * @return {boolean} Whether the event has finished being handled.
111 * @private
112 */
113 handleAutoRepeatIntervalPrefChange_: function(e) {
114 this.updateSliderFromValue_('auto-repeat-interval-range',
115 e.value.value,
116 AUTO_REPEAT_INTERVALS);
117 return true;
118 },
119
120 /**
43 * Show/hide the caps lock remapping section. 121 * Show/hide the caps lock remapping section.
44 * @private 122 * @private
45 */ 123 */
46 showCapsLockOptions_: function(show) { 124 showCapsLockOptions_: function(show) {
47 $('caps-lock-remapping-section').hidden = !show; 125 $('caps-lock-remapping-section').hidden = !show;
48 }, 126 },
49 127
50 /** 128 /**
51 * Show/hide the diamond key remapping section. 129 * Show/hide the diamond key remapping section.
52 * @private 130 * @private
53 */ 131 */
54 showDiamondKeyOptions_: function(show) { 132 showDiamondKeyOptions_: function(show) {
55 $('diamond-key-remapping-section').hidden = !show; 133 $('diamond-key-remapping-section').hidden = !show;
56 }, 134 },
135
136 /**
137 * Sets the slider's value to the number in |values| that is closest to
138 * |value|.
139 * @param {string} id The slider's ID.
140 * @param {number} value The value to find.
141 * @param {!Array.<number>} values The array to search.
142 * @private
143 */
144 updateSliderFromValue_: function(id, value, values) {
145 var index = values.indexOf(value);
146 if (index == -1) {
147 var closestValue = Infinity;
148 for (var i = 0; i < values.length; i++) {
149 if (Math.abs(values[i] - value) <
150 Math.abs(closestValue - value)) {
151 closestValue = values[i];
152 index = i;
153 }
154 }
155
156 assert(index != -1,
157 'Failed to update ' + id + ' from pref with value ' + value);
158 }
159
160 $(id).value = index;
161 },
57 }; 162 };
58 163
59 // Forward public APIs to private implementations. 164 // Forward public APIs to private implementations.
60 [ 165 [
61 'showCapsLockOptions', 166 'showCapsLockOptions',
62 'showDiamondKeyOptions', 167 'showDiamondKeyOptions',
63 ].forEach(function(name) { 168 ].forEach(function(name) {
64 KeyboardOverlay[name] = function() { 169 KeyboardOverlay[name] = function() {
65 var instance = KeyboardOverlay.getInstance(); 170 var instance = KeyboardOverlay.getInstance();
66 return instance[name + '_'].apply(instance, arguments); 171 return instance[name + '_'].apply(instance, arguments);
67 }; 172 };
68 }); 173 });
69 174
70 // Export 175 // Export
71 return { 176 return {
72 KeyboardOverlay: KeyboardOverlay 177 KeyboardOverlay: KeyboardOverlay
73 }; 178 };
74 }); 179 });
OLDNEW
« no previous file with comments | « chrome/browser/resources/options/chromeos/keyboard_overlay.html ('k') | chrome/browser/resources/options/pref_ui.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698