| 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 // Flag to check focus on next focus. |
| 39 checkFocus_: false, |
| 40 // The current focused element. |
| 41 focusedElement_: undefined, |
| 42 |
| 38 /** Transfers focus to the input element. */ | 43 /** Transfers focus to the input element. */ |
| 39 focus: function() { | 44 focus: function() { |
| 40 this.$$('#pin-input').focus(); | 45 this.$$('#pin-input').focus(); |
| 46 this.focusedElement_ = document.activeElement; |
| 47 }, |
| 48 |
| 49 /** Called when a pin keyboard button has focus. */ |
| 50 onButtonFocus_: function(event, detail) { |
| 51 // If the button has been tabbed here it is the current element with focus. |
| 52 if (this.checkFocus_) { |
| 53 this.focusedElement_ = document.activeElement; |
| 54 this.checkFocus_ = false; |
| 55 } |
| 56 }, |
| 57 |
| 58 /** Called when a pin keyboard has a key pressed. */ |
| 59 onButtonKeyDown_: function(event, detail) { |
| 60 // Only if tab has been pressed do we want change the focus. |
| 61 if (event.keyCode == 9) |
| 62 this.checkFocus_ = true; |
| 41 }, | 63 }, |
| 42 | 64 |
| 43 /** Called when a keypad number has been tapped. */ | 65 /** Called when a keypad number has been tapped. */ |
| 44 onNumberTap_: function(event, detail) { | 66 onNumberTap_: function(event, detail) { |
| 45 var numberValue = event.target.getAttribute('value'); | 67 var numberValue = event.target.getAttribute('value'); |
| 46 this.value += numberValue; | 68 this.value += numberValue; |
| 69 |
| 70 // If the tabbed element is clicked we want to keep the focus, otherwise |
| 71 // transfer focus to the input. |
| 72 if (this.focusedElement_ != event.target) |
| 73 this.focus(); |
| 47 }, | 74 }, |
| 48 | 75 |
| 49 /** Fires a submit event with the current PIN value. */ | 76 /** Fires a submit event with the current PIN value. */ |
| 50 firePinSubmitEvent_: function() { | 77 firePinSubmitEvent_: function() { |
| 51 this.fire('submit', { pin: this.value }); | 78 this.fire('submit', { pin: this.value }); |
| 52 }, | 79 }, |
| 53 | 80 |
| 54 /** | 81 /** |
| 55 * Fires an update event with the current PIN value. The event will only be | 82 * Fires an update event with the current PIN value. The event will only be |
| 56 * fired if the PIN value has actually changed. | 83 * fired if the PIN value has actually changed. |
| (...skipping 22 matching lines...) Expand all Loading... |
| 79 } | 106 } |
| 80 | 107 |
| 81 // Enter pressed. | 108 // Enter pressed. |
| 82 if (event.keyCode == 13) { | 109 if (event.keyCode == 13) { |
| 83 this.firePinSubmitEvent_(); | 110 this.firePinSubmitEvent_(); |
| 84 event.preventDefault(); | 111 event.preventDefault(); |
| 85 return; | 112 return; |
| 86 } | 113 } |
| 87 } | 114 } |
| 88 }); | 115 }); |
| OLD | NEW |