Commit 2c0cff64 authored by kevers@chromium.org's avatar kevers@chromium.org

Fix Bluetooth list redraw issues.

BUG=none
TEST=Launch ChromeOS and enable Bluetooth in about://flags. Open chrome settings and ensure that the view is expanded to show advanced settings.   Click "Enable Bluetooth" and "Add a device".  Ensure that available Bluetooth devices are shown.


Review URL: http://codereview.chromium.org/9570018

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@124864 0039d316-1c4b-4281-b951-d872f2087c98
parent eac76c6f
...@@ -12,27 +12,10 @@ cr.define('options.system.bluetooth', function() { ...@@ -12,27 +12,10 @@ cr.define('options.system.bluetooth', function() {
*/ */
function Constants() {} function Constants() {}
/**
* Enumeration of supported device types.
* @enum {string}
*/
// TODO(kevers): Prune list based on the set of devices that will be
// supported for V1 of the feature. The set will likely be restricted to
// mouse and keyboard. Others are temporarily included for testing device
// discovery.
Constants.DEVICE_TYPE = {
COMPUTER: 'computer',
HEADSET: 'headset',
KEYBOARD: 'input-keyboard',
MOUSE: 'input-mouse',
PHONE: 'phone',
};
/** /**
* Creates a new bluetooth list item. * Creates a new bluetooth list item.
* @param {{name: string, * @param {{name: string,
* address: string, * address: string,
* icon: Constants.DEVICE_TYPE,
* paired: boolean, * paired: boolean,
* connected: boolean, * connected: boolean,
* pairing: string|undefined, * pairing: string|undefined,
...@@ -61,7 +44,6 @@ cr.define('options.system.bluetooth', function() { ...@@ -61,7 +44,6 @@ cr.define('options.system.bluetooth', function() {
* Description of the Bluetooth device. * Description of the Bluetooth device.
* @type {{name: string, * @type {{name: string,
* address: string, * address: string,
* icon: Constants.DEVICE_TYPE,
* paired: boolean, * paired: boolean,
* connected: boolean, * connected: boolean,
* pairing: string|undefined, * pairing: string|undefined,
...@@ -124,7 +106,6 @@ cr.define('options.system.bluetooth', function() { ...@@ -124,7 +106,6 @@ cr.define('options.system.bluetooth', function() {
* existing device is updated. * existing device is updated.
* @param {{name: string, * @param {{name: string,
* address: string, * address: string,
* icon: Constants.DEVICE_TYPE,
* paired: boolean, * paired: boolean,
* connected: boolean, * connected: boolean,
* pairing: string|undefined, * pairing: string|undefined,
...@@ -134,8 +115,6 @@ cr.define('options.system.bluetooth', function() { ...@@ -134,8 +115,6 @@ cr.define('options.system.bluetooth', function() {
* @return {boolean} True if the devies was successfully added or updated. * @return {boolean} True if the devies was successfully added or updated.
*/ */
appendDevice: function(device) { appendDevice: function(device) {
if (!this.isSupported_(device))
return false;
var index = this.find(device.address); var index = this.find(device.address);
if (index == undefined) { if (index == undefined) {
this.dataModel.push(device); this.dataModel.push(device);
...@@ -148,6 +127,19 @@ cr.define('options.system.bluetooth', function() { ...@@ -148,6 +127,19 @@ cr.define('options.system.bluetooth', function() {
return true; return true;
}, },
/**
* Forces a revailidation of the list content. Content added while the list
* is hidden is not properly rendered when the list becomes visible. In
* addition, deleting a single item from the list results in a stale cache
* requiring an invalidation.
*/
refresh: function() {
// TODO(kevers): Investigate if the root source of the problems can be
// fixed in cr.ui.list.
this.invalidate();
this.redraw();
},
/** /**
* Perges all devices from the list. * Perges all devices from the list.
*/ */
...@@ -186,28 +178,10 @@ cr.define('options.system.bluetooth', function() { ...@@ -186,28 +178,10 @@ cr.define('options.system.bluetooth', function() {
[item.address, item.connected ? 'disconnect' : 'forget']); [item.address, item.connected ? 'disconnect' : 'forget']);
} }
this.dataModel.splice(index, 1); this.dataModel.splice(index, 1);
// Invalidate the list since it has a stale cache after a splice this.refresh();
// involving a deletion.
this.invalidate();
this.redraw();
this.updateListVisibility_(); this.updateListVisibility_();
}, },
/**
* Tests if the bluetooth device is supported based on the type of device.
* @param {Object.<string,string>} device Desription of the device.
* @return {boolean} true if the device is supported.
* @private
*/
isSupported_: function(device) {
var target = device.icon;
for (var key in Constants.DEVICE_TYPE) {
if (Constants.DEVICE_TYPE[key] == target)
return true;
}
return false;
},
/** /**
* If the list has an associated empty list placholder then update the * If the list has an associated empty list placholder then update the
* visibility of the list and placeholder. * visibility of the list and placeholder.
...@@ -217,8 +191,11 @@ cr.define('options.system.bluetooth', function() { ...@@ -217,8 +191,11 @@ cr.define('options.system.bluetooth', function() {
var empty = this.dataModel.length == 0; var empty = this.dataModel.length == 0;
var listPlaceHolderID = this.id + '-empty-placeholder'; var listPlaceHolderID = this.id + '-empty-placeholder';
if ($(listPlaceHolderID)) { if ($(listPlaceHolderID)) {
this.hidden = empty; if (this.hidden != empty) {
$(listPlaceHolderID).hidden = !empty; this.hidden = empty;
$(listPlaceHolderID).hidden = !empty;
this.refresh();
}
} }
}, },
}; };
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment