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'; | 10 var CONTEXT_KEY_KEYBOARD_STATE = 'keyboard-state'; |
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
64 CONTEXT_KEY_MOUSE_STATE, | 64 CONTEXT_KEY_MOUSE_STATE, |
65 function(stateId) { | 65 function(stateId) { |
66 if (stateId === undefined) | 66 if (stateId === undefined) |
67 return; | 67 return; |
68 self.setDeviceBlockState_('hid-mouse-block', stateId); | 68 self.setDeviceBlockState_('hid-mouse-block', stateId); |
69 } | 69 } |
70 ); | 70 ); |
71 this.context.addObserver( | 71 this.context.addObserver( |
72 CONTEXT_KEY_KEYBOARD_STATE, | 72 CONTEXT_KEY_KEYBOARD_STATE, |
73 function(stateId) { | 73 function(stateId) { |
74 self.updatePincodeKeysState_(); | |
74 if (stateId === undefined) | 75 if (stateId === undefined) |
75 return; | 76 return; |
76 self.setDeviceBlockState_('hid-keyboard-block', stateId); | 77 self.setDeviceBlockState_('hid-keyboard-block', stateId); |
77 if (stateId == self.CONNECTION.PAIRED) { | 78 if (stateId == self.CONNECTION.PAIRED) { |
78 $('hid-keyboard-label-paired').textContent = self.context.get( | 79 $('hid-keyboard-label-paired').textContent = self.context.get( |
79 CONTEXT_KEY_KEYBOARD_LABEL, ''); | 80 CONTEXT_KEY_KEYBOARD_LABEL, ''); |
80 } else if (stateId == self.CONNECTION.PAIRING) { | 81 } else if (stateId == self.CONNECTION.PAIRING) { |
81 $('hid-keyboard-label-pairing').textContent = self.context.get( | 82 $('hid-keyboard-label-pairing').textContent = self.context.get( |
82 CONTEXT_KEY_KEYBOARD_LABEL, ''); | 83 CONTEXT_KEY_KEYBOARD_LABEL, ''); |
83 } else if (stateId == self.CONNECTION.CONNECTED) { | |
84 } | 84 } |
85 } | 85 } |
86 ); | 86 ); |
87 this.context.addObserver( | 87 this.context.addObserver( |
88 CONTEXT_KEY_KEYBOARD_PINCODE, | 88 CONTEXT_KEY_KEYBOARD_PINCODE, |
89 function(pincode) { | 89 this.updatePincodeKeysState_.bind(this)); |
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( | 90 this.context.addObserver( |
110 CONTEXT_KEY_KEYBOARD_ENTERED_PART_EXPECTED, | 91 CONTEXT_KEY_KEYBOARD_ENTERED_PART_EXPECTED, |
111 function(entered_part_expected) { | 92 this.updatePincodeKeysState_.bind(this)); |
112 if (self.context.get(CONTEXT_KEY_KEYBOARD_STATE, '') != 'pairing') | |
113 return; | |
114 self.setPincodeKeysState_(); | |
115 } | |
116 ); | |
117 this.context.addObserver( | 93 this.context.addObserver( |
118 CONTEXT_KEY_KEYBOARD_ENTERED_PART_PINCODE, | 94 CONTEXT_KEY_KEYBOARD_ENTERED_PART_PINCODE, |
119 function(entered_part) { | 95 this.updatePincodeKeysState_.bind(this)); |
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( | 96 this.context.addObserver( |
128 CONTEXT_KEY_CONTINUE_BUTTON_ENABLED, | 97 CONTEXT_KEY_CONTINUE_BUTTON_ENABLED, |
129 function(enabled) { | 98 function(enabled) { |
130 $('hid-continue-button').disabled = !enabled; | 99 $('hid-continue-button').disabled = !enabled; |
131 } | 100 } |
132 ); | 101 ); |
133 }, | 102 }, |
134 | 103 |
135 /** | 104 /** |
136 * Buttons in oobe wizard's button strip. | 105 * Buttons in oobe wizard's button strip. |
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
179 * Sets state for mouse-block. | 148 * Sets state for mouse-block. |
180 * @param {state} one of keys of this.CONNECTION dict. | 149 * @param {state} one of keys of this.CONNECTION dict. |
181 */ | 150 */ |
182 setPointingDeviceState: function(state) { | 151 setPointingDeviceState: function(state) { |
183 if (state === undefined) | 152 if (state === undefined) |
184 return; | 153 return; |
185 this.setDeviceBlockState_(this.BLOCK.MOUSE, state); | 154 this.setDeviceBlockState_(this.BLOCK.MOUSE, state); |
186 }, | 155 }, |
187 | 156 |
188 /** | 157 /** |
189 * Sets state for pincode key elements. | 158 * Updates state for pincode key elements based on context state. |
190 */ | 159 */ |
191 setPincodeKeysState_: function() { | 160 updatePincodeKeysState_: function() { |
161 var pincodeKeys = $('hid-keyboard-pincode'); | |
162 var pincode = this.context.get(CONTEXT_KEY_KEYBOARD_PINCODE, ''); | |
163 var state = this.context.get(CONTEXT_KEY_KEYBOARD_STATE, ''); | |
164 | |
165 if (!pincode || state !== this.CONNECTION.PAIRING) { | |
166 pincodeKeys.hidden = true; | |
167 return; | |
168 } | |
169 | |
170 if (pincodeKeys.hidden) { | |
171 pincodeKeys.hidden = false; | |
172 announceAccessibleMessage( | |
173 this.context.get(CONTEXT_KEY_KEYBOARD_LABEL, '') + ' ' + pincode + | |
174 ' ' + loadTimeData.getString('hidDetectionBTEnterKey')); | |
175 } | |
176 | |
192 var entered = this.context.get( | 177 var entered = this.context.get( |
193 CONTEXT_KEY_KEYBOARD_ENTERED_PART_PINCODE, 0); | 178 CONTEXT_KEY_KEYBOARD_ENTERED_PART_PINCODE, 0); |
179 | |
194 // whether the functionality of getting num of entered keys is available. | 180 // whether the functionality of getting num of entered keys is available. |
195 var expected = this.context.get( | 181 var expected = this.context.get( |
196 CONTEXT_KEY_KEYBOARD_ENTERED_PART_EXPECTED, false); | 182 CONTEXT_KEY_KEYBOARD_ENTERED_PART_EXPECTED, false); |
197 var pincodeLength = 7; // including enter-key | 183 |
198 for (var i = 0; i < pincodeLength; i++) { | 184 if (pincode.length != 6) |
Roman Sorokin (ftl)
2015/07/21 12:10:58
nit: Why not create the constant stores 6-value?
dzhioev (left Google)
2015/07/21 21:06:06
Done.
| |
185 console.error('Wrong pincode length'); | |
186 | |
187 // Pincode keys plus Enter key. | |
188 for (var i = 0; i < (pincode.length + 1); i++) { | |
199 var pincodeSymbol = $('hid-keyboard-pincode-sym-' + (i + 1)); | 189 var pincodeSymbol = $('hid-keyboard-pincode-sym-' + (i + 1)); |
200 pincodeSymbol.classList.toggle('key-typed', i < entered && expected); | 190 pincodeSymbol.classList.toggle('key-typed', i < entered && expected); |
201 pincodeSymbol.classList.toggle('key-untyped', i > entered && expected); | 191 pincodeSymbol.classList.toggle('key-untyped', i > entered && expected); |
202 pincodeSymbol.classList.toggle('key-next', i == entered && expected); | 192 pincodeSymbol.classList.toggle('key-next', i == entered && expected); |
193 if (i < pincode.length) | |
194 pincodeSymbol.textContent = pincode[i]; | |
203 } | 195 } |
204 }, | 196 }, |
205 | 197 |
206 /* | 198 /* |
207 * Event handler that is invoked just before the screen in shown. | 199 * Event handler that is invoked just before the screen in shown. |
208 * @param {Object} data Screen init payload. | 200 * @param {Object} data Screen init payload. |
209 */ | 201 */ |
210 onBeforeShow: function(data) { | 202 onBeforeShow: function(data) { |
211 this.setDeviceBlockState_('hid-mouse-block', this.CONNECTION.SEARCHING); | 203 this.setDeviceBlockState_('hid-mouse-block', this.CONNECTION.SEARCHING); |
212 this.setDeviceBlockState_('hid-keyboard-block', | 204 this.setDeviceBlockState_('hid-keyboard-block', |
213 this.CONNECTION.SEARCHING); | 205 this.CONNECTION.SEARCHING); |
214 }, | 206 }, |
215 }; | 207 }; |
216 }); | 208 }); |
OLD | NEW |