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

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 the merge 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 unchecked
61 * state. This is the value sent to prefs if the user unchecks the control.
62 * During initialization, the control is unchecked if and only if the pref
63 * value is equal to the this value. (Values 2, 3, 4, etc. all are checked.)
64 */
65 numericUncheckedValue: {
66 type: Number,
67 value: 0,
68 }
58 }, 69 },
59 70
60 observers: [ 71 observers: [
61 'prefValueChanged_(pref.value)', 72 'prefValueChanged_(pref.value)',
62 ], 73 ],
63 74
64 /** Reset the checked state to match the current pref value. */ 75 /** Reset the checked state to match the current pref value. */
65 resetToPrefValue: function() { 76 resetToPrefValue: function() {
66 this.checked = this.getNewValue_(this.pref.value); 77 this.checked = this.getNewValue_(this.pref.value);
67 }, 78 },
68 79
69 /** Update the pref to the current |checked| value. */ 80 /** Update the pref to the current |checked| value. */
70 sendPrefChange: function() { 81 sendPrefChange: function() {
71 /** @type {boolean} */ var newValue = this.getNewValue_(this.checked);
72 // Ensure that newValue is the correct type for the pref type, either 82 // Ensure that newValue is the correct type for the pref type, either
73 // a boolean or a number. 83 // a boolean or a number.
74 if (this.pref.type == chrome.settingsPrivate.PrefType.NUMBER) { 84 if (this.pref.type == chrome.settingsPrivate.PrefType.NUMBER) {
75 this.set('pref.value', newValue ? 1 : 0); 85 this.set('pref.value', this.checked ? 1 : this.numericUncheckedValue);
76 return; 86 return;
77 } 87 }
78 this.set('pref.value', newValue); 88 this.set('pref.value', this.checked);
79 }, 89 },
80 90
81 /** 91 /**
82 * Polymer observer for pref.value. 92 * Polymer observer for pref.value.
83 * @param {*} prefValue 93 * @param {*} prefValue
84 * @private 94 * @private
85 */ 95 */
86 prefValueChanged_: function(prefValue) { 96 prefValueChanged_: function(prefValue) {
87 this.checked = this.getNewValue_(prefValue); 97 this.checked = this.getNewValue_(prefValue);
88 }, 98 },
89 99
90 /** 100 /**
91 * Polymer observer for checked. 101 * Polymer observer for checked.
92 * @private 102 * @private
93 */ 103 */
94 checkedChanged_: function() { 104 checkedChanged_: function() {
95 if (!this.pref || this.noSetPref) 105 if (!this.pref || this.noSetPref)
96 return; 106 return;
97 this.sendPrefChange(); 107 this.sendPrefChange();
98 }, 108 },
99 109
100 /** 110 /**
101 * @param {*} value 111 * @param {*} value
102 * @return {boolean} The value as a boolean, inverted if |inverted| is true. 112 * @return {boolean} The value as a boolean, inverted if |inverted| is true.
103 * @private 113 * @private
104 */ 114 */
105 getNewValue_: function(value) { 115 getNewValue_: function(value) {
116 // For numeric prefs, the control is only false if the value is exactly
117 // equal to the unchecked-equivalent value.
118 if (this.pref.type == chrome.settingsPrivate.PrefType.NUMBER)
119 value = value != this.numericUncheckedValue;
120
106 return this.inverted ? !value : !!value; 121 return this.inverted ? !value : !!value;
107 }, 122 },
108 123
109 /** 124 /**
110 * @return {boolean} Whether the checkbox should be disabled. 125 * @return {boolean} Whether the checkbox should be disabled.
111 * @private 126 * @private
112 */ 127 */
113 controlDisabled_: function() { 128 controlDisabled_: function() {
114 return this.disabled || this.isPrefPolicyControlled(assert(this.pref)); 129 return this.disabled || this.isPrefPolicyControlled(assert(this.pref));
115 }, 130 },
116 }; 131 };
117 132
118 /** @polymerBehavior */ 133 /** @polymerBehavior */
119 var SettingsBooleanControlBehavior = [ 134 var SettingsBooleanControlBehavior = [
120 CrPolicyPrefBehavior, 135 CrPolicyPrefBehavior,
121 PrefControlBehavior, 136 PrefControlBehavior,
122 SettingsBooleanControlBehaviorImpl, 137 SettingsBooleanControlBehaviorImpl,
123 ]; 138 ];
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