Chromium Code Reviews| OLD | NEW |
|---|---|
| 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', |
| 11 | 11 |
| 12 behaviors: [ | 12 behaviors: [ |
| 13 I18nBehavior, | 13 I18nBehavior, |
| 14 WebUIListenerBehavior, | 14 WebUIListenerBehavior, |
| 15 settings.RouteObserverBehavior, | 15 settings.RouteObserverBehavior, |
| 16 ], | 16 ], |
| 17 | 17 |
| 18 properties: { | 18 properties: { |
| 19 prefs: { | 19 prefs: { |
| 20 type: Object, | 20 type: Object, |
| 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_: {type: Boolean, value: false}, |
|
Daniel Erat
2017/03/01 02:43:31
"git cl format --js" did this. let me know if you'
michaelpg
2017/03/01 05:20:38
no worries, but you'll actually need to rebase two
stevenjb
2017/03/01 17:19:43
Also, if you want this on multuple lines (and we g
Daniel Erat
2017/03/01 23:01:53
done (added trailing commas... it's going to be to
stevenjb
2017/03/01 23:15:38
Oh, BTW, this changed in ToT, you'll need to rebas
| |
| 30 type: Boolean, | |
| 31 value: false | |
| 32 }, | |
| 33 | 30 |
| 34 /** @private */ | 31 /** @private */ |
| 35 hasTouchpad_: { | 32 hasTouchpad_: {type: Boolean, value: false}, |
| 36 type: Boolean, | |
| 37 value: false | |
| 38 }, | |
| 39 | 33 |
| 40 /** @private */ | 34 /** @private */ |
| 41 hasStylus_: { | 35 hasStylus_: {type: Boolean, value: false}, |
| 42 type: Boolean, | |
| 43 value: false | |
| 44 }, | |
| 45 | 36 |
| 46 /** | 37 /** |
| 47 * Whether power status and settings should be fetched and displayed. | 38 * Whether power status and settings should be fetched and displayed. |
| 48 * @private | 39 * @private |
| 49 */ | 40 */ |
| 50 enablePowerSettings_: { | 41 enablePowerSettings_: { |
| 51 type: Boolean, | 42 type: Boolean, |
| 52 value: function() { | 43 value: function() { |
| 53 return loadTimeData.getBoolean('enablePowerSettings'); | 44 return loadTimeData.getBoolean('enablePowerSettings'); |
| 54 }, | 45 }, |
| 55 readOnly: true, | 46 readOnly: true, |
| 56 }, | 47 }, |
| 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 }, | 48 }, |
| 95 | 49 |
| 96 observers: [ | 50 observers: [ |
| 97 'pointersChanged_(hasMouse_, hasTouchpad_)', | 51 'pointersChanged_(hasMouse_, hasTouchpad_)', |
| 98 ], | 52 ], |
| 99 | 53 |
| 100 /** @override */ | 54 /** @override */ |
| 101 attached: function() { | 55 attached: function() { |
| 102 this.addWebUIListener( | 56 this.addWebUIListener( |
| 103 'has-mouse-changed', this.set.bind(this, 'hasMouse_')); | 57 'has-mouse-changed', this.set.bind(this, 'hasMouse_')); |
| 104 this.addWebUIListener( | 58 this.addWebUIListener( |
| 105 'has-touchpad-changed', this.set.bind(this, 'hasTouchpad_')); | 59 'has-touchpad-changed', this.set.bind(this, 'hasTouchpad_')); |
| 106 settings.DevicePageBrowserProxyImpl.getInstance().initializePointers(); | 60 settings.DevicePageBrowserProxyImpl.getInstance().initializePointers(); |
| 107 | 61 |
| 108 this.addWebUIListener( | 62 this.addWebUIListener( |
| 109 'has-stylus-changed', this.set.bind(this, 'hasStylus_')); | 63 'has-stylus-changed', this.set.bind(this, 'hasStylus_')); |
| 110 settings.DevicePageBrowserProxyImpl.getInstance().initializeStylus(); | 64 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 }, | 65 }, |
| 120 | 66 |
| 121 /** | 67 /** |
| 122 * @return {string} | 68 * @return {string} |
| 123 * @private | 69 * @private |
| 124 */ | 70 */ |
| 125 getPointersTitle_: function() { | 71 getPointersTitle_: function() { |
| 126 if (this.hasMouse_ && this.hasTouchpad_) | 72 if (this.hasMouse_ && this.hasTouchpad_) |
| 127 return this.i18n('mouseAndTouchpadTitle'); | 73 return this.i18n('mouseAndTouchpadTitle'); |
| 128 if (this.hasMouse_) | 74 if (this.hasMouse_) |
| 129 return this.i18n('mouseTitle'); | 75 return this.i18n('mouseTitle'); |
| 130 if (this.hasTouchpad_) | 76 if (this.hasTouchpad_) |
| 131 return this.i18n('touchpadTitle'); | 77 return this.i18n('touchpadTitle'); |
| 132 return ''; | 78 return ''; |
| 133 }, | 79 }, |
| 134 | 80 |
| 135 /** | 81 /** |
| 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. | 82 * Handler for tapping the mouse and touchpad settings menu item. |
| 183 * @private | 83 * @private |
| 184 */ | 84 */ |
| 185 onPointersTap_: function() { | 85 onPointersTap_: function() { |
| 186 settings.navigateTo(settings.Route.POINTERS); | 86 settings.navigateTo(settings.Route.POINTERS); |
| 187 }, | 87 }, |
| 188 | 88 |
| 189 /** | 89 /** |
| 190 * Handler for tapping the Keyboard settings menu item. | 90 * Handler for tapping the Keyboard settings menu item. |
| 191 * @private | 91 * @private |
| (...skipping 12 matching lines...) Expand all Loading... | |
| 204 | 104 |
| 205 /** | 105 /** |
| 206 * Handler for tapping the Display settings menu item. | 106 * Handler for tapping the Display settings menu item. |
| 207 * @private | 107 * @private |
| 208 */ | 108 */ |
| 209 onDisplayTap_: function() { | 109 onDisplayTap_: function() { |
| 210 settings.navigateTo(settings.Route.DISPLAY); | 110 settings.navigateTo(settings.Route.DISPLAY); |
| 211 }, | 111 }, |
| 212 | 112 |
| 213 /** | 113 /** |
| 114 * Handler for tapping the Power settings menu item. | |
| 115 * @private | |
| 116 */ | |
| 117 onPowerTap_: function() { | |
|
michaelpg
2017/03/01 05:20:38
opt. nit: place in the same order as the HTML elem
Daniel Erat
2017/03/01 23:01:53
Done.
| |
| 118 settings.navigateTo(settings.Route.POWER); | |
| 119 }, | |
| 120 | |
| 121 /** | |
| 214 * Handler for tapping the Storage settings menu item. | 122 * Handler for tapping the Storage settings menu item. |
| 215 * @private | 123 * @private |
| 216 */ | 124 */ |
| 217 onStorageTap_: function() { | 125 onStorageTap_: function() { |
| 218 settings.navigateTo(settings.Route.STORAGE); | 126 settings.navigateTo(settings.Route.STORAGE); |
| 219 }, | 127 }, |
| 220 | 128 |
| 221 onPowerSourceChange_: function() { | |
| 222 settings.DevicePageBrowserProxyImpl.getInstance().setPowerSource( | |
| 223 this.$$('#powerSource').value); | |
| 224 }, | |
| 225 | |
| 226 /** @protected */ | 129 /** @protected */ |
| 227 currentRouteChanged: function() { | 130 currentRouteChanged: function() { |
| 228 this.checkPointerSubpage_(); | 131 this.checkPointerSubpage_(); |
| 229 }, | 132 }, |
| 230 | 133 |
| 231 /** | 134 /** |
| 232 * @param {boolean} hasMouse | 135 * @param {boolean} hasMouse |
| 233 * @param {boolean} hasTouchpad | 136 * @param {boolean} hasTouchpad |
| 234 * @private | 137 * @private |
| 235 */ | 138 */ |
| 236 pointersChanged_: function(hasMouse, hasTouchpad) { | 139 pointersChanged_: function(hasMouse, hasTouchpad) { |
| 237 this.$.pointersRow.hidden = !hasMouse && !hasTouchpad; | 140 this.$.pointersRow.hidden = !hasMouse && !hasTouchpad; |
| 238 this.checkPointerSubpage_(); | 141 this.checkPointerSubpage_(); |
| 239 }, | 142 }, |
| 240 | 143 |
| 241 /** | 144 /** |
| 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. | 145 * Leaves the pointer subpage if all pointing devices are detached. |
| 256 * @private | 146 * @private |
| 257 */ | 147 */ |
| 258 checkPointerSubpage_: function() { | 148 checkPointerSubpage_: function() { |
| 259 // Check that the properties have explicitly been set to false. | 149 // Check that the properties have explicitly been set to false. |
| 260 if (this.hasMouse_ === false && this.hasTouchpad_ === false && | 150 if (this.hasMouse_ === false && this.hasTouchpad_ === false && |
| 261 settings.getCurrentRoute() == settings.Route.POINTERS) { | 151 settings.getCurrentRoute() == settings.Route.POINTERS) { |
| 262 settings.navigateTo(settings.Route.DEVICE); | 152 settings.navigateTo(settings.Route.DEVICE); |
| 263 } | 153 } |
| 264 }, | 154 }, |
| 265 }); | 155 }); |
| OLD | NEW |