| OLD | NEW |
| 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 */ var ArrayDataModel = cr.ui.ArrayDataModel; | 6 /** @const */ var ArrayDataModel = cr.ui.ArrayDataModel; |
| 7 /** @const */ var DeletableItem = options.DeletableItem; | 7 /** @const */ var DeletableItem = options.DeletableItem; |
| 8 /** @const */ var DeletableItemList = options.DeletableItemList; | 8 /** @const */ var DeletableItemList = options.DeletableItemList; |
| 9 /** @const */ var ListSingleSelectionModel = cr.ui.ListSingleSelectionModel; | 9 /** @const */ var ListSingleSelectionModel = cr.ui.ListSingleSelectionModel; |
| 10 | 10 |
| (...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 52 var connected = !!this.data.connected; | 52 var connected = !!this.data.connected; |
| 53 var connectable = !!this.data.connectable; | 53 var connectable = !!this.data.connectable; |
| 54 var paired = !!this.data.paired; | 54 var paired = !!this.data.paired; |
| 55 | 55 |
| 56 // There are four kinds of devices we want to distinguish: | 56 // There are four kinds of devices we want to distinguish: |
| 57 // * Connecting devices: in bold with a "connecting" label, | 57 // * Connecting devices: in bold with a "connecting" label, |
| 58 // * Connected devices: in bold, | 58 // * Connected devices: in bold, |
| 59 // * Paired, not connected but connectable devices: regular and | 59 // * Paired, not connected but connectable devices: regular and |
| 60 // * Paired, not connected and not connectable devices: grayed out. | 60 // * Paired, not connected and not connectable devices: grayed out. |
| 61 this.connected = connecting || (paired && connected); | 61 this.connected = connecting || (paired && connected); |
| 62 this.notconnectable = paired && !connecting && | 62 this.notconnectable = paired && !connecting && !connected && !connectable; |
| 63 !connected && !connectable; | |
| 64 // "paired" devices are those that are remembered but not connected. | 63 // "paired" devices are those that are remembered but not connected. |
| 65 this.paired = paired && !connected && connectable; | 64 this.paired = paired && !connected && connectable; |
| 66 | 65 |
| 67 var content = this.data.name; | 66 var content = this.data.name; |
| 68 // Update the device's label according to its state. A "connecting" device | 67 // Update the device's label according to its state. A "connecting" device |
| 69 // can be in the process of connecting and pairing, so we check connecting | 68 // can be in the process of connecting and pairing, so we check connecting |
| 70 // first. | 69 // first. |
| 71 if (connecting) { | 70 if (connecting) { |
| 72 content = loadTimeData.getStringF('bluetoothDeviceConnecting', | 71 content = loadTimeData.getStringF( |
| 73 this.data.name); | 72 'bluetoothDeviceConnecting', this.data.name); |
| 74 } | 73 } |
| 75 label.textContent = content; | 74 label.textContent = content; |
| 76 this.contentElement.appendChild(label); | 75 this.contentElement.appendChild(label); |
| 77 }, | 76 }, |
| 78 }; | 77 }; |
| 79 | 78 |
| 80 /** | 79 /** |
| 81 * Class for displaying a list of Bluetooth devices. | 80 * Class for displaying a list of Bluetooth devices. |
| 82 * @constructor | 81 * @constructor |
| 83 * @extends {options.DeletableItemList} | 82 * @extends {options.DeletableItemList} |
| (...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 141 | 140 |
| 142 /** | 141 /** |
| 143 * Forces a revailidation of the list content. Deleting a single item from | 142 * Forces a revailidation of the list content. Deleting a single item from |
| 144 * the list results in a stale cache requiring an invalidation. | 143 * the list results in a stale cache requiring an invalidation. |
| 145 * @param {string=} opt_selection Optional address of device to select | 144 * @param {string=} opt_selection Optional address of device to select |
| 146 * after refreshing the list. | 145 * after refreshing the list. |
| 147 */ | 146 */ |
| 148 refresh: function(opt_selection) { | 147 refresh: function(opt_selection) { |
| 149 // TODO(kevers): Investigate if the stale cache issue can be fixed in | 148 // TODO(kevers): Investigate if the stale cache issue can be fixed in |
| 150 // cr.ui.list. | 149 // cr.ui.list. |
| 151 var selectedDevice = opt_selection ? opt_selection : | 150 var selectedDevice = |
| 152 this.getSelectedDevice_(); | 151 opt_selection ? opt_selection : this.getSelectedDevice_(); |
| 153 this.invalidate(); | 152 this.invalidate(); |
| 154 this.redraw(); | 153 this.redraw(); |
| 155 if (selectedDevice) | 154 if (selectedDevice) |
| 156 this.setSelectedDevice_(selectedDevice); | 155 this.setSelectedDevice_(selectedDevice); |
| 157 }, | 156 }, |
| 158 | 157 |
| 159 /** | 158 /** |
| 160 * Retrieves the address of the selected device, or null if no device is | 159 * Retrieves the address of the selected device, or null if no device is |
| 161 * selected. | 160 * selected. |
| 162 * @return {(string|undefined)} Address of selected device or null. | 161 * @return {(string|undefined)} Address of selected device or null. |
| (...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 237 }, | 236 }, |
| 238 | 237 |
| 239 /** | 238 /** |
| 240 * Override the default implementation to return a predetermined size, | 239 * Override the default implementation to return a predetermined size, |
| 241 * which in turns allows proper layout of items even if the list is hidden. | 240 * which in turns allows proper layout of items even if the list is hidden. |
| 242 * @return {{height: number, width: number}} Dimensions of a single item in | 241 * @return {{height: number, width: number}} Dimensions of a single item in |
| 243 * the list of bluetooth device. | 242 * the list of bluetooth device. |
| 244 * @private | 243 * @private |
| 245 */ | 244 */ |
| 246 getDefaultItemSize_: function() { | 245 getDefaultItemSize_: function() { |
| 247 return { | 246 return {height: this.itemHeight_, width: this.itemWidth_}; |
| 248 height: this.itemHeight_, | |
| 249 width: this.itemWidth_ | |
| 250 }; | |
| 251 }, | 247 }, |
| 252 | 248 |
| 253 /** | 249 /** |
| 254 * Override base implementation of handleClick, which unconditionally | 250 * Override base implementation of handleClick, which unconditionally |
| 255 * removes the item. In this case, removal of the element is deferred | 251 * removes the item. In this case, removal of the element is deferred |
| 256 * pending confirmation from the Bluetooth adapter. | 252 * pending confirmation from the Bluetooth adapter. |
| 257 * @param {Event} e The click event object. | 253 * @param {Event} e The click event object. |
| 258 * @override | 254 * @override |
| 259 */ | 255 */ |
| 260 handleClick: function(e) { | 256 handleClick: function(e) { |
| 261 if (this.disabled) | 257 if (this.disabled) |
| 262 return; | 258 return; |
| 263 | 259 |
| 264 var target = /** @type {HTMLElement} */(e.target); | 260 var target = /** @type {HTMLElement} */ (e.target); |
| 265 if (!target.classList.contains('row-delete-button')) | 261 if (!target.classList.contains('row-delete-button')) |
| 266 return; | 262 return; |
| 267 | 263 |
| 268 var item = this.getListItemAncestor(target); | 264 var item = this.getListItemAncestor(target); |
| 269 var selected = this.selectionModel.selectedIndex; | 265 var selected = this.selectionModel.selectedIndex; |
| 270 var index = this.getIndexOfListItem(item); | 266 var index = this.getIndexOfListItem(item); |
| 271 if (item && item.deletable) { | 267 if (item && item.deletable) { |
| 272 if (selected != index) | 268 if (selected != index) |
| 273 this.setSelectedDevice_(item.data.address); | 269 this.setSelectedDevice_(item.data.address); |
| 274 // Device is busy until we hear back from the Bluetooth adapter. | 270 // Device is busy until we hear back from the Bluetooth adapter. |
| (...skipping 12 matching lines...) Expand all Loading... |
| 287 } | 283 } |
| 288 }); | 284 }); |
| 289 } else { | 285 } else { |
| 290 chrome.bluetoothPrivate.forgetDevice(address, function() { | 286 chrome.bluetoothPrivate.forgetDevice(address, function() { |
| 291 if (chrome.runtime.lastError) { | 287 if (chrome.runtime.lastError) { |
| 292 options.BluetoothPairing.showMessage( | 288 options.BluetoothPairing.showMessage( |
| 293 {message: 'bluetoothForgetFailed', address: address}); | 289 {message: 'bluetoothForgetFailed', address: address}); |
| 294 } | 290 } |
| 295 }); | 291 }); |
| 296 } | 292 } |
| 297 chrome.send('coreOptionsUserMetricsAction', | 293 chrome.send( |
| 298 ['Options_BluetoothRemoveDevice']); | 294 'coreOptionsUserMetricsAction', ['Options_BluetoothRemoveDevice']); |
| 299 } | 295 } |
| 300 }, | 296 }, |
| 301 | 297 |
| 302 /** @override */ | 298 /** @override */ |
| 303 deleteItemAtIndex: function(index) { | 299 deleteItemAtIndex: function(index) { |
| 304 var selectedDevice = this.getSelectedDevice_(); | 300 var selectedDevice = this.getSelectedDevice_(); |
| 305 this.dataModel.splice(index, 1); | 301 this.dataModel.splice(index, 1); |
| 306 this.refresh(selectedDevice); | 302 this.refresh(selectedDevice); |
| 307 this.updateListVisibility_(); | 303 this.updateListVisibility_(); |
| 308 }, | 304 }, |
| (...skipping 15 matching lines...) Expand all Loading... |
| 324 } | 320 } |
| 325 }, | 321 }, |
| 326 }; | 322 }; |
| 327 | 323 |
| 328 cr.defineProperty(BluetoothListItem, 'connected', cr.PropertyKind.BOOL_ATTR); | 324 cr.defineProperty(BluetoothListItem, 'connected', cr.PropertyKind.BOOL_ATTR); |
| 329 | 325 |
| 330 cr.defineProperty(BluetoothListItem, 'paired', cr.PropertyKind.BOOL_ATTR); | 326 cr.defineProperty(BluetoothListItem, 'paired', cr.PropertyKind.BOOL_ATTR); |
| 331 | 327 |
| 332 cr.defineProperty(BluetoothListItem, 'connecting', cr.PropertyKind.BOOL_ATTR); | 328 cr.defineProperty(BluetoothListItem, 'connecting', cr.PropertyKind.BOOL_ATTR); |
| 333 | 329 |
| 334 cr.defineProperty(BluetoothListItem, 'notconnectable', | 330 cr.defineProperty( |
| 335 cr.PropertyKind.BOOL_ATTR); | 331 BluetoothListItem, 'notconnectable', cr.PropertyKind.BOOL_ATTR); |
| 336 | 332 |
| 337 return { | 333 return { |
| 338 BluetoothListItem: BluetoothListItem, | 334 BluetoothListItem: BluetoothListItem, |
| 339 BluetoothDeviceList: BluetoothDeviceList, | 335 BluetoothDeviceList: BluetoothDeviceList, |
| 340 Constants: Constants | 336 Constants: Constants |
| 341 }; | 337 }; |
| 342 }); | 338 }); |
| OLD | NEW |