Vectorize sad tab image.
[chromium-blink-merge.git] / chrome / browser / resources / settings / checkbox / checkbox.js
blob49ebb3ab3fa8d1c5b982b250810bc82f0f9990a4
1 // Copyright 2015 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 /**
6 * @fileoverview
7 * `cr-settings-checkbox` is a checkbox that controls a supplied preference.
9 * Example:
10 * <cr-settings-checkbox pref="{{prefs.settings.enableFoo}}"
11 * label="Enable foo setting." subLabel="(bar also)">
12 * </cr-settings-checkbox>
14 * @element cr-settings-checkbox
16 Polymer({
17 is: 'cr-settings-checkbox',
19 properties: {
20 /**
21 * The boolean preference object to control.
22 * @type {?chrome.settingsPrivate.PrefObject}
24 pref: {
25 type: Object,
26 notify: true,
29 /** Whether the checkbox should represent the inverted value. */
30 inverted: {
31 type: Boolean,
32 value: false,
35 /** Whether the checkbox is checked. */
36 checked: {
37 type: Boolean,
38 value: false,
39 observer: 'checkedChanged_',
42 /** Disabled property for the element. */
43 disabled: {
44 type: Boolean,
45 value: false,
48 /** Checkbox label. */
49 label: {
50 type: String,
51 value: '',
54 /** Additional sub-label for the checkbox. */
55 subLabel: {
56 type: String,
57 value: '',
61 observers: [
62 'prefValueChanged_(pref.value)'
65 /** @override */
66 ready: function() {
67 this.$.events.forward(this.$.checkbox, ['change']);
70 /**
71 * Polymer observer for pref.value.
72 * @param {*} prefValue
73 * @private
75 prefValueChanged_: function(prefValue) {
76 this.checked = this.getNewValue_(prefValue);
79 /**
80 * Polymer observer for checked.
81 * @private
83 checkedChanged_: function() {
84 this.set('pref.value', this.getNewValue_(this.checked));
87 /**
88 * @param {*} value
89 * @return {boolean} The value as a boolean, inverted if |inverted| is true.
90 * @private
92 getNewValue_: function(value) {
93 return this.inverted ? !value : !!value;
96 /**
97 * @param {boolean} disabled
98 * @param {?chrome.settingsPrivate.PrefObject} pref
99 * @return {boolean} Whether the checkbox should be disabled.
100 * @private
102 checkboxDisabled_: function(disabled, pref) {
103 return disabled || (!!pref &&
104 pref.policyEnforcement ==
105 chrome.settingsPrivate.PolicyEnforcement.ENFORCED);