| OLD | NEW |
| 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 | 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 | 9 * long to short. The values were chosen to provide a large range while giving |
| 10 * several options near the defaults. | 10 * several options near the defaults. |
| 11 * @type {!Array<number>} | 11 * @type {!Array<number>} |
| 12 * @const | 12 * @const |
| 13 */ | 13 */ |
| 14 var AUTO_REPEAT_DELAYS = | 14 var AUTO_REPEAT_DELAYS = [2000, 1500, 1000, 500, 300, 200, 150]; |
| 15 [2000, 1500, 1000, 500, 300, 200, 150]; | |
| 16 | 15 |
| 17 /** | 16 /** |
| 18 * Auto-repeat intervals (in ms) for the corresponding slider values, from | 17 * Auto-repeat intervals (in ms) for the corresponding slider values, from |
| 19 * long to short. The slider itself is labeled "rate", the inverse of | 18 * long to short. The slider itself is labeled "rate", the inverse of |
| 20 * interval, and goes from slow (long interval) to fast (short interval). | 19 * interval, and goes from slow (long interval) to fast (short interval). |
| 21 * @type {!Array<number>} | 20 * @type {!Array<number>} |
| 22 * @const | 21 * @const |
| 23 */ | 22 */ |
| 24 var AUTO_REPEAT_INTERVALS = | 23 var AUTO_REPEAT_INTERVALS = [2000, 1000, 500, 300, 200, 100, 50, 30, 20]; |
| 25 [2000, 1000, 500, 300, 200, 100, 50, 30, 20]; | |
| 26 | 24 |
| 27 /** | 25 /** |
| 28 * Encapsulated handling of the keyboard overlay. | 26 * Encapsulated handling of the keyboard overlay. |
| 29 * @constructor | 27 * @constructor |
| 30 * @extends {options.SettingsDialog} | 28 * @extends {options.SettingsDialog} |
| 31 */ | 29 */ |
| 32 function KeyboardOverlay() { | 30 function KeyboardOverlay() { |
| 33 options.SettingsDialog.call(this, 'keyboard-overlay', | 31 options.SettingsDialog.call( |
| 34 loadTimeData.getString('keyboardOverlayTabTitle'), | 32 this, 'keyboard-overlay', |
| 35 'keyboard-overlay', | 33 loadTimeData.getString('keyboardOverlayTabTitle'), 'keyboard-overlay', |
| 36 assertInstanceof($('keyboard-confirm'), HTMLButtonElement), | 34 assertInstanceof($('keyboard-confirm'), HTMLButtonElement), |
| 37 assertInstanceof($('keyboard-cancel'), HTMLButtonElement)); | 35 assertInstanceof($('keyboard-cancel'), HTMLButtonElement)); |
| 38 } | 36 } |
| 39 | 37 |
| 40 cr.addSingletonGetter(KeyboardOverlay); | 38 cr.addSingletonGetter(KeyboardOverlay); |
| 41 | 39 |
| 42 KeyboardOverlay.prototype = { | 40 KeyboardOverlay.prototype = { |
| 43 __proto__: options.SettingsDialog.prototype, | 41 __proto__: options.SettingsDialog.prototype, |
| 44 | 42 |
| 45 /** @override */ | 43 /** @override */ |
| (...skipping 10 matching lines...) Expand all Loading... |
| 56 this.handleAutoRepeatDelayPrefChange_.bind(this); | 54 this.handleAutoRepeatDelayPrefChange_.bind(this); |
| 57 | 55 |
| 58 var autoRepeatIntervalRange = $('auto-repeat-interval-range'); | 56 var autoRepeatIntervalRange = $('auto-repeat-interval-range'); |
| 59 autoRepeatIntervalRange.valueMap = AUTO_REPEAT_INTERVALS; | 57 autoRepeatIntervalRange.valueMap = AUTO_REPEAT_INTERVALS; |
| 60 autoRepeatIntervalRange.max = AUTO_REPEAT_INTERVALS.length - 1; | 58 autoRepeatIntervalRange.max = AUTO_REPEAT_INTERVALS.length - 1; |
| 61 autoRepeatIntervalRange.customPrefChangeHandler = | 59 autoRepeatIntervalRange.customPrefChangeHandler = |
| 62 this.handleAutoRepeatIntervalPrefChange_.bind(this); | 60 this.handleAutoRepeatIntervalPrefChange_.bind(this); |
| 63 | 61 |
| 64 $('languages-and-input-settings').onclick = function(e) { | 62 $('languages-and-input-settings').onclick = function(e) { |
| 65 PageManager.showPageByName('languages'); | 63 PageManager.showPageByName('languages'); |
| 66 chrome.send('coreOptionsUserMetricsAction', | 64 chrome.send( |
| 67 ['Options_KeyboardShowLanguageSettings']); | 65 'coreOptionsUserMetricsAction', |
| 66 ['Options_KeyboardShowLanguageSettings']); |
| 68 }; | 67 }; |
| 69 | 68 |
| 70 $('keyboard-shortcuts').onclick = function(e) { | 69 $('keyboard-shortcuts').onclick = function(e) { |
| 71 chrome.send('showKeyboardShortcuts'); | 70 chrome.send('showKeyboardShortcuts'); |
| 72 chrome.send('coreOptionsUserMetricsAction', | 71 chrome.send( |
| 73 ['Options_KeyboardShowKeyboardShortcuts']); | 72 'coreOptionsUserMetricsAction', |
| 73 ['Options_KeyboardShowKeyboardShortcuts']); |
| 74 }; | 74 }; |
| 75 }, | 75 }, |
| 76 | 76 |
| 77 /** | 77 /** |
| 78 * Handles auto-repeat enabled pref change and allows the event to continue | 78 * Handles auto-repeat enabled pref change and allows the event to continue |
| 79 * propagating. | 79 * propagating. |
| 80 * @param {Event} e Change event. | 80 * @param {Event} e Change event. |
| 81 * @return {boolean} Whether the event has finished being handled. | 81 * @return {boolean} Whether the event has finished being handled. |
| 82 * @private | 82 * @private |
| 83 */ | 83 */ |
| 84 handleAutoRepeatEnabledPrefChange_: function(e) { | 84 handleAutoRepeatEnabledPrefChange_: function(e) { |
| 85 $('auto-repeat-settings-section').classList.toggle('disabled', | 85 $('auto-repeat-settings-section') |
| 86 !e.value.value); | 86 .classList.toggle('disabled', !e.value.value); |
| 87 $('auto-repeat-delay-range').disabled = | 87 $('auto-repeat-delay-range').disabled = |
| 88 $('auto-repeat-interval-range').disabled = !e.value.value; | 88 $('auto-repeat-interval-range').disabled = !e.value.value; |
| 89 return false; | 89 return false; |
| 90 }, | 90 }, |
| 91 | 91 |
| 92 /** | 92 /** |
| 93 * Handles auto-repeat delay pref change and stops the event from | 93 * Handles auto-repeat delay pref change and stops the event from |
| 94 * propagating. | 94 * propagating. |
| 95 * @param {Event} e Change event. | 95 * @param {Event} e Change event. |
| 96 * @return {boolean} Whether the event has finished being handled. | 96 * @return {boolean} Whether the event has finished being handled. |
| 97 * @private | 97 * @private |
| 98 */ | 98 */ |
| 99 handleAutoRepeatDelayPrefChange_: function(e) { | 99 handleAutoRepeatDelayPrefChange_: function(e) { |
| 100 this.updateSliderFromValue_('auto-repeat-delay-range', | 100 this.updateSliderFromValue_( |
| 101 e.value.value, | 101 'auto-repeat-delay-range', e.value.value, AUTO_REPEAT_DELAYS); |
| 102 AUTO_REPEAT_DELAYS); | |
| 103 return true; | 102 return true; |
| 104 }, | 103 }, |
| 105 | 104 |
| 106 /** | 105 /** |
| 107 * Handles auto-repeat interval pref change and stops the event from | 106 * Handles auto-repeat interval pref change and stops the event from |
| 108 * propagating. | 107 * propagating. |
| 109 * @param {Event} e Change event. | 108 * @param {Event} e Change event. |
| 110 * @return {boolean} Whether the event has finished being handled. | 109 * @return {boolean} Whether the event has finished being handled. |
| 111 * @private | 110 * @private |
| 112 */ | 111 */ |
| 113 handleAutoRepeatIntervalPrefChange_: function(e) { | 112 handleAutoRepeatIntervalPrefChange_: function(e) { |
| 114 this.updateSliderFromValue_('auto-repeat-interval-range', | 113 this.updateSliderFromValue_( |
| 115 e.value.value, | 114 'auto-repeat-interval-range', e.value.value, AUTO_REPEAT_INTERVALS); |
| 116 AUTO_REPEAT_INTERVALS); | |
| 117 return true; | 115 return true; |
| 118 }, | 116 }, |
| 119 | 117 |
| 120 /** | 118 /** |
| 121 * Show/hide the caps lock remapping section. | 119 * Show/hide the caps lock remapping section. |
| 122 * @private | 120 * @private |
| 123 */ | 121 */ |
| 124 showCapsLockOptions_: function(show) { | 122 showCapsLockOptions_: function(show) { |
| 125 $('caps-lock-remapping-section').hidden = !show; | 123 $('caps-lock-remapping-section').hidden = !show; |
| 126 }, | 124 }, |
| (...skipping 12 matching lines...) Expand all Loading... |
| 139 * @param {string} id The slider's ID. | 137 * @param {string} id The slider's ID. |
| 140 * @param {number} value The value to find. | 138 * @param {number} value The value to find. |
| 141 * @param {!Array<number>} values The array to search. | 139 * @param {!Array<number>} values The array to search. |
| 142 * @private | 140 * @private |
| 143 */ | 141 */ |
| 144 updateSliderFromValue_: function(id, value, values) { | 142 updateSliderFromValue_: function(id, value, values) { |
| 145 var index = values.indexOf(value); | 143 var index = values.indexOf(value); |
| 146 if (index == -1) { | 144 if (index == -1) { |
| 147 var closestValue = Infinity; | 145 var closestValue = Infinity; |
| 148 for (var i = 0; i < values.length; i++) { | 146 for (var i = 0; i < values.length; i++) { |
| 149 if (Math.abs(values[i] - value) < | 147 if (Math.abs(values[i] - value) < Math.abs(closestValue - value)) { |
| 150 Math.abs(closestValue - value)) { | |
| 151 closestValue = values[i]; | 148 closestValue = values[i]; |
| 152 index = i; | 149 index = i; |
| 153 } | 150 } |
| 154 } | 151 } |
| 155 | 152 |
| 156 assert(index != -1, | 153 assert( |
| 157 'Failed to update ' + id + ' from pref with value ' + value); | 154 index != -1, |
| 155 'Failed to update ' + id + ' from pref with value ' + value); |
| 158 } | 156 } |
| 159 | 157 |
| 160 $(id).value = index; | 158 $(id).value = index; |
| 161 }, | 159 }, |
| 162 }; | 160 }; |
| 163 | 161 |
| 164 // Forward public APIs to private implementations. | 162 // Forward public APIs to private implementations. |
| 165 cr.makePublic(KeyboardOverlay, [ | 163 cr.makePublic(KeyboardOverlay, [ |
| 166 'showCapsLockOptions', | 164 'showCapsLockOptions', |
| 167 'showDiamondKeyOptions', | 165 'showDiamondKeyOptions', |
| 168 ]); | 166 ]); |
| 169 | 167 |
| 170 // Export | 168 // Export |
| 171 return { | 169 return {KeyboardOverlay: KeyboardOverlay}; |
| 172 KeyboardOverlay: KeyboardOverlay | |
| 173 }; | |
| 174 }); | 170 }); |
| OLD | NEW |