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

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

Issue 2718253006: MD Settings: checkbox: Support inverted when setting pref (Closed)
Patch Set: Rebase Created 3 years, 9 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/test/data/webui/settings/settings_toggle_button_tests.js » ('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 72 matching lines...) Expand 10 before | Expand all | Expand 10 after
83 /** Reset the checked state to match the current pref value. */ 83 /** Reset the checked state to match the current pref value. */
84 resetToPrefValue: function() { 84 resetToPrefValue: function() {
85 this.checked = this.getNewValue_(this.pref.value); 85 this.checked = this.getNewValue_(this.pref.value);
86 }, 86 },
87 87
88 /** Update the pref to the current |checked| value. */ 88 /** Update the pref to the current |checked| value. */
89 sendPrefChange: function() { 89 sendPrefChange: function() {
90 // Ensure that newValue is the correct type for the pref type, either 90 // Ensure that newValue is the correct type for the pref type, either
91 // a boolean or a number. 91 // a boolean or a number.
92 if (this.pref.type == chrome.settingsPrivate.PrefType.NUMBER) { 92 if (this.pref.type == chrome.settingsPrivate.PrefType.NUMBER) {
93 assert(!this.inverted);
93 this.set('pref.value', this.checked ? 1 : this.numericUncheckedValue); 94 this.set('pref.value', this.checked ? 1 : this.numericUncheckedValue);
94 return; 95 return;
95 } 96 }
96 this.set('pref.value', this.checked); 97 this.set('pref.value', this.inverted ? !this.checked : this.checked);
97 }, 98 },
98 99
99 /** 100 /**
100 * Polymer observer for pref.value. 101 * Polymer observer for pref.value.
101 * @param {*} prefValue 102 * @param {*} prefValue
102 * @private 103 * @private
103 */ 104 */
104 prefValueChanged_: function(prefValue) { 105 prefValueChanged_: function(prefValue) {
105 this.checked = this.getNewValue_(prefValue); 106 this.checked = this.getNewValue_(prefValue);
106 }, 107 },
107 108
108 /** 109 /**
109 * @param {*} value 110 * @param {*} value
110 * @return {boolean} The value as a boolean, inverted if |inverted| is true. 111 * @return {boolean} The value as a boolean, inverted if |inverted| is true.
111 * @private 112 * @private
112 */ 113 */
113 getNewValue_: function(value) { 114 getNewValue_: function(value) {
114 // For numeric prefs, the control is only false if the value is exactly 115 // For numeric prefs, the control is only false if the value is exactly
115 // equal to the unchecked-equivalent value. 116 // equal to the unchecked-equivalent value.
116 if (this.pref.type == chrome.settingsPrivate.PrefType.NUMBER) 117 if (this.pref.type == chrome.settingsPrivate.PrefType.NUMBER) {
117 value = value != this.numericUncheckedValue; 118 assert(!this.inverted);
118 119 return value != this.numericUncheckedValue;
120 }
119 return this.inverted ? !value : !!value; 121 return this.inverted ? !value : !!value;
120 }, 122 },
121 123
122 /** 124 /**
123 * @return {boolean} Whether the checkbox should be disabled. 125 * @return {boolean} Whether the checkbox should be disabled.
124 * @private 126 * @private
125 */ 127 */
126 controlDisabled_: function() { 128 controlDisabled_: function() {
127 return this.disabled || this.isPrefPolicyControlled(); 129 return this.disabled || this.isPrefPolicyControlled();
128 }, 130 },
129 }; 131 };
130 132
131 /** @polymerBehavior */ 133 /** @polymerBehavior */
132 var SettingsBooleanControlBehavior = [ 134 var SettingsBooleanControlBehavior = [
133 CrPolicyPrefBehavior, 135 CrPolicyPrefBehavior,
134 PrefControlBehavior, 136 PrefControlBehavior,
135 SettingsBooleanControlBehaviorImpl, 137 SettingsBooleanControlBehaviorImpl,
136 ]; 138 ];
OLDNEW
« no previous file with comments | « no previous file | chrome/test/data/webui/settings/settings_toggle_button_tests.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698