OLD | NEW |
(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). |
| 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 |
| 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) { return string1 != string2; }, |
| 95 |
| 96 /** |
| 97 * Sets current state in mouse pairing process. |
| 98 * @param {string} state Connection state (one of screen.CONNECTION). |
| 99 */ |
| 100 setMouseState: function(state) { |
| 101 this.mouseState_ = this.calculateState_(this.mouseState_, state); |
| 102 }, |
| 103 |
| 104 /** |
| 105 * Updates visibility of keyboard pincode. |
| 106 * @param {string} state Connection state (one of screen.CONNECTION). |
| 107 * @private |
| 108 */ |
| 109 updateKeyboardPincodeVisible_: function(state) { |
| 110 this.keyboardPincodeVisible_ = this.keyboardPincode_ && |
| 111 (this.keyboardState_ == this.screen.CONNECTION.PAIRING); |
| 112 }, |
| 113 |
| 114 /** |
| 115 * Sets current state in keyboard pairing process. |
| 116 * @param {string} state Connection state (one of screen.CONNECTION). |
| 117 */ |
| 118 setKeyboardState: function(state) { |
| 119 this.keyboardState_ = this.calculateState_(this.keyboardState_, state); |
| 120 this.updateKeyboardPincodeVisible_(); |
| 121 }, |
| 122 |
| 123 /** |
| 124 * Sets displayed keyboard pin. |
| 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 |
| 137 if (pincode.length != PINCODE_LENGTH) |
| 138 console.error('Wrong pincode length'); |
| 139 |
| 140 // Pincode keys plus Enter key. |
| 141 for (let i = 0; i < (PINCODE_LENGTH + 1); i++) { |
| 142 var pincodeSymbol = this.$['hid-keyboard-pincode-sym-' + (i + 1)]; |
| 143 pincodeSymbol.classList.toggle('key-typed', i < entered && expected); |
| 144 pincodeSymbol.classList.toggle('key-untyped', i > entered && expected); |
| 145 pincodeSymbol.classList.toggle('key-next', i == entered && expected); |
| 146 if (i < PINCODE_LENGTH) |
| 147 pincodeSymbol.textContent = pincode[i] ? pincode[i] : ''; |
| 148 } |
| 149 |
| 150 var wasVisible = this.keyboardPincodeVisible_; |
| 151 this.updateKeyboardPincodeVisible_(); |
| 152 if (this.keyboardPincodeVisible_ && !wasVisible) { |
| 153 announceAccessibleMessage( |
| 154 label + ' ' + pincode + ' ' + |
| 155 loadTimeData.getString('hidDetectionBTEnterKey')); |
| 156 } |
| 157 }, |
| 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 })(); |
OLD | NEW |