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 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 63 get inputElement() { | 63 get inputElement() { |
| 64 return this.$$('#pin-input'); | 64 return this.$$('#pin-input'); |
| 65 }, | 65 }, |
| 66 | 66 |
| 67 /** Transfers focus to the input element. */ | 67 /** Transfers focus to the input element. */ |
| 68 focus: function() { | 68 focus: function() { |
| 69 this.$$('#pin-input').focus(); | 69 this.$$('#pin-input').focus(); |
| 70 }, | 70 }, |
| 71 | 71 |
| 72 /** | 72 /** |
| 73 * Sets the value of the pin keyboard. Used by the user pod to ensure the | |
| 74 * password element has the same value as the pin keyboard. | |
| 75 * @param {string} newValue | |
| 76 */ | |
| 77 setNewValue: function(newValue) { | |
| 78 this.value = newValue; | |
|
jdufault
2016/08/19 01:06:47
We should be able to assign to value directly whic
sammiequon
2016/08/23 17:28:11
Done.
| |
| 79 }, | |
| 80 | |
| 81 /** | |
| 73 * Called when a keypad number has been tapped. | 82 * Called when a keypad number has been tapped. |
| 74 * @param {!{target: !PaperButtonElement}} event | 83 * @param {!{target: !PaperButtonElement}} event |
| 75 * @private | 84 * @private |
| 76 */ | 85 */ |
| 77 onNumberTap_: function(event, detail) { | 86 onNumberTap_: function(event, detail) { |
| 78 var numberValue = event.target.getAttribute('value'); | 87 var numberValue = event.target.getAttribute('value'); |
| 79 this.value += numberValue; | 88 this.value += numberValue; |
| 80 | |
| 81 // 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 | |
| 83 // button is tabbed into, it should keep focus, so users can use tab and | |
| 84 // spacebar/return to enter their PIN. | |
| 85 if (!event.target.receivedFocusFromKeyboard) | |
| 86 this.focus(); | |
| 87 }, | 89 }, |
| 88 | 90 |
| 89 /** Fires a submit event with the current PIN value. */ | 91 /** Fires a submit event with the current PIN value. */ |
| 90 firePinSubmitEvent_: function() { | 92 firePinSubmitEvent_: function() { |
| 91 this.fire('submit', { pin: this.value }); | 93 this.fire('submit', { pin: this.value }); |
| 92 }, | 94 }, |
| 93 | 95 |
| 94 /** | 96 /** |
| 95 * Fires an update event with the current PIN value. The event will only be | 97 * Fires an update event with the current PIN value. The event will only be |
| 96 * fired if the PIN value has actually changed. | 98 * fired if the PIN value has actually changed. |
| 97 * @param {string} value | 99 * @param {string} value |
| 98 * @param {string} previous | 100 * @param {string} previous |
| 99 */ | 101 */ |
| 100 onPinValueChange_: function(value, previous) { | 102 onPinValueChange_: function(value, previous) { |
| 101 if (value != previous) | 103 if (value != previous) |
| 102 this.fire('pin-change', { pin: value }); | 104 this.fire('pin-change', { pin: value }); |
| 103 }, | 105 }, |
| 104 | 106 |
| 105 /** Called when the user wants to erase the last character of the entered | 107 /** Called when the user wants to erase the last character of the entered |
|
jdufault
2016/08/19 17:28:18
Please fix this comment's formatting, ie,
/**
*
sammiequon
2016/08/23 17:28:11
Done.
| |
| 106 * PIN value. | 108 * PIN value. |
| 107 */ | 109 */ |
| 108 onPinClear_: function() { | 110 onPinClear_: function() { |
| 109 this.value = this.value.substring(0, this.value.length - 1); | 111 this.value = this.value.substring(0, this.value.length - 1); |
| 110 }, | 112 }, |
| 111 | 113 |
| 112 /** Called when a key event is pressed while the input element has focus. */ | 114 /** Called when a key event is pressed while the input element has focus. */ |
| 113 onInputKeyDown_: function(event) { | 115 onInputKeyDown_: function(event) { |
| 114 // Up/down pressed, swallow the event to prevent the input value from | 116 // Up/down pressed, swallow the event to prevent the input value from |
| 115 // being incremented or decremented. | 117 // being incremented or decremented. |
| 116 if (event.keyCode == 38 || event.keyCode == 40) { | 118 if (event.keyCode == 38 || event.keyCode == 40) { |
| 117 event.preventDefault(); | 119 event.preventDefault(); |
| 118 return; | 120 return; |
| 119 } | 121 } |
| 120 | 122 |
| 121 // Enter pressed. | 123 // Enter pressed. |
| 122 if (event.keyCode == 13) { | 124 if (event.keyCode == 13) { |
| 123 this.firePinSubmitEvent_(); | 125 this.firePinSubmitEvent_(); |
| 124 event.preventDefault(); | 126 event.preventDefault(); |
| 125 return; | 127 return; |
| 126 } | 128 } |
| 127 }, | 129 }, |
| 128 | 130 |
| 129 /** | 131 /** |
| 132 * Keypress does not handle backspace but handles the char codes nicely, so we | |
| 133 * have a seperate event to process the backspaces. | |
| 134 * @param {Event} e Keypress Event object. | |
| 135 * @private | |
| 136 */ | |
| 137 onKeyDown_: function(event) { | |
| 138 // Backspace pressed. | |
| 139 if (event.keyCode == 8) { | |
| 140 this.onPinClear_(); | |
| 141 event.preventDefault(); | |
| 142 return; | |
| 143 } | |
| 144 }, | |
| 145 | |
| 146 /** | |
| 147 * Called when a key press event is fired while the number button is focused. | |
| 148 * Ideally we would want to pass focus back to the input element, but the we | |
| 149 * cannot or the virtual keyboard will keep poping up. | |
| 150 * @param {Event} e Keypress Event object. | |
| 151 * @private | |
| 152 */ | |
| 153 onKeyPress_: function(event) { | |
| 154 var code = event.keyCode; | |
| 155 | |
| 156 // Enter pressed. | |
| 157 if (code == 13) { | |
| 158 this.firePinSubmitEvent_(); | |
| 159 event.preventDefault(); | |
| 160 return; | |
| 161 } | |
| 162 | |
| 163 var stringValue = String.fromCharCode(code); | |
| 164 this.value += stringValue; | |
|
jdufault
2016/08/19 01:06:47
eliminate stringValue temp
sammiequon
2016/08/23 17:28:11
Done.
| |
| 165 }, | |
| 166 | |
| 167 /** | |
| 130 * Changes the color of the submit button if PIN is ready. | 168 * Changes the color of the submit button if PIN is ready. |
| 131 * @param {string} value | 169 * @param {string} value |
| 132 * @private | 170 * @private |
| 133 */ | 171 */ |
| 134 getSubmitClass_: function(value) { | 172 getSubmitClass_: function(value) { |
| 135 return value.length > 0 ? 'ready-background' : ''; | 173 return value.length > 0 ? 'ready-background' : ''; |
| 136 }, | 174 }, |
| 137 | 175 |
| 138 /** | 176 /** |
| 139 * Computes whether the input type for the pin input should be password or | 177 * Computes whether the input type for the pin input should be password or |
| (...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 175 | 213 |
| 176 /** | 214 /** |
| 177 * Computes if the submit button is visible. | 215 * Computes if the submit button is visible. |
| 178 * @param {boolean} submitEnabled | 216 * @param {boolean} submitEnabled |
| 179 * @private | 217 * @private |
| 180 */ | 218 */ |
| 181 getSubmitHiddenClass_: function(submitEnabled) { | 219 getSubmitHiddenClass_: function(submitEnabled) { |
| 182 return submitEnabled ? '' : 'submit-button-hidden'; | 220 return submitEnabled ? '' : 'submit-button-hidden'; |
| 183 } | 221 } |
| 184 }); | 222 }); |
| OLD | NEW |