| 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) { |
| 200 if (this.customPrefChangeHandler(event)) |
| 201 return; |
| 187 var value = Boolean(event.value.value); | 202 var value = Boolean(event.value.value); |
| 188 this.checked = this.inverted_pref ? !value : value; | 203 this.checked = this.inverted_pref ? !value : value; |
| 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); |
| (...skipping 60 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 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 323 * handler is invoked that updates the associated pref. | 339 * handler is invoked that updates the associated pref. |
| 324 * @param {Event} event Change event. | 340 * @param {Event} event Change event. |
| 325 * @private | 341 * @private |
| 326 */ | 342 */ |
| 327 handleRelease_: function(event) { | 343 handleRelease_: function(event) { |
| 328 if (!this.customChangeHandler(event)) | 344 if (!this.customChangeHandler(event)) |
| 329 this.updatePrefFromState_(); | 345 this.updatePrefFromState_(); |
| 330 }, | 346 }, |
| 331 | 347 |
| 332 /** | 348 /** |
| 333 * Update the slider position when the associated pref changes. | 349 * Handles changes to the pref associated with the slider. If a custom |
| 350 * change handler does not suppress it, a default handler is invoked that |
| 351 * updates the slider position. |
| 334 * @param {Event} event Pref change event. | 352 * @param {Event} event Pref change event. |
| 335 * @private | 353 * @private |
| 336 */ | 354 */ |
| 337 updateStateFromPref_: function(event) { | 355 updateStateFromPref_: function(event) { |
| 356 if (this.customPrefChangeHandler(event)) |
| 357 return; |
| 338 var value = event.value.value; | 358 var value = event.value.value; |
| 339 this.value = this.valueMap ? this.valueMap.indexOf(value) : value; | 359 this.value = this.valueMap ? this.valueMap.indexOf(value) : value; |
| 340 }, | 360 }, |
| 341 | 361 |
| 342 /** | 362 /** |
| 343 * Map slider position to the range of values provided by the client, | 363 * Map slider position to the range of values provided by the client, |
| 344 * represented by |valueMap|. | 364 * represented by |valueMap|. |
| 345 * @param {number} position The slider position to map. | 365 * @param {number} position The slider position to map. |
| 346 */ | 366 */ |
| 347 mapPositionToPref: function(position) { | 367 mapPositionToPref: function(position) { |
| (...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 387 this.dataType); | 407 this.dataType); |
| 388 } | 408 } |
| 389 }, | 409 }, |
| 390 | 410 |
| 391 /** | 411 /** |
| 392 * Update the selected item when the associated pref changes. | 412 * Update the selected item when the associated pref changes. |
| 393 * @param {Event} event Pref change event. | 413 * @param {Event} event Pref change event. |
| 394 * @private | 414 * @private |
| 395 */ | 415 */ |
| 396 updateStateFromPref_: function(event) { | 416 updateStateFromPref_: function(event) { |
| 417 if (this.customPrefChangeHandler(event)) |
| 418 return; |
| 419 |
| 397 // Make sure the value is a string, because the value is stored as a | 420 // Make sure the value is a string, because the value is stored as a |
| 398 // string in the HTMLOptionElement. | 421 // string in the HTMLOptionElement. |
| 399 value = String(event.value.value); | 422 value = String(event.value.value); |
| 400 | 423 |
| 401 var found = false; | 424 var found = false; |
| 402 for (var i = 0; i < this.options.length; i++) { | 425 for (var i = 0; i < this.options.length; i++) { |
| 403 if (this.options[i].value == value) { | 426 if (this.options[i].value == value) { |
| 404 this.selectedIndex = i; | 427 this.selectedIndex = i; |
| 405 found = true; | 428 found = true; |
| 406 } | 429 } |
| (...skipping 148 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 555 PrefNumber: PrefNumber, | 578 PrefNumber: PrefNumber, |
| 556 PrefRadio: PrefRadio, | 579 PrefRadio: PrefRadio, |
| 557 PrefRange: PrefRange, | 580 PrefRange: PrefRange, |
| 558 PrefSelect: PrefSelect, | 581 PrefSelect: PrefSelect, |
| 559 PrefTextField: PrefTextField, | 582 PrefTextField: PrefTextField, |
| 560 PrefPortNumber: PrefPortNumber, | 583 PrefPortNumber: PrefPortNumber, |
| 561 PrefButton: PrefButton | 584 PrefButton: PrefButton |
| 562 }; | 585 }; |
| 563 | 586 |
| 564 }); | 587 }); |
| OLD | NEW |