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: |
| 11 * value: The value of the PIN keyboard. Writing to this property will adjust | 11 * value: The value of the PIN keyboard. Writing to this property will adjust |
| 12 * the PIN keyboard's value. | 12 * the PIN keyboard's value. |
| 13 * | 13 * |
| 14 * Events: | 14 * Events: |
| 15 * pin-change: Fired when the PIN value has changed. The pin is available at | 15 * pin-change: Fired when the PIN value has changed. The pin is available at |
| 16 * event.detail.pin. | 16 * event.detail.pin. |
| 17 * submit: Fired when the PIN is submitted. The pin is available at | 17 * submit: Fired when the PIN is submitted. The pin is available at |
| 18 * event.detail.pin. | 18 * event.detail.pin. |
| 19 * | 19 * |
| 20 * Example: | 20 * Example: |
| 21 * <pin-keyboard on-pin-change="onPinChange" on-submit="onPinSubmit" | 21 * <pin-keyboard on-pin-change="onPinChange" on-submit="onPinSubmit" |
| 22 * value="{{pinValue}}"> | 22 * value="{{pinValue}}"> |
| 23 * </pin-keyboard> | 23 * </pin-keyboard> |
| 24 */ | 24 */ |
| 25 | |
| 26 /** | |
| 27 * Time in milliseconds for which the backspace button clears a character when | |
|
jdufault
2016/09/02 20:03:43
What about:
How long the backspace button must
sammiequon
2016/09/02 22:47:39
Done.
| |
| 28 * held down. | |
| 29 * @type {number} | |
| 30 * @const | |
| 31 */ | |
| 32 var repeatClearIntervalMs = 250; | |
| 33 | |
|
jdufault
2016/09/02 20:03:44
Make sure to wrap this all in a function to avoid
sammiequon
2016/09/02 22:47:39
Done.
| |
| 25 Polymer({ | 34 Polymer({ |
| 26 is: 'pin-keyboard', | 35 is: 'pin-keyboard', |
| 27 | 36 |
| 28 behaviors: [ | 37 behaviors: [ |
| 29 I18nBehavior, | 38 I18nBehavior, |
| 30 ], | 39 ], |
| 31 | 40 |
| 32 properties: { | 41 properties: { |
| 33 /** | 42 /** |
| 34 * Whether or not the keyboard's input element should be numerical | 43 * Whether or not the keyboard's input element should be numerical |
| (...skipping 11 matching lines...) Expand all Loading... | |
| 46 type: Boolean, | 55 type: Boolean, |
| 47 value: false | 56 value: false |
| 48 }, | 57 }, |
| 49 | 58 |
| 50 /** The value stored in the keyboard's input element. */ | 59 /** The value stored in the keyboard's input element. */ |
| 51 value: { | 60 value: { |
| 52 type: String, | 61 type: String, |
| 53 notify: true, | 62 notify: true, |
| 54 value: '', | 63 value: '', |
| 55 observer: 'onPinValueChange_' | 64 observer: 'onPinValueChange_' |
| 65 }, | |
| 66 | |
| 67 /** | |
| 68 * The intervalID used for the backspace button set/clear interval. | |
|
jdufault
2016/09/02 20:03:43
Please add @private
sammiequon
2016/09/02 22:47:39
Done.
| |
| 69 */ | |
| 70 repeatClearIntervalId_: { | |
| 71 type: Number, | |
| 72 value: 0 | |
| 56 } | 73 } |
| 57 }, | 74 }, |
| 58 | 75 |
| 59 /** | 76 /** |
| 60 * Gets the container holding the password field. | 77 * Gets the container holding the password field. |
| 61 * @type {!HTMLInputElement} | 78 * @type {!HTMLInputElement} |
| 62 */ | 79 */ |
| 63 get inputElement() { | 80 get inputElement() { |
| 64 return this.$$('#pin-input'); | 81 return this.$$('#pin-input'); |
| 65 }, | 82 }, |
| (...skipping 24 matching lines...) Expand all Loading... | |
| 90 * @param {string} value | 107 * @param {string} value |
| 91 * @param {string} previous | 108 * @param {string} previous |
| 92 */ | 109 */ |
| 93 onPinValueChange_: function(value, previous) { | 110 onPinValueChange_: function(value, previous) { |
| 94 if (value != previous) | 111 if (value != previous) |
| 95 this.fire('pin-change', { pin: value }); | 112 this.fire('pin-change', { pin: value }); |
| 96 }, | 113 }, |
| 97 | 114 |
| 98 /** | 115 /** |
| 99 * Called when the user wants to erase the last character of the entered | 116 * Called when the user wants to erase the last character of the entered |
| 100 * PIN value. | 117 * PIN value. |
| 101 */ | 118 */ |
| 102 onPinClear_: function() { | 119 onPinClear_: function() { |
| 103 this.value = this.value.substring(0, this.value.length - 1); | 120 this.value = this.value.substring(0, this.value.length - 1); |
| 104 }, | 121 }, |
| 105 | 122 |
| 123 /** | |
| 124 * Called when the user presses or touches the backspace button. Starts an | |
| 125 * interval callback to repeatedly clear the last pin value until the interval | |
| 126 * is cleared. | |
| 127 * @param {Event} event The event object. | |
| 128 * @private | |
| 129 */ | |
| 130 onBackspaceGetFocus_: function(event) { | |
|
jdufault
2016/09/02 20:03:43
Is there an actual "on-focus" event this could lis
sammiequon
2016/09/02 22:47:39
on-blur and on-foucsout don't seem to trigger on-m
| |
| 131 this.onPinClear_(); | |
| 132 this.repeatClearIntervalId_ = setInterval( | |
| 133 this.onPinClear_.bind(this), repeatClearIntervalMs); | |
| 134 event.preventDefault(); | |
| 135 }, | |
| 136 | |
| 137 /** | |
| 138 * Called when the user unpresses or untouches the backspace button. Stops the | |
| 139 * interval callback. | |
| 140 * @param {Event} event The event object. | |
| 141 * @private | |
| 142 */ | |
| 143 onBackspaceLoseFocus_: function(event) { | |
| 144 clearInterval(this.repeatClearIntervalId_); | |
|
jdufault
2016/09/02 20:03:43
reset repeatClearIntervalId_ value to 0?
sammiequon
2016/09/02 22:47:39
Done.
| |
| 145 event.preventDefault(); | |
| 146 }, | |
| 147 | |
| 106 /** Called when a key event is pressed while the input element has focus. */ | 148 /** Called when a key event is pressed while the input element has focus. */ |
| 107 onInputKeyDown_: function(event) { | 149 onInputKeyDown_: function(event) { |
| 108 // Up/down pressed, swallow the event to prevent the input value from | 150 // Up/down pressed, swallow the event to prevent the input value from |
| 109 // being incremented or decremented. | 151 // being incremented or decremented. |
| 110 if (event.keyCode == 38 || event.keyCode == 40) { | 152 if (event.keyCode == 38 || event.keyCode == 40) { |
| 111 event.preventDefault(); | 153 event.preventDefault(); |
| 112 return; | 154 return; |
| 113 } | 155 } |
| 114 | 156 |
| 115 // Enter pressed. | 157 // Enter pressed. |
| (...skipping 20 matching lines...) Expand all Loading... | |
| 136 }, | 178 }, |
| 137 | 179 |
| 138 /** | 180 /** |
| 139 * Called when a key press event is fired while the number button is focused. | 181 * Called when a key press event is fired while the number button is focused. |
| 140 * Ideally we would want to pass focus back to the input element, but the we | 182 * Ideally we would want to pass focus back to the input element, but the we |
| 141 * cannot or the virtual keyboard will keep poping up. | 183 * cannot or the virtual keyboard will keep poping up. |
| 142 * @param {Event} event Keypress Event object. | 184 * @param {Event} event Keypress Event object. |
| 143 * @private | 185 * @private |
| 144 */ | 186 */ |
| 145 onKeyPress_: function(event) { | 187 onKeyPress_: function(event) { |
| 188 // If the active element is the input element, the input element itself will | |
| 189 // handle the keypresses, so we do not handle them here. | |
| 190 if (this.shadowRoot.activeElement == this.inputElement) | |
| 191 return; | |
| 192 | |
| 146 var code = event.keyCode; | 193 var code = event.keyCode; |
| 147 | 194 |
| 148 // Enter pressed. | 195 // Enter pressed. |
| 149 if (code == 13) { | 196 if (code == 13) { |
| 150 this.firePinSubmitEvent_(); | 197 this.firePinSubmitEvent_(); |
| 151 event.preventDefault(); | 198 event.preventDefault(); |
| 152 return; | 199 return; |
| 153 } | 200 } |
| 154 | 201 |
| 155 this.value += String.fromCharCode(code); | 202 this.value += String.fromCharCode(code); |
| (...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 194 // possible. Number.isInteger will verify the value is not a NaN and that it | 241 // possible. Number.isInteger will verify the value is not a NaN and that it |
| 195 // does not contain decimals. | 242 // does not contain decimals. |
| 196 // This heuristic will fail for inputs like '1.0'. | 243 // This heuristic will fail for inputs like '1.0'. |
| 197 // | 244 // |
| 198 // Since we still support users entering their passwords through the PIN | 245 // Since we still support users entering their passwords through the PIN |
| 199 // keyboard, we swap the input box to rtl when we think it is a password | 246 // keyboard, we swap the input box to rtl when we think it is a password |
| 200 // (just numbers), if the document direction is rtl. | 247 // (just numbers), if the document direction is rtl. |
| 201 return (document.dir == 'rtl') && !Number.isInteger(+password); | 248 return (document.dir == 'rtl') && !Number.isInteger(+password); |
| 202 }, | 249 }, |
| 203 }); | 250 }); |
| OLD | NEW |