No dual_mode on Win10+ shortcuts.
[chromium-blink-merge.git] / chrome / browser / resources / options / chromeos / keyboard_overlay.js
blobb18af10166e3d07f18f45a7d9880e5d5c0ade7f1
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() {
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
14 var AUTO_REPEAT_DELAYS =
15 [2000, 1500, 1000, 500, 300, 200, 150];
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
24 var AUTO_REPEAT_INTERVALS =
25 [2000, 1000, 500, 300, 200, 100, 50, 30, 20];
27 /**
28 * Encapsulated handling of the keyboard overlay.
29 * @constructor
30 * @extends {options.SettingsDialog}
32 function KeyboardOverlay() {
33 options.SettingsDialog.call(this, 'keyboard-overlay',
34 loadTimeData.getString('keyboardOverlayTabTitle'),
35 'keyboard-overlay',
36 assertInstanceof($('keyboard-confirm'), HTMLButtonElement),
37 assertInstanceof($('keyboard-cancel'), HTMLButtonElement));
40 cr.addSingletonGetter(KeyboardOverlay);
42 KeyboardOverlay.prototype = {
43 __proto__: options.SettingsDialog.prototype,
45 /** @override */
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']);
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
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;
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
99 handleAutoRepeatDelayPrefChange_: function(e) {
100 this.updateSliderFromValue_('auto-repeat-delay-range',
101 e.value.value,
102 AUTO_REPEAT_DELAYS);
103 return true;
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
113 handleAutoRepeatIntervalPrefChange_: function(e) {
114 this.updateSliderFromValue_('auto-repeat-interval-range',
115 e.value.value,
116 AUTO_REPEAT_INTERVALS);
117 return true;
121 * Show/hide the caps lock remapping section.
122 * @private
124 showCapsLockOptions_: function(show) {
125 $('caps-lock-remapping-section').hidden = !show;
129 * Show/hide the diamond key remapping section.
130 * @private
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
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
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;
156 assert(index != -1,
157 'Failed to update ' + id + ' from pref with value ' + value);
160 $(id).value = index;
164 // Forward public APIs to private implementations.
165 cr.makePublic(KeyboardOverlay, [
166 'showCapsLockOptions',
167 'showDiamondKeyOptions',
170 // Export
171 return {
172 KeyboardOverlay: KeyboardOverlay