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