Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(617)

Side by Side Diff: chrome/browser/resources/chromeos/quick_unlock/pin_keyboard.js

Issue 2357743002: chromeos: Backspace and enter key works as intended. (Closed)
Patch Set: Removed blank-space class. Created 4 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « chrome/browser/resources/chromeos/quick_unlock/pin_keyboard.html ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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
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 * Removes the space/enter key binds from the polymer iron-a11y-keys-behavior.
jdufault 2016/09/22 20:04:01 I would move the function comment into the functio
sammiequon 2016/09/22 23:15:48 Done.
97 * @override
98 */
99 attached: function() {
100 var digitButtons = Polymer.dom(this.root).querySelectorAll('.digit-button');
101 for (var i = 0; i < digitButtons.length; ++i)
102 digitButtons[i].keyEventTarget = null;
103 },
104
105 /**
96 * Gets the container holding the password field. 106 * Gets the container holding the password field.
97 * @type {!HTMLInputElement} 107 * @type {!HTMLInputElement}
98 */ 108 */
99 get inputElement() { 109 get inputElement() {
100 return this.$$('#pin-input'); 110 return this.$$('#pin-input');
101 }, 111 },
102 112
103 /** Transfers focus to the input element. */ 113 /** Transfers focus to the input element. */
104 focus: function() { 114 focus: function() {
105 this.$$('#pin-input').focus(); 115 this.$$('#pin-input').focus();
(...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after
202 if (event.keyCode == 13) { 212 if (event.keyCode == 13) {
203 this.firePinSubmitEvent_(); 213 this.firePinSubmitEvent_();
204 event.preventDefault(); 214 event.preventDefault();
205 return; 215 return;
206 } 216 }
207 }, 217 },
208 218
209 /** 219 /**
210 * Keypress does not handle backspace but handles the char codes nicely, so we 220 * Keypress does not handle backspace but handles the char codes nicely, so we
211 * have a seperate event to process the backspaces. 221 * have a seperate event to process the backspaces.
212 * @param {Event} event Keypress Event object. 222 * @param {Event} event Keydown Event object.
213 * @private 223 * @private
214 */ 224 */
215 onKeyDown_: function(event) { 225 onKeyDown_: function(event) {
216 // Backspace pressed. 226 // Backspace pressed.
217 if (event.keyCode == 8) { 227 if (event.keyCode == 8) {
218 this.onPinClear_(); 228 this.onPinClear_();
219 event.preventDefault(); 229 event.preventDefault();
220 return; 230 return;
221 } 231 }
222 }, 232 },
(...skipping 13 matching lines...) Expand all
236 246
237 var code = event.keyCode; 247 var code = event.keyCode;
238 248
239 // Enter pressed. 249 // Enter pressed.
240 if (code == 13) { 250 if (code == 13) {
241 this.firePinSubmitEvent_(); 251 this.firePinSubmitEvent_();
242 event.preventDefault(); 252 event.preventDefault();
243 return; 253 return;
244 } 254 }
245 255
256 // Space pressed.
257 if (code == 32) {
258 // Check if target was a number button.
259 if (event.target.hasAttribute('value')) {
260 var numberValue = event.target.getAttribute('value');
261 this.value += numberValue;
262 return;
263 }
264 // Check if target was backspace button.
265 if (event.target.classList.contains('backspace-button')) {
266 this.onPinClear_();
267 return;
268 }
269 }
270
246 this.value += String.fromCharCode(code); 271 this.value += String.fromCharCode(code);
247 }, 272 },
248 273
249 /** 274 /**
250 * Disables the submit and backspace button if nothing is entered. 275 * Disables the submit and backspace button if nothing is entered.
251 * @param {string} value 276 * @param {string} value
252 * @private 277 * @private
253 */ 278 */
254 hasInput_: function(value) { 279 hasInput_: function(value) {
255 return value.length > 0; 280 return value.length > 0;
(...skipping 30 matching lines...) Expand all
286 // does not contain decimals. 311 // does not contain decimals.
287 // This heuristic will fail for inputs like '1.0'. 312 // This heuristic will fail for inputs like '1.0'.
288 // 313 //
289 // Since we still support users entering their passwords through the PIN 314 // 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 315 // keyboard, we swap the input box to rtl when we think it is a password
291 // (just numbers), if the document direction is rtl. 316 // (just numbers), if the document direction is rtl.
292 return (document.dir == 'rtl') && !Number.isInteger(+password); 317 return (document.dir == 'rtl') && !Number.isInteger(+password);
293 }, 318 },
294 }); 319 });
295 })(); 320 })();
OLDNEW
« no previous file with comments | « chrome/browser/resources/chromeos/quick_unlock/pin_keyboard.html ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698