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 372 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
383 }; | 383 }; |
384 | 384 |
385 ///////////////////////////////////////////////////////////////////////////// | 385 ///////////////////////////////////////////////////////////////////////////// |
386 // PrefSelect class: | 386 // PrefSelect class: |
387 | 387 |
388 // Define a constructor that uses a select element as its underlying element. | 388 // Define a constructor that uses a select element as its underlying element. |
389 var PrefSelect = cr.ui.define('select'); | 389 var PrefSelect = cr.ui.define('select'); |
390 | 390 |
391 PrefSelect.prototype = { | 391 PrefSelect.prototype = { |
392 // Set up the prototype chain | 392 // Set up the prototype chain |
393 __proto__: PrefInputElement.prototype, | 393 __proto__: HTMLSelectElement.prototype, |
Dan Beam
2015/04/20 15:06:26
keep in mind that settings is being rewritten acti
arv (Not doing code reviews)
2015/04/24 14:22:45
With ES6 you can do traits.
function PrefTrait(su
Yuki
2015/04/27 09:22:38
Looks cool to me. I defer this re-design task to
| |
394 | |
395 /** | |
396 * Initialization function for the cr.ui framework. | |
397 */ | |
398 decorate: PrefInputElement.prototype.decorate, | |
399 | |
400 /** | |
401 * Handle changes to the input element's state made by the user. If a custom | |
402 * change handler does not suppress it, a default handler is invoked that | |
403 * updates the associated pref. | |
404 * @param {Event} event Change event. | |
405 * @protected | |
406 */ | |
407 handleChange: PrefInputElement.prototype.handleChange, | |
394 | 408 |
395 /** | 409 /** |
396 * Update the associated pref when when the user selects an item. | 410 * Update the associated pref when when the user selects an item. |
397 * @override | 411 * @override |
398 */ | 412 */ |
399 updatePrefFromState: function() { | 413 updatePrefFromState: function() { |
400 var value = this.options[this.selectedIndex].value; | 414 var value = this.options[this.selectedIndex].value; |
401 switch (this.dataType) { | 415 switch (this.dataType) { |
402 case 'number': | 416 case 'number': |
403 Preferences.setIntegerPref(this.pref, value, | 417 Preferences.setIntegerPref(this.pref, value, |
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
442 if (!found) | 456 if (!found) |
443 this.selectedIndex = 0; | 457 this.selectedIndex = 0; |
444 | 458 |
445 // The "onchange" event automatically fires when the user makes a manual | 459 // The "onchange" event automatically fires when the user makes a manual |
446 // change. It should never be fired for a programmatic change. However, | 460 // change. It should never be fired for a programmatic change. However, |
447 // these two lines were here already and it is hard to tell who may be | 461 // these two lines were here already and it is hard to tell who may be |
448 // relying on them. | 462 // relying on them. |
449 if (this.onchange) | 463 if (this.onchange) |
450 this.onchange(event); | 464 this.onchange(event); |
451 }, | 465 }, |
466 | |
467 /** | |
468 * See |updateDisabledState| above. | |
469 */ | |
470 setDisabled: PrefInputElement.prototype.setDisabled, | |
471 | |
472 /** | |
473 * Custom change handler that is invoked first when the user makes changes | |
arv (Not doing code reviews)
2015/04/24 14:22:45
Are these comments just copied from PrefInputEleme
Dan Beam
2015/04/24 21:48:29
or [just] @override
Yuki
2015/04/27 09:22:38
Done.
| |
474 * to the input element's state. If it returns false, a default handler is | |
475 * invoked next that updates the associated pref. If it returns true, the | |
476 * default handler is suppressed (i.e., this works like stopPropagation or | |
477 * cancelBubble). | |
478 * @param {Event} event Input element change event. | |
479 */ | |
480 customChangeHandler: PrefInputElement.prototype.customChangeHandler, | |
481 | |
482 /** | |
483 * Custom change handler that is invoked first when the preference | |
484 * associated with the input element changes. If it returns false, a default | |
485 * handler is invoked next that updates the input element. If it returns | |
486 * true, the default handler is suppressed. | |
487 * @param {Event} event Input element change event. | |
488 */ | |
489 customPrefChangeHandler: PrefInputElement.prototype.customPrefChangeHandler, | |
452 }; | 490 }; |
453 | 491 |
492 /** | |
493 * The name of the associated preference. | |
494 */ | |
495 cr.defineProperty(PrefSelect, 'pref', cr.PropertyKind.ATTR); | |
496 | |
497 /** | |
498 * The data type of the associated preference, only relevant for derived | |
499 * classes that support different data types. | |
500 */ | |
501 cr.defineProperty(PrefSelect, 'dataType', cr.PropertyKind.ATTR); | |
502 | |
503 /** | |
504 * Whether this input element is part of a dialog. If so, changes take effect | |
505 * in the settings UI immediately but are only actually committed when the | |
506 * user confirms the dialog. If the user cancels the dialog instead, the | |
507 * changes are rolled back in the settings UI and never committed. | |
508 */ | |
509 cr.defineProperty(PrefSelect, 'dialogPref', cr.PropertyKind.BOOL_ATTR); | |
510 | |
511 /** | |
512 * Whether the associated preference is controlled by a source other than the | |
513 * user's setting (can be 'policy', 'extension', 'recommended' or unset). | |
514 */ | |
515 cr.defineProperty(PrefSelect, 'controlledBy', cr.PropertyKind.ATTR); | |
516 | |
517 /** | |
518 * The user metric string. | |
519 */ | |
520 cr.defineProperty(PrefSelect, 'metric', cr.PropertyKind.ATTR); | |
521 | |
454 ///////////////////////////////////////////////////////////////////////////// | 522 ///////////////////////////////////////////////////////////////////////////// |
455 // PrefTextField class: | 523 // PrefTextField class: |
456 | 524 |
457 // Define a constructor that uses an input element as its underlying element. | 525 // Define a constructor that uses an input element as its underlying element. |
458 var PrefTextField = cr.ui.define('input'); | 526 var PrefTextField = cr.ui.define('input'); |
459 | 527 |
460 PrefTextField.prototype = { | 528 PrefTextField.prototype = { |
461 // Set up the prototype chain | 529 // Set up the prototype chain |
462 __proto__: PrefInputElement.prototype, | 530 __proto__: PrefInputElement.prototype, |
463 | 531 |
(...skipping 121 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
585 PrefInputElement: PrefInputElement, | 653 PrefInputElement: PrefInputElement, |
586 PrefNumber: PrefNumber, | 654 PrefNumber: PrefNumber, |
587 PrefRadio: PrefRadio, | 655 PrefRadio: PrefRadio, |
588 PrefRange: PrefRange, | 656 PrefRange: PrefRange, |
589 PrefSelect: PrefSelect, | 657 PrefSelect: PrefSelect, |
590 PrefTextField: PrefTextField, | 658 PrefTextField: PrefTextField, |
591 PrefPortNumber: PrefPortNumber, | 659 PrefPortNumber: PrefPortNumber, |
592 PrefButton: PrefButton | 660 PrefButton: PrefButton |
593 }; | 661 }; |
594 }); | 662 }); |
OLD | NEW |