| 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', function() { | 5 cr.define('options', function() { |
| 6 /** @const */ var Page = cr.ui.pageManager.Page; | 6 /** @const */ var Page = cr.ui.pageManager.Page; |
| 7 /** @const */ var PageManager = cr.ui.pageManager.PageManager; | 7 /** @const */ var PageManager = cr.ui.pageManager.PageManager; |
| 8 | 8 |
| 9 /** | 9 /** |
| 10 * Enumeration of possible states during pairing. The value associated with | 10 * Enumeration of possible states during pairing. The value associated with |
| (...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 50 'bluetooth-pairing'); | 50 'bluetooth-pairing'); |
| 51 } | 51 } |
| 52 | 52 |
| 53 cr.addSingletonGetter(BluetoothPairing); | 53 cr.addSingletonGetter(BluetoothPairing); |
| 54 | 54 |
| 55 BluetoothPairing.prototype = { | 55 BluetoothPairing.prototype = { |
| 56 __proto__: Page.prototype, | 56 __proto__: Page.prototype, |
| 57 | 57 |
| 58 /** | 58 /** |
| 59 * Description of the bluetooth device. | 59 * Description of the bluetooth device. |
| 60 * @type {{name: string, | 60 * @type {?BluetoothDevice} |
| 61 * address: string, | |
| 62 * paired: boolean, | |
| 63 * connected: boolean, | |
| 64 * connecting: boolean, | |
| 65 * connectable: boolean, | |
| 66 * pairing: (string|undefined), | |
| 67 * passkey: (number|undefined), | |
| 68 * pincode: (string|undefined), | |
| 69 * entered: (number|undefined)}} | |
| 70 * @private | 61 * @private |
| 71 */ | 62 */ |
| 72 device_: null, | 63 device_: null, |
| 73 | 64 |
| 74 /** | 65 /** |
| 75 * Can the dialog be programmatically dismissed. | 66 * Can the dialog be programmatically dismissed. |
| 76 * @type {boolean} | 67 * @type {boolean} |
| 77 */ | 68 */ |
| 78 dismissible_: true, | 69 dismissible_: true, |
| 79 | 70 |
| (...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 163 $('bluetooth-pincode').focus(); | 154 $('bluetooth-pincode').focus(); |
| 164 else if (!$('bluetooth-passkey').hidden) | 155 else if (!$('bluetooth-passkey').hidden) |
| 165 $('bluetooth-passkey').focus(); | 156 $('bluetooth-passkey').focus(); |
| 166 }, | 157 }, |
| 167 | 158 |
| 168 /** | 159 /** |
| 169 * Configures the overlay for pairing a device. | 160 * Configures the overlay for pairing a device. |
| 170 * @param {Object} device Description of the bluetooth device. | 161 * @param {Object} device Description of the bluetooth device. |
| 171 */ | 162 */ |
| 172 update: function(device) { | 163 update: function(device) { |
| 173 this.device_ = {}; | 164 this.device_ = /** @type {BluetoothDevice} */({}); |
| 174 for (var key in device) | 165 for (var key in device) |
| 175 this.device_[key] = device[key]; | 166 this.device_[key] = device[key]; |
| 176 // Update the pairing instructions. | 167 // Update the pairing instructions. |
| 177 var instructionsEl = $('bluetooth-pairing-instructions'); | 168 var instructionsEl = assert($('bluetooth-pairing-instructions')); |
| 178 this.clearElement_(instructionsEl); | 169 this.clearElement_(instructionsEl); |
| 179 this.dismissible_ = ('dismissible' in device) ? | 170 this.dismissible_ = ('dismissible' in device) ? |
| 180 device.dismissible : true; | 171 device.dismissible : true; |
| 181 | 172 |
| 182 var message = loadTimeData.getString(device.pairing); | 173 var message = loadTimeData.getString(device.pairing); |
| 183 message = message.replace('%1', this.device_.name); | 174 message = message.replace('%1', this.device_.name); |
| 184 instructionsEl.textContent = message; | 175 instructionsEl.textContent = message; |
| 185 | 176 |
| 186 // Update visibility of dialog elements. | 177 // Update visibility of dialog elements. |
| 187 if (this.device_.passkey) { | 178 if (this.device_.passkey) { |
| (...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 221 this.displayElements_(['bluetooth-pair-device-dismiss-button']); | 212 this.displayElements_(['bluetooth-pair-device-dismiss-button']); |
| 222 } | 213 } |
| 223 // User is required to enter a passkey or pincode before the connect | 214 // User is required to enter a passkey or pincode before the connect |
| 224 // button can be enabled. The 'oninput' methods for the input fields | 215 // button can be enabled. The 'oninput' methods for the input fields |
| 225 // determine when the connect button becomes active. | 216 // determine when the connect button becomes active. |
| 226 $('bluetooth-pair-device-connect-button').disabled = true; | 217 $('bluetooth-pair-device-connect-button').disabled = true; |
| 227 }, | 218 }, |
| 228 | 219 |
| 229 /** | 220 /** |
| 230 * Handles the ENTER key for the passkey or pincode entry field. | 221 * Handles the ENTER key for the passkey or pincode entry field. |
| 231 * @return {Event} a keydown event. | 222 * @param {Event} event A keydown event. |
| 232 * @private | 223 * @private |
| 233 */ | 224 */ |
| 234 keyDownEventHandler_: function(event) { | 225 keyDownEventHandler_: function(event) { |
| 235 /** @const */ var ENTER_KEY_CODE = 13; | 226 /** @const */ var ENTER_KEY_CODE = 13; |
| 236 if (event.keyCode == ENTER_KEY_CODE) { | 227 if (event.keyCode == ENTER_KEY_CODE) { |
| 237 var button = $('bluetooth-pair-device-connect-button'); | 228 var button = $('bluetooth-pair-device-connect-button'); |
| 238 if (!button.hidden) | 229 if (!button.hidden) |
| 239 button.click(); | 230 button.click(); |
| 240 } | 231 } |
| 241 }, | 232 }, |
| (...skipping 26 matching lines...) Expand all Loading... |
| 268 element.removeChild(child); | 259 element.removeChild(child); |
| 269 child = element.firstChild; | 260 child = element.firstChild; |
| 270 } | 261 } |
| 271 }, | 262 }, |
| 272 | 263 |
| 273 /** | 264 /** |
| 274 * Formats an element for displaying the passkey or PIN code. | 265 * Formats an element for displaying the passkey or PIN code. |
| 275 * @param {string} key Passkey or PIN to display. | 266 * @param {string} key Passkey or PIN to display. |
| 276 */ | 267 */ |
| 277 updatePasskey_: function(key) { | 268 updatePasskey_: function(key) { |
| 278 var passkeyEl = $('bluetooth-pairing-passkey-display'); | 269 var passkeyEl = assert($('bluetooth-pairing-passkey-display')); |
| 279 var keyClass = (this.device_.pairing == PAIRING.REMOTE_PASSKEY || | 270 var keyClass = (this.device_.pairing == PAIRING.REMOTE_PASSKEY || |
| 280 this.device_.pairing == PAIRING.REMOTE_PIN_CODE) ? | 271 this.device_.pairing == PAIRING.REMOTE_PIN_CODE) ? |
| 281 'bluetooth-keyboard-button' : 'bluetooth-passkey-char'; | 272 'bluetooth-keyboard-button' : 'bluetooth-passkey-char'; |
| 282 this.clearElement_(passkeyEl); | 273 this.clearElement_(passkeyEl); |
| 283 // Passkey should always have 6 digits. | 274 // Passkey should always have 6 digits. |
| 284 key = '000000'.substring(0, 6 - key.length) + key; | 275 key = '000000'.substring(0, 6 - key.length) + key; |
| 285 var progress = this.device_.entered; | 276 var progress = this.device_.entered; |
| 286 for (var i = 0; i < key.length; i++) { | 277 for (var i = 0; i < key.length; i++) { |
| 287 var keyEl = document.createElement('span'); | 278 var keyEl = document.createElement('span'); |
| 288 keyEl.textContent = key.charAt(i); | 279 keyEl.textContent = key.charAt(i); |
| (...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 375 dialog.device_.pairing = PAIRING.DISMISSED; | 366 dialog.device_.pairing = PAIRING.DISMISSED; |
| 376 PageManager.closeOverlay(); | 367 PageManager.closeOverlay(); |
| 377 } | 368 } |
| 378 }; | 369 }; |
| 379 | 370 |
| 380 // Export | 371 // Export |
| 381 return { | 372 return { |
| 382 BluetoothPairing: BluetoothPairing | 373 BluetoothPairing: BluetoothPairing |
| 383 }; | 374 }; |
| 384 }); | 375 }); |
| OLD | NEW |