| 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 var PairingEventType = chrome.bluetoothPrivate.PairingEventType; | 7 var PairingEventType = chrome.bluetoothPrivate.PairingEventType; |
| 8 | 8 |
| 9 // NOTE(dbeam): even though these behaviors are only used privately, they must | 9 // NOTE(dbeam): even though these behaviors are only used privately, they must |
| 10 // be globally accessible for Closure's --polymer_pass to compile happily. | 10 // be globally accessible for Closure's --polymer_pass to compile happily. |
| (...skipping 12 matching lines...) Expand all Loading... |
| 23 | 23 |
| 24 /** | 24 /** |
| 25 * The ordered list of bluetooth devices. | 25 * The ordered list of bluetooth devices. |
| 26 * @type {!Array<!chrome.bluetooth.Device>} | 26 * @type {!Array<!chrome.bluetooth.Device>} |
| 27 */ | 27 */ |
| 28 deviceList: { | 28 deviceList: { |
| 29 type: Array, | 29 type: Array, |
| 30 value: /** @return {Array} */ function() { | 30 value: /** @return {Array} */ function() { |
| 31 return []; | 31 return []; |
| 32 }, | 32 }, |
| 33 observer: 'deviceListChanged_', | 33 }, |
| 34 |
| 35 /** |
| 36 * The ordered list of unpaired bluetooth devices. |
| 37 * @type {!Array<!chrome.bluetooth.Device>} |
| 38 */ |
| 39 unpairedDeviceList_: { |
| 40 type: Array, |
| 41 value: /** @return {Array} */ function() { |
| 42 return []; |
| 43 }, |
| 34 }, | 44 }, |
| 35 | 45 |
| 36 /** | 46 /** |
| 37 * Reflects the iron-list selecteditem property. | 47 * Reflects the iron-list selecteditem property. |
| 38 * @type {!chrome.bluetooth.Device} | 48 * @type {!chrome.bluetooth.Device} |
| 39 */ | 49 */ |
| 40 selectedItem: { | 50 selectedItem_: { |
| 41 type: Object, | 51 type: Object, |
| 42 observer: 'selectedItemChanged_', | 52 observer: 'selectedItemChanged_', |
| 43 }, | 53 }, |
| 44 }, | 54 }, |
| 45 | 55 |
| 56 observers: ['deviceListChanged_(deviceList.*)'], |
| 57 |
| 46 /** @type {boolean} */ | 58 /** @type {boolean} */ |
| 47 itemWasFocused_: false, | 59 itemWasFocused_: false, |
| 48 | 60 |
| 49 /** @private */ | 61 /** @private */ |
| 50 adapterStateChanged_: function() { | 62 adapterStateChanged_: function() { |
| 51 if (!this.adapterState.powered) | 63 if (!this.adapterState.powered) |
| 52 this.close(); | 64 this.close(); |
| 53 }, | 65 }, |
| 54 | 66 |
| 55 /** @private */ | 67 /** @private */ |
| 56 deviceListChanged_: function() { | 68 deviceListChanged_: function() { |
| 69 this.saveScroll(this.$.devices); |
| 70 this.unpairedDeviceList_ = this.deviceList.filter(function(device) { |
| 71 return !device.paired; |
| 72 }); |
| 57 this.updateScrollableContents(); | 73 this.updateScrollableContents(); |
| 58 if (this.itemWasFocused_ || !this.getUnpaired_().length) | 74 this.restoreScroll(this.$.devices); |
| 75 |
| 76 if (this.itemWasFocused_ || !this.unpairedDeviceList_.length) |
| 59 return; | 77 return; |
| 60 // If the iron-list is populated with at least one visible item then | 78 // If the iron-list is populated with at least one visible item then |
| 61 // focus it. | 79 // focus it. |
| 62 var item = this.$$('iron-list bluetooth-device-list-item'); | 80 var item = this.$$('iron-list bluetooth-device-list-item'); |
| 63 if (item && item.offsetParent != null) { | 81 if (item && item.offsetParent != null) { |
| 64 item.focus(); | 82 item.focus(); |
| 65 this.itemWasFocused_ = true; | 83 this.itemWasFocused_ = true; |
| 66 return; | 84 return; |
| 67 } | 85 } |
| 68 // Otherwise try again. | 86 // Otherwise try again. |
| 69 setTimeout(function() { | 87 setTimeout(function() { |
| 70 this.deviceListChanged_(); | 88 this.deviceListChanged_(); |
| 71 }.bind(this), 100); | 89 }.bind(this), 100); |
| 72 }, | 90 }, |
| 73 | 91 |
| 74 /** @private */ | 92 /** @private */ |
| 75 selectedItemChanged_: function() { | 93 selectedItemChanged_: function() { |
| 76 if (this.selectedItem) | 94 if (!this.selectedItem_) |
| 77 this.fire('device-event', {action: 'connect', device: this.selectedItem}); | 95 return; |
| 96 this.fire('device-event', {action: 'connect', device: this.selectedItem_}); |
| 78 }, | 97 }, |
| 79 | 98 |
| 80 /** | 99 /** |
| 81 * @return {!Array<!chrome.bluetooth.Device>} | 100 * @return {boolean} |
| 82 * @private | 101 * @private |
| 83 */ | 102 */ |
| 84 getUnpaired_: function() { | 103 haveUnpaired_: function() { |
| 85 return this.deviceList.filter(function(device) { | 104 return this.unpairedDeviceList_.length > 0; |
| 86 return !device.paired; | |
| 87 }); | |
| 88 }, | |
| 89 | |
| 90 /** | |
| 91 * @return {boolean} True if deviceList contains any unpaired devices. | |
| 92 * @private | |
| 93 */ | |
| 94 haveUnpaired_: function(deviceList) { | |
| 95 return this.getUnpaired_().length > 0; | |
| 96 }, | 105 }, |
| 97 }; | 106 }; |
| 98 | 107 |
| 99 /** @polymerBehavior */ | 108 /** @polymerBehavior */ |
| 100 settings.BluetoothPairDeviceBehavior = { | 109 settings.BluetoothPairDeviceBehavior = { |
| 101 properties: { | 110 properties: { |
| 102 /** | 111 /** |
| 103 * Current Pairing device. | 112 * Current Pairing device. |
| 104 * @type {!chrome.bluetooth.Device|undefined} | 113 * @type {!chrome.bluetooth.Device|undefined} |
| 105 */ | 114 */ |
| (...skipping 371 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 477 this.getDialog_().cancel(); | 486 this.getDialog_().cancel(); |
| 478 }, | 487 }, |
| 479 | 488 |
| 480 /** @private */ | 489 /** @private */ |
| 481 onDialogCanceled_: function() { | 490 onDialogCanceled_: function() { |
| 482 if (this.dialogId == 'pairDevice') | 491 if (this.dialogId == 'pairDevice') |
| 483 this.sendResponse_(chrome.bluetoothPrivate.PairingResponse.CANCEL); | 492 this.sendResponse_(chrome.bluetoothPrivate.PairingResponse.CANCEL); |
| 484 this.endPairing(); | 493 this.endPairing(); |
| 485 }, | 494 }, |
| 486 }); | 495 }); |
| OLD | NEW |