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 |
38 /** @private */ | 48 /** @private */ |
39 adapterStateChanged_: function() { | 49 adapterStateChanged_: function() { |
40 if (!this.adapterState.powered) | 50 if (!this.adapterState.powered) |
41 this.close(); | 51 this.close(); |
42 }, | 52 }, |
43 | 53 |
| 54 /** @private */ |
| 55 deviceListChanged_: function() { |
| 56 this.updateScrollableContents(); |
| 57 }, |
| 58 |
| 59 /** @private */ |
| 60 selectedItemChanged_: function() { |
| 61 if (this.selectedItem) |
| 62 this.fire('device-event', {action: 'connect', device: this.selectedItem}); |
| 63 }, |
| 64 |
44 /** | 65 /** |
45 * @param {!chrome.bluetooth.Device} device | 66 * @return {!Array<!chrome.bluetooth.Device>} |
46 * @return {boolean} | |
47 * @private | 67 * @private |
48 */ | 68 */ |
49 deviceNotPaired_: function(device) { | 69 getUnpaired_: function() { |
50 return !device.paired; | 70 return this.deviceList.filter(function(device) { |
| 71 return !device.paired; |
| 72 }); |
51 }, | 73 }, |
52 | 74 |
53 /** | 75 /** |
54 * @return {boolean} True if deviceList contains any unpaired devices. | 76 * @return {boolean} True if deviceList contains any unpaired devices. |
55 * @private | 77 * @private |
56 */ | 78 */ |
57 haveDevices_: function(deviceList) { | 79 haveUnpaired_: function(deviceList) { |
58 return this.deviceList.findIndex(function(d) { | 80 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 }, | 81 }, |
71 }; | 82 }; |
72 | 83 |
73 /** @polymerBehavior */ | 84 /** @polymerBehavior */ |
74 settings.BluetoothPairDeviceBehavior = { | 85 settings.BluetoothPairDeviceBehavior = { |
75 properties: { | 86 properties: { |
76 /** | 87 /** |
77 * Current Pairing device. | 88 * Current Pairing device. |
78 * @type {?chrome.bluetooth.Device|undefined} | 89 * @type {?chrome.bluetooth.Device|undefined} |
79 */ | 90 */ |
(...skipping 234 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
314 } | 325 } |
315 return cssClass; | 326 return cssClass; |
316 }, | 327 }, |
317 }; | 328 }; |
318 | 329 |
319 Polymer({ | 330 Polymer({ |
320 is: 'bluetooth-device-dialog', | 331 is: 'bluetooth-device-dialog', |
321 | 332 |
322 behaviors: [ | 333 behaviors: [ |
323 I18nBehavior, | 334 I18nBehavior, |
| 335 CrScrollableBehavior, |
324 settings.BluetoothAddDeviceBehavior, | 336 settings.BluetoothAddDeviceBehavior, |
325 settings.BluetoothPairDeviceBehavior, | 337 settings.BluetoothPairDeviceBehavior, |
326 ], | 338 ], |
327 | 339 |
328 properties: { | 340 properties: { |
329 /** Which version of this dialog to show (adding or pairing). */ | 341 /** |
| 342 * The version of this dialog to show: 'addDevice', 'pairDevice', or |
| 343 * 'connectError'. Must be set before the dialog is opened. |
| 344 */ |
330 dialogId: String, | 345 dialogId: String, |
331 }, | 346 }, |
332 | 347 |
333 observers: [ | 348 observers: [ |
334 'dialogUpdated_(dialogId, pairingEvent)', | 349 'dialogUpdated_(dialogId, pairingEvent)', |
335 ], | 350 ], |
336 | 351 |
337 open: function() { | 352 open: function() { |
338 this.pinOrPass = ''; | 353 this.pinOrPass = ''; |
339 this.getDialog_().showModal(); | 354 this.getDialog_().showModal(); |
| 355 |
| 356 assert(!!this.dialogId); |
| 357 if (this.dialogId != 'addDevice') |
| 358 return; |
| 359 |
| 360 // Wait until the iron-list is populated with at least one visible item |
| 361 // then focus it. |
| 362 var intervalId = setInterval(function() { |
| 363 let item = this.$$('iron-list bluetooth-device-list-item'); |
| 364 if (item && item.offsetParent != null) { |
| 365 clearInterval(intervalId); |
| 366 item.focus(); |
| 367 } |
| 368 }.bind(this), 100); |
340 }, | 369 }, |
341 | 370 |
342 close: function() { | 371 close: function() { |
343 var dialog = this.getDialog_(); | 372 var dialog = this.getDialog_(); |
344 if (dialog.open) | 373 if (dialog.open) |
345 dialog.close(); | 374 dialog.close(); |
346 }, | 375 }, |
347 | 376 |
348 /** @private */ | 377 /** @private */ |
349 dialogUpdated_: function() { | 378 dialogUpdated_: function() { |
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
387 }, | 416 }, |
388 | 417 |
389 /** @private */ | 418 /** @private */ |
390 onDialogCanceled_: function() { | 419 onDialogCanceled_: function() { |
391 if (this.dialogId == 'pairDevice') | 420 if (this.dialogId == 'pairDevice') |
392 this.sendResponse_(chrome.bluetoothPrivate.PairingResponse.CANCEL); | 421 this.sendResponse_(chrome.bluetoothPrivate.PairingResponse.CANCEL); |
393 }, | 422 }, |
394 }); | 423 }); |
395 | 424 |
396 })(); | 425 })(); |
OLD | NEW |