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
3 // found in the LICENSE file.
6 * @fileoverview Oobe HID detection screen implementation.
9 login
.createScreen('HIDDetectionScreen', 'hid-detection', function() {
10 var CONTEXT_KEY_KEYBOARD_STATE
= 'keyboard-state';
11 var CONTEXT_KEY_MOUSE_STATE
= 'mouse-state';
12 var CONTEXT_KEY_KEYBOARD_PINCODE
= 'keyboard-pincode';
13 var CONTEXT_KEY_KEYBOARD_ENTERED_PART_EXPECTED
= 'num-keys-entered-expected';
14 var CONTEXT_KEY_KEYBOARD_ENTERED_PART_PINCODE
= 'num-keys-entered-pincode';
15 var CONTEXT_KEY_MOUSE_DEVICE_NAME
= 'mouse-device-name';
16 var CONTEXT_KEY_KEYBOARD_DEVICE_NAME
= 'keyboard-device-name';
17 var CONTEXT_KEY_KEYBOARD_LABEL
= 'keyboard-device-label';
18 var CONTEXT_KEY_CONTINUE_BUTTON_ENABLED
= 'continue-button-enabled';
20 var PINCODE_LENGTH
= 6;
25 * Enumeration of possible states during pairing. The value associated with
26 * each state maps to a localized string in the global variable
31 STARTUP
: 'bluetoothStartConnecting',
32 REMOTE_PIN_CODE
: 'bluetoothRemotePinCode',
33 CONNECT_FAILED
: 'bluetoothConnectFailed',
34 CANCELED
: 'bluetoothPairingCanceled',
35 // Pairing dismissed (succeeded or canceled).
36 DISMISSED
: 'bluetoothPairingDismissed'
39 // Enumeration of possible connection states of a device.
41 SEARCHING
: 'searching',
42 CONNECTED
: 'connected',
45 // Special info state.
49 // Possible ids of device blocks.
51 MOUSE
: 'hid-mouse-block',
52 KEYBOARD
: 'hid-keyboard-block'
56 * Button to move to usual OOBE flow after detection.
59 continueButton_
: null,
62 decorate: function() {
65 this.context
.addObserver(
66 CONTEXT_KEY_MOUSE_STATE
,
68 if (stateId
=== undefined)
70 self
.setDeviceBlockState_('hid-mouse-block', stateId
);
73 this.context
.addObserver(
74 CONTEXT_KEY_KEYBOARD_STATE
,
76 self
.updatePincodeKeysState_();
77 if (stateId
=== undefined)
79 self
.setDeviceBlockState_('hid-keyboard-block', stateId
);
80 if (stateId
== self
.CONNECTION
.PAIRED
) {
81 $('hid-keyboard-label-paired').textContent
= self
.context
.get(
82 CONTEXT_KEY_KEYBOARD_LABEL
, '');
83 } else if (stateId
== self
.CONNECTION
.PAIRING
) {
84 $('hid-keyboard-label-pairing').textContent
= self
.context
.get(
85 CONTEXT_KEY_KEYBOARD_LABEL
, '');
89 this.context
.addObserver(
90 CONTEXT_KEY_KEYBOARD_PINCODE
,
91 this.updatePincodeKeysState_
.bind(this));
92 this.context
.addObserver(
93 CONTEXT_KEY_KEYBOARD_ENTERED_PART_EXPECTED
,
94 this.updatePincodeKeysState_
.bind(this));
95 this.context
.addObserver(
96 CONTEXT_KEY_KEYBOARD_ENTERED_PART_PINCODE
,
97 this.updatePincodeKeysState_
.bind(this));
98 this.context
.addObserver(
99 CONTEXT_KEY_CONTINUE_BUTTON_ENABLED
,
101 $('hid-continue-button').disabled
= !enabled
;
107 * Buttons in oobe wizard's button strip.
108 * @type {array} Array of Buttons.
112 var continueButton
= this.ownerDocument
.createElement('button');
113 continueButton
.id
= 'hid-continue-button';
114 continueButton
.textContent
= loadTimeData
.getString(
115 'hidDetectionContinue');
116 continueButton
.addEventListener('click', function(e
) {
117 chrome
.send('HIDDetectionOnContinue');
120 buttons
.push(continueButton
);
126 * Returns a control which should receive an initial focus.
128 get defaultControl() {
129 return $('hid-continue-button');
133 * Sets a device-block css class to reflect device state of searching,
134 * connected, pairing or paired (for BT devices).
135 * @param {blockId} id one of keys of this.BLOCK dict.
136 * @param {state} one of keys of this.CONNECTION dict.
139 setDeviceBlockState_: function(blockId
, state
) {
140 if (state
== 'update')
142 var deviceBlock
= $(blockId
);
143 for (var key
in this.CONNECTION
) {
144 var stateCase
= this.CONNECTION
[key
];
145 deviceBlock
.classList
.toggle(stateCase
, stateCase
== state
);
150 * Sets state for mouse-block.
151 * @param {state} one of keys of this.CONNECTION dict.
153 setPointingDeviceState: function(state
) {
154 if (state
=== undefined)
156 this.setDeviceBlockState_(this.BLOCK
.MOUSE
, state
);
160 * Updates state for pincode key elements based on context state.
162 updatePincodeKeysState_: function() {
163 var pincodeKeys
= $('hid-keyboard-pincode');
164 var pincode
= this.context
.get(CONTEXT_KEY_KEYBOARD_PINCODE
, '');
165 var state
= this.context
.get(CONTEXT_KEY_KEYBOARD_STATE
, '');
167 if (!pincode
|| state
!== this.CONNECTION
.PAIRING
) {
168 pincodeKeys
.hidden
= true;
172 if (pincodeKeys
.hidden
) {
173 pincodeKeys
.hidden
= false;
174 announceAccessibleMessage(
175 this.context
.get(CONTEXT_KEY_KEYBOARD_LABEL
, '') + ' ' + pincode
+
176 ' ' + loadTimeData
.getString('hidDetectionBTEnterKey'));
179 var entered
= this.context
.get(
180 CONTEXT_KEY_KEYBOARD_ENTERED_PART_PINCODE
, 0);
182 // whether the functionality of getting num of entered keys is available.
183 var expected
= this.context
.get(
184 CONTEXT_KEY_KEYBOARD_ENTERED_PART_EXPECTED
, false);
186 if (pincode
.length
!= PINCODE_LENGTH
)
187 console
.error('Wrong pincode length');
189 // Pincode keys plus Enter key.
190 for (var i
= 0; i
< (PINCODE_LENGTH
+ 1); i
++) {
191 var pincodeSymbol
= $('hid-keyboard-pincode-sym-' + (i
+ 1));
192 pincodeSymbol
.classList
.toggle('key-typed', i
< entered
&& expected
);
193 pincodeSymbol
.classList
.toggle('key-untyped', i
> entered
&& expected
);
194 pincodeSymbol
.classList
.toggle('key-next', i
== entered
&& expected
);
195 if (i
< PINCODE_LENGTH
)
196 pincodeSymbol
.textContent
= pincode
[i
] ? pincode
[i
] : '';
201 * Event handler that is invoked just before the screen in shown.
202 * @param {Object} data Screen init payload.
204 onBeforeShow: function(data
) {
205 this.setDeviceBlockState_('hid-mouse-block', this.CONNECTION
.SEARCHING
);
206 this.setDeviceBlockState_('hid-keyboard-block',
207 this.CONNECTION
.SEARCHING
);