| OLD | NEW | 
|    1 // Copyright 2016 The Chromium Authors. All rights reserved. |    1 // Copyright 2016 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 /** |    5 /** | 
|    6  * @fileoverview |    6  * @fileoverview | 
|    7  * 'settings-keyboard' is the settings subpage with keyboard settings. |    7  * 'settings-keyboard' is the settings subpage with keyboard settings. | 
|    8  */ |    8  */ | 
|    9  |    9  | 
|   10 // TODO(michaelpg): The docs below are duplicates of settings_dropdown_menu, |   10 // TODO(michaelpg): The docs below are duplicates of settings_dropdown_menu, | 
|   11 // because we can't depend on settings_dropdown_menu in compiled_resources2.gyp |   11 // because we can't depend on settings_dropdown_menu in compiled_resources2.gyp | 
|   12 // withhout first converting settings_dropdown_menu to compiled_resources2.gyp. |   12 // withhout first converting settings_dropdown_menu to compiled_resources2.gyp. | 
|   13 // After the conversion, we should remove these. |   13 // After the conversion, we should remove these. | 
|   14 /** @typedef {{name: string, value: (number|string)}} */ |   14 /** @typedef {{name: string, value: (number|string)}} */ | 
|   15 var DropdownMenuOption; |   15 var DropdownMenuOption; | 
|   16 /** @typedef {!Array<!DropdownMenuOption>} */ |   16 /** @typedef {!Array<!DropdownMenuOption>} */ | 
|   17 var DropdownMenuOptionList; |   17 var DropdownMenuOptionList; | 
|   18  |   18  | 
|   19 /** |  | 
|   20  * Auto-repeat delays (in ms) for the corresponding slider values, from |  | 
|   21  * long to short. The values were chosen to provide a large range while giving |  | 
|   22  * several options near the defaults. |  | 
|   23  * @type {!Array<number>} |  | 
|   24  * @const |  | 
|   25  */ |  | 
|   26 var AUTO_REPEAT_DELAYS = |  | 
|   27     [2000, 1500, 1000, 500, 300, 200, 150]; |  | 
|   28  |  | 
|   29 /** |  | 
|   30  * Auto-repeat intervals (in ms) for the corresponding slider values, from |  | 
|   31  * long to short. The slider itself is labeled "rate", the inverse of |  | 
|   32  * interval, and goes from slow (long interval) to fast (short interval). |  | 
|   33  * @type {!Array<number>} |  | 
|   34  * @const |  | 
|   35  */ |  | 
|   36 var AUTO_REPEAT_INTERVALS = |  | 
|   37     [2000, 1000, 500, 300, 200, 100, 50, 30, 20]; |  | 
|   38  |  | 
|   39 var AUTO_REPEAT_DELAY_PREF = 'settings.language.xkb_auto_repeat_delay_r2'; |  | 
|   40 var AUTO_REPEAT_INTERVAL_PREF = 'settings.language.xkb_auto_repeat_interval_r2'; |  | 
|   41  |  | 
|   42 Polymer({ |   19 Polymer({ | 
|   43   is: 'settings-keyboard', |   20   is: 'settings-keyboard', | 
|   44  |   21  | 
|   45   behaviors: [ |  | 
|   46     PrefsBehavior, |  | 
|   47   ], |  | 
|   48  |  | 
|   49   properties: { |   22   properties: { | 
|   50     /** Preferences state. */ |   23     /** Preferences state. */ | 
|   51     prefs: { |   24     prefs: { | 
|   52       type: Object, |   25       type: Object, | 
|   53       notify: true, |   26       notify: true, | 
|   54     }, |   27     }, | 
|   55  |   28  | 
|   56     /** The current active route. */ |   29     /** The current active route. */ | 
|   57     currentRoute: { |   30     currentRoute: { | 
|   58       type: Object, |   31       type: Object, | 
|   59       notify: true, |   32       notify: true, | 
|   60     }, |   33     }, | 
|   61  |   34  | 
|   62     /** @private Whether to show Caps Lock options. */ |   35     /** @private Whether to show Caps Lock options. */ | 
|   63     showCapsLock_: Boolean, |   36     showCapsLock_: Boolean, | 
|   64  |   37  | 
|   65     /** @private Whether to show diamond key options. */ |   38     /** @private Whether to show diamond key options. */ | 
|   66     showDiamondKey_: Boolean, |   39     showDiamondKey_: Boolean, | 
|   67  |   40  | 
|   68     /** @private {!DropdownMenuOptionList} Menu items for key mapping. */ |   41     /** @private {!DropdownMenuOptionList} Menu items for key mapping. */ | 
|   69     keyMapTargets_: Object, |   42     keyMapTargets_: Object, | 
|   70  |   43  | 
|   71     /** |   44     /** | 
|   72      * @private {!DropdownMenuOptionList} Menu items for key mapping, including |   45      * @private {!DropdownMenuOptionList} Menu items for key mapping, including | 
|   73      * Caps Lock. |   46      * Caps Lock. | 
|   74      */ |   47      */ | 
|   75     keyMapTargetsWithCapsLock_: Object, |   48     keyMapTargetsWithCapsLock_: Object, | 
 |   49  | 
 |   50     /** | 
 |   51      * Auto-repeat delays (in ms) for the corresponding slider values, from | 
 |   52      * long to short. The values were chosen to provide a large range while | 
 |   53      * giving several options near the defaults. | 
 |   54      * @private {!Array<number>} | 
 |   55      */ | 
 |   56     autoRepeatDelays_: { | 
 |   57       type: Array, | 
 |   58       value: [2000, 1500, 1000, 500, 300, 200, 150], | 
 |   59       readOnly: true, | 
 |   60     }, | 
 |   61  | 
 |   62     /** | 
 |   63      * Auto-repeat intervals (in ms) for the corresponding slider values, from | 
 |   64      * long to short. The slider itself is labeled "rate", the inverse of | 
 |   65      * interval, and goes from slow (long interval) to fast (short interval). | 
 |   66      * @private {!Array<number>} | 
 |   67      */ | 
 |   68     autoRepeatIntervals_: { | 
 |   69       type: Array, | 
 |   70       value: [2000, 1000, 500, 300, 200, 100, 50, 30, 20], | 
 |   71       readOnly: true, | 
 |   72     }, | 
|   76   }, |   73   }, | 
|   77  |   74  | 
|   78   observers: [ |  | 
|   79     'autoRepeatDelayPrefChanged_(' + |  | 
|   80         'prefs.' + AUTO_REPEAT_DELAY_PREF + '.*)', |  | 
|   81     'autoRepeatIntervalPrefChanged_(' + |  | 
|   82         'prefs.' + AUTO_REPEAT_INTERVAL_PREF + '.*)', |  | 
|   83   ], |  | 
|   84  |  | 
|   85   /** @override */ |   75   /** @override */ | 
|   86   ready: function() { |   76   ready: function() { | 
|   87     cr.addWebUIListener('show-keys-changed', this.onShowKeysChange_.bind(this)); |   77     cr.addWebUIListener('show-keys-changed', this.onShowKeysChange_.bind(this)); | 
|   88     settings.DevicePageBrowserProxyImpl.getInstance().initializeKeyboard(); |   78     settings.DevicePageBrowserProxyImpl.getInstance().initializeKeyboard(); | 
|   89     this.setUpKeyMapTargets_(); |   79     this.setUpKeyMapTargets_(); | 
|   90   }, |   80   }, | 
|   91  |   81  | 
|   92   /** |   82   /** | 
|   93    * Initializes the dropdown menu options for remapping keys. |   83    * Initializes the dropdown menu options for remapping keys. | 
|   94    * @private |   84    * @private | 
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
|  126         .showKeyboardShortcutsOverlay(); |  116         .showKeyboardShortcutsOverlay(); | 
|  127   }, |  117   }, | 
|  128  |  118  | 
|  129   onShowLanguageInputTap_: function() { |  119   onShowLanguageInputTap_: function() { | 
|  130     this.currentRoute = { |  120     this.currentRoute = { | 
|  131       page: 'advanced', |  121       page: 'advanced', | 
|  132       section: 'languages', |  122       section: 'languages', | 
|  133       subpage: [], |  123       subpage: [], | 
|  134     }; |  124     }; | 
|  135   }, |  125   }, | 
|  136  |  | 
|  137   /** @private */ |  | 
|  138   autoRepeatDelayPrefChanged_: function() { |  | 
|  139     var delay = /** @type number */(this.getPref(AUTO_REPEAT_DELAY_PREF).value); |  | 
|  140     this.$.delaySlider.value = |  | 
|  141         this.findNearestIndex_(AUTO_REPEAT_DELAYS, delay); |  | 
|  142   }, |  | 
|  143  |  | 
|  144   /** @private */ |  | 
|  145   autoRepeatIntervalPrefChanged_: function() { |  | 
|  146     var interval = /** @type number */( |  | 
|  147         this.getPref(AUTO_REPEAT_INTERVAL_PREF).value); |  | 
|  148     this.$.repeatRateSlider.value = |  | 
|  149         this.findNearestIndex_(AUTO_REPEAT_INTERVALS, interval); |  | 
|  150   }, |  | 
|  151  |  | 
|  152   /** @private */ |  | 
|  153   onDelaySliderChange_: function() { |  | 
|  154     var index = this.$.delaySlider.value; |  | 
|  155     assert(index >= 0 && index < AUTO_REPEAT_DELAYS.length); |  | 
|  156     this.setPrefValue(AUTO_REPEAT_DELAY_PREF, AUTO_REPEAT_DELAYS[index]); |  | 
|  157   }, |  | 
|  158  |  | 
|  159   /** @private */ |  | 
|  160   onRepeatRateSliderChange_: function() { |  | 
|  161     var index = this.$.repeatRateSlider.value; |  | 
|  162     assert(index >= 0 && index < AUTO_REPEAT_INTERVALS.length); |  | 
|  163     this.setPrefValue(AUTO_REPEAT_INTERVAL_PREF, AUTO_REPEAT_INTERVALS[index]); |  | 
|  164   }, |  | 
|  165  |  | 
|  166   /** |  | 
|  167    * @return {number} |  | 
|  168    * @private |  | 
|  169    */ |  | 
|  170   delayMaxTick_: function() { |  | 
|  171     return AUTO_REPEAT_DELAYS.length - 1; |  | 
|  172   }, |  | 
|  173  |  | 
|  174   /** |  | 
|  175    * @return {number} |  | 
|  176    * @private |  | 
|  177    */ |  | 
|  178   repeatRateMaxTick_: function() { |  | 
|  179     return AUTO_REPEAT_INTERVALS.length - 1; |  | 
|  180   }, |  | 
|  181  |  | 
|  182   /** |  | 
|  183    * Returns the index of the item in |arr| closest to |value|. Same cost as |  | 
|  184    * Array.prototype.indexOf if an exact match exists. |  | 
|  185    * @param {!Array<number>} arr |  | 
|  186    * @param {number} value |  | 
|  187    * @return {number} |  | 
|  188    * @private |  | 
|  189    */ |  | 
|  190   findNearestIndex_: function(arr, value) { |  | 
|  191     assert(arr.length); |  | 
|  192  |  | 
|  193     // The common case has an exact match. |  | 
|  194     var closestIndex = arr.indexOf(value); |  | 
|  195     if (closestIndex != -1) |  | 
|  196       return closestIndex; |  | 
|  197  |  | 
|  198     // No exact match. Find the element closest to |value|. |  | 
|  199     var minDifference = Number.MAX_VALUE; |  | 
|  200     for (var i = 0; i < arr.length; i++) { |  | 
|  201       var difference = Math.abs(arr[i] - value); |  | 
|  202       if (difference < minDifference) { |  | 
|  203         closestIndex = i; |  | 
|  204         minDifference = difference; |  | 
|  205       } |  | 
|  206     } |  | 
|  207  |  | 
|  208     return closestIndex; |  | 
|  209   }, |  | 
|  210 }); |  126 }); | 
| OLD | NEW |