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

Unified Diff: chrome/browser/resources/settings/checkbox/checkbox.js

Issue 1310373008: Add cr_policy_indicator for settings controls (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@md_settings_compiled_resources_3
Patch Set: Revert unrelated changes Created 5 years, 3 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 side-by-side diff with in-line comments
Download patch
Index: chrome/browser/resources/settings/checkbox/checkbox.js
diff --git a/chrome/browser/resources/settings/checkbox/checkbox.js b/chrome/browser/resources/settings/checkbox/checkbox.js
index 2109aba704b116f176e0fb79a4e7f9dc2c25dd2f..f70d993bd154eb83baf3a79085b9fcafcc9dfaa5 100644
--- a/chrome/browser/resources/settings/checkbox/checkbox.js
+++ b/chrome/browser/resources/settings/checkbox/checkbox.js
@@ -24,25 +24,45 @@ Polymer({
pref: {
type: Object,
notify: true,
- value: null
+ value: null,
},
+ /** Whether the checkbox should represent the inverted value. */
inverted: {
type: Boolean,
- value: false
+ value: false,
},
+ /** Whether the checkbox is checked. */
checked: {
type: Boolean,
value: false,
- observer: 'checkedChanged_'
+ observer: 'checkedChanged_',
+ },
+
+ /** Set to disable the element programatically. */
michaelpg 2015/09/14 05:14:51 programatically... or via HTML, like any other pro
stevenjb 2015/09/14 23:05:31 Simplified not that checkboxDisabled_ is a method.
+ disabled: {
+ type: Boolean,
+ value: false,
+ observer: 'disabledChanged_',
+ },
+
+ /**
+ * Internal disabled state of the checkbox. Always false if |disabled| is
+ * false, otherwise may be set to false by a pref policy.
michaelpg 2015/09/14 05:14:51 if you're going to keep this, make it @private
stevenjb 2015/09/14 23:05:31 Acknowledged.
+ */
+ checkboxDisabled: {
+ type: Boolean,
+ value: false,
},
+ /** Checkbox label. */
label: {
type: String,
value: '',
},
+ /** Additional sub-label for the checkbox. */
subLabel: {
type: String,
value: '',
@@ -50,7 +70,7 @@ Polymer({
},
observers: [
- 'prefValueChanged_(pref.value)'
+ 'prefPropertyChanged_(pref.*)'
],
/** @override */
@@ -58,23 +78,61 @@ Polymer({
this.$.events.forward(this.$.checkbox, ['change']);
},
- /** @private */
- prefValueChanged_: function(prefValue) {
- // prefValue is initially undefined when Polymer initializes pref.
- if (prefValue !== undefined) {
- this.checked = this.getNewValue_(prefValue);
+ /**
+ * Polymer observer for pref.
+ * @param {?{path: string, value: *}} change
+ * @private
+ */
+ prefPropertyChanged_: function(change) {
+ if (!this.pref)
+ return;
+ var path = change.path;
+ if (path == 'pref' || path == 'pref.value') {
+ this.checked = this.getNewValue_(this.pref.value);
+ }
+ if (path == 'pref' || path == 'pref.policySource' ||
+ path == 'pref.policyEnforcement') {
+ this.checkboxDisabled =
+ this.disabled || this.isSettingDisabled_(this.pref);
}
},
- /** @private */
+ /**
+ * Polymer observer for checked.
+ * @private
+ */
checkedChanged_: function() {
- if (this.pref) {
- this.set('pref.value', this.getNewValue_(this.checked));
- }
+ if (!this.pref)
+ return;
+ this.set('pref.value', this.getNewValue_(this.checked));
michaelpg 2015/09/14 05:14:51 this.set('pref.value', foo) does nothing if this.p
stevenjb 2015/09/14 23:05:31 I only changed this to match disabledChanged_, whi
},
- /** @private */
- getNewValue_: function(val) {
- return this.inverted ? !val : val;
- }
+ /**
+ * Polymer observer for disabled.
+ * @private
+ */
+ disabledChanged_: function() {
+ if (!this.pref)
+ return;
+ this.checkboxDisabled = this.disabled || this.isSettingDisabled_(this.pref);
+ },
+
+ /**
+ * @param {*} value
+ * @return {boolean} The value as a boolean, inverted if |inverted| is true.
+ * @private
+ */
+ getNewValue_: function(value) {
+ return this.inverted ? !value : !!value;
+ },
+
+ /**
+ * @param {?chrome.settingsPrivate.PrefObject} pref
+ * @return {boolean} True if the setting is either explicitly disabled, or
+ * disabled by the policyEnforcement property.
+ */
+ isSettingDisabled_: function(pref) {
+ return !!pref && pref.policyEnforcement ==
+ chrome.settingsPrivate.PolicyEnforcement.ENFORCED;
+ },
});

Powered by Google App Engine
This is Rietveld 408576698