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 17 matching lines...) Expand all Loading... | |
| 28 properties: { | 28 properties: { |
| 29 /** The value stored in the keyboard's input element. */ | 29 /** The value stored in the keyboard's input element. */ |
| 30 value: { | 30 value: { |
| 31 type: String, | 31 type: String, |
| 32 notify: true, | 32 notify: true, |
| 33 value: '', | 33 value: '', |
| 34 observer: 'onPinValueChange_' | 34 observer: 'onPinValueChange_' |
| 35 } | 35 } |
| 36 }, | 36 }, |
| 37 | 37 |
| 38 // The current focused element. | |
| 39 focusedElement_: undefined, | |
| 40 | |
| 38 /** Transfers focus to the input element. */ | 41 /** Transfers focus to the input element. */ |
| 39 focus: function() { | 42 focus: function() { |
| 40 this.$$('#pin-input').focus(); | 43 var pinInput = this.$$('#pin-input'); |
| 44 pinInput.focus(); | |
| 45 this.focusedElement_ = pinInput; | |
| 46 }, | |
| 47 | |
| 48 /** Called when a pin keyboard has a key pressed. */ | |
| 49 onButtonKeyUp_: function(event, detail) { | |
| 50 // Only if tab has been pressed do we want change the focus. | |
| 51 if (event.target.receivedFocusFromKeyboard) | |
| 52 this.focusedElement_ = event.target; | |
| 41 }, | 53 }, |
| 42 | 54 |
| 43 /** Called when a keypad number has been tapped. */ | 55 /** Called when a keypad number has been tapped. */ |
| 44 onNumberTap_: function(event, detail) { | 56 onNumberTap_: function(event, detail) { |
| 45 var numberValue = event.target.getAttribute('value'); | 57 var numberValue = event.target.getAttribute('value'); |
| 46 this.value += numberValue; | 58 this.value += numberValue; |
| 59 | |
| 60 // If the tabbed element is clicked we want to keep the focus, otherwise | |
| 61 // transfer focus to the input. | |
| 62 if (this.focusedElement_ != event.target) | |
|
jdufault
2016/07/01 21:20:52
Can we traverse the DOM to find the focused elemen
sammiequon
2016/07/01 22:19:14
document.activeElement always returns the button i
| |
| 63 this.focus(); | |
| 47 }, | 64 }, |
| 48 | 65 |
| 49 /** Fires a submit event with the current PIN value. */ | 66 /** Fires a submit event with the current PIN value. */ |
| 50 firePinSubmitEvent_: function() { | 67 firePinSubmitEvent_: function() { |
| 51 this.fire('submit', { pin: this.value }); | 68 this.fire('submit', { pin: this.value }); |
| 52 }, | 69 }, |
| 53 | 70 |
| 54 /** | 71 /** |
| 55 * Fires an update event with the current PIN value. The event will only be | 72 * Fires an update event with the current PIN value. The event will only be |
| 56 * fired if the PIN value has actually changed. | 73 * fired if the PIN value has actually changed. |
| (...skipping 22 matching lines...) Expand all Loading... | |
| 79 } | 96 } |
| 80 | 97 |
| 81 // Enter pressed. | 98 // Enter pressed. |
| 82 if (event.keyCode == 13) { | 99 if (event.keyCode == 13) { |
| 83 this.firePinSubmitEvent_(); | 100 this.firePinSubmitEvent_(); |
| 84 event.preventDefault(); | 101 event.preventDefault(); |
| 85 return; | 102 return; |
| 86 } | 103 } |
| 87 } | 104 } |
| 88 }); | 105 }); |
| OLD | NEW |