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

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

Issue 2617663002: WIP: run clang-format-js on lots of things (Closed)
Patch Set: merge Created 3 years, 11 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
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({
11 is: 'settings-input', 11 is: 'settings-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: { 21 pref: {observer: 'prefChanged_'},
22 observer: 'prefChanged_'
23 },
24 22
25 /* The current value of the input, reflected to/from |pref|. */ 23 /* The current value of the input, reflected to/from |pref|. */
26 value: { 24 value: {
27 type: String, 25 type: String,
28 value: '', 26 value: '',
29 notify: true, 27 notify: true,
30 }, 28 },
31 29
32 /* Set to true to disable editing the input. */ 30 /* Set to true to disable editing the input. */
33 disabled: { 31 disabled: {type: Boolean, value: false, reflectToAttribute: true},
34 type: Boolean,
35 value: false,
36 reflectToAttribute: true
37 },
38 32
39 canTab: Boolean, 33 canTab: Boolean,
40 34
41 /* Properties for paper-input. This is not strictly necessary. 35 /* Properties for paper-input. This is not strictly necessary.
42 * Though it does define the types for the closure compiler. */ 36 * Though it does define the types for the closure compiler. */
43 errorMessage: { type: String }, 37 errorMessage: {type: String},
44 label: { type: String }, 38 label: {type: String},
45 noLabelFloat: { type: Boolean, value: false }, 39 noLabelFloat: {type: Boolean, value: false},
46 pattern: { type: String }, 40 pattern: {type: String},
47 readonly: { type: Boolean, value: false }, 41 readonly: {type: Boolean, value: false},
48 required: { type: Boolean, value: false }, 42 required: {type: Boolean, value: false},
49 stopKeyboardEventPropagation: { type: Boolean, value: false }, 43 stopKeyboardEventPropagation: {type: Boolean, value: false},
50 type: { type: String }, 44 type: {type: String},
51 }, 45 },
52 46
53 /** 47 /**
54 * Focuses the 'input' element. 48 * Focuses the 'input' element.
55 */ 49 */
56 focus: function() { 50 focus: function() {
57 this.$.input.focus(); 51 this.$.input.focus();
58 }, 52 },
59 53
60 /** 54 /**
61 * Polymer changed observer for |pref|. 55 * Polymer changed observer for |pref|.
62 * @private 56 * @private
63 */ 57 */
64 prefChanged_: function() { 58 prefChanged_: function() {
65 if (!this.pref) 59 if (!this.pref)
66 return; 60 return;
67 61
68 // Ignore updates while the input is focused so that user input is not 62 // Ignore updates while the input is focused so that user input is not
69 // overwritten. 63 // overwritten.
70 if (this.$.input.focused) 64 if (this.$.input.focused)
71 return; 65 return;
72 66
73 if (this.pref.type == chrome.settingsPrivate.PrefType.NUMBER) { 67 if (this.pref.type == chrome.settingsPrivate.PrefType.NUMBER) {
74 this.value = this.pref.value.toString(); 68 this.value = this.pref.value.toString();
75 } else { 69 } else {
76 assert(this.pref.type == chrome.settingsPrivate.PrefType.STRING || 70 assert(
77 this.pref.type == chrome.settingsPrivate.PrefType.URL); 71 this.pref.type == chrome.settingsPrivate.PrefType.STRING ||
78 this.value = /** @type {string} */(this.pref.value); 72 this.pref.type == chrome.settingsPrivate.PrefType.URL);
73 this.value = /** @type {string} */ (this.pref.value);
79 } 74 }
80 }, 75 },
81 76
82 /** 77 /**
83 * Gets a tab index for this control if it can be tabbed to. 78 * Gets a tab index for this control if it can be tabbed to.
84 * @param {boolean} canTab 79 * @param {boolean} canTab
85 * @return {number} 80 * @return {number}
86 * @private 81 * @private
87 */ 82 */
88 getTabindex_: function(canTab) { 83 getTabindex_: function(canTab) {
(...skipping 14 matching lines...) Expand all
103 this.value = this.pref.value.toString(); 98 this.value = this.pref.value.toString();
104 return; 99 return;
105 } 100 }
106 var n = parseInt(this.value, 10); 101 var n = parseInt(this.value, 10);
107 if (isNaN(n)) { 102 if (isNaN(n)) {
108 console.error('Bad value for numerical pref: ' + this.value); 103 console.error('Bad value for numerical pref: ' + this.value);
109 return; 104 return;
110 } 105 }
111 this.set('pref.value', n); 106 this.set('pref.value', n);
112 } else { 107 } else {
113 assert(this.pref.type == chrome.settingsPrivate.PrefType.STRING || 108 assert(
114 this.pref.type == chrome.settingsPrivate.PrefType.URL); 109 this.pref.type == chrome.settingsPrivate.PrefType.STRING ||
110 this.pref.type == chrome.settingsPrivate.PrefType.URL);
115 this.set('pref.value', this.value); 111 this.set('pref.value', this.value);
116 } 112 }
117 }, 113 },
118 114
119 /** 115 /**
120 * @param {boolean} disabled 116 * @param {boolean} disabled
121 * @param {!chrome.settingsPrivate.PrefObject} pref 117 * @param {!chrome.settingsPrivate.PrefObject} pref
122 * @return {boolean} Whether the element should be disabled. 118 * @return {boolean} Whether the element should be disabled.
123 * @private 119 * @private
124 */ 120 */
125 isDisabled_: function(disabled, pref) { 121 isDisabled_: function(disabled, pref) {
126 return disabled || this.isPrefPolicyControlled(pref); 122 return disabled || this.isPrefPolicyControlled(pref);
127 }, 123 },
128 }); 124 });
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698