Chromium Code Reviews| 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 * `home-url-input` is a single-line text field intending to be used with |
| 8 * with a pref value. | 8 * prefs.homepage |
| 9 */ | 9 */ |
| 10 Polymer({ | 10 Polymer({ |
| 11 is: 'settings-input', | 11 is: 'home-url-input', |
| 12 | 12 |
| 13 behaviors: [CrPolicyPrefBehavior, PrefControlBehavior], | 13 behaviors: [CrPolicyPrefBehavior, PrefControlBehavior], |
| 14 | 14 |
| 15 properties: { | 15 properties: { |
| 16 /** | 16 /** |
| 17 * The preference object to control. | 17 * The preference object to control. |
| 18 * @type {!chrome.settingsPrivate.PrefObject|undefined} | 18 * @type {!chrome.settingsPrivate.PrefObject|undefined} |
| 19 * @override | 19 * @override |
| 20 */ | 20 */ |
| 21 pref: {observer: 'prefChanged_'}, | 21 pref: {observer: 'prefChanged_'}, |
| 22 | 22 |
| 23 /* Set to true to disable editing the input. */ | |
| 24 disabled: {type: Boolean, value: false, reflectToAttribute: true}, | |
| 25 | |
| 26 canTab: Boolean, | |
| 27 | |
| 28 invalid: {type: Boolean, value: false}, | |
| 29 | |
| 23 /* The current value of the input, reflected to/from |pref|. */ | 30 /* The current value of the input, reflected to/from |pref|. */ |
| 24 value: { | 31 value: { |
| 25 type: String, | 32 type: String, |
| 26 value: '', | 33 value: '', |
| 27 notify: true, | 34 notify: true, |
| 28 }, | 35 }, |
| 36 }, | |
| 29 | 37 |
| 30 /* Set to true to disable editing the input. */ | 38 /** @private {?settings.AppearanceBrowserProxy} */ |
| 31 disabled: {type: Boolean, value: false, reflectToAttribute: true}, | 39 browserProxy_: null, |
| 32 | 40 |
| 33 canTab: Boolean, | 41 created: function() { |
| 34 | 42 this.browserProxy_ = settings.AppearanceBrowserProxyImpl.getInstance(); |
| 35 invalid: { | 43 this.noExtensionIndicator = true; // Prevent double indicator. |
| 36 type: Boolean, | |
| 37 value: false, | |
| 38 notify: true, | |
| 39 }, | |
| 40 | |
| 41 /* Properties for paper-input. This is not strictly necessary. | |
| 42 * Though it does define the types for the closure compiler. */ | |
| 43 errorMessage: {type: String}, | |
| 44 label: {type: String}, | |
| 45 }, | 44 }, |
| 46 | 45 |
| 47 /** | 46 /** |
| 48 * Focuses the 'input' element. | 47 * Focuses the 'input' element. |
| 49 */ | 48 */ |
| 50 focus: function() { | 49 focus: function() { |
| 51 this.$.input.focus(); | 50 this.$.input.focus(); |
| 52 }, | 51 }, |
| 53 | 52 |
| 54 /** | 53 /** |
| (...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 105 this.$.input.blur(); | 104 this.$.input.blur(); |
| 106 }, | 105 }, |
| 107 | 106 |
| 108 /** | 107 /** |
| 109 * Keydown handler to specify enter-key and escape-key interactions. | 108 * Keydown handler to specify enter-key and escape-key interactions. |
| 110 * @param {!Event} event | 109 * @param {!Event} event |
| 111 * @private | 110 * @private |
| 112 */ | 111 */ |
| 113 onKeydown_: function(event) { | 112 onKeydown_: function(event) { |
| 114 // If pressed enter when input is invalid, do not trigger on-change. | 113 // If pressed enter when input is invalid, do not trigger on-change. |
| 115 if (event.key == 'Enter' && this.invalid) { | 114 if (event.key == 'Enter' && this.invalid) |
| 116 event.preventDefault(); | 115 event.preventDefault(); |
| 117 return; | 116 else if (event.key == 'Escape') |
| 118 } | 117 this.resetValue_(); |
| 119 | |
| 120 if (event.key != 'Escape') | |
| 121 return; | |
| 122 | |
| 123 this.resetValue_(); | |
| 124 }, | 118 }, |
| 125 | 119 |
| 126 /** | 120 /** |
| 127 * @param {boolean} disabled | 121 * @param {boolean} disabled |
| 128 * @return {boolean} Whether the element should be disabled. | 122 * @return {boolean} Whether the element should be disabled. |
| 129 * @private | 123 * @private |
| 130 */ | 124 */ |
| 131 isDisabled_: function(disabled) { | 125 isDisabled_: function(disabled) { |
| 132 return disabled || this.isPrefEnforced(); | 126 return disabled || this.isPrefEnforced(); |
| 133 }, | 127 }, |
| 128 | |
| 129 /** | |
|
dpapad
2017/03/28 00:09:27
Nit: /** @private */
scottchen
2017/03/30 07:05:03
Done.
| |
| 130 * @private | |
| 131 */ | |
| 132 validate_: function() { | |
| 133 if (this.value == '') { | |
| 134 this.invalid = false; | |
| 135 return; | |
| 136 } | |
| 137 | |
| 138 this.browserProxy_.validateStartupPage(this.value).then(function(isValid) { | |
| 139 this.invalid = !isValid; | |
| 140 }.bind(this)); | |
| 141 }, | |
| 134 }); | 142 }); |
| OLD | NEW |