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 * The problem to display on the pin keyboard. | |
| 52 */ | |
| 53 problemMessage: { | |
|
jdufault
2016/08/24 01:20:18
This should be private (problemMessage_)
sammiequon
2016/08/25 23:50:02
No more problem message.
| |
| 54 type: String, | |
| 55 value: '' | |
| 56 }, | |
| 57 | |
| 58 /** | |
| 59 * Whether the problem is an error or a warning. | |
| 60 */ | |
| 61 problemClass: { | |
|
jdufault
2016/08/24 01:20:18
This should be private (problemClass_)
sammiequon
2016/08/25 23:50:02
No more problem message.
| |
| 62 type: String, | |
| 63 value: 'warning' | |
| 64 }, | |
| 65 | |
| 50 /** The value stored in the keyboard's input element. */ | 66 /** The value stored in the keyboard's input element. */ |
| 51 value: { | 67 value: { |
| 52 type: String, | 68 type: String, |
| 53 notify: true, | 69 notify: true, |
| 54 value: '', | 70 value: '', |
| 55 observer: 'onPinValueChange_' | 71 observer: 'onPinValueChange_' |
| 56 } | 72 } |
| 57 }, | 73 }, |
| 58 | 74 |
| 59 /** | 75 /** |
| 60 * Gets the container holding the password field. | 76 * Gets the container holding the password field. |
| 61 * @type {!HTMLInputElement} | 77 * @type {!HTMLInputElement} |
| 62 */ | 78 */ |
| 63 get inputElement() { | 79 get inputElement() { |
| 64 return this.$$('#pin-input'); | 80 return this.$$('#pin-input'); |
| 65 }, | 81 }, |
| 66 | 82 |
| 67 /** Transfers focus to the input element. */ | 83 /** Transfers focus to the input element. */ |
| 68 focus: function() { | 84 focus: function() { |
| 69 this.$$('#pin-input').focus(); | 85 this.$$('#pin-input').focus(); |
| 70 }, | 86 }, |
| 71 | 87 |
| 72 /** | 88 /** |
| 89 * Called when a different problem message wants to be displayed. | |
| 90 * @param {string} problemMessage the message to be displayed | |
| 91 * @param {boolean} isError | |
| 92 */ | |
| 93 setProblem: function(problemMessage, isError) { | |
| 94 this.problemClass = isError ? 'error' : 'warning'; | |
| 95 this.problemMessage = problemMessage; | |
| 96 }, | |
| 97 | |
| 98 /** | |
| 73 * Called when a keypad number has been tapped. | 99 * Called when a keypad number has been tapped. |
| 74 * @param {!{target: !PaperButtonElement}} event | 100 * @param {!{target: !PaperButtonElement}} event |
| 75 * @private | 101 * @private |
| 76 */ | 102 */ |
| 77 onNumberTap_: function(event, detail) { | 103 onNumberTap_: function(event, detail) { |
| 78 var numberValue = event.target.getAttribute('value'); | 104 var numberValue = event.target.getAttribute('value'); |
| 79 this.value += numberValue; | 105 this.value += numberValue; |
| 80 | 106 |
| 81 // If a number button is clicked, we do not want to switch focus to the | 107 // 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 | 108 // 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 | 146 |
| 121 // Enter pressed. | 147 // Enter pressed. |
| 122 if (event.keyCode == 13) { | 148 if (event.keyCode == 13) { |
| 123 this.firePinSubmitEvent_(); | 149 this.firePinSubmitEvent_(); |
| 124 event.preventDefault(); | 150 event.preventDefault(); |
| 125 return; | 151 return; |
| 126 } | 152 } |
| 127 }, | 153 }, |
| 128 | 154 |
| 129 /** | 155 /** |
| 130 * Changes the color of the submit button if PIN is ready. | 156 * Changes the color of the input text if it is not empty. |
| 131 * @param {string} value | 157 * @param {string} value |
| 132 * @private | 158 * @private |
| 133 */ | 159 */ |
| 134 getSubmitClass_: function(value) { | 160 getContentClass_: function(value) { |
| 135 return value.length > 0 ? 'ready-background' : ''; | 161 return value.length > 0 ? 'has-content' : ''; |
| 136 }, | 162 }, |
| 137 | 163 |
| 138 /** | 164 /** |
| 165 * Disables the submit and backspace button if nothing is entered. | |
| 166 * @param {string} value | |
| 167 * @private | |
| 168 */ | |
| 169 hasInput_: function(value) { | |
| 170 return value.length > 0; | |
| 171 }, | |
| 172 | |
| 173 /** | |
| 139 * Computes whether the input type for the pin input should be password or | 174 * Computes whether the input type for the pin input should be password or |
| 140 * numerical. | 175 * numerical. |
| 141 * @param {boolean} enablePassword | 176 * @param {boolean} enablePassword |
| 142 * @private | 177 * @private |
| 143 */ | 178 */ |
| 144 getInputType_: function(enablePassword) { | 179 getInputType_: function(enablePassword) { |
| 145 return enablePassword ? 'password' : 'number'; | 180 return enablePassword ? 'password' : 'number'; |
| 146 }, | 181 }, |
| 147 | 182 |
| 148 /** | 183 /** |
| 149 * Computes the value of the pin input placeholder. | 184 * Computes the value of the pin input placeholder. |
| 150 * @param {boolean} enablePassword | 185 * @param {boolean} enablePassword |
| 151 * @private | 186 * @private |
| 152 */ | 187 */ |
| 153 getInputPlaceholder_: function(enablePassword) { | 188 getInputPlaceholder_: function(enablePassword) { |
| 154 return enablePassword ? this.i18n('pinKeyboardPlaceholderPinPassword') : | 189 return enablePassword ? this.i18n('pinKeyboardPlaceholderPinPassword') : |
| 155 this.i18n('pinKeyboardPlaceholderPin'); | 190 this.i18n('pinKeyboardPlaceholderPin'); |
| 156 }, | 191 }, |
| 157 | 192 |
| 158 /** | 193 /** |
| 194 * Hides the problem message div if no error is to be shown. | |
| 195 * @param {string} problemMessage | |
| 196 * @private | |
| 197 */ | |
| 198 hasProblemMessage_: function(problemMessage) { | |
| 199 return problemMessage.length > 0; | |
| 200 }, | |
| 201 | |
| 202 /** | |
| 203 * Computes the whether the error message should be shown. | |
| 204 * @param {boolean} problemMessage | |
| 205 * @private | |
| 206 */ | |
| 207 getProblemClass_: function(problemMessage) { | |
|
jdufault
2016/08/24 01:20:18
Showing the problem should be controlled by the em
sammiequon
2016/08/25 23:50:02
No more problem message.
| |
| 208 return problemMessage.length > 0 ? 'problem-show' : ''; | |
| 209 }, | |
| 210 | |
| 211 /** | |
| 212 * Computes the direction of the problem message. | |
| 213 * @private | |
| 214 */ | |
| 215 getProblemDirection_: function() { | |
| 216 return document.dir == 'rtl' ? 'problem-rtl' : ''; | |
| 217 }, | |
| 218 | |
| 219 /** | |
| 159 * Computes the direction of the pin input. | 220 * Computes the direction of the pin input. |
| 160 * @param {string} password | 221 * @param {string} password |
| 161 * @private | 222 * @private |
| 162 */ | 223 */ |
| 163 getInputClass_: function(password) { | 224 getInputClass_: function(password) { |
| 164 // +password will convert a string to a number or to NaN if that's not | 225 // +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 | 226 // possible. Number.isInteger will verify the value is not a NaN and that it |
| 166 // does not contain decimals. | 227 // does not contain decimals. |
| 167 // This heuristic will fail for inputs like '1.0'. | 228 // This heuristic will fail for inputs like '1.0'. |
| 168 // | 229 // |
| 169 // Since we still support users entering their passwords through the PIN | 230 // 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 | 231 // keyboard, we swap the input box to rtl when we think it is a password |
| 171 // (just numbers), if the document direction is rtl. | 232 // (just numbers), if the document direction is rtl. |
| 172 var enableRtl = (document.dir == 'rtl') && !Number.isInteger(+password); | 233 var enableRtl = (document.dir == 'rtl') && !Number.isInteger(+password); |
| 173 return enableRtl ? 'input-non-pin' : ''; | 234 return enableRtl ? 'input-non-pin' : ''; |
| 174 }, | 235 }, |
| 175 | 236 |
| 176 /** | 237 /** |
| 177 * Computes if the submit button is visible. | 238 * Computes if the submit button is visible. |
| 178 * @param {boolean} submitEnabled | 239 * @param {boolean} submitEnabled |
| 179 * @private | 240 * @private |
| 180 */ | 241 */ |
| 181 getSubmitHiddenClass_: function(submitEnabled) { | 242 getSubmitClass_: function(submitEnabled) { |
| 182 return submitEnabled ? '' : 'submit-button-hidden'; | 243 return submitEnabled ? '' : 'submit-button-hidden'; |
| 183 } | 244 } |
| 184 }); | 245 }); |
| OLD | NEW |