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

Side by Side Diff: chrome/browser/resources/options/chromeos/bluetooth_list_element.js

Issue 8137003: Add display of available bluetooth devices, and mechanism for retrieving the list. (Closed) Base URL: http://git.chromium.org/git/chromium.git@trunk
Patch Set: Remove addition of animated spinner in favour of reusing an existing throbber class. Created 9 years, 2 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
OLDNEW
(Empty)
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 cr.define('options.system.bluetooth', function() {
6 /**
7 * Bluetooth settings constants.
8 */
9 function Constants() {}
10
11 /**
12 * Enumeration of supported device types. Each device type has an
13 * associated icon and CSS style.
14 * @enum {string}
15 */
16 Constants.DEVICE_TYPE = {
17 HEADSET: 'headset',
18 KEYBOARD: 'keyboard',
19 MOUSE: 'mouse',
20 };
21
22 /**
23 * Enumeration of possible states for a bluetooth device. The value
24 * associated with each state maps to a localized string in the global
25 * variable 'templateData'.
26 * @enum {string}
27 */
28 Constants.DEVICE_STATUS = {
29 CONNECTED: 'bluetoothDeviceConnected',
30 NOT_PAIRED: 'bluetoothDeviceNotPaired'
31 };
32
33 /**
34 * Creates an element for storing a list of bluetooth devices.
35 * @param {Object=} opt_propertyBag Optional properties.
36 * @constructor
37 * @extends {HTMLDivElement}
38 */
39 var BluetoothListElement = cr.ui.define('div');
40
41 BluetoothListElement.prototype = {
42 __proto__: HTMLDivElement.prototype,
43
44 /** @inheritDoc */
45 decorate: function() {
46 // TODO (kevers) - Implement me.
47 },
48
49 /**
50 * Loads given list of bluetooth devices. This list will comprise of
51 * devices that are currently connected. New devices are discovered
52 * via the 'Find devices' button.
53 * @param {Array} devices An array of bluetooth devices.
54 */
55 load: function(devices) {
56 this.textContent = '';
57 for (var i = 0; i < devices.length; i++) {
58 if (this.isSupported_(devices[i]))
59 this.appendChild(new BluetoothItem(devices[i]));
60 }
61 },
62
63 /**
64 * Adds a bluetooth device to the list of available devices.
65 * @param {Object.<string,string>} device Description of the bluetooth
66 * device.
67 */
68 appendDevice: function(device) {
69 // TODO (kevers) - check device ID to determine if already in list, in
70 // which case we should be updating the existing element.
71 // Display connected devices at the top of the list.
72 if (this.isSupported_(device))
73 this.appendChild(new BluetoothItem(device));
74 },
75
76 /**
77 * Tests if the bluetooth device is supported based on the type of device.
78 * @param {Object.<string,string>} device Desription of the device.
79 * @return {boolean} true if the device is supported.
80 * @private
81 */
82 isSupported_: function(device) {
83 var target = device.deviceType;
84 for (var key in Constants.DEVICE_TYPE) {
85 if (Constants.DEVICE_TYPE[key] == target)
86 return true;
87 }
88 return false;
89 }
90 };
91
92 /**
93 * Creates an element in the list of bluetooth devices.
94 * @param{{'deviceName': string,
95 * 'deviceId': string,
96 * 'deviceType': Constants.DEVICE_TYPE,
97 * 'deviceStatus': Constants.DEVICE_STATUS} device
98 * Decription of the bluetooth device.
99 * @constructor
100 */
101 function BluetoothItem(device) {
102 var el = cr.doc.createElement('div');
103 el.data = {};
104 for (var key in device)
105 el.data[key] = device[key];
106 BluetoothItem.decorate(el);
107 return el;
108 }
109
110 /**
111 * Decorates an element as a network item.
112 * @param {!HTMLElement} el The element to decorate.
113 */
114 BluetoothItem.decorate = function(el) {
115 el.__proto__ = BluetoothItem.prototype;
116 el.decorate();
117 };
118
119 BluetoothItem.prototype = {
120 __proto__: HTMLDivElement.prototype,
121
122 /** @inheritDoc */
123 decorate: function() {
124 this.className = 'network-item';
125 this.connected = this.data.connected;
126 if (this.data.deviceId)
127 this.id = this.data.deviceId;
128
129 // |textDiv| holds icon, name and status text.
130 var textDiv = this.ownerDocument.createElement('div');
131 textDiv.className = 'network-item-text';
132
133 var deviceSpecificClassName = 'bluetooth-' + this.data.deviceType;
134 this.classList.add(deviceSpecificClassName);
135
136 var nameEl = this.ownerDocument.createElement('div');
137 nameEl.className = 'network-name-label';
138 nameEl.textContent = this.data.deviceName;
139 textDiv.appendChild(nameEl);
140
141 if (this.data.deviceStatus) {
142 var statusMessage = templateData[this.data.deviceStatus];
143 if (statusMessage) {
144 var statusEl = this.ownerDocument.createElement('div');
145 statusEl.className = 'network-status-label';
146 statusEl.textContent = statusMessage;
147 textDiv.appendChild(statusEl);
148 }
149 }
150 this.appendChild(textDiv);
151 }
152 };
153
154 return {
155 Constants: Constants,
156 BluetoothListElement: BluetoothListElement
157 };
158 });
159
160
OLDNEW
« no previous file with comments | « chrome/app/generated_resources.grd ('k') | chrome/browser/resources/options/chromeos/system_options.html » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698