| 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 |
| (...skipping 14 matching lines...) Expand all Loading... |
| 25 | 25 |
| 26 /** | 26 /** |
| 27 * The ordered list of bluetooth devices. | 27 * The ordered list of bluetooth devices. |
| 28 * @type {!Array<!chrome.bluetooth.Device>} | 28 * @type {!Array<!chrome.bluetooth.Device>} |
| 29 */ | 29 */ |
| 30 deviceList: { | 30 deviceList: { |
| 31 type: Array, | 31 type: Array, |
| 32 value: /** @return {Array} */ function() { | 32 value: /** @return {Array} */ function() { |
| 33 return []; | 33 return []; |
| 34 }, | 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_', |
| 35 }, | 45 }, |
| 36 }, | 46 }, |
| 37 | 47 |
| 48 /** @type {boolean} */ itemWasFocused_: false, |
| 49 |
| 38 /** @private */ | 50 /** @private */ |
| 39 adapterStateChanged_: function() { | 51 adapterStateChanged_: function() { |
| 40 if (!this.adapterState.powered) | 52 if (!this.adapterState.powered) |
| 41 this.close(); | 53 this.close(); |
| 42 }, | 54 }, |
| 43 | 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 |
| 44 /** | 79 /** |
| 45 * @param {!chrome.bluetooth.Device} device | 80 * @return {!Array<!chrome.bluetooth.Device>} |
| 46 * @return {boolean} | |
| 47 * @private | 81 * @private |
| 48 */ | 82 */ |
| 49 deviceNotPaired_: function(device) { | 83 getUnpaired_: function() { |
| 50 return !device.paired; | 84 return this.deviceList.filter(function(device) { |
| 85 return !device.paired; |
| 86 }); |
| 51 }, | 87 }, |
| 52 | 88 |
| 53 /** | 89 /** |
| 54 * @return {boolean} True if deviceList contains any unpaired devices. | 90 * @return {boolean} True if deviceList contains any unpaired devices. |
| 55 * @private | 91 * @private |
| 56 */ | 92 */ |
| 57 haveDevices_: function(deviceList) { | 93 haveUnpaired_: function(deviceList) { |
| 58 return this.deviceList.findIndex(function(d) { | 94 return this.getUnpaired_().length > 0; |
| 59 return !d.paired; | |
| 60 }) != -1; | |
| 61 }, | |
| 62 | |
| 63 /** | |
| 64 * @param {!{detail: {action: string, device: !chrome.bluetooth.Device}}} e | |
| 65 * @private | |
| 66 */ | |
| 67 onDeviceEvent_: function(e) { | |
| 68 this.fire('device-event', e.detail); | |
| 69 /** @type {Event} */ (e).stopPropagation(); | |
| 70 }, | 95 }, |
| 71 }; | 96 }; |
| 72 | 97 |
| 73 /** @polymerBehavior */ | 98 /** @polymerBehavior */ |
| 74 settings.BluetoothPairDeviceBehavior = { | 99 settings.BluetoothPairDeviceBehavior = { |
| 75 properties: { | 100 properties: { |
| 76 /** | 101 /** |
| 77 * Current Pairing device. | 102 * Current Pairing device. |
| 78 * @type {?chrome.bluetooth.Device|undefined} | 103 * @type {?chrome.bluetooth.Device|undefined} |
| 79 */ | 104 */ |
| (...skipping 234 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 314 } | 339 } |
| 315 return cssClass; | 340 return cssClass; |
| 316 }, | 341 }, |
| 317 }; | 342 }; |
| 318 | 343 |
| 319 Polymer({ | 344 Polymer({ |
| 320 is: 'bluetooth-device-dialog', | 345 is: 'bluetooth-device-dialog', |
| 321 | 346 |
| 322 behaviors: [ | 347 behaviors: [ |
| 323 I18nBehavior, | 348 I18nBehavior, |
| 349 CrScrollableBehavior, |
| 324 settings.BluetoothAddDeviceBehavior, | 350 settings.BluetoothAddDeviceBehavior, |
| 325 settings.BluetoothPairDeviceBehavior, | 351 settings.BluetoothPairDeviceBehavior, |
| 326 ], | 352 ], |
| 327 | 353 |
| 328 properties: { | 354 properties: { |
| 329 /** Which version of this dialog to show (adding or pairing). */ | 355 /** |
| 356 * The version of this dialog to show: 'addDevice', 'pairDevice', or |
| 357 * 'connectError'. Must be set before the dialog is opened. |
| 358 */ |
| 330 dialogId: String, | 359 dialogId: String, |
| 331 }, | 360 }, |
| 332 | 361 |
| 333 observers: [ | 362 observers: [ |
| 334 'dialogUpdated_(dialogId, pairingEvent)', | 363 'dialogUpdated_(dialogId, pairingEvent)', |
| 335 ], | 364 ], |
| 336 | 365 |
| 337 open: function() { | 366 open: function() { |
| 338 this.pinOrPass = ''; | 367 this.pinOrPass = ''; |
| 339 this.getDialog_().showModal(); | 368 this.getDialog_().showModal(); |
| 369 this.itemWasFocused_ = false; |
| 340 }, | 370 }, |
| 341 | 371 |
| 342 close: function() { | 372 close: function() { |
| 343 var dialog = this.getDialog_(); | 373 var dialog = this.getDialog_(); |
| 344 if (dialog.open) | 374 if (dialog.open) |
| 345 dialog.close(); | 375 dialog.close(); |
| 346 }, | 376 }, |
| 347 | 377 |
| 348 /** @private */ | 378 /** @private */ |
| 349 dialogUpdated_: function() { | 379 dialogUpdated_: function() { |
| (...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 387 }, | 417 }, |
| 388 | 418 |
| 389 /** @private */ | 419 /** @private */ |
| 390 onDialogCanceled_: function() { | 420 onDialogCanceled_: function() { |
| 391 if (this.dialogId == 'pairDevice') | 421 if (this.dialogId == 'pairDevice') |
| 392 this.sendResponse_(chrome.bluetoothPrivate.PairingResponse.CANCEL); | 422 this.sendResponse_(chrome.bluetoothPrivate.PairingResponse.CANCEL); |
| 393 }, | 423 }, |
| 394 }); | 424 }); |
| 395 | 425 |
| 396 })(); | 426 })(); |
| OLD | NEW |