Chromium Code Reviews| Index: chrome/browser/resources/settings/controls/settings_boolean_control_behavior.js |
| diff --git a/chrome/browser/resources/settings/controls/settings_boolean_control_behavior.js b/chrome/browser/resources/settings/controls/settings_boolean_control_behavior.js |
| index 248397e3f782e6efefb3e63c957bd43b129c1bc5..1cdb89cf793d974a88ed4d8055a21a5d76c88f86 100644 |
| --- a/chrome/browser/resources/settings/controls/settings_boolean_control_behavior.js |
| +++ b/chrome/browser/resources/settings/controls/settings_boolean_control_behavior.js |
| @@ -22,7 +22,6 @@ var SettingsBooleanControlBehaviorImpl = { |
| type: Boolean, |
| value: false, |
| notify: true, |
| - observer: 'checkedChanged_', |
| reflectToAttribute: true, |
| }, |
| @@ -55,6 +54,17 @@ var SettingsBooleanControlBehaviorImpl = { |
| type: String, |
| value: '', |
| }, |
| + |
| + /** |
| + * For numeric prefs only, the integer value equivalent to the unchecked |
| + * state. This is the value sent to prefs if the user unchecks the control. |
| + * During initialization, the control is unchecked if and only if the pref |
| + * value is equal to the this value. (Values 2, 3, 4, etc. all are checked.) |
| + */ |
| + numericUncheckedValue: { |
|
Dan Beam
2017/02/15 23:25:53
nit: does readOnly: true, work here?
tommycli
2017/02/15 23:36:52
Done. Did a quick scan of the code. Doesn't look l
|
| + type: Number, |
| + value: 0, |
| + } |
| }, |
| observers: [ |
| @@ -63,6 +73,10 @@ var SettingsBooleanControlBehaviorImpl = { |
| notifyChangedByUserInteraction: function() { |
| this.fire('settings-boolean-control-change'); |
| + |
| + if (!this.pref || this.noSetPref) |
| + return; |
| + this.sendPrefChange(); |
| }, |
| /** Reset the checked state to match the current pref value. */ |
| @@ -72,14 +86,13 @@ var SettingsBooleanControlBehaviorImpl = { |
| /** Update the pref to the current |checked| value. */ |
| sendPrefChange: function() { |
| - /** @type {boolean} */ var newValue = this.getNewValue_(this.checked); |
| // Ensure that newValue is the correct type for the pref type, either |
| // a boolean or a number. |
| if (this.pref.type == chrome.settingsPrivate.PrefType.NUMBER) { |
| - this.set('pref.value', newValue ? 1 : 0); |
| + this.set('pref.value', this.checked ? 1 : this.numericUncheckedValue); |
| return; |
| } |
| - this.set('pref.value', newValue); |
| + this.set('pref.value', this.checked); |
| }, |
| /** |
| @@ -92,21 +105,16 @@ var SettingsBooleanControlBehaviorImpl = { |
| }, |
| /** |
| - * Polymer observer for checked. |
| - * @private |
| - */ |
| - checkedChanged_: function() { |
| - if (!this.pref || this.noSetPref) |
| - return; |
| - this.sendPrefChange(); |
| - }, |
| - |
| - /** |
| * @param {*} value |
| * @return {boolean} The value as a boolean, inverted if |inverted| is true. |
| * @private |
| */ |
| getNewValue_: function(value) { |
| + // For numeric prefs, the control is only false if the value is exactly |
| + // equal to the unchecked-equivalent value. |
| + if (this.pref.type == chrome.settingsPrivate.PrefType.NUMBER) |
| + value = value != this.numericUncheckedValue; |
| + |
| return this.inverted ? !value : !!value; |
| }, |