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

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

Powered by Google App Engine
This is Rietveld 408576698