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

Side by Side Diff: ui/keyboard/resources/elements/kb-keyboard.html

Issue 23534021: Added persistent capitalization to the Virtual Keyboard. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Changed polymer attributes to camel case. Created 7 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 | « no previous file | ui/keyboard/resources/elements/kb-keyset.html » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 <!-- 1 <!--
2 -- Copyright 2013 The Chromium Authors. All rights reserved. 2 -- Copyright 2013 The Chromium Authors. All rights reserved.
3 -- Use of this source code is governed by a BSD-style license that can be 3 -- Use of this source code is governed by a BSD-style license that can be
4 -- found in the LICENSE file. 4 -- found in the LICENSE file.
5 --> 5 -->
6 6
7 <polymer-element name="kb-keyboard" on-key-over="keyOver" on-key-up="keyUp" 7 <polymer-element name="kb-keyboard" on-key-over="keyOver" on-key-up="keyUp"
8 on-key-down="keyDown" on-key-longpress="keyLongpress" on-pointerup="up" 8 on-key-down="keyDown" on-key-longpress="keyLongpress" on-pointerup="up"
9 on-pointerdown="down" on-enable-sel="enableSel" 9 on-pointerdown="down" on-enable-sel="enableSel"
10 on-enable-dbl="enableDbl" attributes="keyset layout rows"> 10 on-enable-dbl="enableDbl" attributes="keyset layout rows">
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
43 var REPEAT_INTERVAL_MSEC = 50; 43 var REPEAT_INTERVAL_MSEC = 50;
44 44
45 /** 45 /**
46 * The double click/tap interval. 46 * The double click/tap interval.
47 * @const 47 * @const
48 * @type {number} 48 * @type {number}
49 */ 49 */
50 var DBL_INTERVAL_MSEC = 300; 50 var DBL_INTERVAL_MSEC = 300;
51 51
52 /** 52 /**
53 * The index of the name of the keyset when searching for all keysets.
54 * @const
55 * @type {number}
56 */
57 var REGEX_KEYSET_INDEX = 1;
58
59 /**
60 * The integer number of matches when searching for keysets.
61 * @const
62 * @type {number}
63 */
64 var REGEX_MATCH_COUNT = 2;
65
66 /**
53 * The boolean to decide if keyboard should transit to upper case keyset 67 * The boolean to decide if keyboard should transit to upper case keyset
54 * when spacebar is pressed. If a closing punctuation is followed by a 68 * when spacebar is pressed. If a closing punctuation is followed by a
55 * spacebar, keyboard should automatically transit to upper case. 69 * spacebar, keyboard should automatically transit to upper case.
56 * @type {boolean} 70 * @type {boolean}
57 */ 71 */
58 var enterUpperOnSpace = false; 72 var enterUpperOnSpace = false;
59 73
60 /** 74 /**
61 * A structure to track the currently repeating key on the keyboard. 75 * A structure to track the currently repeating key on the keyboard.
62 */ 76 */
(...skipping 116 matching lines...) Expand 10 before | Expand all | Expand 10 after
179 dblTimer_: null, 193 dblTimer_: null,
180 swipeHandler: null, 194 swipeHandler: null,
181 195
182 /** 196 /**
183 * Handles the state of the shift key. 197 * Handles the state of the shift key.
184 */ 198 */
185 keysetChanged: function() { 199 keysetChanged: function() {
186 var keysetId = '#' + this.layout + '-' + this.keyset; 200 var keysetId = '#' + this.layout + '-' + this.keyset;
187 var keyset = this.querySelector(keysetId); 201 var keyset = this.querySelector(keysetId);
188 202
189 // Unlocks the keyboard if the current keyset is not lockable. 203 // Capitalizes keyboard if capslock is enabled but we are in the lower
190 if (!keyset.getAttribute('lockable')) 204 // keyset.
bshe 2013/08/30 15:33:16 Could you rephrase this comment? Not all keyboard
191 this.classList.remove('locked'); 205 if (this.classList.contains('shift-locked') && keyset.shiftLocksTo)
bshe 2013/08/30 15:33:16 Any particular reason not use caps-locked and capL
206 this.keyset = keyset.shiftLocksTo;
192 207
193 }, 208 },
194 209
195 ready: function() { 210 ready: function() {
196 this.voiceInput_ = new VoiceInput(this); 211 this.voiceInput_ = new VoiceInput(this);
197 this.swipeHandler = this.onSwipeUpdate.bind(this); 212 this.swipeHandler = this.onSwipeUpdate.bind(this);
198 }, 213 },
199 214
200 /** 215 /**
201 * When double click/tap event is enabled, the second key-down and key-up 216 * When double click/tap event is enabled, the second key-down and key-up
(...skipping 139 matching lines...) Expand 10 before | Expand all | Expand 10 after
341 up: function(event) { 356 up: function(event) {
342 if (this.dblDetail_) { 357 if (this.dblDetail_) {
343 this.dblDetail_.clickCount++; 358 this.dblDetail_.clickCount++;
344 if (this.dblDetail_.clickCount == 2) { 359 if (this.dblDetail_.clickCount == 2) {
345 this.keyset = this.dblDetail_.toKeyset; 360 this.keyset = this.dblDetail_.toKeyset;
346 var keysetId = '#' + this.layout + '-' + this.keyset; 361 var keysetId = '#' + this.layout + '-' + this.keyset;
347 var keyset = this.querySelector(keysetId); 362 var keyset = this.querySelector(keysetId);
348 keyset.nextKeyset = this.dblTimer_.nextKeyset; 363 keyset.nextKeyset = this.dblTimer_.nextKeyset;
349 clearTimeout(this.dblTimer_); 364 clearTimeout(this.dblTimer_);
350 365
351 // Checks if shift is capitalized. 366 this.classList.add('shift-locked');
352 if (keyset.getAttribute('lockable'))
353 this.classList.add('locked');
354 367
355 this.dblDetail_ = null; 368 this.dblDetail_ = null;
356 } 369 }
357 } 370 }
358 371
359 // TODO(zyaozhujun): There are some edge cases to deal with later. 372 // TODO(zyaozhujun): There are some edge cases to deal with later.
360 // (for instance, what if a second finger trigger a down and up 373 // (for instance, what if a second finger trigger a down and up
361 // event sequence while swiping). 374 // event sequence while swiping).
362 // When pointer up from the screen, a swipe selection session finished, 375 // When pointer up from the screen, a swipe selection session finished,
363 // all the data should be reset to prepare for the next session. 376 // all the data should be reset to prepare for the next session.
(...skipping 14 matching lines...) Expand all
378 return; 391 return;
379 if (swipeInProgress) 392 if (swipeInProgress)
380 return; 393 return;
381 this.lastPressedKey.classList.remove('active'); 394 this.lastPressedKey.classList.remove('active');
382 if (this.lastPressedKey != event.target) 395 if (this.lastPressedKey != event.target)
383 return; 396 return;
384 if (repeatKey.key == event.target) { 397 if (repeatKey.key == event.target) {
385 repeatKey.cancel(); 398 repeatKey.cancel();
386 return; 399 return;
387 } 400 }
388 var toKeyset = detail.toKeyset; 401 var toKeysetId = detail.toKeyset;
389 // Keyset transition key. 402 // Keyset transition key.
390 if (toKeyset) { 403 if (toKeysetId) {
391 this.keyset = toKeyset; 404 this.keyset = toKeysetId;
392 this.querySelector('#' + this.layout + '-' + this.keyset).nextKeyset = 405 this.querySelector('#' + this.layout + '-' + this.keyset).nextKeyset =
393 detail.nextKeyset; 406 detail.nextKeyset;
394 } 407 }
395 var toLayout = detail.toLayout; 408 var toLayoutId = detail.toLayout;
396 // Layout transition key. 409 // Layout transition key.
397 if (toLayout) 410 if (toLayoutId)
398 this.layout = toLayout; 411 this.layout = toLayoutId;
399 var char = detail.char; 412 var char = detail.char;
400 if (enterUpperOnSpace) { 413 if (enterUpperOnSpace) {
401 enterUpperOnSpace = false; 414 enterUpperOnSpace = false;
402 if (char == ' ') 415 if (char == ' ')
403 this.keyset = 'upper'; 416 this.keyset = 'upper';
404 } 417 }
405 switch(char) { 418 switch(char) {
406 case 'Invalid': 419 case 'Invalid':
420 swipeStatus.swipeFlags = 0;
421 return;
407 case 'Shift': 422 case 'Shift':
408 swipeStatus.swipeFlags = 0; 423 swipeStatus.swipeFlags = 0;
424 // We have reverted to lower case.
425 if(this.classList.contains('shift-locked'))
426 this.classList.remove('shift-locked');
409 return; 427 return;
410 case 'Microphone': 428 case 'Microphone':
411 this.voiceInput_.onDown(); 429 this.voiceInput_.onDown();
412 return; 430 return;
413 case '.': 431 case '.':
414 case '?': 432 case '?':
415 case '!': 433 case '!':
416 enterUpperOnSpace = true; 434 enterUpperOnSpace = true;
417 break; 435 break;
418 default: 436 default:
(...skipping 12 matching lines...) Expand all
431 // If the gesture is long press, remove the pointermove listener. 449 // If the gesture is long press, remove the pointermove listener.
432 this.removeEventListener('pointermove', this.swipeHandler, false); 450 this.removeEventListener('pointermove', this.swipeHandler, false);
433 var toKeyset = detail.toKeyset; 451 var toKeyset = detail.toKeyset;
434 // Keyset transtion key. 452 // Keyset transtion key.
435 if (toKeyset) { 453 if (toKeyset) {
436 this.keyset = toKeyset; 454 this.keyset = toKeyset;
437 this.querySelector('#' + this.layout + '-' + this.keyset).nextKeyset = 455 this.querySelector('#' + this.layout + '-' + this.keyset).nextKeyset =
438 detail.nextKeyset; 456 detail.nextKeyset;
439 457
440 // Locks the keyset before removing active to prevent flicker. 458 // Locks the keyset before removing active to prevent flicker.
441 this.classList.add('locked'); 459 this.classList.add('shift-locked');
442 // Makes last pressed key inactive if transit to a new keyset on long 460 // Makes last pressed key inactive if transit to a new keyset on long
443 // press. 461 // press.
444 this.lastPressedKey.classList.remove('active'); 462 this.lastPressedKey.classList.remove('active');
445 } 463 }
446 }, 464 },
447 465
448 /** 466 /**
449 * Handles a change in the keyboard layout. Auto-selects the default 467 * Handles a change in the keyboard layout. Auto-selects the default
450 * keyset for the new layout. 468 * keyset for the new layout.
451 */ 469 */
(...skipping 15 matching lines...) Expand all
467 * @return {boolean} True if successful. This method can fail if the 485 * @return {boolean} True if successful. This method can fail if the
468 * keysets corresponding to the layout have not been injected. 486 * keysets corresponding to the layout have not been injected.
469 */ 487 */
470 selectDefaultKeyset: function() { 488 selectDefaultKeyset: function() {
471 var keysets = this.querySelectorAll('kb-keyset'); 489 var keysets = this.querySelectorAll('kb-keyset');
472 // Full name of the keyset is of the form 'layout-keyset'. 490 // Full name of the keyset is of the form 'layout-keyset'.
473 var regex = new RegExp('^' + this.layout + '-(.+)'); 491 var regex = new RegExp('^' + this.layout + '-(.+)');
474 var keysetsLoaded = false; 492 var keysetsLoaded = false;
475 for (var i = 0; i < keysets.length; i++) { 493 for (var i = 0; i < keysets.length; i++) {
476 var matches = keysets[i].id.match(regex); 494 var matches = keysets[i].id.match(regex);
477 if (matches && matches.length == 2) { 495 if (matches && matches.length == REGEX_MATCH_COUNT) {
478 keysetsLoaded = true; 496 keysetsLoaded = true;
479 if (keysets[i].isDefault) { 497 if (keysets[i].isDefault) {
480 this.keyset = matches[1]; 498 this.keyset = matches[REGEX_KEYSET_INDEX];
481 return true; 499 return true;
482 } 500 }
483 } 501 }
484 } 502 }
485 if (keysetsLoaded) 503 if (keysetsLoaded)
486 console.error('No default keyset found for ' + this.layout); 504 console.error('No default keyset found for ' + this.layout);
487 return false; 505 return false;
488 } 506 }
489 }); 507 });
490 </script> 508 </script>
491 </polymer-element> 509 </polymer-element>
492 510
OLDNEW
« no previous file with comments | « no previous file | ui/keyboard/resources/elements/kb-keyset.html » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698