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