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

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 use of 'hidden' attribute to toglle visibility of scanning indicator. 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 *
James Hawkins 2011/10/06 20:50:16 Remove blank line.
kevers 2011/10/07 20:37:32 Done.
27 * @enum {string}
28 */
29 Constants.DEVICE_STATUS = {
30 CONNECTED: 'bluetoothDeviceConnected',
31 NOT_PAIRED: 'bluetoothDeviceNotPaired'
32 };
33
34 /**
35 * Creates an element for storing a list of bluetooth devices.
36 * @param {Object=} opt_propertyBag Optional properties.
37 * @constructor
38 * @extends {HTMLDivElement}
39 */
40 var BluetoothListElement = cr.ui.define('div');
41
42 BluetoothListElement.prototype = {
43 __proto__: HTMLDivElement.prototype,
44
45 /** @inheritDoc */
46 decorate: function() {
47 // TODO (kevers) - Implement me.
48 },
49
50 /**
51 * Loads given list of bluetooth devices. This list will comprise of
52 * devices that are currently connected. New devices are discovered
53 * via the 'Find devices' button.
54 * @param {Array} devices An array of bluetooth devices.
55 */
56 load: function(devices) {
57 this.textContent = '';
58 for (var i = 0; i < devices.length; i++) {
59 if (this.isSupported_(devices[i]))
60 this.appendChild(new BluetoothItem(devices[i]));
61 }
62 },
63
64 /**
65 * Adds a bluetooth device to the list of available devices.
66 * @param {Object.<string,string>} device Description of the bluetooth
67 * device.
68 */
69 appendDevice: function(device) {
70 // TODO (kevers) - check device ID to determine if already in list, in
71 // which case we should be updating the existing element.
72 // Display connected devices at the top of the list.
73 if (this.isSupported_(device))
74 this.appendChild(new BluetoothItem(device));
75 },
76
77 /**
78 * Tests if the bluetooth device is supported based on the type of device.
79 * @param {Object.<string,string>} device Desription of the device.
80 * @return {boolean} true if the device is supported.
81 * @private
82 */
83 isSupported_: function(device) {
84 var target = device.deviceType;
85 for (var key in Constants.DEVICE_TYPE) {
86 if (Constants.DEVICE_TYPE[key] == target)
87 return true;
88 }
89 return false;
90 }
91 };
92
93 /**
94 * Creates an element in the list of bluetooth devices.
95 * @param{{'deviceName': string,
96 * 'deviceId': string,
97 * 'deviceType': Constants.DEVICE_TYPE,
98 * 'deviceStatus': Constants.DEVICE_STATUS} device
99 * Decription of the bluetooth device.
100 * @constructor
101 */
102 function BluetoothItem(device) {
103 var el = cr.doc.createElement('div');
104 el.data = {};
105 for (var key in device)
106 el.data[key] = device[key];
107 BluetoothItem.decorate(el);
108 return el;
109 }
110
111 /**
112 * Decorates an element as a network item.
113 * @param {!HTMLElement} el The element to decorate.
114 */
115 BluetoothItem.decorate = function(el) {
116 el.__proto__ = BluetoothItem.prototype;
117 el.decorate();
118 };
119
120 BluetoothItem.prototype = {
121 __proto__: HTMLDivElement.prototype,
122
123 /** @inheritDoc */
124 decorate: function() {
125 this.className = 'network-item';
126 this.connected = this.data.connected;
127 if (this.data.deviceId)
128 this.id = this.data.deviceId;
129
130 // |textDiv| holds icon, name and status text.
131 var textDiv = this.ownerDocument.createElement('div');
132 textDiv.className = 'network-item-text';
133
134 var deviceSpecificClassName = 'bluetooth-' + this.data.deviceType;
135 this.classList.add(deviceSpecificClassName);
136
137 var nameEl = this.ownerDocument.createElement('div');
138 nameEl.className = 'network-name-label';
139 nameEl.textContent = this.data.deviceName;
140 textDiv.appendChild(nameEl);
141
142 if (this.data.deviceStatus) {
143 var statusMessage = templateData[this.data.deviceStatus];
144 if (statusMessage) {
145 var statusEl = this.ownerDocument.createElement('div');
146 statusEl.className = 'network-status-label';
147 statusEl.textContent = statusMessage;
148 textDiv.appendChild(statusEl);
149 }
150 }
151 this.appendChild(textDiv);
152 }
153 };
154
155 return {
156 Constants: Constants,
157 BluetoothListElement: BluetoothListElement
158 };
159 });
160
161
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698