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 d15e3eb48f89f815c66809f0a8a898369fbe38e8..be353b56e2723a9561ed40dfc3762de81159ef2f 100644 |
| --- a/chrome/browser/resources/settings/controls/settings_boolean_control_behavior.js |
| +++ b/chrome/browser/resources/settings/controls/settings_boolean_control_behavior.js |
| @@ -55,6 +55,26 @@ var SettingsBooleanControlBehaviorImpl = { |
| type: String, |
| value: '', |
| }, |
| + |
| + /** |
| + * For numeric prefs only, the integer value equivalent to the checked |
| + * state. This is the value sent to prefs if the user checks the control. |
| + */ |
| + numericCheckedValue: { |
| + type: Number, |
| + value: 1, |
| + }, |
| + |
| + /** |
| + * 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: { |
| + type: Number, |
| + value: 0, |
| + } |
|
Dan Beam
2017/02/09 18:39:10
can we only add numericUncheckedValue until we nee
tommycli
2017/02/09 19:19:22
Done.
But I can't make this a plain prototype mem
|
| }, |
| observers: [ |
| @@ -68,14 +88,14 @@ 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 ? this.numericCheckedValue : |
| + this.numericUncheckedValue); |
| return; |
| } |
| - this.set('pref.value', newValue); |
| + this.set('pref.value', this.checked); |
| }, |
| /** |
| @@ -103,6 +123,11 @@ var SettingsBooleanControlBehaviorImpl = { |
| * @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; |
| }, |