Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(389)

Side by Side Diff: chrome/browser/resources/chromeos/login/oobe_screen_hid_detection.js

Issue 2600983003: ChromeOS MD-OOBE: Add HID detection screen. (Closed)
Patch Set: Rebased. Created 3 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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';
11 var CONTEXT_KEY_MOUSE_STATE = 'mouse-state'; 11 var CONTEXT_KEY_MOUSE_STATE = 'mouse-state';
12 var CONTEXT_KEY_KEYBOARD_PINCODE = 'keyboard-pincode'; 12 var CONTEXT_KEY_KEYBOARD_PINCODE = 'keyboard-pincode';
13 var CONTEXT_KEY_KEYBOARD_ENTERED_PART_EXPECTED = 'num-keys-entered-expected'; 13 var CONTEXT_KEY_KEYBOARD_ENTERED_PART_EXPECTED = 'num-keys-entered-expected';
14 var CONTEXT_KEY_KEYBOARD_ENTERED_PART_PINCODE = 'num-keys-entered-pincode'; 14 var CONTEXT_KEY_KEYBOARD_ENTERED_PART_PINCODE = 'num-keys-entered-pincode';
15 var CONTEXT_KEY_MOUSE_DEVICE_NAME = 'mouse-device-name'; 15 var CONTEXT_KEY_MOUSE_DEVICE_NAME = 'mouse-device-name';
16 var CONTEXT_KEY_KEYBOARD_DEVICE_NAME = 'keyboard-device-name'; 16 var CONTEXT_KEY_KEYBOARD_DEVICE_NAME = 'keyboard-device-name';
17 var CONTEXT_KEY_KEYBOARD_LABEL = 'keyboard-device-label'; 17 var CONTEXT_KEY_KEYBOARD_LABEL = 'keyboard-device-label';
18 var CONTEXT_KEY_CONTINUE_BUTTON_ENABLED = 'continue-button-enabled'; 18 var CONTEXT_KEY_CONTINUE_BUTTON_ENABLED = 'continue-button-enabled';
19 19
20 var PINCODE_LENGTH = 6; 20 var PINCODE_LENGTH = 6;
21 21
22 return { 22 return {
23 // Enumeration of possible connection states of a device.
24 CONNECTION: {
25 SEARCHING: 'searching',
26 USB: 'usb',
27 CONNECTED: 'connected',
28 PAIRING: 'pairing',
29 PAIRED: 'paired',
30 // Special info state.
31 UPDATE: 'update',
32 },
23 33
24 /** 34 // Possible ids of device blocks.
25 * Enumeration of possible states during pairing. The value associated with 35 BLOCK: {
26 * each state maps to a localized string in the global variable 36 MOUSE: 'hid-mouse-block',
27 * |loadTimeData|. 37 KEYBOARD: 'hid-keyboard-block',
28 * @enum {string} 38 },
29 */
30 PAIRING: {
31 STARTUP: 'bluetoothStartConnecting',
32 REMOTE_PIN_CODE: 'bluetoothRemotePinCode',
33 CONNECT_FAILED: 'bluetoothConnectFailed',
34 CANCELED: 'bluetoothPairingCanceled',
35 // Pairing dismissed (succeeded or canceled).
36 DISMISSED: 'bluetoothPairingDismissed'
37 },
38
39 // Enumeration of possible connection states of a device.
40 CONNECTION: {
41 SEARCHING: 'searching',
42 USB: 'usb',
43 CONNECTED: 'connected',
44 PAIRING: 'pairing',
45 PAIRED: 'paired',
46 // Special info state.
47 UPDATE: 'update'
48 },
49
50 // Possible ids of device blocks.
51 BLOCK: {
52 MOUSE: 'hid-mouse-block',
53 KEYBOARD: 'hid-keyboard-block'
54 },
55 39
56 /** 40 /**
57 * Button to move to usual OOBE flow after detection. 41 * Button to move to usual OOBE flow after detection.
58 * @private 42 * @private
59 */ 43 */
60 continueButton_: null, 44 continueButton_: null,
61 45
62 /** @override */ 46 /** @override */
63 decorate: function() { 47 decorate: function() {
64 var self = this; 48 var self = this;
65 49
50 $('oobe-hid-detection-md').screen = this;
51
66 this.context.addObserver( 52 this.context.addObserver(
67 CONTEXT_KEY_MOUSE_STATE, 53 CONTEXT_KEY_MOUSE_STATE,
68 function(stateId) { 54 function(stateId) {
69 if (stateId === undefined) 55 if (stateId === undefined)
70 return; 56 return;
71 self.setDeviceBlockState_('hid-mouse-block', stateId); 57 self.setDeviceBlockState_('hid-mouse-block', stateId);
58 $('oobe-hid-detection-md').setMouseState(stateId);
72 } 59 }
73 ); 60 );
74 this.context.addObserver( 61 this.context.addObserver(
75 CONTEXT_KEY_KEYBOARD_STATE, 62 CONTEXT_KEY_KEYBOARD_STATE,
76 function(stateId) { 63 function(stateId) {
77 self.updatePincodeKeysState_(); 64 self.updatePincodeKeysState_();
78 if (stateId === undefined) 65 if (stateId === undefined)
79 return; 66 return;
80 self.setDeviceBlockState_('hid-keyboard-block', stateId); 67 self.setDeviceBlockState_('hid-keyboard-block', stateId);
68 $('oobe-hid-detection-md').setKeyboardState(stateId);
81 if (stateId == self.CONNECTION.PAIRED) { 69 if (stateId == self.CONNECTION.PAIRED) {
82 $('hid-keyboard-label-paired').textContent = self.context.get( 70 var label = self.context.get(CONTEXT_KEY_KEYBOARD_LABEL, '');
83 CONTEXT_KEY_KEYBOARD_LABEL, ''); 71 $('hid-keyboard-label-paired').textContent = label;
72 $('oobe-hid-detection-md').keyboardPairedLabel = label;
84 } else if (stateId == self.CONNECTION.PAIRING) { 73 } else if (stateId == self.CONNECTION.PAIRING) {
85 $('hid-keyboard-label-pairing').textContent = self.context.get( 74 var label = self.context.get(CONTEXT_KEY_KEYBOARD_LABEL, '');
86 CONTEXT_KEY_KEYBOARD_LABEL, ''); 75 $('hid-keyboard-label-pairing').textContent = label;
76 $('oobe-hid-detection-md').keyboardPairingLabel = label;
87 } 77 }
88 } 78 }
89 ); 79 );
90 this.context.addObserver( 80 this.context.addObserver(
91 CONTEXT_KEY_KEYBOARD_PINCODE, 81 CONTEXT_KEY_KEYBOARD_PINCODE,
92 this.updatePincodeKeysState_.bind(this)); 82 this.updatePincodeKeysState_.bind(this));
93 this.context.addObserver( 83 this.context.addObserver(
94 CONTEXT_KEY_KEYBOARD_ENTERED_PART_EXPECTED, 84 CONTEXT_KEY_KEYBOARD_ENTERED_PART_EXPECTED,
95 this.updatePincodeKeysState_.bind(this)); 85 this.updatePincodeKeysState_.bind(this));
96 this.context.addObserver( 86 this.context.addObserver(
97 CONTEXT_KEY_KEYBOARD_ENTERED_PART_PINCODE, 87 CONTEXT_KEY_KEYBOARD_ENTERED_PART_PINCODE,
98 this.updatePincodeKeysState_.bind(this)); 88 this.updatePincodeKeysState_.bind(this));
99 this.context.addObserver( 89 this.context.addObserver(
100 CONTEXT_KEY_CONTINUE_BUTTON_ENABLED, 90 CONTEXT_KEY_CONTINUE_BUTTON_ENABLED,
101 function(enabled) { 91 function(enabled) {
102 $('hid-continue-button').disabled = !enabled; 92 $('hid-continue-button').disabled = !enabled;
93 $('oobe-hid-detection-md').continueButtonDisabled = !enabled;
103 } 94 }
104 ); 95 );
105 }, 96 },
106 97
107 /** 98 /**
108 * Buttons in oobe wizard's button strip. 99 * Buttons in oobe wizard's button strip.
109 * @type {array} Array of Buttons. 100 * @type {array} Array of Buttons.
110 */ 101 */
111 get buttons() { 102 get buttons() {
112 var buttons = []; 103 var buttons = [];
113 var continueButton = this.ownerDocument.createElement('button'); 104 var continueButton = this.ownerDocument.createElement('button');
114 continueButton.id = 'hid-continue-button'; 105 continueButton.id = 'hid-continue-button';
115 continueButton.textContent = loadTimeData.getString( 106 continueButton.textContent = loadTimeData.getString(
116 'hidDetectionContinue'); 107 'hidDetectionContinue');
117 continueButton.addEventListener('click', function(e) { 108 continueButton.addEventListener('click', function(e) {
118 chrome.send('HIDDetectionOnContinue'); 109 chrome.send('HIDDetectionOnContinue');
119 e.stopPropagation(); 110 e.stopPropagation();
120 }); 111 });
121 buttons.push(continueButton); 112 buttons.push(continueButton);
122 113
123 return buttons; 114 return buttons;
124 }, 115 },
125 116
126 /** 117 /**
127 * Returns a control which should receive an initial focus. 118 * Returns a control which should receive an initial focus.
128 */ 119 */
129 get defaultControl() { 120 get defaultControl() { return $('hid-continue-button'); },
130 return $('hid-continue-button');
131 },
132 121
133 /** 122 /**
134 * Sets a device-block css class to reflect device state of searching, usb, 123 * Sets a device-block css class to reflect device state of searching, usb,
135 * connected, pairing or paired (for BT devices). 124 * connected, pairing or paired (for BT devices).
136 * @param {blockId} id one of keys of this.BLOCK dict. 125 * @param {blockId} id one of keys of this.BLOCK dict.
137 * @param {state} one of keys of this.CONNECTION dict. 126 * @param {state} one of keys of this.CONNECTION dict.
138 * @private 127 * @private
139 */ 128 */
140 setDeviceBlockState_: function(blockId, state) { 129 setDeviceBlockState_: function(blockId, state) {
141 if (state == 'update') 130 if (state == 'update')
142 return; 131 return;
143 var deviceBlock = $(blockId); 132 var deviceBlock = $(blockId);
144 for (var key in this.CONNECTION) { 133 for (var key in this.CONNECTION) {
145 var stateCase = this.CONNECTION[key]; 134 var stateCase = this.CONNECTION[key];
146 deviceBlock.classList.toggle(stateCase, stateCase == state); 135 deviceBlock.classList.toggle(stateCase, stateCase == state);
147 } 136 }
148 }, 137 },
149 138
150 /** 139 /**
151 * Sets state for mouse-block. 140 * Sets state for mouse-block.
152 * @param {state} one of keys of this.CONNECTION dict. 141 * @param {state} one of keys of this.CONNECTION dict.
153 */ 142 */
154 setPointingDeviceState: function(state) { 143 setPointingDeviceState: function(state) {
155 if (state === undefined) 144 if (state === undefined)
156 return; 145 return;
157 this.setDeviceBlockState_(this.BLOCK.MOUSE, state); 146 this.setDeviceBlockState_(this.BLOCK.MOUSE, state);
147 $('oobe-hid-detection-md').setMouseState(state);
158 }, 148 },
159 149
160 /** 150 /**
161 * Updates state for pincode key elements based on context state. 151 * Updates state for pincode key elements based on context state.
162 */ 152 */
163 updatePincodeKeysState_: function() { 153 updatePincodeKeysState_: function() {
164 var pincodeKeys = $('hid-keyboard-pincode'); 154 var pincodeKeys = $('hid-keyboard-pincode');
165 var pincode = this.context.get(CONTEXT_KEY_KEYBOARD_PINCODE, ''); 155 var pincode = this.context.get(CONTEXT_KEY_KEYBOARD_PINCODE, '');
166 var state = this.context.get(CONTEXT_KEY_KEYBOARD_STATE, ''); 156 var state = this.context.get(CONTEXT_KEY_KEYBOARD_STATE, '');
157 var label = this.context.get(CONTEXT_KEY_KEYBOARD_LABEL, '');
158
159 var entered =
160 this.context.get(CONTEXT_KEY_KEYBOARD_ENTERED_PART_PINCODE, 0);
161
162 // Whether the functionality of getting num of entered keys is available.
163 var expected =
164 this.context.get(CONTEXT_KEY_KEYBOARD_ENTERED_PART_EXPECTED, false);
165
166 $('oobe-hid-detection-md').setKeyboardState(state);
167 $('oobe-hid-detection-md')
168 .setPincodeState(pincode, entered, expected, label);
167 169
168 if (!pincode || state !== this.CONNECTION.PAIRING) { 170 if (!pincode || state !== this.CONNECTION.PAIRING) {
169 pincodeKeys.hidden = true; 171 pincodeKeys.hidden = true;
170 return; 172 return;
171 } 173 }
172 174
173 if (pincodeKeys.hidden) { 175 if (pincodeKeys.hidden) {
174 pincodeKeys.hidden = false; 176 pincodeKeys.hidden = false;
175 announceAccessibleMessage( 177 announceAccessibleMessage(
176 this.context.get(CONTEXT_KEY_KEYBOARD_LABEL, '') + ' ' + pincode + 178 this.context.get(CONTEXT_KEY_KEYBOARD_LABEL, '') + ' ' + pincode +
177 ' ' + loadTimeData.getString('hidDetectionBTEnterKey')); 179 ' ' + loadTimeData.getString('hidDetectionBTEnterKey'));
178 } 180 }
179 181
180 var entered = this.context.get(
181 CONTEXT_KEY_KEYBOARD_ENTERED_PART_PINCODE, 0);
182
183 // whether the functionality of getting num of entered keys is available.
184 var expected = this.context.get(
185 CONTEXT_KEY_KEYBOARD_ENTERED_PART_EXPECTED, false);
186
187 if (pincode.length != PINCODE_LENGTH) 182 if (pincode.length != PINCODE_LENGTH)
188 console.error('Wrong pincode length'); 183 console.error('Wrong pincode length');
189 184
190 // Pincode keys plus Enter key. 185 // Pincode keys plus Enter key.
191 for (var i = 0; i < (PINCODE_LENGTH + 1); i++) { 186 for (var i = 0; i < (PINCODE_LENGTH + 1); i++) {
192 var pincodeSymbol = $('hid-keyboard-pincode-sym-' + (i + 1)); 187 var pincodeSymbol = $('hid-keyboard-pincode-sym-' + (i + 1));
193 pincodeSymbol.classList.toggle('key-typed', i < entered && expected); 188 pincodeSymbol.classList.toggle('key-typed', i < entered && expected);
194 pincodeSymbol.classList.toggle('key-untyped', i > entered && expected); 189 pincodeSymbol.classList.toggle('key-untyped', i > entered && expected);
195 pincodeSymbol.classList.toggle('key-next', i == entered && expected); 190 pincodeSymbol.classList.toggle('key-next', i == entered && expected);
196 if (i < PINCODE_LENGTH) 191 if (i < PINCODE_LENGTH)
197 pincodeSymbol.textContent = pincode[i] ? pincode[i] : ''; 192 pincodeSymbol.textContent = pincode[i] ? pincode[i] : '';
198 } 193 }
199 }, 194 },
200 195
201 /* 196 /**
202 * Event handler that is invoked just before the screen in shown. 197 * Event handler that is invoked just before the screen in shown.
203 * @param {Object} data Screen init payload. 198 * @param {Object} data Screen init payload.
204 */ 199 */
205 onBeforeShow: function(data) { 200 onBeforeShow: function(data) {
201 this.setMDMode_();
206 this.setDeviceBlockState_('hid-mouse-block', this.CONNECTION.SEARCHING); 202 this.setDeviceBlockState_('hid-mouse-block', this.CONNECTION.SEARCHING);
207 this.setDeviceBlockState_('hid-keyboard-block', 203 this.setDeviceBlockState_('hid-keyboard-block',
208 this.CONNECTION.SEARCHING); 204 this.CONNECTION.SEARCHING);
205 $('oobe-hid-detection-md').setMouseState(this.CONNECTION.SEARCHING);
206 $('oobe-hid-detection-md').setKeyboardState(this.CONNECTION.SEARCHING);
207 },
208
209 /**
210 * This method takes care of switching to material-design OOBE.
211 * @private
212 */
213 setMDMode_: function() {
214 var useMDOobe = (loadTimeData.getString('newOobeUI') == 'on');
215 $('oobe-hid-detection-md').hidden = !useMDOobe;
216 $('oobe-hid-detection').hidden = useMDOobe;
209 }, 217 },
210 }; 218 };
211 }); 219 });
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698