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

Side by Side Diff: chrome/browser/resources/options2/chromeos/bluetooth_device_list.js

Issue 9570018: Fix Bluetooth list redraw issues. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Remove all use of the 'icon' property. Created 8 years, 9 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 | Annotate | Revision Log
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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.define('options.system.bluetooth', function() { 5 cr.define('options.system.bluetooth', function() {
6 const ArrayDataModel = cr.ui.ArrayDataModel; 6 const ArrayDataModel = cr.ui.ArrayDataModel;
7 const DeletableItem = options.DeletableItem; 7 const DeletableItem = options.DeletableItem;
8 const DeletableItemList = options.DeletableItemList; 8 const DeletableItemList = options.DeletableItemList;
9 9
10 /** 10 /**
11 * Bluetooth settings constants. 11 * Bluetooth settings constants.
12 */ 12 */
13 function Constants() {} 13 function Constants() {}
14 14
15 /** 15 /**
16 * Enumeration of supported device types.
17 * @enum {string}
18 */
19 // TODO(kevers): Prune list based on the set of devices that will be
20 // supported for V1 of the feature. The set will likely be restricted to
21 // mouse and keyboard. Others are temporarily included for testing device
22 // discovery.
23 Constants.DEVICE_TYPE = {
24 COMPUTER: 'computer',
25 HEADSET: 'headset',
26 KEYBOARD: 'input-keyboard',
27 MOUSE: 'input-mouse',
28 PHONE: 'phone',
29 };
30
31 /**
32 * Creates a new bluetooth list item. 16 * Creates a new bluetooth list item.
33 * @param {{name: string, 17 * @param {{name: string,
34 * address: string, 18 * address: string,
35 * icon: Constants.DEVICE_TYPE,
36 * paired: boolean, 19 * paired: boolean,
37 * connected: boolean, 20 * connected: boolean,
38 * pairing: string|undefined, 21 * pairing: string|undefined,
39 * passkey: number|undefined, 22 * passkey: number|undefined,
40 * entered: number|undefined}} device 23 * entered: number|undefined}} device
41 * Description of the Bluetooth device. 24 * Description of the Bluetooth device.
42 * @constructor 25 * @constructor
43 * @extends {options.DeletableItem} 26 * @extends {options.DeletableItem}
44 */ 27 */
45 function BluetoothListItem(device) { 28 function BluetoothListItem(device) {
46 var el = cr.doc.createElement('div'); 29 var el = cr.doc.createElement('div');
47 el.__proto__ = BluetoothListItem.prototype; 30 el.__proto__ = BluetoothListItem.prototype;
48 el.data = {}; 31 el.data = {};
49 for (var key in device) 32 for (var key in device)
50 el.data[key] = device[key]; 33 el.data[key] = device[key];
51 el.decorate(); 34 el.decorate();
52 // Only show the close button for paired devices. 35 // Only show the close button for paired devices.
53 el.deletable = device.paired; 36 el.deletable = device.paired;
54 return el; 37 return el;
55 } 38 }
56 39
57 BluetoothListItem.prototype = { 40 BluetoothListItem.prototype = {
58 __proto__: DeletableItem.prototype, 41 __proto__: DeletableItem.prototype,
59 42
60 /** 43 /**
61 * Description of the Bluetooth device. 44 * Description of the Bluetooth device.
62 * @type {{name: string, 45 * @type {{name: string,
63 * address: string, 46 * address: string,
64 * icon: Constants.DEVICE_TYPE,
65 * paired: boolean, 47 * paired: boolean,
66 * connected: boolean, 48 * connected: boolean,
67 * pairing: string|undefined, 49 * pairing: string|undefined,
68 * passkey: number|undefined, 50 * passkey: number|undefined,
69 * entered: number|undefined}} 51 * entered: number|undefined}}
70 */ 52 */
71 data: null, 53 data: null,
72 54
73 /** @inheritDoc */ 55 /** @inheritDoc */
74 decorate: function() { 56 decorate: function() {
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after
117 // TODO(kevers): Should this be pushed up to the list class? 99 // TODO(kevers): Should this be pushed up to the list class?
118 this.selectionModel.unselectAll(); 100 this.selectionModel.unselectAll();
119 }, 101 },
120 102
121 /** 103 /**
122 * Adds a bluetooth device to the list of available devices. A check is 104 * Adds a bluetooth device to the list of available devices. A check is
123 * made to see if the device is already in the list, in which case the 105 * made to see if the device is already in the list, in which case the
124 * existing device is updated. 106 * existing device is updated.
125 * @param {{name: string, 107 * @param {{name: string,
126 * address: string, 108 * address: string,
127 * icon: Constants.DEVICE_TYPE,
128 * paired: boolean, 109 * paired: boolean,
129 * connected: boolean, 110 * connected: boolean,
130 * pairing: string|undefined, 111 * pairing: string|undefined,
131 * passkey: number|undefined, 112 * passkey: number|undefined,
132 * entered: number|undefined}} device 113 * entered: number|undefined}} device
133 * Description of the bluetooth device. 114 * Description of the bluetooth device.
134 * @return {boolean} True if the devies was successfully added or updated. 115 * @return {boolean} True if the devies was successfully added or updated.
135 */ 116 */
136 appendDevice: function(device) { 117 appendDevice: function(device) {
137 if (!this.isSupported_(device))
138 return false;
139 var index = this.find(device.address); 118 var index = this.find(device.address);
140 if (index == undefined) { 119 if (index == undefined) {
141 this.dataModel.push(device); 120 this.dataModel.push(device);
142 this.redraw(); 121 this.redraw();
143 } else { 122 } else {
144 this.dataModel.splice(index, 1, device); 123 this.dataModel.splice(index, 1, device);
145 this.redrawItem(index); 124 this.redrawItem(index);
146 } 125 }
147 this.updateListVisibility_(); 126 this.updateListVisibility_();
148 return true; 127 return true;
149 }, 128 },
150 129
151 /** 130 /**
131 * Forces a revailidation of the list content. Content added while the list
132 * is hidden is not properly rendered when the list becomes visible. In
133 * addition, deleting a single item from the list results in a stale cache
134 * requiring an invalidation.
135 */
136 refresh: function() {
137 // TODO(kevers): Investigate if the root source of the problems can be
138 // fixed in cr.ui.list.
139 this.invalidate();
140 this.redraw();
141 },
142
143 /**
152 * Perges all devices from the list. 144 * Perges all devices from the list.
153 */ 145 */
154 clear: function() { 146 clear: function() {
155 this.dataModel = new ArrayDataModel([]); 147 this.dataModel = new ArrayDataModel([]);
156 this.redraw(); 148 this.redraw();
157 this.updateListVisibility_(); 149 this.updateListVisibility_();
158 }, 150 },
159 151
160 /** 152 /**
161 * Returns the index of the list entry with the matching address. 153 * Returns the index of the list entry with the matching address.
(...skipping 17 matching lines...) Expand all
179 171
180 /** @inheritDoc */ 172 /** @inheritDoc */
181 deleteItemAtIndex: function(index) { 173 deleteItemAtIndex: function(index) {
182 var item = this.dataModel.item(index); 174 var item = this.dataModel.item(index);
183 if (item && (item.connected || item.paired)) { 175 if (item && (item.connected || item.paired)) {
184 // Inform the bluetooth adapter that we are disconnecting the device. 176 // Inform the bluetooth adapter that we are disconnecting the device.
185 chrome.send('updateBluetoothDevice', 177 chrome.send('updateBluetoothDevice',
186 [item.address, item.connected ? 'disconnect' : 'forget']); 178 [item.address, item.connected ? 'disconnect' : 'forget']);
187 } 179 }
188 this.dataModel.splice(index, 1); 180 this.dataModel.splice(index, 1);
189 // Invalidate the list since it has a stale cache after a splice 181 this.refresh();
190 // involving a deletion.
191 this.invalidate();
192 this.redraw();
193 this.updateListVisibility_(); 182 this.updateListVisibility_();
194 }, 183 },
195 184
196 /** 185 /**
197 * Tests if the bluetooth device is supported based on the type of device.
198 * @param {Object.<string,string>} device Desription of the device.
199 * @return {boolean} true if the device is supported.
200 * @private
201 */
202 isSupported_: function(device) {
203 var target = device.icon;
204 for (var key in Constants.DEVICE_TYPE) {
205 if (Constants.DEVICE_TYPE[key] == target)
206 return true;
207 }
208 return false;
209 },
210
211 /**
212 * If the list has an associated empty list placholder then update the 186 * If the list has an associated empty list placholder then update the
213 * visibility of the list and placeholder. 187 * visibility of the list and placeholder.
214 * @private 188 * @private
215 */ 189 */
216 updateListVisibility_: function() { 190 updateListVisibility_: function() {
217 var empty = this.dataModel.length == 0; 191 var empty = this.dataModel.length == 0;
218 var listPlaceHolderID = this.id + '-empty-placeholder'; 192 var listPlaceHolderID = this.id + '-empty-placeholder';
219 if ($(listPlaceHolderID)) { 193 if ($(listPlaceHolderID)) {
220 this.hidden = empty; 194 if (this.hidden != empty) {
221 $(listPlaceHolderID).hidden = !empty; 195 this.hidden = empty;
196 $(listPlaceHolderID).hidden = !empty;
197 this.refresh();
198 }
222 } 199 }
223 }, 200 },
224 }; 201 };
225 202
226 cr.defineProperty(BluetoothListItem, 'connected', cr.PropertyKind.BOOL_ATTR); 203 cr.defineProperty(BluetoothListItem, 'connected', cr.PropertyKind.BOOL_ATTR);
227 204
228 cr.defineProperty(BluetoothListItem, 'paired', cr.PropertyKind.BOOL_ATTR); 205 cr.defineProperty(BluetoothListItem, 'paired', cr.PropertyKind.BOOL_ATTR);
229 206
230 cr.defineProperty(BluetoothListItem, 'connecting', cr.PropertyKind.BOOL_ATTR); 207 cr.defineProperty(BluetoothListItem, 'connecting', cr.PropertyKind.BOOL_ATTR);
231 208
232 return { 209 return {
233 BluetoothListItem: BluetoothListItem, 210 BluetoothListItem: BluetoothListItem,
234 BluetoothDeviceList: BluetoothDeviceList, 211 BluetoothDeviceList: BluetoothDeviceList,
235 Constants: Constants 212 Constants: Constants
236 }; 213 };
237 }); 214 });
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698