Chromium Code Reviews| 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 | 6 * @fileoverview |
| 7 * 'pin-keyboard' is a keyboard that can be used to enter PINs or more generally | 7 * 'pin-keyboard' is a keyboard that can be used to enter PINs or more generally |
| 8 * numeric values. | 8 * numeric values. |
| 9 * | 9 * |
| 10 * Properties: | 10 * Properties: |
| (...skipping 29 matching lines...) Expand all Loading... | |
| 40 }, | 40 }, |
| 41 | 41 |
| 42 /** | 42 /** |
| 43 * Whether or not the keyboard's submit button should be shown. | 43 * Whether or not the keyboard's submit button should be shown. |
| 44 */ | 44 */ |
| 45 enableSubmitButton: { | 45 enableSubmitButton: { |
| 46 type: Boolean, | 46 type: Boolean, |
| 47 value: false | 47 value: false |
| 48 }, | 48 }, |
| 49 | 49 |
| 50 /** | |
| 51 * Whether or not to show an error. | |
| 52 */ | |
| 53 enableError: { | |
| 54 type: Boolean, | |
| 55 value: false | |
| 56 }, | |
| 57 | |
| 50 /** The value stored in the keyboard's input element. */ | 58 /** The value stored in the keyboard's input element. */ |
| 51 value: { | 59 value: { |
| 52 type: String, | 60 type: String, |
| 53 notify: true, | 61 notify: true, |
| 54 value: '', | 62 value: '', |
| 55 observer: 'onPinValueChange_' | 63 observer: 'onPinValueChange_' |
| 56 } | 64 } |
| 57 }, | 65 }, |
| 58 | 66 |
| 59 /** | 67 /** |
| 60 * Gets the container holding the password field. | 68 * Gets the container holding the password field. |
| 61 * @type {!HTMLInputElement} | 69 * @type {!HTMLInputElement} |
| 62 */ | 70 */ |
| 63 get inputElement() { | 71 get inputElement() { |
| 64 return this.$$('#pin-input'); | 72 return this.$$('#pin-input'); |
| 65 }, | 73 }, |
| 66 | 74 |
| 67 /** Transfers focus to the input element. */ | 75 /** Transfers focus to the input element. */ |
| 68 focus: function() { | 76 focus: function() { |
| 69 this.$$('#pin-input').focus(); | 77 this.$$('#pin-input').focus(); |
| 70 }, | 78 }, |
| 71 | 79 |
| 72 /** | 80 /** |
| 81 * Sets the error message to the new message. | |
| 82 * @param {string} newMessage | |
| 83 */ | |
| 84 setMessage: function(newMessage) { | |
|
jdufault
2016/08/19 17:47:57
Remove this, use a property instead.
sammiequon
2016/08/22 20:43:59
Done.
| |
| 85 this.$$('#error-message').innerHTML = newMessage; | |
| 86 }, | |
| 87 | |
| 88 /** | |
| 73 * Called when a keypad number has been tapped. | 89 * Called when a keypad number has been tapped. |
| 74 * @param {!{target: !PaperButtonElement}} event | 90 * @param {!{target: !PaperButtonElement}} event |
| 75 * @private | 91 * @private |
| 76 */ | 92 */ |
| 77 onNumberTap_: function(event, detail) { | 93 onNumberTap_: function(event, detail) { |
| 78 var numberValue = event.target.getAttribute('value'); | 94 var numberValue = event.target.getAttribute('value'); |
| 79 this.value += numberValue; | 95 this.value += numberValue; |
| 80 | 96 |
| 81 // If a number button is clicked, we do not want to switch focus to the | 97 // If a number button is clicked, we do not want to switch focus to the |
| 82 // button, therefore we transfer focus back to the input, but if a number | 98 // button, therefore we transfer focus back to the input, but if a number |
| (...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 120 | 136 |
| 121 // Enter pressed. | 137 // Enter pressed. |
| 122 if (event.keyCode == 13) { | 138 if (event.keyCode == 13) { |
| 123 this.firePinSubmitEvent_(); | 139 this.firePinSubmitEvent_(); |
| 124 event.preventDefault(); | 140 event.preventDefault(); |
| 125 return; | 141 return; |
| 126 } | 142 } |
| 127 }, | 143 }, |
| 128 | 144 |
| 129 /** | 145 /** |
| 130 * Changes the color of the submit button if PIN is ready. | 146 * Changes the color of the input text if it is not empty. |
| 131 * @param {string} value | 147 * @param {string} value |
| 132 * @private | 148 * @private |
| 133 */ | 149 */ |
| 134 getSubmitClass_: function(value) { | 150 getContentClass_: function(value) { |
| 135 return value.length > 0 ? 'ready-background' : ''; | 151 return value.length > 0 ? 'has-content' : ''; |
| 136 }, | 152 }, |
| 137 | 153 |
| 138 /** | 154 /** |
| 155 * Disables the submit and backspace button if nothing is entered. | |
| 156 * @param {string} value | |
| 157 * @private | |
| 158 */ | |
| 159 hasInput_: function(value) { | |
| 160 return value.length > 0; | |
| 161 }, | |
| 162 | |
| 163 /** | |
| 139 * Computes whether the input type for the pin input should be password or | 164 * Computes whether the input type for the pin input should be password or |
| 140 * numerical. | 165 * numerical. |
| 141 * @param {boolean} enablePassword | 166 * @param {boolean} enablePassword |
| 142 * @private | 167 * @private |
| 143 */ | 168 */ |
| 144 getInputType_: function(enablePassword) { | 169 getInputType_: function(enablePassword) { |
| 145 return enablePassword ? 'password' : 'number'; | 170 return enablePassword ? 'password' : 'number'; |
| 146 }, | 171 }, |
| 147 | 172 |
| 148 /** | 173 /** |
| 149 * Computes the value of the pin input placeholder. | 174 * Computes the value of the pin input placeholder. |
| 150 * @param {boolean} enablePassword | 175 * @param {boolean} enablePassword |
| 151 * @private | 176 * @private |
| 152 */ | 177 */ |
| 153 getInputPlaceholder_: function(enablePassword) { | 178 getInputPlaceholder_: function(enablePassword) { |
| 154 return enablePassword ? this.i18n('pinKeyboardPlaceholderPinPassword') : | 179 return enablePassword ? this.i18n('pinKeyboardPlaceholderPinPassword') : |
| 155 this.i18n('pinKeyboardPlaceholderPin'); | 180 this.i18n('pinKeyboardPlaceholderPin'); |
| 156 }, | 181 }, |
| 157 | 182 |
| 158 /** | 183 /** |
| 184 * Computes the value of the pin input placeholder. | |
| 185 * @param {boolean} enablePassword | |
| 186 * @private | |
| 187 */ | |
| 188 getErrorClass_: function(showError) { | |
| 189 return showError ? 'error-show' : ''; | |
| 190 }, | |
| 191 | |
| 192 /** | |
| 159 * Computes the direction of the pin input. | 193 * Computes the direction of the pin input. |
| 160 * @param {string} password | 194 * @param {string} password |
| 161 * @private | 195 * @private |
| 162 */ | 196 */ |
| 163 getInputClass_: function(password) { | 197 getInputClass_: function(password) { |
| 164 // +password will convert a string to a number or to NaN if that's not | 198 // +password will convert a string to a number or to NaN if that's not |
| 165 // possible. Number.isInteger will verify the value is not a NaN and that it | 199 // possible. Number.isInteger will verify the value is not a NaN and that it |
| 166 // does not contain decimals. | 200 // does not contain decimals. |
| 167 // This heuristic will fail for inputs like '1.0'. | 201 // This heuristic will fail for inputs like '1.0'. |
| 168 // | 202 // |
| 169 // Since we still support users entering their passwords through the PIN | 203 // Since we still support users entering their passwords through the PIN |
| 170 // keyboard, we swap the input box to rtl when we think it is a password | 204 // keyboard, we swap the input box to rtl when we think it is a password |
| 171 // (just numbers), if the document direction is rtl. | 205 // (just numbers), if the document direction is rtl. |
| 172 var enableRtl = (document.dir == 'rtl') && !Number.isInteger(+password); | 206 var enableRtl = (document.dir == 'rtl') && !Number.isInteger(+password); |
| 173 return enableRtl ? 'input-non-pin' : ''; | 207 return enableRtl ? 'input-non-pin' : ''; |
| 174 }, | 208 }, |
| 175 | 209 |
| 176 /** | 210 /** |
| 177 * Computes if the submit button is visible. | 211 * Computes if the submit button is visible. |
| 178 * @param {boolean} submitEnabled | 212 * @param {boolean} submitEnabled |
| 179 * @private | 213 * @private |
| 180 */ | 214 */ |
| 181 getSubmitHiddenClass_: function(submitEnabled) { | 215 getSubmitClass_: function(submitEnabled) { |
| 182 return submitEnabled ? '' : 'submit-button-hidden'; | 216 return submitEnabled ? '' : 'submit-button-hidden'; |
| 183 } | 217 } |
| 184 }); | 218 }); |
| OLD | NEW |