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

Side by Side Diff: chrome/browser/resources/settings/input/input.js

Issue 1379483003: Rename cr-settings-elements (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Rebase Created 5 years, 2 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 * `cr-settings-input` is a single-line text field for user input associated
8 * with a pref value.
9 *
10 * @element cr-settings-input
11 */
12 Polymer({
13 is: 'cr-settings-input',
14
15 behaviors: [PolicyControllable],
16
17 properties: {
18 /**
19 * The preference object to control.
20 * @type {chrome.settingsPrivate.PrefObject|undefined}
21 */
22 pref: {
23 type: Object,
24 notify: true,
25 observer: 'prefChanged_'
26 },
27
28 /**
29 * The current value of the input, reflected to/from |pref|.
30 */
31 value: {
32 type: String,
33 value: '',
34 notify: true,
35 },
36
37 /**
38 * Set to true to disable editing the input.
39 */
40 disabled: {
41 type: Boolean,
42 value: false,
43 reflectToAttribute: true
44 },
45
46 /** Propagate the errorMessage property. */
47 errorMessage: { type: String },
48
49 /** Propagate the label property. */
50 label: { type: String },
51
52 /** Propagate the no-label-float property. */
53 noLabelFloat: { type: Boolean, value: false },
54
55 /** Propagate the pattern property. */
56 pattern: { type: String },
57
58 /** Propagate the readonly property. */
59 readonly: { type: Boolean, value: false },
60
61 /** Propagate the required property. */
62 required: { type: Boolean, value: false },
63
64 /** Propagate the type property. */
65 type: { type: String },
66 },
67
68 /** @override */
69 ready: function() {
70 this.$.events.forward(this.$.input, ['change']);
71 },
72
73 /**
74 * Focuses the 'input' element.
75 */
76 focus: function() {
77 this.$.input.inputElement.focus();
78 },
79
80 /**
81 * Polymer changed observer for |pref|.
82 * @private
83 */
84 prefChanged_: function() {
85 if (!this.pref)
86 return;
87
88 // Ignore updates while the input is focused so that user input is not
89 // overwritten.
90 if (this.$.input.focused)
91 return;
92
93 if (this.pref.type == chrome.settingsPrivate.PrefType.NUMBER) {
94 this.value = this.pref.value.toString();
95 } else {
96 assert(this.pref.type == chrome.settingsPrivate.PrefType.STRING ||
97 this.pref.type == chrome.settingsPrivate.PrefType.URL);
98 this.value = /** @type {string} */(this.pref.value);
99 }
100 },
101
102 /**
103 * Blur method for paper-input. Only update the pref value on a blur event.
104 * @private
105 */
106 onBlur_: function() {
107 if (!this.pref)
108 return;
109
110 if (this.pref.type == chrome.settingsPrivate.PrefType.NUMBER) {
111 if (!this.value) {
112 // Ignore empty input field and restore value.
113 this.value = this.pref.value.toString();
114 return;
115 }
116 var n = parseInt(this.value, 10);
117 if (isNaN(n)) {
118 console.error('Bad value for numerical pref: ' + this.value);
119 return;
120 }
121 this.set('pref.value', n);
122 } else {
123 assert(this.pref.type == chrome.settingsPrivate.PrefType.STRING ||
124 this.pref.type == chrome.settingsPrivate.PrefType.URL);
125 this.set('pref.value', this.value);
126 }
127 },
128
129 /**
130 * @param {boolean} disabled
131 * @param {?chrome.settingsPrivate.PrefObject} pref
132 * @return {boolean} Whether the element should be disabled.
133 * @private
134 */
135 isDisabled_: function(disabled, pref) {
136 return disabled || this.isPolicyControlled(pref);
137 },
138 });
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698