| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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 /** | 5 /** |
| 6 * @fileoverview Oobe HID detection screen implementation. | 6 * @fileoverview Oobe HID detection screen implementation. |
| 7 */ | 7 */ |
| 8 | 8 |
| 9 login.createScreen('HIDDetectionScreen', 'hid-detection', function() { | 9 login.createScreen('HIDDetectionScreen', 'hid-detection', function() { |
| 10 var CONTEXT_KEY_KEYBOARD_STATE = 'keyboard-state'; |
| 11 var CONTEXT_KEY_MOUSE_STATE = 'mouse-state'; |
| 12 var CONTEXT_KEY_KEYBOARD_PINCODE = 'keyboard-pincode'; |
| 13 var CONTEXT_KEY_KEYBOARD_ENTERED_PART_EXPECTED = 'num-keys-entered-expected'; |
| 14 var CONTEXT_KEY_KEYBOARD_ENTERED_PART_PINCODE = 'num-keys-entered-pincode'; |
| 15 var CONTEXT_KEY_MOUSE_DEVICE_NAME = 'mouse-device-name'; |
| 16 var CONTEXT_KEY_KEYBOARD_DEVICE_NAME = 'keyboard-device-name'; |
| 17 var CONTEXT_KEY_KEYBOARD_LABEL = 'keyboard-device-label'; |
| 18 var CONTEXT_KEY_CONTINUE_BUTTON_ENABLED = 'continue-button-enabled'; |
| 19 |
| 10 return { | 20 return { |
| 11 EXTERNAL_API: [ | |
| 12 'setPointingDeviceState', | |
| 13 'setKeyboardDeviceState', | |
| 14 ], | |
| 15 | 21 |
| 16 /** | 22 /** |
| 17 * Enumeration of possible states during pairing. The value associated with | 23 * Enumeration of possible states during pairing. The value associated with |
| 18 * each state maps to a localized string in the global variable | 24 * each state maps to a localized string in the global variable |
| 19 * |loadTimeData|. | 25 * |loadTimeData|. |
| 20 * @enum {string} | 26 * @enum {string} |
| 21 */ | 27 */ |
| 22 PAIRING: { | 28 PAIRING: { |
| 23 STARTUP: 'bluetoothStartConnecting', | 29 STARTUP: 'bluetoothStartConnecting', |
| 24 REMOTE_PIN_CODE: 'bluetoothRemotePinCode', | 30 REMOTE_PIN_CODE: 'bluetoothRemotePinCode', |
| 25 REMOTE_PASSKEY: 'bluetoothRemotePasskey', | |
| 26 CONNECT_FAILED: 'bluetoothConnectFailed', | 31 CONNECT_FAILED: 'bluetoothConnectFailed', |
| 27 CANCELED: 'bluetoothPairingCanceled', | 32 CANCELED: 'bluetoothPairingCanceled', |
| 28 // Pairing dismissed (succeeded or canceled). | 33 // Pairing dismissed (succeeded or canceled). |
| 29 DISMISSED: 'bluetoothPairingDismissed' | 34 DISMISSED: 'bluetoothPairingDismissed' |
| 30 }, | 35 }, |
| 31 | 36 |
| 32 // Enumeration of possible connection states of a device. | 37 // Enumeration of possible connection states of a device. |
| 33 CONNECTION: { | 38 CONNECTION: { |
| 34 SEARCHING: 'searching', | 39 SEARCHING: 'searching', |
| 35 CONNECTED: 'connected', | 40 CONNECTED: 'connected', |
| 36 PAIRING: 'pairing', | 41 PAIRING: 'pairing', |
| 37 PAIRED: 'paired', | 42 PAIRED: 'paired', |
| 38 // Special info state. | 43 // Special info state. |
| 39 UPDATE: 'update' | 44 UPDATE: 'update' |
| 40 }, | 45 }, |
| 41 | 46 |
| 42 // Possible ids of device blocks. | 47 // Possible ids of device blocks. |
| 43 BLOCK: { | 48 BLOCK: { |
| 44 MOUSE: 'hid-mouse-block', | 49 MOUSE: 'hid-mouse-block', |
| 45 KEYBOARD: 'hid-keyboard-block' | 50 KEYBOARD: 'hid-keyboard-block' |
| 46 }, | 51 }, |
| 47 | 52 |
| 48 /** | 53 /** |
| 49 * Button to move to usual OOBE flow after detection. | 54 * Button to move to usual OOBE flow after detection. |
| 50 * @private | 55 * @private |
| 51 */ | 56 */ |
| 52 continueButton_: null, | 57 continueButton_: null, |
| 53 | 58 |
| 59 /** @override */ |
| 60 decorate: function() { |
| 61 var self = this; |
| 62 |
| 63 this.context.addObserver( |
| 64 CONTEXT_KEY_MOUSE_STATE, |
| 65 function(stateId) { |
| 66 if (stateId === undefined) |
| 67 return; |
| 68 self.setDeviceBlockState_('hid-mouse-block', stateId); |
| 69 } |
| 70 ); |
| 71 this.context.addObserver( |
| 72 CONTEXT_KEY_KEYBOARD_STATE, |
| 73 function(stateId) { |
| 74 if (stateId === undefined) |
| 75 return; |
| 76 self.setDeviceBlockState_('hid-keyboard-block', stateId); |
| 77 if (stateId == self.CONNECTION.PAIRED) { |
| 78 $('hid-keyboard-label-paired').textContent = self.context.get( |
| 79 CONTEXT_KEY_KEYBOARD_LABEL, ''); |
| 80 } else if (stateId == self.CONNECTION.PAIRING) { |
| 81 $('hid-keyboard-label-pairing').textContent = self.context.get( |
| 82 CONTEXT_KEY_KEYBOARD_LABEL, ''); |
| 83 } else if (stateId == self.CONNECTION.CONNECTED) { |
| 84 } |
| 85 } |
| 86 ); |
| 87 this.context.addObserver( |
| 88 CONTEXT_KEY_KEYBOARD_PINCODE, |
| 89 function(pincode) { |
| 90 self.setPincodeKeysState_(); |
| 91 if (!pincode) { |
| 92 $('hid-keyboard-pincode').classList.remove('show-pincode'); |
| 93 return; |
| 94 } |
| 95 if (self.context.get(CONTEXT_KEY_KEYBOARD_STATE, '') != |
| 96 self.CONNECTION.PAIRING) { |
| 97 return; |
| 98 } |
| 99 $('hid-keyboard-pincode').classList.add('show-pincode'); |
| 100 for (var i = 0, len = pincode.length; i < len; i++) { |
| 101 var pincodeSymbol = $('hid-keyboard-pincode-sym-' + (i + 1)); |
| 102 pincodeSymbol.textContent = pincode[i]; |
| 103 } |
| 104 announceAccessibleMessage( |
| 105 self.context.get(CONTEXT_KEY_KEYBOARD_LABEL, '') + ' ' + pincode + |
| 106 ' ' + loadTimeData.getString('hidDetectionBTEnterKey')); |
| 107 } |
| 108 ); |
| 109 this.context.addObserver( |
| 110 CONTEXT_KEY_KEYBOARD_ENTERED_PART_EXPECTED, |
| 111 function(entered_part_expected) { |
| 112 if (self.context.get(CONTEXT_KEY_KEYBOARD_STATE, '') != 'pairing') |
| 113 return; |
| 114 self.setPincodeKeysState_(); |
| 115 } |
| 116 ); |
| 117 this.context.addObserver( |
| 118 CONTEXT_KEY_KEYBOARD_ENTERED_PART_PINCODE, |
| 119 function(entered_part) { |
| 120 if (self.context.get(CONTEXT_KEY_KEYBOARD_STATE, '') != |
| 121 self.CONNECTION.PAIRING) { |
| 122 return; |
| 123 } |
| 124 self.setPincodeKeysState_(); |
| 125 } |
| 126 ); |
| 127 this.context.addObserver( |
| 128 CONTEXT_KEY_CONTINUE_BUTTON_ENABLED, |
| 129 function(enabled) { |
| 130 $('hid-continue-button').disabled = !enabled; |
| 131 } |
| 132 ); |
| 133 }, |
| 134 |
| 54 /** | 135 /** |
| 55 * Buttons in oobe wizard's button strip. | 136 * Buttons in oobe wizard's button strip. |
| 56 * @type {array} Array of Buttons. | 137 * @type {array} Array of Buttons. |
| 57 */ | 138 */ |
| 58 get buttons() { | 139 get buttons() { |
| 59 var buttons = []; | 140 var buttons = []; |
| 60 var continueButton = this.ownerDocument.createElement('button'); | 141 var continueButton = this.ownerDocument.createElement('button'); |
| 61 continueButton.id = 'hid-continue-button'; | 142 continueButton.id = 'hid-continue-button'; |
| 62 continueButton.textContent = loadTimeData.getString( | 143 continueButton.textContent = loadTimeData.getString( |
| 63 'hidDetectionContinue'); | 144 'hidDetectionContinue'); |
| 64 continueButton.addEventListener('click', function(e) { | 145 continueButton.addEventListener('click', function(e) { |
| 65 chrome.send('HIDDetectionOnContinue'); | 146 chrome.send('HIDDetectionOnContinue'); |
| 66 e.stopPropagation(); | 147 e.stopPropagation(); |
| 67 }); | 148 }); |
| 68 buttons.push(continueButton); | 149 buttons.push(continueButton); |
| 69 this.continueButton_ = continueButton; | |
| 70 | 150 |
| 71 return buttons; | 151 return buttons; |
| 72 }, | 152 }, |
| 73 | 153 |
| 74 /** | 154 /** |
| 75 * Returns a control which should receive an initial focus. | 155 * Returns a control which should receive an initial focus. |
| 76 */ | 156 */ |
| 77 get defaultControl() { | 157 get defaultControl() { |
| 78 return this.continueButton_; | 158 return $('hid-continue-button'); |
| 79 }, | 159 }, |
| 80 | 160 |
| 81 /** | 161 /** |
| 82 * Sets a device-block css class to reflect device state of searching, | 162 * Sets a device-block css class to reflect device state of searching, |
| 83 * connected, pairing or paired (for BT devices). | 163 * connected, pairing or paired (for BT devices). |
| 84 * @param {blockId} id one of keys of this.BLOCK dict. | 164 * @param {blockId} id one of keys of this.BLOCK dict. |
| 85 * @param {state} one of keys of this.CONNECTION dict. | 165 * @param {state} one of keys of this.CONNECTION dict. |
| 86 * @private | 166 * @private |
| 87 */ | 167 */ |
| 88 setDeviceBlockState_: function(blockId, state) { | 168 setDeviceBlockState_: function(blockId, state) { |
| (...skipping 18 matching lines...) Expand all Loading... |
| 107 * @param {state} one of keys of this.CONNECTION dict. | 187 * @param {state} one of keys of this.CONNECTION dict. |
| 108 */ | 188 */ |
| 109 setPointingDeviceState: function(state) { | 189 setPointingDeviceState: function(state) { |
| 110 if (state === undefined) | 190 if (state === undefined) |
| 111 return; | 191 return; |
| 112 this.setDeviceBlockState_(this.BLOCK.MOUSE, state); | 192 this.setDeviceBlockState_(this.BLOCK.MOUSE, state); |
| 113 }, | 193 }, |
| 114 | 194 |
| 115 /** | 195 /** |
| 116 * Sets state for pincode key elements. | 196 * Sets state for pincode key elements. |
| 117 * @param {entered} int, number of typed keys of pincode, -1 if keys press | |
| 118 * detection is not supported by device. | |
| 119 */ | 197 */ |
| 120 setPincodeKeysState_: function(entered) { | 198 setPincodeKeysState_: function() { |
| 199 var entered = this.context.get( |
| 200 CONTEXT_KEY_KEYBOARD_ENTERED_PART_PINCODE, 0); |
| 201 // whether the functionality of getting num of entered keys is available. |
| 202 var expected = this.context.get( |
| 203 CONTEXT_KEY_KEYBOARD_ENTERED_PART_EXPECTED, false); |
| 121 var pincodeLength = 7; // including enter-key | 204 var pincodeLength = 7; // including enter-key |
| 122 for (var i = 0; i < pincodeLength; i++) { | 205 for (var i = 0; i < pincodeLength; i++) { |
| 123 var pincodeSymbol = $('hid-keyboard-pincode-sym-' + (i + 1)); | 206 var pincodeSymbol = $('hid-keyboard-pincode-sym-' + (i + 1)); |
| 124 pincodeSymbol.classList.remove('key-typed'); | 207 pincodeSymbol.classList.toggle('key-typed', i < entered && expected); |
| 125 pincodeSymbol.classList.remove('key-untyped'); | 208 pincodeSymbol.classList.toggle('key-untyped', i > entered && expected); |
| 126 pincodeSymbol.classList.remove('key-next'); | 209 pincodeSymbol.classList.toggle('key-next', i == entered && expected); |
| 127 if (i < entered) | |
| 128 pincodeSymbol.classList.add('key-typed'); | |
| 129 else if (i == entered) | |
| 130 pincodeSymbol.classList.add('key-next'); | |
| 131 else if (entered != -1) | |
| 132 pincodeSymbol.classList.add('key-untyped'); | |
| 133 } | 210 } |
| 134 }, | 211 }, |
| 135 | 212 |
| 136 /** | 213 /* |
| 137 * Sets state for keyboard-block. | 214 * Event handler that is invoked just before the screen in shown. |
| 138 * @param {data} dict with parameters. | 215 * @param {Object} data Screen init payload. |
| 139 */ | 216 */ |
| 140 setKeyboardDeviceState: function(data) { | 217 onBeforeShow: function(data) { |
| 141 if (data === undefined || !('state' in data)) | 218 this.setDeviceBlockState_('hid-mouse-block', this.CONNECTION.SEARCHING); |
| 142 return; | 219 this.setDeviceBlockState_('hid-keyboard-block', |
| 143 var state = data['state']; | 220 this.CONNECTION.SEARCHING); |
| 144 this.setDeviceBlockState_(this.BLOCK.KEYBOARD, state); | |
| 145 if (state == this.CONNECTION.PAIRED) | |
| 146 $('hid-keyboard-label-paired').textContent = data['keyboard-label']; | |
| 147 else if (state == this.CONNECTION.PAIRING) { | |
| 148 $('hid-keyboard-label-pairing').textContent = data['keyboard-label']; | |
| 149 if (data['pairing-state'] == this.PAIRING.REMOTE_PIN_CODE || | |
| 150 data['pairing-state'] == this.PAIRING.REMOTE_PASSKEY) { | |
| 151 this.setPincodeKeysState_(-1); | |
| 152 for (var i = 0, len = data['pincode'].length; i < len; i++) { | |
| 153 var pincodeSymbol = $('hid-keyboard-pincode-sym-' + (i + 1)); | |
| 154 pincodeSymbol.textContent = data['pincode'][i]; | |
| 155 } | |
| 156 announceAccessibleMessage( | |
| 157 data['keyboard-label'] + ' ' + data['pincode'] + ' ' + | |
| 158 loadTimeData.getString('hidDetectionBTEnterKey')); | |
| 159 } | |
| 160 } else if (state == this.CONNECTION.UPDATE) { | |
| 161 if ('keysEntered' in data) { | |
| 162 this.setPincodeKeysState_(data['keysEntered']); | |
| 163 } | |
| 164 } | |
| 165 }, | 221 }, |
| 166 }; | 222 }; |
| 167 }); | 223 }); |
| OLD | NEW |