| 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 var Preferences = options.Preferences; | 6 var Preferences = options.Preferences; |
| 7 | 7 |
| 8 /** | 8 /** |
| 9 * Allows an element to be disabled for several reasons. | 9 * Allows an element to be disabled for several reasons. |
| 10 * The element is disabled if at least one reason is true, and the reasons | 10 * The element is disabled if at least one reason is true, and the reasons |
| (...skipping 181 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 192 this.updatePrefFromState(); | 192 this.updatePrefFromState(); |
| 193 }, | 193 }, |
| 194 | 194 |
| 195 /** | 195 /** |
| 196 * Update the associated pref when when the user makes changes to the | 196 * Update the associated pref when when the user makes changes to the |
| 197 * checkbox state. | 197 * checkbox state. |
| 198 * @override | 198 * @override |
| 199 */ | 199 */ |
| 200 updatePrefFromState: function() { | 200 updatePrefFromState: function() { |
| 201 var value = this.inverted_pref ? !this.checked : this.checked; | 201 var value = this.inverted_pref ? !this.checked : this.checked; |
| 202 Preferences.setBooleanPref(this.pref, value, | 202 Preferences.setBooleanPref( |
| 203 !this.dialogPref, this.metric); | 203 this.pref, value, !this.dialogPref, this.metric); |
| 204 }, | 204 }, |
| 205 | 205 |
| 206 /** @override */ | 206 /** @override */ |
| 207 updateStateFromPref: function(event) { | 207 updateStateFromPref: function(event) { |
| 208 if (!this.customPrefChangeHandler(event)) | 208 if (!this.customPrefChangeHandler(event)) |
| 209 this.defaultPrefChangeHandler(event); | 209 this.defaultPrefChangeHandler(event); |
| 210 }, | 210 }, |
| 211 | 211 |
| 212 /** | 212 /** |
| 213 * @param {Event} event A pref change event. | 213 * @param {Event} event A pref change event. |
| (...skipping 26 matching lines...) Expand all Loading... |
| 240 PrefInputElement.prototype.decorate.call(this); | 240 PrefInputElement.prototype.decorate.call(this); |
| 241 this.type = 'number'; | 241 this.type = 'number'; |
| 242 }, | 242 }, |
| 243 | 243 |
| 244 /** | 244 /** |
| 245 * Update the associated pref when the user inputs a number. | 245 * Update the associated pref when the user inputs a number. |
| 246 * @override | 246 * @override |
| 247 */ | 247 */ |
| 248 updatePrefFromState: function() { | 248 updatePrefFromState: function() { |
| 249 if (this.validity.valid) { | 249 if (this.validity.valid) { |
| 250 Preferences.setIntegerPref(this.pref, this.value, | 250 Preferences.setIntegerPref( |
| 251 !this.dialogPref, this.metric); | 251 this.pref, this.value, !this.dialogPref, this.metric); |
| 252 } | 252 } |
| 253 }, | 253 }, |
| 254 }; | 254 }; |
| 255 | 255 |
| 256 ///////////////////////////////////////////////////////////////////////////// | 256 ///////////////////////////////////////////////////////////////////////////// |
| 257 // PrefRadio class: | 257 // PrefRadio class: |
| 258 | 258 |
| 259 //Define a constructor that uses an input element as its underlying element. | 259 // Define a constructor that uses an input element as its underlying element. |
| 260 var PrefRadio = cr.ui.define('input'); | 260 var PrefRadio = cr.ui.define('input'); |
| 261 | 261 |
| 262 PrefRadio.prototype = { | 262 PrefRadio.prototype = { |
| 263 // Set up the prototype chain | 263 // Set up the prototype chain |
| 264 __proto__: PrefInputElement.prototype, | 264 __proto__: PrefInputElement.prototype, |
| 265 | 265 |
| 266 /** | 266 /** |
| 267 * Initialization function for the cr.ui framework. | 267 * Initialization function for the cr.ui framework. |
| 268 */ | 268 */ |
| 269 decorate: function() { | 269 decorate: function() { |
| 270 PrefInputElement.prototype.decorate.call(this); | 270 PrefInputElement.prototype.decorate.call(this); |
| 271 this.type = 'radio'; | 271 this.type = 'radio'; |
| 272 }, | 272 }, |
| 273 | 273 |
| 274 /** | 274 /** |
| 275 * Update the associated pref when when the user selects the radio button. | 275 * Update the associated pref when when the user selects the radio button. |
| 276 * @override | 276 * @override |
| 277 */ | 277 */ |
| 278 updatePrefFromState: function() { | 278 updatePrefFromState: function() { |
| 279 if (this.value == 'true' || this.value == 'false') { | 279 if (this.value == 'true' || this.value == 'false') { |
| 280 Preferences.setBooleanPref(this.pref, | 280 Preferences.setBooleanPref( |
| 281 this.value == String(this.checked), | 281 this.pref, this.value == String(this.checked), !this.dialogPref, |
| 282 !this.dialogPref, this.metric); | 282 this.metric); |
| 283 } else { | 283 } else { |
| 284 Preferences.setIntegerPref(this.pref, this.value, | 284 Preferences.setIntegerPref( |
| 285 !this.dialogPref, this.metric); | 285 this.pref, this.value, !this.dialogPref, this.metric); |
| 286 } | 286 } |
| 287 }, | 287 }, |
| 288 | 288 |
| 289 /** @override */ | 289 /** @override */ |
| 290 updateStateFromPref: function(event) { | 290 updateStateFromPref: function(event) { |
| 291 if (!this.customPrefChangeHandler(event)) | 291 if (!this.customPrefChangeHandler(event)) |
| 292 this.checked = this.value == String(event.value.value); | 292 this.checked = this.value == String(event.value.value); |
| 293 }, | 293 }, |
| 294 }; | 294 }; |
| 295 | 295 |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 328 this.addEventListener('touchcancel', this.handleRelease_.bind(this)); | 328 this.addEventListener('touchcancel', this.handleRelease_.bind(this)); |
| 329 this.addEventListener('touchend', this.handleRelease_.bind(this)); | 329 this.addEventListener('touchend', this.handleRelease_.bind(this)); |
| 330 }, | 330 }, |
| 331 | 331 |
| 332 /** | 332 /** |
| 333 * Update the associated pref when when the user releases the slider. | 333 * Update the associated pref when when the user releases the slider. |
| 334 * @override | 334 * @override |
| 335 */ | 335 */ |
| 336 updatePrefFromState: function() { | 336 updatePrefFromState: function() { |
| 337 Preferences.setIntegerPref( | 337 Preferences.setIntegerPref( |
| 338 this.pref, | 338 this.pref, this.mapPositionToPref(parseInt(this.value, 10)), |
| 339 this.mapPositionToPref(parseInt(this.value, 10)), | 339 !this.dialogPref, this.metric); |
| 340 !this.dialogPref, | |
| 341 this.metric); | |
| 342 }, | 340 }, |
| 343 | 341 |
| 344 /** @override */ | 342 /** @override */ |
| 345 handleChange: function() { | 343 handleChange: function() { |
| 346 // Ignore changes to the slider position made by the user while the slider | 344 // Ignore changes to the slider position made by the user while the slider |
| 347 // has not been released. | 345 // has not been released. |
| 348 }, | 346 }, |
| 349 | 347 |
| 350 /** | 348 /** |
| 351 * Handle changes to the slider position made by the user when the slider is | 349 * Handle changes to the slider position made by the user when the slider is |
| (...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 399 handleChange: PrefInputElement.prototype.handleChange, | 397 handleChange: PrefInputElement.prototype.handleChange, |
| 400 | 398 |
| 401 /** | 399 /** |
| 402 * Update the associated pref when when the user selects an item. | 400 * Update the associated pref when when the user selects an item. |
| 403 * @override | 401 * @override |
| 404 */ | 402 */ |
| 405 updatePrefFromState: function() { | 403 updatePrefFromState: function() { |
| 406 var value = this.options[this.selectedIndex].value; | 404 var value = this.options[this.selectedIndex].value; |
| 407 switch (this.dataType) { | 405 switch (this.dataType) { |
| 408 case 'number': | 406 case 'number': |
| 409 Preferences.setIntegerPref(this.pref, value, | 407 Preferences.setIntegerPref( |
| 410 !this.dialogPref, this.metric); | 408 this.pref, value, !this.dialogPref, this.metric); |
| 411 break; | 409 break; |
| 412 case 'double': | 410 case 'double': |
| 413 Preferences.setDoublePref(this.pref, value, | 411 Preferences.setDoublePref( |
| 414 !this.dialogPref, this.metric); | 412 this.pref, value, !this.dialogPref, this.metric); |
| 415 break; | 413 break; |
| 416 case 'boolean': | 414 case 'boolean': |
| 417 Preferences.setBooleanPref(this.pref, value == 'true', | 415 Preferences.setBooleanPref( |
| 418 !this.dialogPref, this.metric); | 416 this.pref, value == 'true', !this.dialogPref, this.metric); |
| 419 break; | 417 break; |
| 420 case 'string': | 418 case 'string': |
| 421 Preferences.setStringPref(this.pref, value, | 419 Preferences.setStringPref( |
| 422 !this.dialogPref, this.metric); | 420 this.pref, value, !this.dialogPref, this.metric); |
| 423 break; | 421 break; |
| 424 default: | 422 default: |
| 425 console.error('Unknown data type for <select> UI element: ' + | 423 console.error( |
| 426 this.dataType); | 424 'Unknown data type for <select> UI element: ' + this.dataType); |
| 427 } | 425 } |
| 428 }, | 426 }, |
| 429 | 427 |
| 430 /** @override */ | 428 /** @override */ |
| 431 updateStateFromPref: function(event) { | 429 updateStateFromPref: function(event) { |
| 432 if (this.customPrefChangeHandler(event)) | 430 if (this.customPrefChangeHandler(event)) |
| 433 return; | 431 return; |
| 434 | 432 |
| 435 // Make sure the value is a string, because the value is stored as a | 433 // Make sure the value is a string, because the value is stored as a |
| 436 // string in the HTMLOptionElement. | 434 // string in the HTMLOptionElement. |
| (...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 520 }); | 518 }); |
| 521 }, | 519 }, |
| 522 | 520 |
| 523 /** | 521 /** |
| 524 * Update the associated pref when when the user inputs text. | 522 * Update the associated pref when when the user inputs text. |
| 525 * @override | 523 * @override |
| 526 */ | 524 */ |
| 527 updatePrefFromState: function(event) { | 525 updatePrefFromState: function(event) { |
| 528 switch (this.dataType) { | 526 switch (this.dataType) { |
| 529 case 'number': | 527 case 'number': |
| 530 Preferences.setIntegerPref(this.pref, this.value, | 528 Preferences.setIntegerPref( |
| 531 !this.dialogPref, this.metric); | 529 this.pref, this.value, !this.dialogPref, this.metric); |
| 532 break; | 530 break; |
| 533 case 'double': | 531 case 'double': |
| 534 Preferences.setDoublePref(this.pref, this.value, | 532 Preferences.setDoublePref( |
| 535 !this.dialogPref, this.metric); | 533 this.pref, this.value, !this.dialogPref, this.metric); |
| 536 break; | 534 break; |
| 537 case 'url': | 535 case 'url': |
| 538 Preferences.setURLPref(this.pref, this.value, | 536 Preferences.setURLPref( |
| 539 !this.dialogPref, this.metric); | 537 this.pref, this.value, !this.dialogPref, this.metric); |
| 540 break; | 538 break; |
| 541 default: | 539 default: |
| 542 Preferences.setStringPref(this.pref, this.value, | 540 Preferences.setStringPref( |
| 543 !this.dialogPref, this.metric); | 541 this.pref, this.value, !this.dialogPref, this.metric); |
| 544 break; | 542 break; |
| 545 } | 543 } |
| 546 }, | 544 }, |
| 547 }; | 545 }; |
| 548 | 546 |
| 549 ///////////////////////////////////////////////////////////////////////////// | 547 ///////////////////////////////////////////////////////////////////////////// |
| 550 // PrefPortNumber class: | 548 // PrefPortNumber class: |
| 551 | 549 |
| 552 // Define a constructor that uses an input element as its underlying element. | 550 // Define a constructor that uses an input element as its underlying element. |
| 553 var PrefPortNumber = cr.ui.define('input'); | 551 var PrefPortNumber = cr.ui.define('input'); |
| (...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 592 decorate: function() { | 590 decorate: function() { |
| 593 var self = this; | 591 var self = this; |
| 594 | 592 |
| 595 // Listen for pref changes. | 593 // Listen for pref changes. |
| 596 // This element behaves like a normal button and does not affect the | 594 // This element behaves like a normal button and does not affect the |
| 597 // underlying preference; it just becomes disabled when the preference is | 595 // underlying preference; it just becomes disabled when the preference is |
| 598 // managed, and its value is false. This is useful for buttons that should | 596 // managed, and its value is false. This is useful for buttons that should |
| 599 // be disabled when the underlying Boolean preference is set to false by a | 597 // be disabled when the underlying Boolean preference is set to false by a |
| 600 // policy or extension. | 598 // policy or extension. |
| 601 Preferences.getInstance().addEventListener(this.pref, function(event) { | 599 Preferences.getInstance().addEventListener(this.pref, function(event) { |
| 602 updateDisabledState(self, 'notUserModifiable', | 600 updateDisabledState( |
| 603 event.value.disabled && !event.value.value); | 601 self, 'notUserModifiable', |
| 602 event.value.disabled && !event.value.value); |
| 604 self.controlledBy = event.value.controlledBy; | 603 self.controlledBy = event.value.controlledBy; |
| 605 }); | 604 }); |
| 606 }, | 605 }, |
| 607 | 606 |
| 608 /** | 607 /** |
| 609 * See |updateDisabledState| above. | 608 * See |updateDisabledState| above. |
| 610 */ | 609 */ |
| 611 setDisabled: function(reason, disabled) { | 610 setDisabled: function(reason, disabled) { |
| 612 updateDisabledState(this, reason, disabled); | 611 updateDisabledState(this, reason, disabled); |
| 613 }, | 612 }, |
| (...skipping 16 matching lines...) Expand all Loading... |
| 630 PrefInputElement: PrefInputElement, | 629 PrefInputElement: PrefInputElement, |
| 631 PrefNumber: PrefNumber, | 630 PrefNumber: PrefNumber, |
| 632 PrefRadio: PrefRadio, | 631 PrefRadio: PrefRadio, |
| 633 PrefRange: PrefRange, | 632 PrefRange: PrefRange, |
| 634 PrefSelect: PrefSelect, | 633 PrefSelect: PrefSelect, |
| 635 PrefTextField: PrefTextField, | 634 PrefTextField: PrefTextField, |
| 636 PrefPortNumber: PrefPortNumber, | 635 PrefPortNumber: PrefPortNumber, |
| 637 PrefButton: PrefButton | 636 PrefButton: PrefButton |
| 638 }; | 637 }; |
| 639 }); | 638 }); |
| OLD | NEW |