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 return { | 10 return { |
(...skipping 11 matching lines...) Expand all Loading... |
22 PAIRING: { | 22 PAIRING: { |
23 STARTUP: 'bluetoothStartConnecting', | 23 STARTUP: 'bluetoothStartConnecting', |
24 REMOTE_PIN_CODE: 'bluetoothRemotePinCode', | 24 REMOTE_PIN_CODE: 'bluetoothRemotePinCode', |
25 REMOTE_PASSKEY: 'bluetoothRemotePasskey', | 25 REMOTE_PASSKEY: 'bluetoothRemotePasskey', |
26 CONNECT_FAILED: 'bluetoothConnectFailed', | 26 CONNECT_FAILED: 'bluetoothConnectFailed', |
27 CANCELED: 'bluetoothPairingCanceled', | 27 CANCELED: 'bluetoothPairingCanceled', |
28 // Pairing dismissed (succeeded or canceled). | 28 // Pairing dismissed (succeeded or canceled). |
29 DISMISSED: 'bluetoothPairingDismissed' | 29 DISMISSED: 'bluetoothPairingDismissed' |
30 }, | 30 }, |
31 | 31 |
| 32 // Enumeration of possible connection states of a device. |
| 33 CONNECTION: { |
| 34 SEARCHING: 'searching', |
| 35 CONNECTED: 'connected', |
| 36 PAIRING: 'pairing', |
| 37 PAIRED: 'paired', |
| 38 // Special info state. |
| 39 UPDATE: 'update' |
| 40 }, |
| 41 |
| 42 // Possible ids of device blocks. |
| 43 BLOCK: { |
| 44 MOUSE: 'hid-mouse-block', |
| 45 KEYBOARD: 'hid-keyboard-block' |
| 46 }, |
| 47 |
32 /** | 48 /** |
33 * Button to move to usual OOBE flow after detection. | 49 * Button to move to usual OOBE flow after detection. |
34 * @private | 50 * @private |
35 */ | 51 */ |
36 continueButton_: null, | 52 continueButton_: null, |
37 | 53 |
38 /** | 54 /** |
39 * Buttons in oobe wizard's button strip. | 55 * Buttons in oobe wizard's button strip. |
40 * @type {array} Array of Buttons. | 56 * @type {array} Array of Buttons. |
41 */ | 57 */ |
(...skipping 16 matching lines...) Expand all Loading... |
58 /** | 74 /** |
59 * Returns a control which should receive an initial focus. | 75 * Returns a control which should receive an initial focus. |
60 */ | 76 */ |
61 get defaultControl() { | 77 get defaultControl() { |
62 return this.continueButton_; | 78 return this.continueButton_; |
63 }, | 79 }, |
64 | 80 |
65 /** | 81 /** |
66 * 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, |
67 * connected, pairing or paired (for BT devices). | 83 * connected, pairing or paired (for BT devices). |
68 * @param {blockId} id one of 'hid-mouse-block' or 'hid-keyboard-block'. | 84 * @param {blockId} id one of keys of this.BLOCK dict. |
69 * @param {state} one of 'searching', 'connected', 'pairing', 'paired', | 85 * @param {state} one of keys of this.CONNECTION dict. |
70 * @private | 86 * @private |
71 */ | 87 */ |
72 setDeviceBlockState_: function(blockId, state) { | 88 setDeviceBlockState_: function(blockId, state) { |
73 if (state == 'update') | 89 if (state == 'update') |
74 return; | 90 return; |
75 var deviceBlock = $(blockId); | 91 var deviceBlock = $(blockId); |
76 var states = ['searching', 'connected', 'pairing', 'paired']; | 92 for (var stateCase in this.CONNECTION) |
77 for (var i = 0; i < states.length; ++i) { | 93 deviceBlock.classList.toggle(stateCase, stateCase == state); |
78 if (states[i] != state) | 94 |
79 deviceBlock.classList.remove(states[i]); | 95 // 'Continue' button available iff at least one device is connected, |
| 96 if ((blockId in this.BLOCK) && |
| 97 (state == this.CONNECTION.CONNECTED || |
| 98 state == this.CONNECTION.PAIRED)) { |
| 99 $('hid-continue-button').disabled = false; |
| 100 } else { |
| 101 $('hid-continue-button').disabled = true; |
80 } | 102 } |
81 deviceBlock.classList.add(state); | |
82 }, | 103 }, |
83 | 104 |
84 /** | 105 /** |
85 * Sets state for mouse-block. | 106 * Sets state for mouse-block. |
86 * @param {state} one of 'searching', 'connected', 'paired'. | 107 * @param {state} one of keys of this.CONNECTION dict. |
87 */ | 108 */ |
88 setPointingDeviceState: function(state) { | 109 setPointingDeviceState: function(state) { |
89 if (state === undefined) | 110 if (state === undefined) |
90 return; | 111 return; |
91 this.setDeviceBlockState_('hid-mouse-block', state); | 112 this.setDeviceBlockState_(this.BLOCK.MOUSE, state); |
92 }, | 113 }, |
93 | 114 |
94 /** | 115 /** |
95 * Sets state for pincode key elements. | 116 * Sets state for pincode key elements. |
96 * @param {entered} int, number of typed keys of pincode, -1 if keys press | 117 * @param {entered} int, number of typed keys of pincode, -1 if keys press |
97 * detection is not supported by device. | 118 * detection is not supported by device. |
98 */ | 119 */ |
99 setPincodeKeysState_: function(entered) { | 120 setPincodeKeysState_: function(entered) { |
100 var pincodeLength = 7; // including enter-key | 121 var pincodeLength = 7; // including enter-key |
101 for (var i = 0; i < pincodeLength; i++) { | 122 for (var i = 0; i < pincodeLength; i++) { |
(...skipping 11 matching lines...) Expand all Loading... |
113 }, | 134 }, |
114 | 135 |
115 /** | 136 /** |
116 * Sets state for keyboard-block. | 137 * Sets state for keyboard-block. |
117 * @param {data} dict with parameters. | 138 * @param {data} dict with parameters. |
118 */ | 139 */ |
119 setKeyboardDeviceState: function(data) { | 140 setKeyboardDeviceState: function(data) { |
120 if (data === undefined || !('state' in data)) | 141 if (data === undefined || !('state' in data)) |
121 return; | 142 return; |
122 var state = data['state']; | 143 var state = data['state']; |
123 this.setDeviceBlockState_('hid-keyboard-block', state); | 144 this.setDeviceBlockState_(this.BLOCK.KEYBOARD, state); |
124 if (state == 'paired') | 145 if (state == this.CONNECTION.PAIRED) |
125 $('hid-keyboard-label-paired').textContent = data['keyboard-label']; | 146 $('hid-keyboard-label-paired').textContent = data['keyboard-label']; |
126 else if (state == 'pairing') { | 147 else if (state == this.CONNECTION.PAIRING) { |
127 $('hid-keyboard-label-pairing').textContent = data['keyboard-label']; | 148 $('hid-keyboard-label-pairing').textContent = data['keyboard-label']; |
128 if (data['pairing-state'] == this.PAIRING.REMOTE_PIN_CODE || | 149 if (data['pairing-state'] == this.PAIRING.REMOTE_PIN_CODE || |
129 data['pairing-state'] == this.PAIRING.REMOTE_PASSKEY) { | 150 data['pairing-state'] == this.PAIRING.REMOTE_PASSKEY) { |
130 this.setPincodeKeysState_(-1); | 151 this.setPincodeKeysState_(-1); |
131 for (var i = 0, len = data['pincode'].length; i < len; i++) { | 152 for (var i = 0, len = data['pincode'].length; i < len; i++) { |
132 var pincodeSymbol = $('hid-keyboard-pincode-sym-' + (i + 1)); | 153 var pincodeSymbol = $('hid-keyboard-pincode-sym-' + (i + 1)); |
133 pincodeSymbol.textContent = data['pincode'][i]; | 154 pincodeSymbol.textContent = data['pincode'][i]; |
134 } | 155 } |
135 announceAccessibleMessage( | 156 announceAccessibleMessage( |
136 data['keyboard-label'] + ' ' + data['pincode'] + ' ' + | 157 data['keyboard-label'] + ' ' + data['pincode'] + ' ' + |
137 loadTimeData.getString('hidDetectionBTEnterKey')); | 158 loadTimeData.getString('hidDetectionBTEnterKey')); |
138 } | 159 } |
139 } else if (state == 'update') { | 160 } else if (state == this.CONNECTION.UPDATE) { |
140 if ('keysEntered' in data) { | 161 if ('keysEntered' in data) { |
141 this.setPincodeKeysState_(data['keysEntered']); | 162 this.setPincodeKeysState_(data['keysEntered']); |
142 } | 163 } |
143 } | 164 } |
144 }, | 165 }, |
145 | |
146 /** | |
147 * Event handler that is invoked just before the screen in shown. | |
148 * @param {Object} data Screen init payload. | |
149 */ | |
150 onBeforeShow: function(data) { | |
151 $('hid-continue-button').disabled = true; | |
152 this.setDeviceBlockState_('hid-mouse-block', 'searching'); | |
153 this.setDeviceBlockState_('hid-keyboard-block', 'searching'); | |
154 }, | |
155 }; | 166 }; |
156 }); | 167 }); |
OLD | NEW |