Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(61)

Side by Side Diff: chrome/browser/resources/settings/controls/settings_input.js

Issue 2773233002: MD Settings: change settings-input to home-url-input due to reduced usage. (Closed)
Patch Set: updates based on comments Created 3 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
(Empty)
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
3 // found in the LICENSE file.
4
5 /**
6 * @fileoverview
7 * `settings-input` is a single-line text field for user input associated
8 * with a pref value.
9 */
10 Polymer({
11 is: 'settings-input',
12
13 behaviors: [CrPolicyPrefBehavior, PrefControlBehavior],
14
15 properties: {
16 /**
17 * The preference object to control.
18 * @type {!chrome.settingsPrivate.PrefObject|undefined}
19 * @override
20 */
21 pref: {observer: 'prefChanged_'},
22
23 /* The current value of the input, reflected to/from |pref|. */
24 value: {
25 type: String,
26 value: '',
27 notify: true,
28 },
29
30 /* Set to true to disable editing the input. */
31 disabled: {type: Boolean, value: false, reflectToAttribute: true},
32
33 canTab: Boolean,
34
35 invalid: {
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 },
46
47 /**
48 * Focuses the 'input' element.
49 */
50 focus: function() {
51 this.$.input.focus();
52 },
53
54 /**
55 * Polymer changed observer for |pref|.
56 * @private
57 */
58 prefChanged_: function() {
59 if (!this.pref)
60 return;
61
62 // Ignore updates while the input is focused so that user input is not
63 // overwritten.
64 if (this.$.input.focused)
65 return;
66
67 this.setInputValueFromPref_();
68 },
69
70 /** @private */
71 setInputValueFromPref_: function() {
72 assert(this.pref.type == chrome.settingsPrivate.PrefType.URL);
73 this.value = /** @type {string} */ (this.pref.value);
74 },
75
76 /**
77 * Gets a tab index for this control if it can be tabbed to.
78 * @param {boolean} canTab
79 * @return {number}
80 * @private
81 */
82 getTabindex_: function(canTab) {
83 return canTab ? 0 : -1;
84 },
85
86 /**
87 * Change event handler for paper-input. Updates the pref value.
88 * settings-input uses the change event because it is fired by the Enter key.
89 * @private
90 */
91 onChange_: function() {
92 if (this.invalid) {
93 this.resetValue_();
94 return;
95 }
96
97 assert(this.pref.type == chrome.settingsPrivate.PrefType.URL);
98 this.set('pref.value', this.value);
99 },
100
101 /** @private */
102 resetValue_: function() {
103 this.invalid = false;
104 this.setInputValueFromPref_();
105 this.$.input.blur();
106 },
107
108 /**
109 * Keydown handler to specify enter-key and escape-key interactions.
110 * @param {!Event} event
111 * @private
112 */
113 onKeydown_: function(event) {
114 // If pressed enter when input is invalid, do not trigger on-change.
115 if (event.key == 'Enter' && this.invalid)
116 event.preventDefault();
117 else if (event.key == 'Escape')
118 this.resetValue_();
119 },
120
121 /**
122 * @param {boolean} disabled
123 * @return {boolean} Whether the element should be disabled.
124 * @private
125 */
126 isDisabled_: function(disabled) {
127 return disabled || this.isPrefEnforced();
128 },
129 });
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698