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

Unified Diff: chrome/browser/resources/settings/controls/settings_boolean_control_behavior.js

Issue 2499483002: MD Settings: Internet: Allow Shared Proxies (Closed)
Patch Set: Created 4 years, 1 month 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 side-by-side diff with in-line comments
Download patch
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 c33553b68b6d6fabe226f6be2493f17aac81d4e3..cb2c265563a138aec9ff7a4031a0ad0c82fbe9d7 100644
--- a/chrome/browser/resources/settings/controls/settings_boolean_control_behavior.js
+++ b/chrome/browser/resources/settings/controls/settings_boolean_control_behavior.js
@@ -23,7 +23,7 @@ var SettingsBooleanControlBehaviorImpl = {
value: false,
notify: true,
observer: 'checkedChanged_',
- reflectToAttribute: true
+ reflectToAttribute: true,
},
/** Disabled property for the element. */
@@ -31,7 +31,18 @@ var SettingsBooleanControlBehaviorImpl = {
type: Boolean,
value: false,
notify: true,
- reflectToAttribute: true
+ reflectToAttribute: true,
+ },
+
+ /**
+ * If true, do not automatically set the preference value. This allows the
+ * container to confirm the change first then call either sendPrefChange
+ * or resetToPrefValue accordingly.
+ */
+ noSetPref: {
+ type: Boolean,
+ value: false,
+ reflectToAttribute: true,
michaelpg 2016/11/15 22:22:04 Unnecessary unless you're styling based on this or
stevenjb 2016/11/17 01:43:28 Done.
},
/** The main label. */
@@ -48,9 +59,26 @@ var SettingsBooleanControlBehaviorImpl = {
},
observers: [
- 'prefValueChanged_(pref.value)'
+ 'prefValueChanged_(pref.value)',
],
+ /** Reset the checked state to match the current pref value. */
+ resetToPrefValue: function() {
+ this.checked = this.getNewValue_(this.pref.value);
+ },
+
+ /** 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);
+ return;
+ }
+ this.set('pref.value', newValue);
+ },
+
/**
* Polymer observer for pref.value.
* @param {*} prefValue
@@ -65,16 +93,9 @@ var SettingsBooleanControlBehaviorImpl = {
* @private
*/
checkedChanged_: function() {
- if (!this.pref)
- return;
- /** @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);
+ if (!this.pref || this.noSetPref)
return;
- }
- this.set('pref.value', newValue);
+ this.sendPrefChange();
},
/**

Powered by Google App Engine
This is Rietveld 408576698