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

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

Issue 2627373002: MD Settings: Save and restore scroll position in iron-list (Closed)
Patch Set: Use scrollTop Created 3 years, 11 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 (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
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_', 35 },
36
37 /**
38 * The ordered list of unpaired bluetooth devices.
39 * @type {!Array<!chrome.bluetooth.Device>}
40 */
41 unpairedDeviceList_: {
42 type: Array,
43 value: /** @return {Array} */ function() {
44 return [];
45 },
36 }, 46 },
37 47
38 /** 48 /**
39 * Reflects the iron-list selecteditem property. 49 * Reflects the iron-list selecteditem property.
40 * @type {!chrome.bluetooth.Device} 50 * @type {!chrome.bluetooth.Device}
41 */ 51 */
42 selectedItem: { 52 selectedItem_: {
43 type: Object, 53 type: Object,
44 observer: 'selectedItemChanged_', 54 observer: 'selectedItemChanged_',
45 }, 55 },
46 }, 56 },
47 57
48 /** @type {boolean} */ itemWasFocused_: false, 58 observers: ['deviceListChanged_(deviceList.*)'],
59
60 /** @type {boolean} */
61 itemWasFocused_: false,
49 62
50 /** @private */ 63 /** @private */
51 adapterStateChanged_: function() { 64 adapterStateChanged_: function() {
52 if (!this.adapterState.powered) 65 if (!this.adapterState.powered)
53 this.close(); 66 this.close();
54 }, 67 },
55 68
56 /** @private */ 69 /** @private */
57 deviceListChanged_: function() { 70 deviceListChanged_: function() {
71 var devices = this.$.devices;
72 this.saveScroll(devices);
73 this.unpairedDeviceList_ = this.deviceList.filter(function(device) {
74 return !device.paired;
75 });
Dan Beam 2017/01/24 06:15:18 can't we just make this do a diff instead? iron-l
58 this.updateScrollableContents(); 76 this.updateScrollableContents();
59 if (this.itemWasFocused_ || !this.getUnpaired_().length) 77 this.restoreScroll(devices);
78
79 if (this.itemWasFocused_ || !this.unpairedDeviceList_.length)
60 return; 80 return;
61 // If the iron-list is populated with at least one visible item then 81 // If the iron-list is populated with at least one visible item then
62 // focus it. 82 // focus it.
63 let item = this.$$('iron-list bluetooth-device-list-item'); 83 let item = this.$$('iron-list bluetooth-device-list-item');
64 if (item && item.offsetParent != null) { 84 if (item && item.offsetParent != null) {
65 item.focus(); 85 item.focus();
66 this.itemWasFocused_ = true; 86 this.itemWasFocused_ = true;
67 return; 87 return;
68 } 88 }
69 // Otherwise try again. 89 // Otherwise try again.
70 setTimeout(function() { this.deviceListChanged_(); }.bind(this), 100); 90 setTimeout(function() { this.deviceListChanged_(); }.bind(this), 100);
71 }, 91 },
72 92
73 /** @private */ 93 /** @private */
74 selectedItemChanged_: function() { 94 selectedItemChanged_: function() {
75 if (this.selectedItem) 95 if (!this.selectedItem_)
76 this.fire('device-event', {action: 'connect', device: this.selectedItem}); 96 return;
97 this.fire('device-event', {action: 'connect', device: this.selectedItem_});
77 }, 98 },
78 99
79 /** 100 /**
80 * @return {!Array<!chrome.bluetooth.Device>} 101 * @return {boolean}
81 * @private 102 * @private
82 */ 103 */
83 getUnpaired_: function() { 104 haveUnpaired_: function() {
84 return this.deviceList.filter(function(device) { 105 return this.unpairedDeviceList_.length > 0;
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 }, 106 },
96 }; 107 };
97 108
98 /** @polymerBehavior */ 109 /** @polymerBehavior */
99 settings.BluetoothPairDeviceBehavior = { 110 settings.BluetoothPairDeviceBehavior = {
100 properties: { 111 properties: {
101 /** 112 /**
102 * Current Pairing device. 113 * Current Pairing device.
103 * @type {?chrome.bluetooth.Device|undefined} 114 * @type {?chrome.bluetooth.Device|undefined}
104 */ 115 */
(...skipping 301 matching lines...) Expand 10 before | Expand all | Expand 10 after
406 }, 417 },
407 418
408 /** @private */ 419 /** @private */
409 onDialogCanceled_: function() { 420 onDialogCanceled_: function() {
410 if (this.dialogId == 'pairDevice') 421 if (this.dialogId == 'pairDevice')
411 this.sendResponse_(chrome.bluetoothPrivate.PairingResponse.CANCEL); 422 this.sendResponse_(chrome.bluetoothPrivate.PairingResponse.CANCEL);
412 }, 423 },
413 }); 424 });
414 425
415 })(); 426 })();
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698