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

Side by Side Diff: chrome/browser/resources/settings/checkbox/checkbox.js

Issue 1156783004: cr-settings-checkbox: Add 'inverted' property. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 years, 6 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 | « chrome/browser/resources/settings/checkbox/checkbox.html ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2015 The Chromium Authors. All rights reserved. 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 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 * `cr-settings-checkbox` is a checkbox that controls a supplied preference. 7 * `cr-settings-checkbox` is a checkbox that controls a supplied preference.
8 * 8 *
9 * Example: 9 * Example:
10 * <cr-settings-checkbox pref="{{prefs.settings.enableFoo}}" 10 * <cr-settings-checkbox pref="{{prefs.settings.enableFoo}}"
11 * label="Enable foo setting." subLabel="(bar also)"> 11 * label="Enable foo setting." subLabel="(bar also)">
12 * </cr-settings-checkbox> 12 * </cr-settings-checkbox>
13 * 13 *
14 * @element cr-settings-checkbox 14 * @element cr-settings-checkbox
15 */ 15 */
16 Polymer({ 16 Polymer({
17 is: 'cr-settings-checkbox', 17 is: 'cr-settings-checkbox',
18 18
19 properties: { 19 properties: {
20 /** 20 /**
21 * The boolean preference object to control. 21 * The boolean preference object to control.
22 * @type {?chrome.settingsPrivate.PrefObject} 22 * @type {?chrome.settingsPrivate.PrefObject}
23 */ 23 */
24 pref: { 24 pref: {
25 type: Object, 25 type: Object,
26 notify: true, 26 notify: true,
27 value: function() { return {}; }
Jeremy Klein 2015/06/04 00:49:54 Why do we need this? Doesn't it break the pref-tra
Oren Blasberg 2015/06/04 16:10:04 Oddly, without the initial value, I get an error i
Jeremy Klein 2015/06/04 17:20:16 Sorry, by "breaking" I mean preventing real errors
Oren Blasberg 2015/06/04 18:26:11 Oh, I see. Yes, the validation would always succee
28 },
29
30 inverted: {
31 type: Boolean,
32 value: false
33 },
34
35 checked: {
36 type: Boolean,
37 value: false,
38 observer: 'checkedChanged'
27 }, 39 },
28 40
29 label: { 41 label: {
30 type: String, 42 type: String,
31 value: '', 43 value: '',
32 }, 44 },
33 45
34 subLabel: { 46 subLabel: {
35 type: String, 47 type: String,
36 value: '', 48 value: '',
37 }, 49 },
38 }, 50 },
39 51
52 observers: [
53 'prefValueChanged(pref.value)'
54 ],
55
40 /** @override */ 56 /** @override */
41 ready: function() { 57 ready: function() {
42 this.$.events.forward(this.$.checkbox, ['change']); 58 this.$.events.forward(this.$.checkbox, ['change']);
43 }, 59 },
60
61 prefValueChanged: function(prefValue) {
Jeremy Klein 2015/06/04 00:49:54 This and the other 2 new functions can be private.
Oren Blasberg 2015/06/04 16:10:04 Done.
62 if (this.pref) {
63 this.checked = this.computeValue(prefValue);
64 }
65 },
66
67 checkedChanged: function() {
68 this.pref.value = this.computeValue(this.checked);
69 },
70
71 computeValue: function(val) {
Jeremy Klein 2015/06/04 00:49:54 For some reason the name computeValue confuses me
Oren Blasberg 2015/06/04 16:10:04 Ah ok. It's not actually inverting though; it's ju
Jeremy Klein 2015/06/04 17:20:16 The this is that it doesn't only get the prefValue
Oren Blasberg 2015/06/04 18:26:11 Ok, how about "getUpdatedValue_"? "getValueBased
72 return this.inverted ? !val : val;
73 }
44 }); 74 });
OLDNEW
« no previous file with comments | « chrome/browser/resources/settings/checkbox/checkbox.html ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698