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

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: Fix build 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: {MOUSE: 'hid-mouse-block', KEYBOARD: 'hid-keyboard-block'},
stevenjb 2016/12/28 20:47:04 nit: If you put a ',' at the end of the last enum
Alexander Alekseev 2016/12/28 22:56:23 Done.
26 * each state maps to a localized string in the global variable
27 * |loadTimeData|.
28 * @enum {string}
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 36
56 /** 37 /**
57 * Button to move to usual OOBE flow after detection. 38 * Button to move to usual OOBE flow after detection.
58 * @private 39 * @private
59 */ 40 */
60 continueButton_: null, 41 continueButton_: null,
61 42
62 /** @override */ 43 /** @override */
63 decorate: function() { 44 decorate: function() {
64 var self = this; 45 var self = this;
65 46
47 $('oobe-hid-detection-md').screen = this;
48
66 this.context.addObserver( 49 this.context.addObserver(
67 CONTEXT_KEY_MOUSE_STATE, 50 CONTEXT_KEY_MOUSE_STATE,
68 function(stateId) { 51 function(stateId) {
69 if (stateId === undefined) 52 if (stateId === undefined)
70 return; 53 return;
71 self.setDeviceBlockState_('hid-mouse-block', stateId); 54 self.setDeviceBlockState_('hid-mouse-block', stateId);
55 $('oobe-hid-detection-md').setMouseState(stateId);
72 } 56 }
73 ); 57 );
74 this.context.addObserver( 58 this.context.addObserver(
75 CONTEXT_KEY_KEYBOARD_STATE, 59 CONTEXT_KEY_KEYBOARD_STATE,
76 function(stateId) { 60 function(stateId) {
77 self.updatePincodeKeysState_(); 61 self.updatePincodeKeysState_();
78 if (stateId === undefined) 62 if (stateId === undefined)
79 return; 63 return;
80 self.setDeviceBlockState_('hid-keyboard-block', stateId); 64 self.setDeviceBlockState_('hid-keyboard-block', stateId);
65 $('oobe-hid-detection-md').setKeyboardState(stateId);
81 if (stateId == self.CONNECTION.PAIRED) { 66 if (stateId == self.CONNECTION.PAIRED) {
82 $('hid-keyboard-label-paired').textContent = self.context.get( 67 var label = self.context.get(CONTEXT_KEY_KEYBOARD_LABEL, '');
83 CONTEXT_KEY_KEYBOARD_LABEL, ''); 68 $('hid-keyboard-label-paired').textContent = label;
69 $('oobe-hid-detection-md').keyboardPairedLabel = label;
84 } else if (stateId == self.CONNECTION.PAIRING) { 70 } else if (stateId == self.CONNECTION.PAIRING) {
85 $('hid-keyboard-label-pairing').textContent = self.context.get( 71 var label = self.context.get(CONTEXT_KEY_KEYBOARD_LABEL, '');
86 CONTEXT_KEY_KEYBOARD_LABEL, ''); 72 $('hid-keyboard-label-pairing').textContent = label;
73 $('oobe-hid-detection-md').keyboardPairingLabel = label;
87 } 74 }
88 } 75 }
89 ); 76 );
90 this.context.addObserver( 77 this.context.addObserver(
91 CONTEXT_KEY_KEYBOARD_PINCODE, 78 CONTEXT_KEY_KEYBOARD_PINCODE,
92 this.updatePincodeKeysState_.bind(this)); 79 this.updatePincodeKeysState_.bind(this));
93 this.context.addObserver( 80 this.context.addObserver(
94 CONTEXT_KEY_KEYBOARD_ENTERED_PART_EXPECTED, 81 CONTEXT_KEY_KEYBOARD_ENTERED_PART_EXPECTED,
95 this.updatePincodeKeysState_.bind(this)); 82 this.updatePincodeKeysState_.bind(this));
96 this.context.addObserver( 83 this.context.addObserver(
97 CONTEXT_KEY_KEYBOARD_ENTERED_PART_PINCODE, 84 CONTEXT_KEY_KEYBOARD_ENTERED_PART_PINCODE,
98 this.updatePincodeKeysState_.bind(this)); 85 this.updatePincodeKeysState_.bind(this));
99 this.context.addObserver( 86 this.context.addObserver(
100 CONTEXT_KEY_CONTINUE_BUTTON_ENABLED, 87 CONTEXT_KEY_CONTINUE_BUTTON_ENABLED,
101 function(enabled) { 88 function(enabled) {
102 $('hid-continue-button').disabled = !enabled; 89 $('hid-continue-button').disabled = !enabled;
90 $('oobe-hid-detection-md').continueButtonDisabled = !enabled;
103 } 91 }
104 ); 92 );
105 }, 93 },
106 94
107 /** 95 /**
108 * Buttons in oobe wizard's button strip. 96 * Buttons in oobe wizard's button strip.
109 * @type {array} Array of Buttons. 97 * @type {array} Array of Buttons.
110 */ 98 */
111 get buttons() { 99 get buttons() {
112 var buttons = []; 100 var buttons = [];
113 var continueButton = this.ownerDocument.createElement('button'); 101 var continueButton = this.ownerDocument.createElement('button');
114 continueButton.id = 'hid-continue-button'; 102 continueButton.id = 'hid-continue-button';
115 continueButton.textContent = loadTimeData.getString( 103 continueButton.textContent = loadTimeData.getString(
116 'hidDetectionContinue'); 104 'hidDetectionContinue');
117 continueButton.addEventListener('click', function(e) { 105 continueButton.addEventListener('click', function(e) {
118 chrome.send('HIDDetectionOnContinue'); 106 chrome.send('HIDDetectionOnContinue');
119 e.stopPropagation(); 107 e.stopPropagation();
120 }); 108 });
121 buttons.push(continueButton); 109 buttons.push(continueButton);
122 110
123 return buttons; 111 return buttons;
124 }, 112 },
125 113
126 /** 114 /**
127 * Returns a control which should receive an initial focus. 115 * Returns a control which should receive an initial focus.
128 */ 116 */
129 get defaultControl() { 117 get defaultControl() { return $('hid-continue-button'); },
130 return $('hid-continue-button');
131 },
132 118
133 /** 119 /**
134 * Sets a device-block css class to reflect device state of searching, usb, 120 * Sets a device-block css class to reflect device state of searching, usb,
135 * connected, pairing or paired (for BT devices). 121 * connected, pairing or paired (for BT devices).
136 * @param {blockId} id one of keys of this.BLOCK dict. 122 * @param {blockId} id one of keys of this.BLOCK dict.
137 * @param {state} one of keys of this.CONNECTION dict. 123 * @param {state} one of keys of this.CONNECTION dict.
138 * @private 124 * @private
139 */ 125 */
140 setDeviceBlockState_: function(blockId, state) { 126 setDeviceBlockState_: function(blockId, state) {
141 if (state == 'update') 127 if (state == 'update')
142 return; 128 return;
143 var deviceBlock = $(blockId); 129 var deviceBlock = $(blockId);
144 for (var key in this.CONNECTION) { 130 for (var key in this.CONNECTION) {
145 var stateCase = this.CONNECTION[key]; 131 var stateCase = this.CONNECTION[key];
146 deviceBlock.classList.toggle(stateCase, stateCase == state); 132 deviceBlock.classList.toggle(stateCase, stateCase == state);
147 } 133 }
148 }, 134 },
149 135
150 /** 136 /**
151 * Sets state for mouse-block. 137 * Sets state for mouse-block.
152 * @param {state} one of keys of this.CONNECTION dict. 138 * @param {state} one of keys of this.CONNECTION dict.
153 */ 139 */
154 setPointingDeviceState: function(state) { 140 setPointingDeviceState: function(state) {
155 if (state === undefined) 141 if (state === undefined)
156 return; 142 return;
157 this.setDeviceBlockState_(this.BLOCK.MOUSE, state); 143 this.setDeviceBlockState_(this.BLOCK.MOUSE, state);
144 $('oobe-hid-detection-md').setMouseState(state);
158 }, 145 },
159 146
160 /** 147 /**
161 * Updates state for pincode key elements based on context state. 148 * Updates state for pincode key elements based on context state.
162 */ 149 */
163 updatePincodeKeysState_: function() { 150 updatePincodeKeysState_: function() {
164 var pincodeKeys = $('hid-keyboard-pincode'); 151 var pincodeKeys = $('hid-keyboard-pincode');
165 var pincode = this.context.get(CONTEXT_KEY_KEYBOARD_PINCODE, ''); 152 var pincode = this.context.get(CONTEXT_KEY_KEYBOARD_PINCODE, '');
166 var state = this.context.get(CONTEXT_KEY_KEYBOARD_STATE, ''); 153 var state = this.context.get(CONTEXT_KEY_KEYBOARD_STATE, '');
154 var label = this.context.get(CONTEXT_KEY_KEYBOARD_LABEL, '');
155
156 var entered =
157 this.context.get(CONTEXT_KEY_KEYBOARD_ENTERED_PART_PINCODE, 0);
158
159 // whether the functionality of getting num of entered keys is available.
160 var expected =
161 this.context.get(CONTEXT_KEY_KEYBOARD_ENTERED_PART_EXPECTED, false);
162
163 $('oobe-hid-detection-md').setKeyboardState(state);
164 $('oobe-hid-detection-md')
165 .setPincodeState(pincode, entered, expected, label);
167 166
168 if (!pincode || state !== this.CONNECTION.PAIRING) { 167 if (!pincode || state !== this.CONNECTION.PAIRING) {
169 pincodeKeys.hidden = true; 168 pincodeKeys.hidden = true;
170 return; 169 return;
171 } 170 }
172 171
173 if (pincodeKeys.hidden) { 172 if (pincodeKeys.hidden) {
174 pincodeKeys.hidden = false; 173 pincodeKeys.hidden = false;
175 announceAccessibleMessage( 174 announceAccessibleMessage(
176 this.context.get(CONTEXT_KEY_KEYBOARD_LABEL, '') + ' ' + pincode + 175 this.context.get(CONTEXT_KEY_KEYBOARD_LABEL, '') + ' ' + pincode +
177 ' ' + loadTimeData.getString('hidDetectionBTEnterKey')); 176 ' ' + loadTimeData.getString('hidDetectionBTEnterKey'));
178 } 177 }
179 178
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) 179 if (pincode.length != PINCODE_LENGTH)
188 console.error('Wrong pincode length'); 180 console.error('Wrong pincode length');
189 181
190 // Pincode keys plus Enter key. 182 // Pincode keys plus Enter key.
191 for (var i = 0; i < (PINCODE_LENGTH + 1); i++) { 183 for (var i = 0; i < (PINCODE_LENGTH + 1); i++) {
192 var pincodeSymbol = $('hid-keyboard-pincode-sym-' + (i + 1)); 184 var pincodeSymbol = $('hid-keyboard-pincode-sym-' + (i + 1));
193 pincodeSymbol.classList.toggle('key-typed', i < entered && expected); 185 pincodeSymbol.classList.toggle('key-typed', i < entered && expected);
194 pincodeSymbol.classList.toggle('key-untyped', i > entered && expected); 186 pincodeSymbol.classList.toggle('key-untyped', i > entered && expected);
195 pincodeSymbol.classList.toggle('key-next', i == entered && expected); 187 pincodeSymbol.classList.toggle('key-next', i == entered && expected);
196 if (i < PINCODE_LENGTH) 188 if (i < PINCODE_LENGTH)
197 pincodeSymbol.textContent = pincode[i] ? pincode[i] : ''; 189 pincodeSymbol.textContent = pincode[i] ? pincode[i] : '';
198 } 190 }
199 }, 191 },
200 192
201 /* 193 /*
202 * Event handler that is invoked just before the screen in shown. 194 * Event handler that is invoked just before the screen in shown.
203 * @param {Object} data Screen init payload. 195 * @param {Object} data Screen init payload.
204 */ 196 */
205 onBeforeShow: function(data) { 197 onBeforeShow: function(data) {
198 this.setMDMode_();
206 this.setDeviceBlockState_('hid-mouse-block', this.CONNECTION.SEARCHING); 199 this.setDeviceBlockState_('hid-mouse-block', this.CONNECTION.SEARCHING);
207 this.setDeviceBlockState_('hid-keyboard-block', 200 this.setDeviceBlockState_('hid-keyboard-block',
208 this.CONNECTION.SEARCHING); 201 this.CONNECTION.SEARCHING);
202 $('oobe-hid-detection-md').setMouseState(this.CONNECTION.SEARCHING);
203 $('oobe-hid-detection-md').setKeyboardState(this.CONNECTION.SEARCHING);
204 },
205
206 /**
207 * This method takes care of switching to material-design OOBE.
208 * @private
209 */
210 setMDMode_: function() {
211 var useMDOobe = (loadTimeData.getString('newOobeUI') == 'on');
212 $('oobe-hid-detection-md').hidden = !useMDOobe;
213 $('oobe-hid-detection').hidden = useMDOobe;
209 }, 214 },
210 }; 215 };
211 }); 216 });
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698