OLD | NEW |
---|---|
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 cr.define('options', function() { | 5 cr.define('options', function() { |
6 | 6 |
7 var Preferences = options.Preferences; | 7 var Preferences = options.Preferences; |
8 | 8 |
9 /** | 9 /** |
10 * Allows an element to be disabled for several reasons. | 10 * Allows an element to be disabled for several reasons. |
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
74 * updates the associated pref. | 74 * updates the associated pref. |
75 * @param {Event} event Change event. | 75 * @param {Event} event Change event. |
76 * @private | 76 * @private |
77 */ | 77 */ |
78 handleChange_: function(event) { | 78 handleChange_: function(event) { |
79 if (!this.customChangeHandler(event)) | 79 if (!this.customChangeHandler(event)) |
80 this.updatePrefFromState_(); | 80 this.updatePrefFromState_(); |
81 }, | 81 }, |
82 | 82 |
83 /** | 83 /** |
84 * Update the input element's state when the associated pref changes. | 84 * Handles changes to the pref. If a custom change handler does not suppress |
85 * it, a default handler is invoked that update the input element's state. | |
85 * @param {Event} event Pref change event. | 86 * @param {Event} event Pref change event. |
86 * @private | 87 * @private |
87 */ | 88 */ |
88 updateStateFromPref_: function(event) { | 89 updateStateFromPref_: function(event) { |
89 this.value = event.value.value; | 90 if (!this.customPrefChangeHandler(event)) |
91 this.value = event.value.value; | |
90 }, | 92 }, |
91 | 93 |
92 /** | 94 /** |
93 * See |updateDisabledState_| above. | 95 * See |updateDisabledState_| above. |
94 */ | 96 */ |
95 setDisabled: function(reason, disabled) { | 97 setDisabled: function(reason, disabled) { |
96 updateDisabledState_(this, reason, disabled); | 98 updateDisabledState_(this, reason, disabled); |
97 }, | 99 }, |
98 | 100 |
99 /** | 101 /** |
100 * Custom change handler that is invoked first when the user makes changes | 102 * Custom change handler that is invoked first when the user makes changes |
101 * to the input element's state. If it returns false, a default handler is | 103 * to the input element's state. If it returns false, a default handler is |
102 * invoked next that updates the associated pref. If it returns true, the | 104 * invoked next that updates the associated pref. If it returns true, the |
103 * default handler is suppressed (i.e., this works like stopPropagation or | 105 * default handler is suppressed (i.e., this works like stopPropagation or |
104 * cancelBubble). | 106 * cancelBubble). |
105 * @param {Event} event Input element change event. | 107 * @param {Event} event Input element change event. |
106 */ | 108 */ |
107 customChangeHandler: function(event) { | 109 customChangeHandler: function(event) { |
108 return false; | 110 return false; |
109 }, | 111 }, |
112 | |
113 /** | |
114 * Custom change handler that is invoked first when the preference | |
115 * associated with the input element changes. If it returns false, a default | |
116 * handler is invoked next that updates the input element. If it returns | |
117 * true, the default handler is suppressed. | |
118 * @param {Event} event Input element change event. | |
119 */ | |
120 customPrefChangeHandler: function(event) { | |
121 return false; | |
122 }, | |
110 }; | 123 }; |
111 | 124 |
112 /** | 125 /** |
113 * The name of the associated preference. | 126 * The name of the associated preference. |
114 * @type {string} | 127 * @type {string} |
115 */ | 128 */ |
116 cr.defineProperty(PrefInputElement, 'pref', cr.PropertyKind.ATTR); | 129 cr.defineProperty(PrefInputElement, 'pref', cr.PropertyKind.ATTR); |
117 | 130 |
118 /** | 131 /** |
119 * The data type of the associated preference, only relevant for derived | 132 * The data type of the associated preference, only relevant for derived |
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
177 Preferences.setBooleanPref(this.pref, value, | 190 Preferences.setBooleanPref(this.pref, value, |
178 !this.dialogPref, this.metric); | 191 !this.dialogPref, this.metric); |
179 }, | 192 }, |
180 | 193 |
181 /** | 194 /** |
182 * Update the checkbox state when the associated pref changes. | 195 * Update the checkbox state when the associated pref changes. |
183 * @param {Event} event Pref change event. | 196 * @param {Event} event Pref change event. |
184 * @private | 197 * @private |
185 */ | 198 */ |
186 updateStateFromPref_: function(event) { | 199 updateStateFromPref_: function(event) { |
187 var value = Boolean(event.value.value); | 200 if (!this.customPrefChangeHandler(event)) { |
stevenjb
2014/07/22 16:42:23
nit: Here and below, I think the logic would be a
michaelpg
2014/07/22 17:34:54
Done.
| |
188 this.checked = this.inverted_pref ? !value : value; | 201 var value = Boolean(event.value.value); |
202 this.checked = this.inverted_pref ? !value : value; | |
203 } | |
189 }, | 204 }, |
190 }; | 205 }; |
191 | 206 |
192 /** | 207 /** |
193 * Whether the mapping between checkbox state and associated pref is inverted. | 208 * Whether the mapping between checkbox state and associated pref is inverted. |
194 * @type {boolean} | 209 * @type {boolean} |
195 */ | 210 */ |
196 cr.defineProperty(PrefCheckbox, 'inverted_pref', cr.PropertyKind.BOOL_ATTR); | 211 cr.defineProperty(PrefCheckbox, 'inverted_pref', cr.PropertyKind.BOOL_ATTR); |
197 | 212 |
198 ///////////////////////////////////////////////////////////////////////////// | 213 ///////////////////////////////////////////////////////////////////////////// |
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
257 !this.dialogPref, this.metric); | 272 !this.dialogPref, this.metric); |
258 } | 273 } |
259 }, | 274 }, |
260 | 275 |
261 /** | 276 /** |
262 * Update the radio button state when the associated pref changes. | 277 * Update the radio button state when the associated pref changes. |
263 * @param {Event} event Pref change event. | 278 * @param {Event} event Pref change event. |
264 * @private | 279 * @private |
265 */ | 280 */ |
266 updateStateFromPref_: function(event) { | 281 updateStateFromPref_: function(event) { |
267 this.checked = this.value == String(event.value.value); | 282 if (!this.customPrefChangeHandler(event)) |
283 this.checked = this.value == String(event.value.value); | |
268 }, | 284 }, |
269 }; | 285 }; |
270 | 286 |
271 ///////////////////////////////////////////////////////////////////////////// | 287 ///////////////////////////////////////////////////////////////////////////// |
272 // PrefRange class: | 288 // PrefRange class: |
273 | 289 |
274 // Define a constructor that uses an input element as its underlying element. | 290 // Define a constructor that uses an input element as its underlying element. |
275 var PrefRange = cr.ui.define('input'); | 291 var PrefRange = cr.ui.define('input'); |
276 | 292 |
277 PrefRange.prototype = { | 293 PrefRange.prototype = { |
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
321 * handler is invoked that updates the associated pref. | 337 * handler is invoked that updates the associated pref. |
322 * @param {Event} event Change event. | 338 * @param {Event} event Change event. |
323 * @private | 339 * @private |
324 */ | 340 */ |
325 handleRelease_: function(event) { | 341 handleRelease_: function(event) { |
326 if (!this.customChangeHandler(event)) | 342 if (!this.customChangeHandler(event)) |
327 this.updatePrefFromState_(); | 343 this.updatePrefFromState_(); |
328 }, | 344 }, |
329 | 345 |
330 /** | 346 /** |
331 * Update the slider position when the associated pref changes. | 347 * Handles changes to the pref associated with the slider. If a custom |
348 * change handler does not suppress it, a default handler is invoked that | |
349 * updates the slider position. | |
332 * @param {Event} event Pref change event. | 350 * @param {Event} event Pref change event. |
333 * @private | 351 * @private |
334 */ | 352 */ |
335 updateStateFromPref_: function(event) { | 353 updateStateFromPref_: function(event) { |
336 var value = event.value.value; | 354 if (!this.customPrefChangeHandler(event)) { |
337 this.value = this.valueMap ? this.valueMap.indexOf(value) : value; | 355 var value = event.value.value; |
356 this.value = this.valueMap ? this.valueMap.indexOf(value) : value; | |
357 } | |
338 }, | 358 }, |
339 | 359 |
340 /** | 360 /** |
341 * Map slider position to the range of values provided by the client, | 361 * Map slider position to the range of values provided by the client, |
342 * represented by |valueMap|. | 362 * represented by |valueMap|. |
343 * @param {number} position The slider position to map. | 363 * @param {number} position The slider position to map. |
344 */ | 364 */ |
345 mapPositionToPref: function(position) { | 365 mapPositionToPref: function(position) { |
346 return this.valueMap ? this.valueMap[position] : position; | 366 return this.valueMap ? this.valueMap[position] : position; |
347 }, | 367 }, |
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
385 this.dataType); | 405 this.dataType); |
386 } | 406 } |
387 }, | 407 }, |
388 | 408 |
389 /** | 409 /** |
390 * Update the selected item when the associated pref changes. | 410 * Update the selected item when the associated pref changes. |
391 * @param {Event} event Pref change event. | 411 * @param {Event} event Pref change event. |
392 * @private | 412 * @private |
393 */ | 413 */ |
394 updateStateFromPref_: function(event) { | 414 updateStateFromPref_: function(event) { |
415 if (this.customPrefChangeHandler(event)) | |
416 return; | |
417 | |
395 // Make sure the value is a string, because the value is stored as a | 418 // Make sure the value is a string, because the value is stored as a |
396 // string in the HTMLOptionElement. | 419 // string in the HTMLOptionElement. |
397 value = String(event.value.value); | 420 value = String(event.value.value); |
398 | 421 |
399 var found = false; | 422 var found = false; |
400 for (var i = 0; i < this.options.length; i++) { | 423 for (var i = 0; i < this.options.length; i++) { |
401 if (this.options[i].value == value) { | 424 if (this.options[i].value == value) { |
402 this.selectedIndex = i; | 425 this.selectedIndex = i; |
403 found = true; | 426 found = true; |
404 } | 427 } |
(...skipping 148 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
553 PrefNumber: PrefNumber, | 576 PrefNumber: PrefNumber, |
554 PrefRadio: PrefRadio, | 577 PrefRadio: PrefRadio, |
555 PrefRange: PrefRange, | 578 PrefRange: PrefRange, |
556 PrefSelect: PrefSelect, | 579 PrefSelect: PrefSelect, |
557 PrefTextField: PrefTextField, | 580 PrefTextField: PrefTextField, |
558 PrefPortNumber: PrefPortNumber, | 581 PrefPortNumber: PrefPortNumber, |
559 PrefButton: PrefButton | 582 PrefButton: PrefButton |
560 }; | 583 }; |
561 | 584 |
562 }); | 585 }); |
OLD | NEW |