Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(76)

Side by Side Diff: chrome/browser/resources/settings/controls/settings_boolean_control_behavior.js

Issue 2681373002: MD Settings: Fix the Network Prediction toggle box. (Closed)
Patch Set: fix comment Created 3 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | chrome/browser/resources/settings/privacy_page/privacy_page.html » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2016 The Chromium Authors. All rights reserved. 1 // Copyright 2016 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 /** 5 /**
6 * @fileoverview 6 * @fileoverview
7 * A behavior to help controls that handle a boolean preference, such as 7 * A behavior to help controls that handle a boolean preference, such as
8 * checkbox and toggle button. 8 * checkbox and toggle button.
9 */ 9 */
10 10
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
48 label: { 48 label: {
49 type: String, 49 type: String,
50 value: '', 50 value: '',
51 }, 51 },
52 52
53 /** Additional (optional) sub-label. */ 53 /** Additional (optional) sub-label. */
54 subLabel: { 54 subLabel: {
55 type: String, 55 type: String,
56 value: '', 56 value: '',
57 }, 57 },
58
59 /**
60 * For numeric prefs only, the integer value equivalent to the checked
61 * state. This is the value sent to prefs if the user checks the control.
62 */
63 numericCheckedValue: {
64 type: Number,
65 value: 1,
66 },
67
68 /**
69 * For numeric prefs only, the integer value equivalent to the unchecked
70 * state. This is the value sent to prefs if the user unchecks the control.
71 * During initialization, the control is unchecked if and only if the pref
72 * value is equal to the this value. (Values 2, 3, 4, etc. all are checked.)
73 */
74 numericUncheckedValue: {
75 type: Number,
76 value: 0,
77 }
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
58 }, 78 },
59 79
60 observers: [ 80 observers: [
61 'prefValueChanged_(pref.value)', 81 'prefValueChanged_(pref.value)',
62 ], 82 ],
63 83
64 /** Reset the checked state to match the current pref value. */ 84 /** Reset the checked state to match the current pref value. */
65 resetToPrefValue: function() { 85 resetToPrefValue: function() {
66 this.checked = this.getNewValue_(this.pref.value); 86 this.checked = this.getNewValue_(this.pref.value);
67 }, 87 },
68 88
69 /** Update the pref to the current |checked| value. */ 89 /** Update the pref to the current |checked| value. */
70 sendPrefChange: function() { 90 sendPrefChange: function() {
71 /** @type {boolean} */ var newValue = this.getNewValue_(this.checked);
72 // Ensure that newValue is the correct type for the pref type, either 91 // Ensure that newValue is the correct type for the pref type, either
73 // a boolean or a number. 92 // a boolean or a number.
74 if (this.pref.type == chrome.settingsPrivate.PrefType.NUMBER) { 93 if (this.pref.type == chrome.settingsPrivate.PrefType.NUMBER) {
75 this.set('pref.value', newValue ? 1 : 0); 94 this.set('pref.value', this.checked ? this.numericCheckedValue :
95 this.numericUncheckedValue);
76 return; 96 return;
77 } 97 }
78 this.set('pref.value', newValue); 98 this.set('pref.value', this.checked);
79 }, 99 },
80 100
81 /** 101 /**
82 * Polymer observer for pref.value. 102 * Polymer observer for pref.value.
83 * @param {*} prefValue 103 * @param {*} prefValue
84 * @private 104 * @private
85 */ 105 */
86 prefValueChanged_: function(prefValue) { 106 prefValueChanged_: function(prefValue) {
87 this.checked = this.getNewValue_(prefValue); 107 this.checked = this.getNewValue_(prefValue);
88 }, 108 },
89 109
90 /** 110 /**
91 * Polymer observer for checked. 111 * Polymer observer for checked.
92 * @private 112 * @private
93 */ 113 */
94 checkedChanged_: function() { 114 checkedChanged_: function() {
95 if (!this.pref || this.noSetPref) 115 if (!this.pref || this.noSetPref)
96 return; 116 return;
97 this.sendPrefChange(); 117 this.sendPrefChange();
98 }, 118 },
99 119
100 /** 120 /**
101 * @param {*} value 121 * @param {*} value
102 * @return {boolean} The value as a boolean, inverted if |inverted| is true. 122 * @return {boolean} The value as a boolean, inverted if |inverted| is true.
103 * @private 123 * @private
104 */ 124 */
105 getNewValue_: function(value) { 125 getNewValue_: function(value) {
126 // For numeric prefs, the control is only false if the value is exactly
127 // equal to the unchecked-equivalent value.
128 if (this.pref.type == chrome.settingsPrivate.PrefType.NUMBER)
129 value = value != this.numericUncheckedValue;
130
106 return this.inverted ? !value : !!value; 131 return this.inverted ? !value : !!value;
107 }, 132 },
108 133
109 /** 134 /**
110 * @return {boolean} Whether the checkbox should be disabled. 135 * @return {boolean} Whether the checkbox should be disabled.
111 * @private 136 * @private
112 */ 137 */
113 controlDisabled_: function() { 138 controlDisabled_: function() {
114 return this.disabled || this.isPrefPolicyControlled(assert(this.pref)); 139 return this.disabled || this.isPrefPolicyControlled(assert(this.pref));
115 }, 140 },
116 }; 141 };
117 142
118 /** @polymerBehavior */ 143 /** @polymerBehavior */
119 var SettingsBooleanControlBehavior = [ 144 var SettingsBooleanControlBehavior = [
120 CrPolicyPrefBehavior, 145 CrPolicyPrefBehavior,
121 PrefControlBehavior, 146 PrefControlBehavior,
122 SettingsBooleanControlBehaviorImpl, 147 SettingsBooleanControlBehaviorImpl,
123 ]; 148 ];
OLDNEW
« no previous file with comments | « no previous file | chrome/browser/resources/settings/privacy_page/privacy_page.html » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698