Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(362)

Side by Side Diff: chrome/browser/resources/settings/bluetooth_page/bluetooth_device_dialog.js

Issue 2676103002: MD Settings: Move bluetooth UI from dialog to subpage (Closed)
Patch Set: . Created 3 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 this behaviors is only used privately, it must
fukino 2017/02/08 16:58:23 nit: s/behaviors/behavior
stevenjb 2017/02/08 20:27:00 Done.
10 // be globally accessible for Closure's --polymer_pass to compile happily. 10 // be globally accessible for Closure's --polymer_pass to compile happily.
11 11
12 /** @polymerBehavior */ 12 /** @polymerBehavior */
13 settings.BluetoothAddDeviceBehavior = {
14 properties: {
15 /**
16 * The cached bluetooth adapter state.
17 * @type {!chrome.bluetooth.AdapterState|undefined}
18 */
19 adapterState: {
20 type: Object,
21 observer: 'adapterStateChanged_',
22 },
23
24 /**
25 * The ordered list of bluetooth devices.
26 * @type {!Array<!chrome.bluetooth.Device>}
27 */
28 deviceList: {
29 type: Array,
30 value: /** @return {Array} */ function() {
31 return [];
32 },
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 },
44 },
45
46 /**
47 * Reflects the iron-list selecteditem property.
48 * @type {!chrome.bluetooth.Device}
49 */
50 selectedItem_: {
51 type: Object,
52 observer: 'selectedItemChanged_',
53 },
54 },
55
56 observers: ['deviceListChanged_(deviceList.*)'],
57
58 /** @type {boolean} */
59 itemWasFocused_: false,
60
61 /** @private */
62 adapterStateChanged_: function() {
63 if (!this.adapterState.powered)
64 this.close();
65 },
66
67 /** @private */
68 deviceListChanged_: function() {
69 this.saveScroll(this.$.devices);
70 this.unpairedDeviceList_ = this.deviceList.filter(function(device) {
71 return !device.paired;
72 });
73 this.updateScrollableContents();
74 this.restoreScroll(this.$.devices);
75
76 if (this.itemWasFocused_ || !this.unpairedDeviceList_.length)
77 return;
78 // If the iron-list is populated with at least one visible item then
79 // focus it.
80 var item = this.$$('iron-list bluetooth-device-list-item');
81 if (item && item.offsetParent != null) {
82 item.focus();
83 this.itemWasFocused_ = true;
84 return;
85 }
86 // Otherwise try again.
87 setTimeout(function() {
88 this.deviceListChanged_();
89 }.bind(this), 100);
90 },
91
92 /** @private */
93 selectedItemChanged_: function() {
94 if (!this.selectedItem_)
95 return;
96 this.fire('device-event', {action: 'connect', device: this.selectedItem_});
97 },
98
99 /**
100 * @return {boolean}
101 * @private
102 */
103 haveUnpaired_: function() {
104 return this.unpairedDeviceList_.length > 0;
105 },
106 };
107
108 /** @polymerBehavior */
109 settings.BluetoothPairDeviceBehavior = { 13 settings.BluetoothPairDeviceBehavior = {
110 properties: { 14 properties: {
111 /** 15 /**
112 * Current Pairing device. 16 * Current Pairing device.
113 * @type {!chrome.bluetooth.Device|undefined} 17 * @type {!chrome.bluetooth.Device|undefined}
114 */ 18 */
115 pairingDevice: Object, 19 pairingDevice: Object,
116 20
117 /** 21 /**
118 * Current Pairing event. 22 * Current Pairing event.
(...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after
193 // 'keysEntered' event might not include the updated passkey so preserve 97 // 'keysEntered' event might not include the updated passkey so preserve
194 // the current one. 98 // the current one.
195 event.passkey = this.pairingEvent_.passkey; 99 event.passkey = this.pairingEvent_.passkey;
196 } 100 }
197 this.pairingEvent_ = event; 101 this.pairingEvent_ = event;
198 }, 102 },
199 103
200 /** @private */ 104 /** @private */
201 pairingChanged_: function() { 105 pairingChanged_: function() {
202 // Auto-close the dialog when pairing completes. 106 // Auto-close the dialog when pairing completes.
203 if (this.pairingDevice.connected) { 107 if (this.pairingDevice.paired && !this.pairingDevice.connecting &&
108 this.pairingDevice.connected) {
204 this.close(); 109 this.close();
205 return; 110 return;
206 } 111 }
207 this.pinOrPass = ''; 112 this.pinOrPass = '';
208 }, 113 },
209 114
210 /** 115 /**
211 * @return {string} 116 * @return {string}
212 * @private 117 * @private
213 */ 118 */
(...skipping 205 matching lines...) Expand 10 before | Expand all | Expand 10 after
419 return cssClass; 324 return cssClass;
420 }, 325 },
421 }; 326 };
422 327
423 Polymer({ 328 Polymer({
424 is: 'bluetooth-device-dialog', 329 is: 'bluetooth-device-dialog',
425 330
426 behaviors: [ 331 behaviors: [
427 I18nBehavior, 332 I18nBehavior,
428 CrScrollableBehavior, 333 CrScrollableBehavior,
429 settings.BluetoothAddDeviceBehavior,
430 settings.BluetoothPairDeviceBehavior, 334 settings.BluetoothPairDeviceBehavior,
431 ], 335 ],
432 336
433 properties: { 337 properties: {
434 /** 338 /**
435 * The version of this dialog to show: 'addDevice', 'pairDevice', or 339 * The version of this dialog to show: 'pairDevice', or 'connectError'.
436 * 'connectError'. Must be set before the dialog is opened. 340 * Must be set before the dialog is opened.
437 */ 341 */
438 dialogId: String, 342 dialogId: String,
439 }, 343 },
440 344
441 observers: [ 345 observers: [
442 'dialogUpdated_(dialogId, pairingEvent_)', 346 'dialogUpdated_(dialogId, pairingEvent_)',
443 ], 347 ],
444 348
445 open: function() { 349 open: function() {
446 this.startPairing(); 350 this.startPairing();
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after
486 this.getDialog_().cancel(); 390 this.getDialog_().cancel();
487 }, 391 },
488 392
489 /** @private */ 393 /** @private */
490 onDialogCanceled_: function() { 394 onDialogCanceled_: function() {
491 if (this.dialogId == 'pairDevice') 395 if (this.dialogId == 'pairDevice')
492 this.sendResponse_(chrome.bluetoothPrivate.PairingResponse.CANCEL); 396 this.sendResponse_(chrome.bluetoothPrivate.PairingResponse.CANCEL);
493 this.endPairing(); 397 this.endPairing();
494 }, 398 },
495 }); 399 });
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698