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
3 // found in the LICENSE file.
5 cr.define('options', function() {
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>}
14 var AUTO_REPEAT_DELAYS =
15 [2000, 1500, 1000, 500, 300, 200, 150];
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>}
24 var AUTO_REPEAT_INTERVALS =
25 [2000, 1000, 500, 300, 200, 100, 50, 30, 20];
28 * Encapsulated handling of the keyboard overlay.
30 * @extends {options.SettingsDialog}
32 function KeyboardOverlay() {
33 options.SettingsDialog.call(this, 'keyboard-overlay',
34 loadTimeData.getString('keyboardOverlayTabTitle'),
36 assertInstanceof($('keyboard-confirm'), HTMLButtonElement),
37 assertInstanceof($('keyboard-cancel'), HTMLButtonElement));
40 cr.addSingletonGetter(KeyboardOverlay);
42 KeyboardOverlay.prototype = {
43 __proto__: options.SettingsDialog.prototype,
46 initializePage: function() {
47 options.SettingsDialog.prototype.initializePage.call(this);
49 $('enable-auto-repeat').customPrefChangeHandler =
50 this.handleAutoRepeatEnabledPrefChange_.bind(this);
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);
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);
64 $('languages-and-input-settings').onclick = function(e) {
65 PageManager.showPageByName('languages');
66 chrome.send('coreOptionsUserMetricsAction',
67 ['Options_KeyboardShowLanguageSettings']);
70 $('keyboard-shortcuts').onclick = function(e) {
71 chrome.send('showKeyboardShortcuts');
72 chrome.send('coreOptionsUserMetricsAction',
73 ['Options_KeyboardShowKeyboardShortcuts']);
78 * Handles auto-repeat enabled pref change and allows the event to continue
80 * @param {Event} e Change event.
81 * @return {boolean} Whether the event has finished being handled.
84 handleAutoRepeatEnabledPrefChange_: function(e) {
85 $('auto-repeat-settings-section').classList.toggle('disabled',
87 $('auto-repeat-delay-range').disabled =
88 $('auto-repeat-interval-range').disabled = !e.value.value;
93 * Handles auto-repeat delay pref change and stops the event from
95 * @param {Event} e Change event.
96 * @return {boolean} Whether the event has finished being handled.
99 handleAutoRepeatDelayPrefChange_: function(e) {
100 this.updateSliderFromValue_('auto-repeat-delay-range',
107 * Handles auto-repeat interval pref change and stops the event from
109 * @param {Event} e Change event.
110 * @return {boolean} Whether the event has finished being handled.
113 handleAutoRepeatIntervalPrefChange_: function(e) {
114 this.updateSliderFromValue_('auto-repeat-interval-range',
116 AUTO_REPEAT_INTERVALS);
121 * Show/hide the caps lock remapping section.
124 showCapsLockOptions_: function(show) {
125 $('caps-lock-remapping-section').hidden = !show;
129 * Show/hide the diamond key remapping section.
132 showDiamondKeyOptions_: function(show) {
133 $('diamond-key-remapping-section').hidden = !show;
137 * Sets the slider's value to the number in |values| that is closest to
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.
144 updateSliderFromValue_: function(id, value, values) {
145 var index = values.indexOf(value);
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];
157 'Failed to update ' + id + ' from pref with value ' + value);
164 // Forward public APIs to private implementations.
165 cr.makePublic(KeyboardOverlay, [
166 'showCapsLockOptions',
167 'showDiamondKeyOptions',
172 KeyboardOverlay: KeyboardOverlay