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

Side by Side Diff: chrome/browser/resources/chromeos/login/oobe_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
(Empty)
1 // Copyright 2016 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.
4
5 /**
6 * @fileoverview Polymer element for displaying material design HID detection
7 * screen.
8 */
9
10 (function() {
11 /** @const {number} */ var PINCODE_LENGTH = 6;
12
13 Polymer({
14 is: 'oobe-hid-detection-md',
15
16 properties: {
17 /** "Continue" button is disabled until HID devices are paired. */
18 continueButtonDisabled: {
19 type: Boolean,
20 value: true,
21 },
22
23 /** This is the displayed text for keyboard "Pairing" state. */
24 keyboardPairingLabel: String,
25
26 /** This is the displayed text for keyboard "Paired" state. */
27 keyboardPairedLabel: String,
28
29 /**
30 * Current state in mouse pairing process.
31 * @private
32 */
33 mouseState_: String,
34
35 /**
36 * Current state in keyboard pairing process.
37 * @private
38 */
39 keyboardState_: String,
40
41 /**
42 * Controls visibility of keyboard pincode.
43 * @private
44 */
45 keyboardPincodeVisible_: Boolean,
46
47 /**
48 * Reference to OOBE screen object.
49 * @type {!OobeTypes.Screen}
50 */
51 screen: Object,
52 },
53
54 /**
55 * Displayed keyboard pincode.
56 */
57 keyboardPincode_: String,
58
59 /**
60 * Helper function to update keyboard/mouse state.
61 * @param {string} state Existing connection state (one of
62 * screen.CONNECTION).
xiyuan 2017/01/04 21:02:23 nit: 2 more space indent
63 * @param {string} newState New connection state (one of screen.CONNECTION).
64 * @private
65 */
66 calculateState_: function(state, newState) {
67 if (newState === undefined)
68 return state;
69 if (!this.screen)
70 return state;
71 if (newState == this.screen.CONNECTION.UPDATE)
72 return state;
73
74 return newState;
75 },
76
77 /**
78 * Helper function to calculate visibility of 'connected' icons.
79 * @param {string} state Connection state (one of screen.CONNECTION).
80 * @private
81 */
82 tickIsVisible_: function(state) {
83 if (!this.screen)
84 return false;
85 return this.screen && (
xiyuan 2017/01/04 21:02:23 nit: no need to test this.screen since the "if" ab
86 (state == this.screen.CONNECTION.USB) ||
87 (state == this.screen.CONNECTION.CONNECTED) ||
88 (state == this.screen.CONNECTION.PAIRED)
89 );
90 },
91
92 /**
93 * Helper function to update keyboard/mouse state.
94 * Returns true if strings are not equal. False otherwize.
95 * @param {string} string1
96 * @param {string} string2
97 * @private
98 */
99 notEq_: function(string1, string2) { return string1 != string2; },
100
101 /**
102 * Sets current state in mouse pairing process.
103 * @param {string} state Connection state (one of screen.CONNECTION).
104 */
105 setMouseState: function(state) {
106 this.mouseState_ = this.calculateState_(this.mouseState_, state);
107 },
108
109 /**
110 * Updates visibility of keyboard pincode.
111 * @param {string} state Connection state (one of screen.CONNECTION).
112 * @private
113 */
114 updateKeyboardPincodeVisible_: function(state) {
115 this.keyboardPincodeVisible_ = this.keyboardPincode_ && this.screen &&
116 (this.keyboardState_ == this.screen.CONNECTION.PAIRING);
117 },
118
119 /**
120 * Sets current state in keyboard pairing process.
121 * @param {string} state Connection state (one of screen.CONNECTION).
122 */
123 setKeyboardState: function(state) {
124 this.keyboardState_ = this.calculateState_(this.keyboardState_, state);
125 this.updateKeyboardPincodeVisible_();
126 },
127
128 /**
129 * Sets displayed keyboard pin.
130 * @param {string} pincode Pincode.
131 * @param {number} entered Number of digits already entered.
132 * @param {boolean} expected
133 * @param {string} label Connection state displayed description.
134 */
135 setPincodeState: function(pincode, entered, expected, label) {
136 this.keyboardPincode_ = pincode;
137 if (!pincode) {
138 this.updateKeyboardPincodeVisible_();
139 return;
140 }
141 if (!this.screen)
142 return;
143
144 if (pincode.length != PINCODE_LENGTH)
145 console.error('Wrong pincode length');
146
147 // Pincode keys plus Enter key.
148 for (let i = 0; i < (PINCODE_LENGTH + 1); i++) {
149 var pincodeSymbol = this.$['hid-keyboard-pincode-sym-' + (i + 1)];
150 pincodeSymbol.classList.toggle('key-typed', i < entered && expected);
151 pincodeSymbol.classList.toggle('key-untyped', i > entered && expected);
152 pincodeSymbol.classList.toggle('key-next', i == entered && expected);
153 if (i < PINCODE_LENGTH)
154 pincodeSymbol.textContent = pincode[i] ? pincode[i] : '';
155 }
156
157 var wasVisible = this.keyboardPincodeVisible_;
158 this.updateKeyboardPincodeVisible_();
159 if (this.keyboardPincodeVisible_ && !wasVisible) {
160 announceAccessibleMessage(
161 label + ' ' + pincode + ' ' +
162 loadTimeData.getString('hidDetectionBTEnterKey'));
163 }
164 },
165
166 /**
167 * This is 'on-tap' event handler for 'Continue' button.
168 */
169 onHIDContinueTap_: function(event) {
170 chrome.send('HIDDetectionOnContinue');
171 event.stopPropagation();
172 },
173 });
174 })();
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698