| OLD | NEW |
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 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-input` is a single-line text field for user input associated | 7 * `settings-input` is a single-line text field for user input associated |
| 8 * with a pref value. | 8 * with a pref value. |
| 9 */ | 9 */ |
| 10 Polymer({ | 10 Polymer({ |
| (...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 63 */ | 63 */ |
| 64 prefChanged_: function() { | 64 prefChanged_: function() { |
| 65 if (!this.pref) | 65 if (!this.pref) |
| 66 return; | 66 return; |
| 67 | 67 |
| 68 // Ignore updates while the input is focused so that user input is not | 68 // Ignore updates while the input is focused so that user input is not |
| 69 // overwritten. | 69 // overwritten. |
| 70 if (this.$.input.focused) | 70 if (this.$.input.focused) |
| 71 return; | 71 return; |
| 72 | 72 |
| 73 this.setInputValueFromPref_(); |
| 74 }, |
| 75 |
| 76 /** @private */ |
| 77 setInputValueFromPref_: function() { |
| 73 if (this.pref.type == chrome.settingsPrivate.PrefType.NUMBER) { | 78 if (this.pref.type == chrome.settingsPrivate.PrefType.NUMBER) { |
| 74 this.value = this.pref.value.toString(); | 79 this.value = this.pref.value.toString(); |
| 75 } else { | 80 } else { |
| 76 assert(this.pref.type == chrome.settingsPrivate.PrefType.STRING || | 81 assert(this.pref.type == chrome.settingsPrivate.PrefType.STRING || |
| 77 this.pref.type == chrome.settingsPrivate.PrefType.URL); | 82 this.pref.type == chrome.settingsPrivate.PrefType.URL); |
| 78 this.value = /** @type {string} */(this.pref.value); | 83 this.value = /** @type {string} */(this.pref.value); |
| 79 } | 84 } |
| 80 }, | 85 }, |
| 81 | 86 |
| 82 /** | 87 /** |
| (...skipping 28 matching lines...) Expand all Loading... |
| 111 } | 116 } |
| 112 this.set('pref.value', n); | 117 this.set('pref.value', n); |
| 113 } else { | 118 } else { |
| 114 assert(this.pref.type == chrome.settingsPrivate.PrefType.STRING || | 119 assert(this.pref.type == chrome.settingsPrivate.PrefType.STRING || |
| 115 this.pref.type == chrome.settingsPrivate.PrefType.URL); | 120 this.pref.type == chrome.settingsPrivate.PrefType.URL); |
| 116 this.set('pref.value', this.value); | 121 this.set('pref.value', this.value); |
| 117 } | 122 } |
| 118 }, | 123 }, |
| 119 | 124 |
| 120 /** | 125 /** |
| 126 * Handler for profile name keydowns. |
| 127 * @param {!Event} event |
| 128 * @private |
| 129 */ |
| 130 onKeydown_: function(event) { |
| 131 if (event.key != 'Escape') |
| 132 return; |
| 133 |
| 134 this.setInputValueFromPref_(); |
| 135 this.$.input.blur(); |
| 136 }, |
| 137 |
| 138 /** |
| 121 * @param {boolean} disabled | 139 * @param {boolean} disabled |
| 122 * @return {boolean} Whether the element should be disabled. | 140 * @return {boolean} Whether the element should be disabled. |
| 123 * @private | 141 * @private |
| 124 */ | 142 */ |
| 125 isDisabled_: function(disabled) { | 143 isDisabled_: function(disabled) { |
| 126 return disabled || this.isPrefEnforced(); | 144 return disabled || this.isPrefEnforced(); |
| 127 }, | 145 }, |
| 128 }); | 146 }); |
| OLD | NEW |