| 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 cr.exportPath('settings'); | 5 cr.exportPath('settings'); |
| 6 | 6 |
| 7 (function() { | 7 (function() { |
| 8 | 8 |
| 9 var PairingEventType = chrome.bluetoothPrivate.PairingEventType; | 9 var PairingEventType = chrome.bluetoothPrivate.PairingEventType; |
| 10 | 10 |
| 11 // NOTE(dbeam): even though these behaviors are only used privately, they must | 11 // NOTE(dbeam): even though these behaviors are only used privately, they must |
| 12 // be globally accessible for Closure's --polymer_pass to compile happily. | 12 // be globally accessible for Closure's --polymer_pass to compile happily. |
| 13 | 13 |
| 14 /** @polymerBehavior */ | 14 /** @polymerBehavior */ |
| 15 settings.BluetoothAddDeviceBehavior = { | 15 settings.BluetoothAddDeviceBehavior = { |
| 16 properties: { | 16 properties: { |
| 17 /** | 17 /** |
| 18 * The cached bluetooth adapter state. | 18 * The cached bluetooth adapter state. |
| 19 * @type {!chrome.bluetooth.AdapterState|undefined} | 19 * @type {!chrome.bluetooth.AdapterState|undefined} |
| 20 */ |
| 21 adapterState: { |
| 22 type: Object, |
| 23 observer: 'adapterStateChanged_', |
| 24 }, |
| 25 |
| 26 /** |
| 27 * The ordered list of bluetooth devices. |
| 28 * @type {!Array<!chrome.bluetooth.Device>} |
| 29 */ |
| 30 deviceList: { |
| 31 type: Array, |
| 32 value: /** @return {Array} */ function() { |
| 33 return []; |
| 34 }, |
| 35 observer: 'deviceListChanged_', |
| 36 }, |
| 37 |
| 38 /** |
| 39 * Reflects the iron-list selecteditem property. |
| 40 * @type {!chrome.bluetooth.Device} |
| 41 */ |
| 42 selectedItem: { |
| 43 type: Object, |
| 44 observer: 'selectedItemChanged_', |
| 45 }, |
| 46 }, |
| 47 |
| 48 /** @type {boolean} */ |
| 49 itemWasFocused_: false, |
| 50 |
| 51 /** @private */ |
| 52 adapterStateChanged_: function() { |
| 53 if (!this.adapterState.powered) |
| 54 this.close(); |
| 55 }, |
| 56 |
| 57 /** @private */ |
| 58 deviceListChanged_: function() { |
| 59 this.updateScrollableContents(); |
| 60 if (this.itemWasFocused_ || !this.getUnpaired_().length) |
| 61 return; |
| 62 // If the iron-list is populated with at least one visible item then |
| 63 // focus it. |
| 64 let item = this.$$('iron-list bluetooth-device-list-item'); |
| 65 if (item && item.offsetParent != null) { |
| 66 item.focus(); |
| 67 this.itemWasFocused_ = true; |
| 68 return; |
| 69 } |
| 70 // Otherwise try again. |
| 71 setTimeout(function() { |
| 72 this.deviceListChanged_(); |
| 73 }.bind(this), 100); |
| 74 }, |
| 75 |
| 76 /** @private */ |
| 77 selectedItemChanged_: function() { |
| 78 if (this.selectedItem) |
| 79 this.fire( |
| 80 'device-event', {action: 'connect', device: this.selectedItem}); |
| 81 }, |
| 82 |
| 83 /** |
| 84 * @return {!Array<!chrome.bluetooth.Device>} |
| 85 * @private |
| 86 */ |
| 87 getUnpaired_: function() { |
| 88 return this.deviceList.filter(function(device) { |
| 89 return !device.paired; |
| 90 }); |
| 91 }, |
| 92 |
| 93 /** |
| 94 * @return {boolean} True if deviceList contains any unpaired devices. |
| 95 * @private |
| 96 */ |
| 97 haveUnpaired_: function(deviceList) { |
| 98 return this.getUnpaired_().length > 0; |
| 99 }, |
| 100 }; |
| 101 |
| 102 /** @polymerBehavior */ |
| 103 settings.BluetoothPairDeviceBehavior = { |
| 104 properties: { |
| 105 /** |
| 106 * Current Pairing device. |
| 107 * @type {?chrome.bluetooth.Device|undefined} |
| 108 */ |
| 109 pairingDevice: Object, |
| 110 |
| 111 /** |
| 112 * Current Pairing event. |
| 113 * @type {?chrome.bluetoothPrivate.PairingEvent|undefined} |
| 114 */ |
| 115 pairingEvent: Object, |
| 116 |
| 117 /** Pincode or passkey value, used to trigger connect enabled changes. */ |
| 118 pinOrPass: String, |
| 119 |
| 120 /** |
| 121 * @const |
| 122 * @type {!Array<number>} |
| 123 */ |
| 124 digits: { |
| 125 type: Array, |
| 126 readOnly: true, |
| 127 value: [0, 1, 2, 3, 4, 5], |
| 128 }, |
| 129 }, |
| 130 |
| 131 observers: [ |
| 132 'pairingChanged_(pairingDevice, pairingEvent)', |
| 133 ], |
| 134 |
| 135 /** @private */ |
| 136 pairingChanged_: function() { |
| 137 // Auto-close the dialog when pairing completes. |
| 138 if (this.pairingDevice && this.pairingDevice.connected) { |
| 139 this.close(); |
| 140 return; |
| 141 } |
| 142 this.pinOrPass = ''; |
| 143 }, |
| 144 |
| 145 /** |
| 146 * @return {string} |
| 147 * @private |
| 148 */ |
| 149 getMessage_: function() { |
| 150 if (!this.pairingDevice) |
| 151 return ''; |
| 152 var message; |
| 153 if (!this.pairingEvent) |
| 154 message = 'bluetoothStartConnecting'; |
| 155 else |
| 156 message = this.getEventDesc_(this.pairingEvent.pairing); |
| 157 return this.i18n(message, this.pairingDevice.name); |
| 158 }, |
| 159 |
| 160 /** |
| 161 * @return {boolean} |
| 162 * @private |
| 163 */ |
| 164 showEnterPincode_: function() { |
| 165 return !!this.pairingEvent && |
| 166 this.pairingEvent.pairing == PairingEventType.REQUEST_PINCODE; |
| 167 }, |
| 168 |
| 169 /** |
| 170 * @return {boolean} |
| 171 * @private |
| 172 */ |
| 173 showEnterPasskey_: function() { |
| 174 return !!this.pairingEvent && |
| 175 this.pairingEvent.pairing == PairingEventType.REQUEST_PASSKEY; |
| 176 }, |
| 177 |
| 178 /** |
| 179 * @return {boolean} |
| 180 * @private |
| 181 */ |
| 182 showDisplayPassOrPin_: function() { |
| 183 if (!this.pairingEvent) |
| 184 return false; |
| 185 var pairing = this.pairingEvent.pairing; |
| 186 return ( |
| 187 pairing == PairingEventType.DISPLAY_PINCODE || |
| 188 pairing == PairingEventType.DISPLAY_PASSKEY || |
| 189 pairing == PairingEventType.CONFIRM_PASSKEY || |
| 190 pairing == PairingEventType.KEYS_ENTERED); |
| 191 }, |
| 192 |
| 193 /** |
| 194 * @return {boolean} |
| 195 * @private |
| 196 */ |
| 197 showAcceptReject_: function() { |
| 198 return !!this.pairingEvent && |
| 199 this.pairingEvent.pairing == PairingEventType.CONFIRM_PASSKEY; |
| 200 }, |
| 201 |
| 202 /** |
| 203 * @return {boolean} |
| 204 * @private |
| 205 */ |
| 206 showConnect_: function() { |
| 207 if (!this.pairingEvent) |
| 208 return false; |
| 209 var pairing = this.pairingEvent.pairing; |
| 210 return pairing == PairingEventType.REQUEST_PINCODE || |
| 211 pairing == PairingEventType.REQUEST_PASSKEY; |
| 212 }, |
| 213 |
| 214 /** |
| 215 * @return {boolean} |
| 216 * @private |
| 217 */ |
| 218 enableConnect_: function() { |
| 219 if (!this.showConnect_()) |
| 220 return false; |
| 221 var inputId = |
| 222 (this.pairingEvent.pairing == PairingEventType.REQUEST_PINCODE) ? |
| 223 '#pincode' : |
| 224 '#passkey'; |
| 225 var paperInput = /** @type {!PaperInputElement} */ (this.$$(inputId)); |
| 226 assert(paperInput); |
| 227 /** @type {string} */ var value = paperInput.value; |
| 228 return !!value && paperInput.validate(); |
| 229 }, |
| 230 |
| 231 /** |
| 232 * @return {boolean} |
| 233 * @private |
| 234 */ |
| 235 showDismiss_: function() { |
| 236 return (!!this.paringDevice && this.pairingDevice.paired) || |
| 237 (!!this.pairingEvent && |
| 238 this.pairingEvent.pairing == PairingEventType.COMPLETE); |
| 239 }, |
| 240 |
| 241 /** @private */ |
| 242 onAcceptTap_: function() { |
| 243 this.sendResponse_(chrome.bluetoothPrivate.PairingResponse.CONFIRM); |
| 244 }, |
| 245 |
| 246 /** @private */ |
| 247 onConnectTap_: function() { |
| 248 this.sendResponse_(chrome.bluetoothPrivate.PairingResponse.CONFIRM); |
| 249 }, |
| 250 |
| 251 /** @private */ |
| 252 onRejectTap_: function() { |
| 253 this.sendResponse_(chrome.bluetoothPrivate.PairingResponse.REJECT); |
| 254 }, |
| 255 |
| 256 /** |
| 257 * @param {!chrome.bluetoothPrivate.PairingResponse} response |
| 258 * @private |
| 20 */ | 259 */ |
| 21 adapterState: { | 260 sendResponse_: function(response) { |
| 22 type: Object, | 261 if (!this.pairingDevice) |
| 23 observer: 'adapterStateChanged_', | 262 return; |
| 24 }, | 263 var options = |
| 25 | 264 /** @type {!chrome.bluetoothPrivate.SetPairingResponseOptions} */ { |
| 26 /** | 265 device: this.pairingDevice, |
| 27 * The ordered list of bluetooth devices. | 266 response: response |
| 28 * @type {!Array<!chrome.bluetooth.Device>} | 267 }; |
| 29 */ | 268 if (response == chrome.bluetoothPrivate.PairingResponse.CONFIRM) { |
| 30 deviceList: { | 269 var pairing = this.pairingEvent.pairing; |
| 31 type: Array, | 270 if (pairing == PairingEventType.REQUEST_PINCODE) |
| 32 value: /** @return {Array} */ function() { | 271 options.pincode = this.$$('#pincode').value; |
| 33 return []; | 272 else if (pairing == PairingEventType.REQUEST_PASSKEY) |
| 34 }, | 273 options.passkey = parseInt(this.$$('#passkey').value, 10); |
| 35 observer: 'deviceListChanged_', | 274 } |
| 36 }, | 275 this.fire('response', options); |
| 37 | 276 }, |
| 38 /** | 277 |
| 39 * Reflects the iron-list selecteditem property. | 278 /** |
| 40 * @type {!chrome.bluetooth.Device} | |
| 41 */ | |
| 42 selectedItem: { | |
| 43 type: Object, | |
| 44 observer: 'selectedItemChanged_', | |
| 45 }, | |
| 46 }, | |
| 47 | |
| 48 /** @type {boolean} */ itemWasFocused_: false, | |
| 49 | |
| 50 /** @private */ | |
| 51 adapterStateChanged_: function() { | |
| 52 if (!this.adapterState.powered) | |
| 53 this.close(); | |
| 54 }, | |
| 55 | |
| 56 /** @private */ | |
| 57 deviceListChanged_: function() { | |
| 58 this.updateScrollableContents(); | |
| 59 if (this.itemWasFocused_ || !this.getUnpaired_().length) | |
| 60 return; | |
| 61 // If the iron-list is populated with at least one visible item then | |
| 62 // focus it. | |
| 63 let item = this.$$('iron-list bluetooth-device-list-item'); | |
| 64 if (item && item.offsetParent != null) { | |
| 65 item.focus(); | |
| 66 this.itemWasFocused_ = true; | |
| 67 return; | |
| 68 } | |
| 69 // Otherwise try again. | |
| 70 setTimeout(function() { this.deviceListChanged_(); }.bind(this), 100); | |
| 71 }, | |
| 72 | |
| 73 /** @private */ | |
| 74 selectedItemChanged_: function() { | |
| 75 if (this.selectedItem) | |
| 76 this.fire('device-event', {action: 'connect', device: this.selectedItem}); | |
| 77 }, | |
| 78 | |
| 79 /** | |
| 80 * @return {!Array<!chrome.bluetooth.Device>} | |
| 81 * @private | |
| 82 */ | |
| 83 getUnpaired_: function() { | |
| 84 return this.deviceList.filter(function(device) { | |
| 85 return !device.paired; | |
| 86 }); | |
| 87 }, | |
| 88 | |
| 89 /** | |
| 90 * @return {boolean} True if deviceList contains any unpaired devices. | |
| 91 * @private | |
| 92 */ | |
| 93 haveUnpaired_: function(deviceList) { | |
| 94 return this.getUnpaired_().length > 0; | |
| 95 }, | |
| 96 }; | |
| 97 | |
| 98 /** @polymerBehavior */ | |
| 99 settings.BluetoothPairDeviceBehavior = { | |
| 100 properties: { | |
| 101 /** | |
| 102 * Current Pairing device. | |
| 103 * @type {?chrome.bluetooth.Device|undefined} | |
| 104 */ | |
| 105 pairingDevice: Object, | |
| 106 | |
| 107 /** | |
| 108 * Current Pairing event. | |
| 109 * @type {?chrome.bluetoothPrivate.PairingEvent|undefined} | |
| 110 */ | |
| 111 pairingEvent: Object, | |
| 112 | |
| 113 /** Pincode or passkey value, used to trigger connect enabled changes. */ | |
| 114 pinOrPass: String, | |
| 115 | |
| 116 /** | |
| 117 * @const | |
| 118 * @type {!Array<number>} | |
| 119 */ | |
| 120 digits: { | |
| 121 type: Array, | |
| 122 readOnly: true, | |
| 123 value: [0, 1, 2, 3, 4, 5], | |
| 124 }, | |
| 125 }, | |
| 126 | |
| 127 observers: [ | |
| 128 'pairingChanged_(pairingDevice, pairingEvent)', | |
| 129 ], | |
| 130 | |
| 131 /** @private */ | |
| 132 pairingChanged_: function() { | |
| 133 // Auto-close the dialog when pairing completes. | |
| 134 if (this.pairingDevice && this.pairingDevice.connected) { | |
| 135 this.close(); | |
| 136 return; | |
| 137 } | |
| 138 this.pinOrPass = ''; | |
| 139 }, | |
| 140 | |
| 141 /** | |
| 142 * @return {string} | |
| 143 * @private | |
| 144 */ | |
| 145 getMessage_: function() { | |
| 146 if (!this.pairingDevice) | |
| 147 return ''; | |
| 148 var message; | |
| 149 if (!this.pairingEvent) | |
| 150 message = 'bluetoothStartConnecting'; | |
| 151 else | |
| 152 message = this.getEventDesc_(this.pairingEvent.pairing); | |
| 153 return this.i18n(message, this.pairingDevice.name); | |
| 154 }, | |
| 155 | |
| 156 /** | |
| 157 * @return {boolean} | |
| 158 * @private | |
| 159 */ | |
| 160 showEnterPincode_: function() { | |
| 161 return !!this.pairingEvent && | |
| 162 this.pairingEvent.pairing == PairingEventType.REQUEST_PINCODE; | |
| 163 }, | |
| 164 | |
| 165 /** | |
| 166 * @return {boolean} | |
| 167 * @private | |
| 168 */ | |
| 169 showEnterPasskey_: function() { | |
| 170 return !!this.pairingEvent && | |
| 171 this.pairingEvent.pairing == PairingEventType.REQUEST_PASSKEY; | |
| 172 }, | |
| 173 | |
| 174 /** | |
| 175 * @return {boolean} | |
| 176 * @private | |
| 177 */ | |
| 178 showDisplayPassOrPin_: function() { | |
| 179 if (!this.pairingEvent) | |
| 180 return false; | |
| 181 var pairing = this.pairingEvent.pairing; | |
| 182 return ( | |
| 183 pairing == PairingEventType.DISPLAY_PINCODE || | |
| 184 pairing == PairingEventType.DISPLAY_PASSKEY || | |
| 185 pairing == PairingEventType.CONFIRM_PASSKEY || | |
| 186 pairing == PairingEventType.KEYS_ENTERED); | |
| 187 }, | |
| 188 | |
| 189 /** | |
| 190 * @return {boolean} | |
| 191 * @private | |
| 192 */ | |
| 193 showAcceptReject_: function() { | |
| 194 return !!this.pairingEvent && | |
| 195 this.pairingEvent.pairing == PairingEventType.CONFIRM_PASSKEY; | |
| 196 }, | |
| 197 | |
| 198 /** | |
| 199 * @return {boolean} | |
| 200 * @private | |
| 201 */ | |
| 202 showConnect_: function() { | |
| 203 if (!this.pairingEvent) | |
| 204 return false; | |
| 205 var pairing = this.pairingEvent.pairing; | |
| 206 return pairing == PairingEventType.REQUEST_PINCODE || | |
| 207 pairing == PairingEventType.REQUEST_PASSKEY; | |
| 208 }, | |
| 209 | |
| 210 /** | |
| 211 * @return {boolean} | |
| 212 * @private | |
| 213 */ | |
| 214 enableConnect_: function() { | |
| 215 if (!this.showConnect_()) | |
| 216 return false; | |
| 217 var inputId = | |
| 218 (this.pairingEvent.pairing == PairingEventType.REQUEST_PINCODE) ? | |
| 219 '#pincode' : | |
| 220 '#passkey'; | |
| 221 var paperInput = /** @type {!PaperInputElement} */ (this.$$(inputId)); | |
| 222 assert(paperInput); | |
| 223 /** @type {string} */ var value = paperInput.value; | |
| 224 return !!value && paperInput.validate(); | |
| 225 }, | |
| 226 | |
| 227 /** | |
| 228 * @return {boolean} | |
| 229 * @private | |
| 230 */ | |
| 231 showDismiss_: function() { | |
| 232 return (!!this.paringDevice && this.pairingDevice.paired) || | |
| 233 (!!this.pairingEvent && | |
| 234 this.pairingEvent.pairing == PairingEventType.COMPLETE); | |
| 235 }, | |
| 236 | |
| 237 /** @private */ | |
| 238 onAcceptTap_: function() { | |
| 239 this.sendResponse_(chrome.bluetoothPrivate.PairingResponse.CONFIRM); | |
| 240 }, | |
| 241 | |
| 242 /** @private */ | |
| 243 onConnectTap_: function() { | |
| 244 this.sendResponse_(chrome.bluetoothPrivate.PairingResponse.CONFIRM); | |
| 245 }, | |
| 246 | |
| 247 /** @private */ | |
| 248 onRejectTap_: function() { | |
| 249 this.sendResponse_(chrome.bluetoothPrivate.PairingResponse.REJECT); | |
| 250 }, | |
| 251 | |
| 252 /** | |
| 253 * @param {!chrome.bluetoothPrivate.PairingResponse} response | |
| 254 * @private | |
| 255 */ | |
| 256 sendResponse_: function(response) { | |
| 257 if (!this.pairingDevice) | |
| 258 return; | |
| 259 var options = | |
| 260 /** @type {!chrome.bluetoothPrivate.SetPairingResponseOptions} */ { | |
| 261 device: this.pairingDevice, | |
| 262 response: response | |
| 263 }; | |
| 264 if (response == chrome.bluetoothPrivate.PairingResponse.CONFIRM) { | |
| 265 var pairing = this.pairingEvent.pairing; | |
| 266 if (pairing == PairingEventType.REQUEST_PINCODE) | |
| 267 options.pincode = this.$$('#pincode').value; | |
| 268 else if (pairing == PairingEventType.REQUEST_PASSKEY) | |
| 269 options.passkey = parseInt(this.$$('#passkey').value, 10); | |
| 270 } | |
| 271 this.fire('response', options); | |
| 272 }, | |
| 273 | |
| 274 /** | |
| 275 * @param {!PairingEventType} eventType | 279 * @param {!PairingEventType} eventType |
| 276 * @return {string} | 280 * @return {string} |
| 277 * @private | 281 * @private |
| 278 */ | 282 */ |
| 279 getEventDesc_: function(eventType) { | 283 getEventDesc_: function(eventType) { |
| 280 assert(eventType); | 284 assert(eventType); |
| 281 if (eventType == PairingEventType.COMPLETE || | 285 if (eventType == PairingEventType.COMPLETE || |
| 282 eventType == PairingEventType.KEYS_ENTERED || | 286 eventType == PairingEventType.KEYS_ENTERED || |
| 283 eventType == PairingEventType.REQUEST_AUTHORIZATION) { | 287 eventType == PairingEventType.REQUEST_AUTHORIZATION) { |
| 284 return 'bluetoothStartConnecting'; | 288 return 'bluetoothStartConnecting'; |
| 285 } | 289 } |
| 286 return 'bluetooth_' + /** @type {string} */ (eventType); | 290 return 'bluetooth_' + /** @type {string} */ (eventType); |
| 287 }, | 291 }, |
| 288 | 292 |
| 289 /** | 293 /** |
| 290 * @param {number} index | 294 * @param {number} index |
| 291 * @return {string} | 295 * @return {string} |
| 292 * @private | 296 * @private |
| 293 */ | 297 */ |
| 294 getPinDigit_: function(index) { | 298 getPinDigit_: function(index) { |
| 295 if (!this.pairingEvent) | 299 if (!this.pairingEvent) |
| 296 return ''; | 300 return ''; |
| 297 var digit = '0'; | 301 var digit = '0'; |
| 298 var pairing = this.pairingEvent.pairing; | 302 var pairing = this.pairingEvent.pairing; |
| 299 if (pairing == PairingEventType.DISPLAY_PINCODE && | 303 if (pairing == PairingEventType.DISPLAY_PINCODE && |
| 300 this.pairingEvent.pincode && index < this.pairingEvent.pincode.length) { | 304 this.pairingEvent.pincode && |
| 301 digit = this.pairingEvent.pincode[index]; | 305 index < this.pairingEvent.pincode.length) { |
| 302 } else if ( | 306 digit = this.pairingEvent.pincode[index]; |
| 303 this.pairingEvent.passkey && | 307 } else if ( |
| 304 (pairing == PairingEventType.DISPLAY_PASSKEY || | 308 this.pairingEvent.passkey && |
| 305 pairing == PairingEventType.KEYS_ENTERED || | 309 (pairing == PairingEventType.DISPLAY_PASSKEY || |
| 306 pairing == PairingEventType.CONFIRM_PASSKEY)) { | 310 pairing == PairingEventType.KEYS_ENTERED || |
| 307 var passkeyString = String(this.pairingEvent.passkey); | 311 pairing == PairingEventType.CONFIRM_PASSKEY)) { |
| 308 if (index < passkeyString.length) | 312 var passkeyString = String(this.pairingEvent.passkey); |
| 309 digit = passkeyString[index]; | 313 if (index < passkeyString.length) |
| 310 } | 314 digit = passkeyString[index]; |
| 311 return digit; | 315 } |
| 312 }, | 316 return digit; |
| 313 | 317 }, |
| 314 /** | 318 |
| 319 /** |
| 315 * @param {number} index | 320 * @param {number} index |
| 316 * @return {string} | 321 * @return {string} |
| 317 * @private | 322 * @private |
| 318 */ | 323 */ |
| 319 getPinClass_: function(index) { | 324 getPinClass_: function(index) { |
| 320 if (!this.pairingEvent) | 325 if (!this.pairingEvent) |
| 321 return ''; | 326 return ''; |
| 322 if (this.pairingEvent.pairing == PairingEventType.CONFIRM_PASSKEY) | 327 if (this.pairingEvent.pairing == PairingEventType.CONFIRM_PASSKEY) |
| 323 return 'confirm'; | 328 return 'confirm'; |
| 324 var cssClass = 'display'; | 329 var cssClass = 'display'; |
| 325 if (this.pairingEvent.pairing == PairingEventType.DISPLAY_PASSKEY) { | 330 if (this.pairingEvent.pairing == PairingEventType.DISPLAY_PASSKEY) { |
| 326 if (index == 0) | 331 if (index == 0) |
| 327 cssClass += ' next'; | 332 cssClass += ' next'; |
| 328 else | 333 else |
| 329 cssClass += ' untyped'; | 334 cssClass += ' untyped'; |
| 330 } else if ( | 335 } else if ( |
| 331 this.pairingEvent.pairing == PairingEventType.KEYS_ENTERED && | 336 this.pairingEvent.pairing == PairingEventType.KEYS_ENTERED && |
| 332 this.pairingEvent.enteredKey) { | 337 this.pairingEvent.enteredKey) { |
| 333 var enteredKey = this.pairingEvent.enteredKey; // 1-7 | 338 var enteredKey = this.pairingEvent.enteredKey; // 1-7 |
| 334 var lastKey = this.digits.length; // 6 | 339 var lastKey = this.digits.length; // 6 |
| 335 if ((index == -1 && enteredKey > lastKey) || (index + 1 == enteredKey)) | 340 if ((index == -1 && enteredKey > lastKey) || (index + 1 == enteredKey)) |
| 336 cssClass += ' next'; | 341 cssClass += ' next'; |
| 337 else if (index > enteredKey) | 342 else if (index > enteredKey) |
| 338 cssClass += ' untyped'; | 343 cssClass += ' untyped'; |
| 339 } | 344 } |
| 340 return cssClass; | 345 return cssClass; |
| 341 }, | 346 }, |
| 342 }; | 347 }; |
| 343 | 348 |
| 344 Polymer({ | 349 Polymer({ |
| 345 is: 'bluetooth-device-dialog', | 350 is: 'bluetooth-device-dialog', |
| 346 | 351 |
| 347 behaviors: [ | 352 behaviors: [ |
| 348 I18nBehavior, | 353 I18nBehavior, |
| 349 CrScrollableBehavior, | 354 CrScrollableBehavior, |
| 350 settings.BluetoothAddDeviceBehavior, | 355 settings.BluetoothAddDeviceBehavior, |
| 351 settings.BluetoothPairDeviceBehavior, | 356 settings.BluetoothPairDeviceBehavior, |
| 352 ], | 357 ], |
| 353 | 358 |
| 354 properties: { | 359 properties: { |
| 355 /** | 360 /** |
| 356 * The version of this dialog to show: 'addDevice', 'pairDevice', or | 361 * The version of this dialog to show: 'addDevice', 'pairDevice', or |
| 357 * 'connectError'. Must be set before the dialog is opened. | 362 * 'connectError'. Must be set before the dialog is opened. |
| 358 */ | 363 */ |
| 359 dialogId: String, | 364 dialogId: String, |
| 360 }, | 365 }, |
| 361 | 366 |
| 362 observers: [ | 367 observers: [ |
| 363 'dialogUpdated_(dialogId, pairingEvent)', | 368 'dialogUpdated_(dialogId, pairingEvent)', |
| 364 ], | 369 ], |
| 365 | 370 |
| 366 open: function() { | 371 open: function() { |
| 367 this.pinOrPass = ''; | 372 this.pinOrPass = ''; |
| 368 this.getDialog_().showModal(); | 373 this.getDialog_().showModal(); |
| 369 this.itemWasFocused_ = false; | 374 this.itemWasFocused_ = false; |
| 370 }, | 375 }, |
| 371 | 376 |
| 372 close: function() { | 377 close: function() { |
| 373 var dialog = this.getDialog_(); | 378 var dialog = this.getDialog_(); |
| 374 if (dialog.open) | 379 if (dialog.open) |
| 375 dialog.close(); | 380 dialog.close(); |
| 376 }, | 381 }, |
| 377 | 382 |
| 378 /** @private */ | 383 /** @private */ |
| 379 dialogUpdated_: function() { | 384 dialogUpdated_: function() { |
| 380 if (this.showEnterPincode_()) | 385 if (this.showEnterPincode_()) |
| 381 this.$$('#pincode').focus(); | 386 this.$$('#pincode').focus(); |
| 382 else if (this.showEnterPasskey_()) | 387 else if (this.showEnterPasskey_()) |
| 383 this.$$('#passkey').focus(); | 388 this.$$('#passkey').focus(); |
| 384 }, | 389 }, |
| 385 | 390 |
| 386 /** | 391 /** |
| 387 * @return {!CrDialogElement} | 392 * @return {!CrDialogElement} |
| 388 * @private | 393 * @private |
| 389 */ | 394 */ |
| 390 getDialog_: function() { | 395 getDialog_: function() { |
| 391 return /** @type {!CrDialogElement} */ (this.$.dialog); | 396 return /** @type {!CrDialogElement} */ (this.$.dialog); |
| 392 }, | 397 }, |
| 393 | 398 |
| 394 /** | 399 /** |
| 395 * @param {string} desiredDialogType | 400 * @param {string} desiredDialogType |
| 396 * @return {boolean} | 401 * @return {boolean} |
| 397 * @private | 402 * @private |
| 398 */ | 403 */ |
| 399 isDialogType_: function(desiredDialogType, currentDialogType) { | 404 isDialogType_: function(desiredDialogType, currentDialogType) { |
| 400 return currentDialogType == desiredDialogType; | 405 return currentDialogType == desiredDialogType; |
| 401 }, | 406 }, |
| 402 | 407 |
| 403 /** @private */ | 408 /** @private */ |
| 404 onCancelTap_: function() { | 409 onCancelTap_: function() { |
| 405 this.getDialog_().cancel(); | 410 this.getDialog_().cancel(); |
| 406 }, | 411 }, |
| 407 | 412 |
| 408 /** @private */ | 413 /** @private */ |
| 409 onDialogCanceled_: function() { | 414 onDialogCanceled_: function() { |
| 410 if (this.dialogId == 'pairDevice') | 415 if (this.dialogId == 'pairDevice') |
| 411 this.sendResponse_(chrome.bluetoothPrivate.PairingResponse.CANCEL); | 416 this.sendResponse_(chrome.bluetoothPrivate.PairingResponse.CANCEL); |
| 412 }, | 417 }, |
| 413 }); | 418 }); |
| 414 | 419 |
| 415 })(); | 420 })(); |
| OLD | NEW |