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

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: 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
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.
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 // There is a digit button with used for layout purposes that is not a
103 // paper button or paper icon button. Do not call unlisten on this
104 // element.
105 if (!digitButtons[i].classList.contains('blank-space'))
106 digitButtons[i]._unlistenKeyEventListeners();
jdufault 2016/09/20 22:54:00 Is this a polymer internal method? If so, we shoul
sammiequon 2016/09/21 01:37:00 Done. Replaced with keyEventTarget which is part o
107 }
108 },
109
110 /**
96 * Gets the container holding the password field. 111 * Gets the container holding the password field.
97 * @type {!HTMLInputElement} 112 * @type {!HTMLInputElement}
98 */ 113 */
99 get inputElement() { 114 get inputElement() {
100 return this.$$('#pin-input'); 115 return this.$$('#pin-input');
101 }, 116 },
102 117
103 /** Transfers focus to the input element. */ 118 /** Transfers focus to the input element. */
104 focus: function() { 119 focus: function() {
105 this.$$('#pin-input').focus(); 120 this.$$('#pin-input').focus();
(...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after
202 if (event.keyCode == 13) { 217 if (event.keyCode == 13) {
203 this.firePinSubmitEvent_(); 218 this.firePinSubmitEvent_();
204 event.preventDefault(); 219 event.preventDefault();
205 return; 220 return;
206 } 221 }
207 }, 222 },
208 223
209 /** 224 /**
210 * Keypress does not handle backspace but handles the char codes nicely, so we 225 * Keypress does not handle backspace but handles the char codes nicely, so we
211 * have a seperate event to process the backspaces. 226 * have a seperate event to process the backspaces.
212 * @param {Event} event Keypress Event object. 227 * @param {Event} event Keydown Event object.
213 * @private 228 * @private
214 */ 229 */
215 onKeyDown_: function(event) { 230 onKeyDown_: function(event) {
216 // Backspace pressed. 231 // Backspace pressed.
217 if (event.keyCode == 8) { 232 if (event.keyCode == 8) {
218 this.onPinClear_(); 233 this.onPinClear_();
219 event.preventDefault(); 234 event.preventDefault();
220 return; 235 return;
221 } 236 }
222 }, 237 },
(...skipping 13 matching lines...) Expand all
236 251
237 var code = event.keyCode; 252 var code = event.keyCode;
238 253
239 // Enter pressed. 254 // Enter pressed.
240 if (code == 13) { 255 if (code == 13) {
241 this.firePinSubmitEvent_(); 256 this.firePinSubmitEvent_();
242 event.preventDefault(); 257 event.preventDefault();
243 return; 258 return;
244 } 259 }
245 260
261 // Space pressed.
262 if (code == 32) {
263 // Check if target was a number button.
264 if (event.target.hasAttribute('value')) {
265 var numberValue = event.target.getAttribute('value');
266 this.value += numberValue;
267 return;
268 }
269 // Check if target was backspace button.
270 if (event.target.classList.contains('backspace-button')) {
271 this.onPinClear_();
272 return;
273 }
274 }
275
246 this.value += String.fromCharCode(code); 276 this.value += String.fromCharCode(code);
247 }, 277 },
248 278
249 /** 279 /**
250 * Disables the submit and backspace button if nothing is entered. 280 * Disables the submit and backspace button if nothing is entered.
251 * @param {string} value 281 * @param {string} value
252 * @private 282 * @private
253 */ 283 */
254 hasInput_: function(value) { 284 hasInput_: function(value) {
255 return value.length > 0; 285 return value.length > 0;
(...skipping 30 matching lines...) Expand all
286 // does not contain decimals. 316 // does not contain decimals.
287 // This heuristic will fail for inputs like '1.0'. 317 // This heuristic will fail for inputs like '1.0'.
288 // 318 //
289 // Since we still support users entering their passwords through the PIN 319 // 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 320 // keyboard, we swap the input box to rtl when we think it is a password
291 // (just numbers), if the document direction is rtl. 321 // (just numbers), if the document direction is rtl.
292 return (document.dir == 'rtl') && !Number.isInteger(+password); 322 return (document.dir == 'rtl') && !Number.isInteger(+password);
293 }, 323 },
294 }); 324 });
295 })(); 325 })();
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698