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

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: Hide two versions of the screen behind dom-if template. 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
66 this.context.addObserver( 50 this.context.addObserver(
67 CONTEXT_KEY_MOUSE_STATE, 51 CONTEXT_KEY_MOUSE_STATE,
68 function(stateId) { 52 function(stateId) {
69 if (stateId === undefined) 53 if (stateId === undefined)
70 return; 54 return;
71 self.setDeviceBlockState_('hid-mouse-block', stateId); 55 self.setDeviceBlockState_('hid-mouse-block', stateId);
56 var md = $('oobe-hid-detection-md');
57 if (md) {
58 md.screen = self;
59 md.setMouseState(stateId);
60 }
72 } 61 }
73 ); 62 );
74 this.context.addObserver( 63 this.context.addObserver(
75 CONTEXT_KEY_KEYBOARD_STATE, 64 CONTEXT_KEY_KEYBOARD_STATE,
76 function(stateId) { 65 function(stateId) {
77 self.updatePincodeKeysState_(); 66 self.updatePincodeKeysState_();
78 if (stateId === undefined) 67 if (stateId === undefined)
79 return; 68 return;
80 self.setDeviceBlockState_('hid-keyboard-block', stateId); 69 self.setDeviceBlockState_('hid-keyboard-block', stateId);
81 if (stateId == self.CONNECTION.PAIRED) { 70 var md = $('oobe-hid-detection-md');
82 $('hid-keyboard-label-paired').textContent = self.context.get( 71 if (md) {
83 CONTEXT_KEY_KEYBOARD_LABEL, ''); 72 md.screen = self;
84 } else if (stateId == self.CONNECTION.PAIRING) { 73 md.setKeyboardState(stateId);
85 $('hid-keyboard-label-pairing').textContent = self.context.get( 74 }
86 CONTEXT_KEY_KEYBOARD_LABEL, ''); 75 var oldPaired = $('hid-keyboard-label-paired');
76 var oldPairing = $('hid-keyboard-label-pairing');
77
78 var label = self.context.get(CONTEXT_KEY_KEYBOARD_LABEL, '');
79 if (md) {
80 if (stateId == self.CONNECTION.PAIRED) {
81 md.keyboardPairedLabel = label;
82 } else if (stateId == self.CONNECTION.PAIRING) {
83 md.keyboardPairingLabel = label;
84 }
85 }
86 if (oldPaired && oldPairing) {
87 if (stateId == self.CONNECTION.PAIRED) {
88 oldPaired.textContent = label;
xiyuan 2017/01/04 21:02:23 nit: wrong indent
89 } else if (stateId == self.CONNECTION.PAIRING) {
90 oldPairing.textContent = label;
91 }
87 } 92 }
88 } 93 }
89 ); 94 );
90 this.context.addObserver( 95 this.context.addObserver(
91 CONTEXT_KEY_KEYBOARD_PINCODE, 96 CONTEXT_KEY_KEYBOARD_PINCODE,
92 this.updatePincodeKeysState_.bind(this)); 97 this.updatePincodeKeysState_.bind(this));
93 this.context.addObserver( 98 this.context.addObserver(
94 CONTEXT_KEY_KEYBOARD_ENTERED_PART_EXPECTED, 99 CONTEXT_KEY_KEYBOARD_ENTERED_PART_EXPECTED,
95 this.updatePincodeKeysState_.bind(this)); 100 this.updatePincodeKeysState_.bind(this));
96 this.context.addObserver( 101 this.context.addObserver(
97 CONTEXT_KEY_KEYBOARD_ENTERED_PART_PINCODE, 102 CONTEXT_KEY_KEYBOARD_ENTERED_PART_PINCODE,
98 this.updatePincodeKeysState_.bind(this)); 103 this.updatePincodeKeysState_.bind(this));
99 this.context.addObserver( 104 this.context.addObserver(
100 CONTEXT_KEY_CONTINUE_BUTTON_ENABLED, 105 CONTEXT_KEY_CONTINUE_BUTTON_ENABLED,
101 function(enabled) { 106 function(enabled) {
102 $('hid-continue-button').disabled = !enabled; 107 var md = $('oobe-hid-detection-md');
108 if (md) {
109 md.screen = self;
110 md.continueButtonDisabled = !enabled;
111 }
112
113 var oldContinueButton = $('hid-continue-button');
114 if (oldContinueButton)
115 oldContinueButton.disabled = !enabled;
103 } 116 }
104 ); 117 );
105 }, 118 },
106 119
107 /** 120 /**
108 * Buttons in oobe wizard's button strip. 121 * Buttons in oobe wizard's button strip.
109 * @type {array} Array of Buttons. 122 * @type {array} Array of Buttons.
110 */ 123 */
111 get buttons() { 124 get buttons() {
112 var buttons = []; 125 var buttons = [];
113 var continueButton = this.ownerDocument.createElement('button'); 126 var continueButton = this.ownerDocument.createElement('button');
114 continueButton.id = 'hid-continue-button'; 127 continueButton.id = 'hid-continue-button';
115 continueButton.textContent = loadTimeData.getString( 128 continueButton.textContent = loadTimeData.getString(
116 'hidDetectionContinue'); 129 'hidDetectionContinue');
117 continueButton.addEventListener('click', function(e) { 130 continueButton.addEventListener('click', function(e) {
118 chrome.send('HIDDetectionOnContinue'); 131 chrome.send('HIDDetectionOnContinue');
119 e.stopPropagation(); 132 e.stopPropagation();
120 }); 133 });
121 buttons.push(continueButton); 134 buttons.push(continueButton);
122 135
123 return buttons; 136 return buttons;
124 }, 137 },
125 138
126 /** 139 /**
127 * Returns a control which should receive an initial focus. 140 * Returns a control which should receive an initial focus.
128 */ 141 */
129 get defaultControl() { 142 get defaultControl() { return $('hid-continue-button'); },
130 return $('hid-continue-button');
131 },
132 143
133 /** 144 /**
134 * Sets a device-block css class to reflect device state of searching, usb, 145 * Sets a device-block css class to reflect device state of searching, usb,
135 * connected, pairing or paired (for BT devices). 146 * connected, pairing or paired (for BT devices).
136 * @param {blockId} id one of keys of this.BLOCK dict. 147 * @param {blockId} id one of keys of this.BLOCK dict.
137 * @param {state} one of keys of this.CONNECTION dict. 148 * @param {state} one of keys of this.CONNECTION dict.
138 * @private 149 * @private
139 */ 150 */
140 setDeviceBlockState_: function(blockId, state) { 151 setDeviceBlockState_: function(blockId, state) {
141 if (state == 'update') 152 if (state == 'update')
142 return; 153 return;
143 var deviceBlock = $(blockId); 154 var deviceBlock = $(blockId);
155 /* Blocks are hidden in MD-mode */
156 if (!deviceBlock)
157 return;
144 for (var key in this.CONNECTION) { 158 for (var key in this.CONNECTION) {
145 var stateCase = this.CONNECTION[key]; 159 var stateCase = this.CONNECTION[key];
146 deviceBlock.classList.toggle(stateCase, stateCase == state); 160 deviceBlock.classList.toggle(stateCase, stateCase == state);
147 } 161 }
148 }, 162 },
149 163
150 /** 164 /**
151 * Sets state for mouse-block. 165 * Sets state for mouse-block.
152 * @param {state} one of keys of this.CONNECTION dict. 166 * @param {state} one of keys of this.CONNECTION dict.
153 */ 167 */
154 setPointingDeviceState: function(state) { 168 setPointingDeviceState: function(state) {
155 if (state === undefined) 169 if (state === undefined)
156 return; 170 return;
157 this.setDeviceBlockState_(this.BLOCK.MOUSE, state); 171 this.setDeviceBlockState_(this.BLOCK.MOUSE, state);
172 var md = $('oobe-hid-detection-md');
173 if (md) {
174 md.screen = this;
175 md.setMouseState(state);
176 }
158 }, 177 },
159 178
160 /** 179 /**
161 * Updates state for pincode key elements based on context state. 180 * Updates state for pincode key elements based on context state.
162 */ 181 */
163 updatePincodeKeysState_: function() { 182 updatePincodeKeysState_: function() {
164 var pincodeKeys = $('hid-keyboard-pincode');
165 var pincode = this.context.get(CONTEXT_KEY_KEYBOARD_PINCODE, ''); 183 var pincode = this.context.get(CONTEXT_KEY_KEYBOARD_PINCODE, '');
166 var state = this.context.get(CONTEXT_KEY_KEYBOARD_STATE, ''); 184 var state = this.context.get(CONTEXT_KEY_KEYBOARD_STATE, '');
185 var label = this.context.get(CONTEXT_KEY_KEYBOARD_LABEL, '');
186
187 var entered =
188 this.context.get(CONTEXT_KEY_KEYBOARD_ENTERED_PART_PINCODE, 0);
189
190 // whether the functionality of getting num of entered keys is available.
191 var expected =
192 this.context.get(CONTEXT_KEY_KEYBOARD_ENTERED_PART_EXPECTED, false);
193
194 var md = $('oobe-hid-detection-md');
195 if (md) {
196 md.screen = this;
197 md.setKeyboardState(state);
198 md.setPincodeState(pincode, entered, expected, label);
199 return;
200 }
201 /* non-md version */
202 var pincodeKeys = $('hid-keyboard-pincode');
203 if (!pincodeKeys)
204 return;
167 205
168 if (!pincode || state !== this.CONNECTION.PAIRING) { 206 if (!pincode || state !== this.CONNECTION.PAIRING) {
169 pincodeKeys.hidden = true; 207 pincodeKeys.hidden = true;
170 return; 208 return;
171 } 209 }
172 210
173 if (pincodeKeys.hidden) { 211 if (pincodeKeys.hidden) {
174 pincodeKeys.hidden = false; 212 pincodeKeys.hidden = false;
175 announceAccessibleMessage( 213 announceAccessibleMessage(
176 this.context.get(CONTEXT_KEY_KEYBOARD_LABEL, '') + ' ' + pincode + 214 this.context.get(CONTEXT_KEY_KEYBOARD_LABEL, '') + ' ' + pincode +
177 ' ' + loadTimeData.getString('hidDetectionBTEnterKey')); 215 ' ' + loadTimeData.getString('hidDetectionBTEnterKey'));
178 } 216 }
179 217
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) 218 if (pincode.length != PINCODE_LENGTH)
188 console.error('Wrong pincode length'); 219 console.error('Wrong pincode length');
189 220
190 // Pincode keys plus Enter key. 221 // Pincode keys plus Enter key.
191 for (var i = 0; i < (PINCODE_LENGTH + 1); i++) { 222 for (var i = 0; i < (PINCODE_LENGTH + 1); i++) {
192 var pincodeSymbol = $('hid-keyboard-pincode-sym-' + (i + 1)); 223 var pincodeSymbol = $('hid-keyboard-pincode-sym-' + (i + 1));
193 pincodeSymbol.classList.toggle('key-typed', i < entered && expected); 224 pincodeSymbol.classList.toggle('key-typed', i < entered && expected);
194 pincodeSymbol.classList.toggle('key-untyped', i > entered && expected); 225 pincodeSymbol.classList.toggle('key-untyped', i > entered && expected);
195 pincodeSymbol.classList.toggle('key-next', i == entered && expected); 226 pincodeSymbol.classList.toggle('key-next', i == entered && expected);
196 if (i < PINCODE_LENGTH) 227 if (i < PINCODE_LENGTH)
197 pincodeSymbol.textContent = pincode[i] ? pincode[i] : ''; 228 pincodeSymbol.textContent = pincode[i] ? pincode[i] : '';
198 } 229 }
199 }, 230 },
200 231
201 /* 232 /*
202 * Event handler that is invoked just before the screen in shown. 233 * Event handler that is invoked just before the screen in shown.
203 * @param {Object} data Screen init payload. 234 * @param {Object} data Screen init payload.
204 */ 235 */
205 onBeforeShow: function(data) { 236 onBeforeShow: function(data) {
237 this.setMDMode_();
238 var md = $('oobe-hid-detection-md');
239 if (md) {
240 md.screen = this;
241 md.setMouseState(this.CONNECTION.SEARCHING);
242 md.setKeyboardState(this.CONNECTION.SEARCHING);
243 }
206 this.setDeviceBlockState_('hid-mouse-block', this.CONNECTION.SEARCHING); 244 this.setDeviceBlockState_('hid-mouse-block', this.CONNECTION.SEARCHING);
207 this.setDeviceBlockState_('hid-keyboard-block', 245 this.setDeviceBlockState_('hid-keyboard-block',
208 this.CONNECTION.SEARCHING); 246 this.CONNECTION.SEARCHING);
209 }, 247 },
248
249 /**
250 * This method takes care of switching to material-design OOBE.
251 * @private
252 */
253 setMDMode_: function() {
254 var useMDOobe = (loadTimeData.getString('newOobeUI') == 'on');
255 $('hid-detection-md-switch').useMDOobe_ = useMDOobe;
256 //$('oobe-hid-detection-md').hidden = !useMDOobe;
257 //$('oobe-hid-detection').hidden = useMDOobe;
258 },
210 }; 259 };
211 }); 260 });
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698