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 75 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
86 * The timeoutID used for the auto backspace. | 86 * The timeoutID used for the auto backspace. |
87 * @private | 87 * @private |
88 */ | 88 */ |
89 startAutoBackspaceId_: { | 89 startAutoBackspaceId_: { |
90 type: Number, | 90 type: Number, |
91 value: 0 | 91 value: 0 |
92 } | 92 } |
93 }, | 93 }, |
94 | 94 |
95 /** | 95 /** |
| 96 * @override |
| 97 */ |
| 98 attached: function() { |
| 99 // Remove the space/enter key binds from the polymer |
| 100 // iron-a11y-keys-behavior. |
| 101 var digitButtons = Polymer.dom(this.root).querySelectorAll('.digit-button'); |
| 102 for (var i = 0; i < digitButtons.length; ++i) |
| 103 digitButtons[i].keyEventTarget = null; |
| 104 }, |
| 105 |
| 106 /** |
96 * Gets the container holding the password field. | 107 * Gets the container holding the password field. |
97 * @type {!HTMLInputElement} | 108 * @type {!HTMLInputElement} |
98 */ | 109 */ |
99 get inputElement() { | 110 get inputElement() { |
100 return this.$$('#pin-input'); | 111 return this.$$('#pin-input'); |
101 }, | 112 }, |
102 | 113 |
103 /** Transfers focus to the input element. */ | 114 /** Transfers focus to the input element. */ |
104 focus: function() { | 115 focus: function() { |
105 this.$$('#pin-input').focus(); | 116 this.$$('#pin-input').focus(); |
(...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
202 if (event.keyCode == 13) { | 213 if (event.keyCode == 13) { |
203 this.firePinSubmitEvent_(); | 214 this.firePinSubmitEvent_(); |
204 event.preventDefault(); | 215 event.preventDefault(); |
205 return; | 216 return; |
206 } | 217 } |
207 }, | 218 }, |
208 | 219 |
209 /** | 220 /** |
210 * Keypress does not handle backspace but handles the char codes nicely, so we | 221 * Keypress does not handle backspace but handles the char codes nicely, so we |
211 * have a seperate event to process the backspaces. | 222 * have a seperate event to process the backspaces. |
212 * @param {Event} event Keypress Event object. | 223 * @param {Event} event Keydown Event object. |
213 * @private | 224 * @private |
214 */ | 225 */ |
215 onKeyDown_: function(event) { | 226 onKeyDown_: function(event) { |
216 // Backspace pressed. | 227 // Backspace pressed. |
217 if (event.keyCode == 8) { | 228 if (event.keyCode == 8) { |
218 this.onPinClear_(); | 229 this.onPinClear_(); |
219 event.preventDefault(); | 230 event.preventDefault(); |
220 return; | 231 return; |
221 } | 232 } |
222 }, | 233 }, |
(...skipping 13 matching lines...) Expand all Loading... |
236 | 247 |
237 var code = event.keyCode; | 248 var code = event.keyCode; |
238 | 249 |
239 // Enter pressed. | 250 // Enter pressed. |
240 if (code == 13) { | 251 if (code == 13) { |
241 this.firePinSubmitEvent_(); | 252 this.firePinSubmitEvent_(); |
242 event.preventDefault(); | 253 event.preventDefault(); |
243 return; | 254 return; |
244 } | 255 } |
245 | 256 |
| 257 // Space pressed. We want the old polymer function of space activating the |
| 258 // button with focus. |
| 259 if (code == 32) { |
| 260 // Check if target was a number button. |
| 261 if (event.target.hasAttribute('value')) { |
| 262 this.value += event.target.getAttribute('value'); |
| 263 return; |
| 264 } |
| 265 // Check if target was backspace button. |
| 266 if (event.target.classList.contains('backspace-button')) { |
| 267 this.onPinClear_(); |
| 268 return; |
| 269 } |
| 270 } |
| 271 |
246 this.value += String.fromCharCode(code); | 272 this.value += String.fromCharCode(code); |
247 }, | 273 }, |
248 | 274 |
249 /** | 275 /** |
250 * Disables the submit and backspace button if nothing is entered. | 276 * Disables the submit and backspace button if nothing is entered. |
251 * @param {string} value | 277 * @param {string} value |
252 * @private | 278 * @private |
253 */ | 279 */ |
254 hasInput_: function(value) { | 280 hasInput_: function(value) { |
255 return value.length > 0; | 281 return value.length > 0; |
(...skipping 30 matching lines...) Expand all Loading... |
286 // does not contain decimals. | 312 // does not contain decimals. |
287 // This heuristic will fail for inputs like '1.0'. | 313 // This heuristic will fail for inputs like '1.0'. |
288 // | 314 // |
289 // Since we still support users entering their passwords through the PIN | 315 // Since we still support users entering their passwords through the PIN |
290 // keyboard, we swap the input box to rtl when we think it is a password | 316 // keyboard, we swap the input box to rtl when we think it is a password |
291 // (just numbers), if the document direction is rtl. | 317 // (just numbers), if the document direction is rtl. |
292 return (document.dir == 'rtl') && !Number.isInteger(+password); | 318 return (document.dir == 'rtl') && !Number.isInteger(+password); |
293 }, | 319 }, |
294 }); | 320 }); |
295 })(); | 321 })(); |
OLD | NEW |