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

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

Issue 2302483003: Pin keyboard improvements. (Closed)
Patch Set: Fixed patch set 5 errors. 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:
11 * value: The value of the PIN keyboard. Writing to this property will adjust 11 * value: The value of the PIN keyboard. Writing to this property will adjust
12 * the PIN keyboard's value. 12 * the PIN keyboard's value.
13 * 13 *
14 * Events: 14 * Events:
15 * pin-change: Fired when the PIN value has changed. The pin is available at 15 * pin-change: Fired when the PIN value has changed. The pin is available at
16 * event.detail.pin. 16 * event.detail.pin.
17 * submit: Fired when the PIN is submitted. The pin is available at 17 * submit: Fired when the PIN is submitted. The pin is available at
18 * event.detail.pin. 18 * event.detail.pin.
19 * 19 *
20 * Example: 20 * Example:
21 * <pin-keyboard on-pin-change="onPinChange" on-submit="onPinSubmit" 21 * <pin-keyboard on-pin-change="onPinChange" on-submit="onPinSubmit"
22 * value="{{pinValue}}"> 22 * value="{{pinValue}}">
23 * </pin-keyboard> 23 * </pin-keyboard>
24 */ 24 */
25
26 (function() {
27
28 /**
29 * How long the backspace button must be held down before clearing characters.
30 * @type {number}
31 * @const
32 */
33 var repeatClearIntervalMs = 250;
34
25 Polymer({ 35 Polymer({
26 is: 'pin-keyboard', 36 is: 'pin-keyboard',
27 37
28 behaviors: [ 38 behaviors: [
29 I18nBehavior, 39 I18nBehavior,
30 ], 40 ],
31 41
32 properties: { 42 properties: {
33 /** 43 /**
34 * Whether or not the keyboard's input element should be numerical 44 * Whether or not the keyboard's input element should be numerical
(...skipping 11 matching lines...) Expand all
46 type: Boolean, 56 type: Boolean,
47 value: false 57 value: false
48 }, 58 },
49 59
50 /** The value stored in the keyboard's input element. */ 60 /** The value stored in the keyboard's input element. */
51 value: { 61 value: {
52 type: String, 62 type: String,
53 notify: true, 63 notify: true,
54 value: '', 64 value: '',
55 observer: 'onPinValueChange_' 65 observer: 'onPinValueChange_'
66 },
67
68 /**
69 * The intervalID used for the backspace button set/clear interval.
70 * @private
71 */
72 repeatClearIntervalId_: {
73 type: Number,
74 value: 0
56 } 75 }
57 }, 76 },
58 77
59 /** 78 /**
60 * Gets the container holding the password field. 79 * Gets the container holding the password field.
61 * @type {!HTMLInputElement} 80 * @type {!HTMLInputElement}
62 */ 81 */
63 get inputElement() { 82 get inputElement() {
64 return this.$$('#pin-input'); 83 return this.$$('#pin-input');
65 }, 84 },
(...skipping 24 matching lines...) Expand all
90 * @param {string} value 109 * @param {string} value
91 * @param {string} previous 110 * @param {string} previous
92 */ 111 */
93 onPinValueChange_: function(value, previous) { 112 onPinValueChange_: function(value, previous) {
94 if (value != previous) 113 if (value != previous)
95 this.fire('pin-change', { pin: value }); 114 this.fire('pin-change', { pin: value });
96 }, 115 },
97 116
98 /** 117 /**
99 * Called when the user wants to erase the last character of the entered 118 * Called when the user wants to erase the last character of the entered
100 * PIN value. 119 * PIN value.
101 */ 120 */
102 onPinClear_: function() { 121 onPinClear_: function() {
103 this.value = this.value.substring(0, this.value.length - 1); 122 this.value = this.value.substring(0, this.value.length - 1);
104 }, 123 },
105 124
125 /**
126 * Called when the user presses or touches the backspace button. Starts an
127 * interval callback to repeatedly clear the last pin value until the interval
128 * is cleared.
129 * @param {Event} event The event object.
130 * @private
131 */
132 onBackspaceGetFocus_: function(event) {
133 this.onPinClear_();
jdufault 2016/09/02 22:58:53 Buttons normally activate on up events, right? Tha
sammiequon 2016/09/03 00:53:49 Done.
134 this.repeatClearIntervalId_ = setInterval(
135 this.onPinClear_.bind(this), repeatClearIntervalMs);
136 event.preventDefault();
137 },
138
139 /**
140 * Called when the user unpresses or untouches the backspace button. Stops the
141 * interval callback.
142 * @param {Event} event The event object.
143 * @private
144 */
145 onBackspaceLoseFocus_: function(event) {
146 clearInterval(this.repeatClearIntervalId_);
147 this.repeatClearIntervalId_ = 0;
148 event.preventDefault();
149 },
150
106 /** Called when a key event is pressed while the input element has focus. */ 151 /** Called when a key event is pressed while the input element has focus. */
107 onInputKeyDown_: function(event) { 152 onInputKeyDown_: function(event) {
108 // Up/down pressed, swallow the event to prevent the input value from 153 // Up/down pressed, swallow the event to prevent the input value from
109 // being incremented or decremented. 154 // being incremented or decremented.
110 if (event.keyCode == 38 || event.keyCode == 40) { 155 if (event.keyCode == 38 || event.keyCode == 40) {
111 event.preventDefault(); 156 event.preventDefault();
112 return; 157 return;
113 } 158 }
114 159
115 // Enter pressed. 160 // Enter pressed.
(...skipping 20 matching lines...) Expand all
136 }, 181 },
137 182
138 /** 183 /**
139 * Called when a key press event is fired while the number button is focused. 184 * Called when a key press event is fired while the number button is focused.
140 * Ideally we would want to pass focus back to the input element, but the we 185 * Ideally we would want to pass focus back to the input element, but the we
141 * cannot or the virtual keyboard will keep poping up. 186 * cannot or the virtual keyboard will keep poping up.
142 * @param {Event} event Keypress Event object. 187 * @param {Event} event Keypress Event object.
143 * @private 188 * @private
144 */ 189 */
145 onKeyPress_: function(event) { 190 onKeyPress_: function(event) {
191 // If the active element is the input element, the input element itself will
192 // handle the keypresses, so we do not handle them here.
193 if (this.shadowRoot.activeElement == this.inputElement)
194 return;
195
146 var code = event.keyCode; 196 var code = event.keyCode;
147 197
148 // Enter pressed. 198 // Enter pressed.
149 if (code == 13) { 199 if (code == 13) {
150 this.firePinSubmitEvent_(); 200 this.firePinSubmitEvent_();
151 event.preventDefault(); 201 event.preventDefault();
152 return; 202 return;
153 } 203 }
154 204
155 this.value += String.fromCharCode(code); 205 this.value += String.fromCharCode(code);
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
194 // possible. Number.isInteger will verify the value is not a NaN and that it 244 // possible. Number.isInteger will verify the value is not a NaN and that it
195 // does not contain decimals. 245 // does not contain decimals.
196 // This heuristic will fail for inputs like '1.0'. 246 // This heuristic will fail for inputs like '1.0'.
197 // 247 //
198 // Since we still support users entering their passwords through the PIN 248 // Since we still support users entering their passwords through the PIN
199 // keyboard, we swap the input box to rtl when we think it is a password 249 // keyboard, we swap the input box to rtl when we think it is a password
200 // (just numbers), if the document direction is rtl. 250 // (just numbers), if the document direction is rtl.
201 return (document.dir == 'rtl') && !Number.isInteger(+password); 251 return (document.dir == 'rtl') && !Number.isInteger(+password);
202 }, 252 },
203 }); 253 });
254 })();
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698