Chromium Code Reviews| Index: chrome/browser/resources/chromeos/quick_unlock/pin_keyboard.js |
| diff --git a/chrome/browser/resources/chromeos/quick_unlock/pin_keyboard.js b/chrome/browser/resources/chromeos/quick_unlock/pin_keyboard.js |
| index d6c28711b4d28f8981da2fa4aa487e02dafc6e40..1971d40149459a596d9f3a6fc3491a3661037317 100644 |
| --- a/chrome/browser/resources/chromeos/quick_unlock/pin_keyboard.js |
| +++ b/chrome/browser/resources/chromeos/quick_unlock/pin_keyboard.js |
| @@ -22,6 +22,24 @@ |
| * value="{{pinValue}}"> |
| * </pin-keyboard> |
| */ |
| + |
| +(function() { |
| + |
| +/** |
| + * Once auto backspace starts, the time between individual backspaces. |
| + * @type {number} |
| + * @const |
| + */ |
| +var repeatBackspaceIntervalMs = 150; |
| + |
| +/** |
| + * How long the backspace button must be held down before auto backspace |
| + * starts. |
| + * @type {number} |
| + * @const |
| + */ |
| +var startAutoBackspaceMs = 500; |
| + |
| Polymer({ |
| is: 'pin-keyboard', |
| @@ -53,6 +71,24 @@ Polymer({ |
| notify: true, |
| value: '', |
| observer: 'onPinValueChange_' |
| + }, |
| + |
| + /** |
| + * The intervalID used for the backspace button set/clear interval. |
| + * @private |
| + */ |
| + repeatBackspaceIntervalId_: { |
| + type: Number, |
| + value: 0 |
| + }, |
| + |
| + /** |
| + * The timeoutID used for the auto backspace. |
| + * @private |
| + */ |
| + startAutoBackspaceId_: { |
| + type: Number, |
| + value: 0 |
| } |
| }, |
| @@ -97,12 +133,64 @@ Polymer({ |
| /** |
| * Called when the user wants to erase the last character of the entered |
| - * PIN value. |
| + * PIN value. |
| + * @private |
| */ |
| onPinClear_: function() { |
| this.value = this.value.substring(0, this.value.length - 1); |
| }, |
| + /** |
| + * Called when the user presses or touches the backspace button. Starts a |
| + * timer which starts an interval to repeatedly backspace the pin value until |
| + * the interval is cleared. |
| + * @param {Event} event The event object. |
| + * @private |
| + */ |
| + onBackspacePointerDown_: function(event) { |
| + this.startAutoBackspaceId_ = setTimeout(function() { |
|
jdufault
2016/09/06 14:46:37
setTimeout and this.async do the same/similar thin
sammiequon
2016/09/06 17:08:07
Done.
|
| + this.async(function() { |
| + this.repeatBackspaceIntervalId_ = setInterval( |
| + this.onPinClear_.bind(this), repeatBackspaceIntervalMs); |
| + }.bind(this), 1); |
| + }.bind(this), startAutoBackspaceMs); |
| + }, |
| + |
| + /** |
| + * Helper function which clears the timer / interval ids and resets them. |
| + * @private |
| + */ |
| + clearAndReset_: function() { |
| + clearInterval(this.repeatBackspaceIntervalId_); |
|
jdufault
2016/09/06 14:46:37
Do we need separate interval id variables? Can we
sammiequon
2016/09/06 17:08:07
The reason I use two variables is because I change
|
| + this.repeatBackspaceIntervalId_ = 0; |
| + clearTimeout(this.startAutoBackspaceId_); |
| + this.startAutoBackspaceId_ = 0; |
| + }, |
| + |
| + /** |
| + * Called when the user exits the backspace button. Stops the interval |
| + * callback. |
| + * @param {Event} event The event object. |
| + * @private |
| + */ |
| + onBackspacePointerOut_: function(event) { |
| + this.clearAndReset_(); |
| + }, |
| + |
| + /** |
| + * Called when the user unpresses or untouches the backspace button. Stops the |
| + * interval callback and fires a backspace event if there is no interval |
| + * running. |
| + * @param {Event} event The event object. |
| + * @private |
| + */ |
| + onBackspacePointerUp_: function(event) { |
| + // If an interval has started, do not fire event on pointer up. |
| + if (!this.repeatBackspaceIntervalId_) |
| + this.onPinClear_(); |
| + this.clearAndReset_(); |
| + }, |
| + |
| /** Called when a key event is pressed while the input element has focus. */ |
| onInputKeyDown_: function(event) { |
| // Up/down pressed, swallow the event to prevent the input value from |
| @@ -143,6 +231,11 @@ Polymer({ |
| * @private |
| */ |
| onKeyPress_: function(event) { |
| + // If the active element is the input element, the input element itself will |
| + // handle the keypresses, so we do not handle them here. |
| + if (this.shadowRoot.activeElement == this.inputElement) |
| + return; |
| + |
| var code = event.keyCode; |
| // Enter pressed. |
| @@ -201,3 +294,4 @@ Polymer({ |
| return (document.dir == 'rtl') && !Number.isInteger(+password); |
| }, |
| }); |
| +})(); |