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

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

Issue 2629573006: chromeos: Add Power device page to chrome://md-settings. (Closed)
Patch Set: apply review feedback 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
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 'settings-device-page' is the settings page for device and 6 * @fileoverview 'settings-device-page' is the settings page for device and
7 * peripheral settings. 7 * peripheral settings.
8 */ 8 */
9 Polymer({ 9 Polymer({
10 is: 'settings-device-page', 10 is: 'settings-device-page',
(...skipping 10 matching lines...) Expand all
21 notify: true, 21 notify: true,
22 }, 22 },
23 23
24 /** 24 /**
25 * |hasMouse_|, |hasTouchpad_|, and |hasStylus_| start undefined so 25 * |hasMouse_|, |hasTouchpad_|, and |hasStylus_| start undefined so
26 * observers don't trigger until they have been populated. 26 * observers don't trigger until they have been populated.
27 * @private 27 * @private
28 */ 28 */
29 hasMouse_: { 29 hasMouse_: {
30 type: Boolean, 30 type: Boolean,
31 value: false 31 value: false,
michaelpg 2017/03/01 23:39:12 (just make sure this gets rebased correctly to avo
Daniel Erat 2017/03/02 00:17:46 thanks for the heads-up.
32 }, 32 },
33 33
34 /** @private */ 34 /** @private */
35 hasTouchpad_: { 35 hasTouchpad_: {
36 type: Boolean, 36 type: Boolean,
37 value: false 37 value: false,
38 }, 38 },
39 39
40 /** @private */ 40 /** @private */
41 hasStylus_: { 41 hasStylus_: {
42 type: Boolean, 42 type: Boolean,
43 value: false 43 value: false,
44 }, 44 },
45 45
46 /** 46 /**
47 * Whether power status and settings should be fetched and displayed. 47 * Whether power status and settings should be fetched and displayed.
48 * @private 48 * @private
49 */ 49 */
50 enablePowerSettings_: { 50 enablePowerSettings_: {
51 type: Boolean, 51 type: Boolean,
52 value: function() { 52 value: function() {
53 return loadTimeData.getBoolean('enablePowerSettings'); 53 return loadTimeData.getBoolean('enablePowerSettings');
54 }, 54 },
55 readOnly: true, 55 readOnly: true,
56 }, 56 },
57
58 /** @private {string} ID of the selected power source, or ''. */
59 selectedPowerSourceId_: String,
60
61 /** @private {!settings.BatteryStatus|undefined} */
62 batteryStatus_: Object,
63
64 /** @private {boolean} Whether a low-power (USB) charger is being used. */
65 lowPowerCharger_: Boolean,
66
67 /**
68 * List of available dual-role power sources, if enablePowerSettings_ is on.
69 * @private {!Array<!settings.PowerSource>|undefined}
70 */
71 powerSources_: Array,
72
73 /** @private */
74 powerLabel_: {
75 type: String,
76 computed: 'computePowerLabel_(powerSources_, batteryStatus_.calculating)',
77 },
78
79 /** @private */
80 showPowerDropdown_: {
81 type: Boolean,
82 computed: 'computeShowPowerDropdown_(powerSources_)',
83 value: false,
84 },
85
86 /**
87 * The name of the dedicated charging device being used, if present.
88 * @private {string}
89 */
90 powerSourceName_: {
91 type: String,
92 computed: 'computePowerSourceName_(powerSources_, lowPowerCharger_)',
93 },
94 }, 57 },
95 58
96 observers: [ 59 observers: [
97 'pointersChanged_(hasMouse_, hasTouchpad_)', 60 'pointersChanged_(hasMouse_, hasTouchpad_)',
98 ], 61 ],
99 62
100 /** @override */ 63 /** @override */
101 attached: function() { 64 attached: function() {
102 this.addWebUIListener( 65 this.addWebUIListener(
103 'has-mouse-changed', this.set.bind(this, 'hasMouse_')); 66 'has-mouse-changed', this.set.bind(this, 'hasMouse_'));
104 this.addWebUIListener( 67 this.addWebUIListener(
105 'has-touchpad-changed', this.set.bind(this, 'hasTouchpad_')); 68 'has-touchpad-changed', this.set.bind(this, 'hasTouchpad_'));
106 settings.DevicePageBrowserProxyImpl.getInstance().initializePointers(); 69 settings.DevicePageBrowserProxyImpl.getInstance().initializePointers();
107 70
108 this.addWebUIListener( 71 this.addWebUIListener(
109 'has-stylus-changed', this.set.bind(this, 'hasStylus_')); 72 'has-stylus-changed', this.set.bind(this, 'hasStylus_'));
110 settings.DevicePageBrowserProxyImpl.getInstance().initializeStylus(); 73 settings.DevicePageBrowserProxyImpl.getInstance().initializeStylus();
111
112 if (this.enablePowerSettings_) {
113 this.addWebUIListener(
114 'battery-status-changed', this.set.bind(this, 'batteryStatus_'));
115 this.addWebUIListener(
116 'power-sources-changed', this.powerSourcesChanged_.bind(this));
117 settings.DevicePageBrowserProxyImpl.getInstance().updatePowerStatus();
118 }
119 }, 74 },
120 75
121 /** 76 /**
122 * @return {string} 77 * @return {string}
123 * @private 78 * @private
124 */ 79 */
125 getPointersTitle_: function() { 80 getPointersTitle_: function() {
126 if (this.hasMouse_ && this.hasTouchpad_) 81 if (this.hasMouse_ && this.hasTouchpad_)
127 return this.i18n('mouseAndTouchpadTitle'); 82 return this.i18n('mouseAndTouchpadTitle');
128 if (this.hasMouse_) 83 if (this.hasMouse_)
129 return this.i18n('mouseTitle'); 84 return this.i18n('mouseTitle');
130 if (this.hasTouchpad_) 85 if (this.hasTouchpad_)
131 return this.i18n('touchpadTitle'); 86 return this.i18n('touchpadTitle');
132 return ''; 87 return '';
133 }, 88 },
134 89
135 /** 90 /**
136 * @param {*} lhs
137 * @param {*} rhs
138 * @return {boolean}
139 */
140 isEqual_: function(lhs, rhs) {
141 return lhs === rhs;
142 },
143
144 /**
145 * @param {!Array<!settings.PowerSource>|undefined} powerSources
146 * @param {boolean} calculating
147 * @return {string} The primary label for the power row.
148 * @private
149 */
150 computePowerLabel_: function(powerSources, calculating) {
151 return this.i18n(calculating ? 'calculatingPower' :
152 powerSources.length ? 'powerSourceLabel' : 'powerSourceBattery');
153 },
154
155 /**
156 * @param {!Array<!settings.PowerSource>} powerSources
157 * @return {boolean} True if at least one power source is attached and all of
158 * them are dual-role (no dedicated chargers).
159 * @private
160 */
161 computeShowPowerDropdown_: function(powerSources) {
162 return powerSources.length > 0 && powerSources.every(function(source) {
163 return source.type == settings.PowerDeviceType.DUAL_ROLE_USB;
164 });
165 },
166
167 /**
168 * @param {!Array<!settings.PowerSource>} powerSources
169 * @param {boolean} lowPowerCharger
170 * @return {string} Description of the power source.
171 * @private
172 */
173 computePowerSourceName_: function (powerSources, lowPowerCharger) {
174 if (lowPowerCharger)
175 return this.i18n('powerSourceLowPowerCharger');
176 if (powerSources.length)
177 return this.i18n('powerSourceAcAdapter');
178 return '';
179 },
180
181 /**
182 * Handler for tapping the mouse and touchpad settings menu item. 91 * Handler for tapping the mouse and touchpad settings menu item.
183 * @private 92 * @private
184 */ 93 */
185 onPointersTap_: function() { 94 onPointersTap_: function() {
186 settings.navigateTo(settings.Route.POINTERS); 95 settings.navigateTo(settings.Route.POINTERS);
187 }, 96 },
188 97
189 /** 98 /**
190 * Handler for tapping the Keyboard settings menu item. 99 * Handler for tapping the Keyboard settings menu item.
191 * @private 100 * @private
(...skipping 19 matching lines...) Expand all
211 }, 120 },
212 121
213 /** 122 /**
214 * Handler for tapping the Storage settings menu item. 123 * Handler for tapping the Storage settings menu item.
215 * @private 124 * @private
216 */ 125 */
217 onStorageTap_: function() { 126 onStorageTap_: function() {
218 settings.navigateTo(settings.Route.STORAGE); 127 settings.navigateTo(settings.Route.STORAGE);
219 }, 128 },
220 129
221 onPowerSourceChange_: function() { 130 /**
222 settings.DevicePageBrowserProxyImpl.getInstance().setPowerSource( 131 * Handler for tapping the Power settings menu item.
223 this.$$('#powerSource').value); 132 * @private
133 */
134 onPowerTap_: function() {
135 settings.navigateTo(settings.Route.POWER);
224 }, 136 },
225 137
226 /** @protected */ 138 /** @protected */
227 currentRouteChanged: function() { 139 currentRouteChanged: function() {
228 this.checkPointerSubpage_(); 140 this.checkPointerSubpage_();
229 }, 141 },
230 142
231 /** 143 /**
232 * @param {boolean} hasMouse 144 * @param {boolean} hasMouse
233 * @param {boolean} hasTouchpad 145 * @param {boolean} hasTouchpad
234 * @private 146 * @private
235 */ 147 */
236 pointersChanged_: function(hasMouse, hasTouchpad) { 148 pointersChanged_: function(hasMouse, hasTouchpad) {
237 this.$.pointersRow.hidden = !hasMouse && !hasTouchpad; 149 this.$.pointersRow.hidden = !hasMouse && !hasTouchpad;
238 this.checkPointerSubpage_(); 150 this.checkPointerSubpage_();
239 }, 151 },
240 152
241 /** 153 /**
242 * @param {!Array<settings.PowerSource>} sources External power sources.
243 * @param {string} selectedId The ID of the currently used power source.
244 * @param {boolean} lowPowerCharger Whether the currently used power source
245 * is a low-powered USB charger.
246 * @private
247 */
248 powerSourcesChanged_: function(sources, selectedId, lowPowerCharger) {
249 this.powerSources_ = sources;
250 this.selectedPowerSourceId_ = selectedId;
251 this.lowPowerCharger_ = lowPowerCharger;
252 },
253
254 /**
255 * Leaves the pointer subpage if all pointing devices are detached. 154 * Leaves the pointer subpage if all pointing devices are detached.
256 * @private 155 * @private
257 */ 156 */
258 checkPointerSubpage_: function() { 157 checkPointerSubpage_: function() {
259 // Check that the properties have explicitly been set to false. 158 // Check that the properties have explicitly been set to false.
260 if (this.hasMouse_ === false && this.hasTouchpad_ === false && 159 if (this.hasMouse_ === false && this.hasTouchpad_ === false &&
261 settings.getCurrentRoute() == settings.Route.POINTERS) { 160 settings.getCurrentRoute() == settings.Route.POINTERS) {
262 settings.navigateTo(settings.Route.DEVICE); 161 settings.navigateTo(settings.Route.DEVICE);
263 } 162 }
264 }, 163 },
265 }); 164 });
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698