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