OLD | NEW |
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 capsLocked"> | 10 on-enable-dbl="enableDbl" attributes="keyset layout rows capsLocked"> |
11 <template> | 11 <template> |
12 <style> | 12 <style> |
13 @host { | 13 @host { |
14 * { | 14 * { |
15 position: relative; | 15 position: relative; |
16 } | 16 } |
17 } | 17 } |
18 </style> | 18 </style> |
19 <!-- The ID for a keyset follows the naming convention of combining the | 19 <!-- The ID for a keyset follows the naming convention of combining the |
20 -- layout name with a base keyset name. This convention is used to | 20 -- layout name with a base keyset name. This convention is used to |
21 -- allow multiple layouts to be loaded (enablign fast switching) while | 21 -- allow multiple layouts to be loaded (enablign fast switching) while |
22 -- allowing the shift and spacebar keys to be common across multiple | 22 -- allowing the shift and spacebar keys to be common across multiple |
23 -- keyboard layouts. | 23 -- keyboard layouts. |
24 --> | 24 --> |
25 <content select="#{{layout}}-{{keyset}}"></content> | 25 <content select="#{{layout}}-{{keyset}}"></content> |
| 26 <kb-key-codes id="keyCodeMetadata"></kb-key-codes> |
26 </template> | 27 </template> |
27 <script> | 28 <script> |
28 /** | 29 /** |
29 * The repeat delay in milliseconds before a key starts repeating. Use the | 30 * The repeat delay in milliseconds before a key starts repeating. Use the |
30 * same rate as Chromebook. | 31 * same rate as Chromebook. |
31 * (See chrome/browser/chromeos/language_preferences.cc) | 32 * (See chrome/browser/chromeos/language_preferences.cc) |
32 * @const | 33 * @const |
33 * @type {number} | 34 * @type {number} |
34 */ | 35 */ |
35 var REPEAT_DELAY_MSEC = 500; | 36 var REPEAT_DELAY_MSEC = 500; |
(...skipping 254 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
290 repeatKey.cancel(); | 291 repeatKey.cancel(); |
291 var toKeyset = detail.toKeyset; | 292 var toKeyset = detail.toKeyset; |
292 if (toKeyset) { | 293 if (toKeyset) { |
293 this.keyset = toKeyset; | 294 this.keyset = toKeyset; |
294 this.querySelector('#' + this.layout + '-' + this.keyset).nextKeyset = | 295 this.querySelector('#' + this.layout + '-' + this.keyset).nextKeyset = |
295 detail.nextKeyset; | 296 detail.nextKeyset; |
296 return; | 297 return; |
297 } | 298 } |
298 | 299 |
299 if (detail.repeat) { | 300 if (detail.repeat) { |
300 insertText(detail.char); | 301 this.keyTyped(detail); |
301 repeatKey.key = this.lastPressedKey; | 302 repeatKey.key = this.lastPressedKey; |
| 303 var self = this; |
302 repeatKey.timer = setTimeout(function() { | 304 repeatKey.timer = setTimeout(function() { |
303 repeatKey.timer = undefined; | 305 repeatKey.timer = undefined; |
304 repeatKey.interval = setInterval(function() { | 306 repeatKey.interval = setInterval(function() { |
305 insertText(detail.char); | 307 self.keyTyped(detail); |
306 }, REPEAT_INTERVAL_MSEC); | 308 }, REPEAT_INTERVAL_MSEC); |
307 }, Math.max(0, REPEAT_DELAY_MSEC - REPEAT_INTERVAL_MSEC)); | 309 }, Math.max(0, REPEAT_DELAY_MSEC - REPEAT_INTERVAL_MSEC)); |
308 } | 310 } |
309 }, | 311 }, |
310 | 312 |
311 /** | 313 /** |
312 * Enable/start double click/tap event recognition. | 314 * Enable/start double click/tap event recognition. |
313 * @param {CustomEvent} event The enable-dbl event dispatched by | 315 * @param {CustomEvent} event The enable-dbl event dispatched by |
314 * kb-shift-key. | 316 * kb-shift-key. |
315 * @param {Object} detail The detail of pressed kb-shift-key. | 317 * @param {Object} detail The detail of pressed kb-shift-key. |
(...skipping 112 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
428 this.voiceInput_.onDown(); | 430 this.voiceInput_.onDown(); |
429 return; | 431 return; |
430 case '.': | 432 case '.': |
431 case '?': | 433 case '?': |
432 case '!': | 434 case '!': |
433 enterUpperOnSpace = true; | 435 enterUpperOnSpace = true; |
434 break; | 436 break; |
435 default: | 437 default: |
436 break; | 438 break; |
437 } | 439 } |
438 insertText(char); | 440 if (char.length == 1) |
| 441 this.keyTyped(detail); |
| 442 else |
| 443 insertText(char); |
439 }, | 444 }, |
440 | 445 |
441 /* | 446 /* |
442 * Handles key-longpress event that is sent by kb-key-base. | 447 * Handles key-longpress event that is sent by kb-key-base. |
443 * @param {CustomEvent} event The key-longpress event dispatched by | 448 * @param {CustomEvent} event The key-longpress event dispatched by |
444 * kb-key-base. | 449 * kb-key-base. |
445 * @param {Object} detail The detail of pressed key. | 450 * @param {Object} detail The detail of pressed key. |
446 */ | 451 */ |
447 keyLongpress: function(event, detail) { | 452 keyLongpress: function(event, detail) { |
448 // If the gesture is long press, remove the pointermove listener. | 453 // If the gesture is long press, remove the pointermove listener. |
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
487 cacheCapsLock: function() { | 492 cacheCapsLock: function() { |
488 var shift = this.querySelector('kb-shift-key'); | 493 var shift = this.querySelector('kb-shift-key'); |
489 if (shift) { | 494 if (shift) { |
490 this.capsLock = { 'lockedCase' : shift.lockedCase, | 495 this.capsLock = { 'lockedCase' : shift.lockedCase, |
491 'unlockedCase' : shift.unlockedCase | 496 'unlockedCase' : shift.unlockedCase |
492 }; | 497 }; |
493 } | 498 } |
494 }, | 499 }, |
495 | 500 |
496 /** | 501 /** |
| 502 * Generates fabricated key events to simulate typing on a |
| 503 * physical keyboard. |
| 504 * @param {Object} detail Attributes of the key being typed. |
| 505 */ |
| 506 keyTyped: function(detail) { |
| 507 var builder = this.$.keyCodeMetadata; |
| 508 sendKeyEvent(builder.createVirtualKeyEvent(detail, "keydown")); |
| 509 sendKeyEvent(builder.createVirtualKeyEvent(detail, "keyup")); |
| 510 }, |
| 511 |
| 512 /** |
497 * Selects the default keyset for a layout. | 513 * Selects the default keyset for a layout. |
498 * @return {boolean} True if successful. This method can fail if the | 514 * @return {boolean} True if successful. This method can fail if the |
499 * keysets corresponding to the layout have not been injected. | 515 * keysets corresponding to the layout have not been injected. |
500 */ | 516 */ |
501 selectDefaultKeyset: function() { | 517 selectDefaultKeyset: function() { |
502 var keysets = this.querySelectorAll('kb-keyset'); | 518 var keysets = this.querySelectorAll('kb-keyset'); |
503 // Full name of the keyset is of the form 'layout-keyset'. | 519 // Full name of the keyset is of the form 'layout-keyset'. |
504 var regex = new RegExp('^' + this.layout + '-(.+)'); | 520 var regex = new RegExp('^' + this.layout + '-(.+)'); |
505 var keysetsLoaded = false; | 521 var keysetsLoaded = false; |
506 for (var i = 0; i < keysets.length; i++) { | 522 for (var i = 0; i < keysets.length; i++) { |
507 var matches = keysets[i].id.match(regex); | 523 var matches = keysets[i].id.match(regex); |
508 if (matches && matches.length == REGEX_MATCH_COUNT) { | 524 if (matches && matches.length == REGEX_MATCH_COUNT) { |
509 keysetsLoaded = true; | 525 keysetsLoaded = true; |
510 if (keysets[i].isDefault) { | 526 if (keysets[i].isDefault) { |
511 this.keyset = matches[REGEX_KEYSET_INDEX]; | 527 this.keyset = matches[REGEX_KEYSET_INDEX]; |
512 return true; | 528 return true; |
513 } | 529 } |
514 } | 530 } |
515 } | 531 } |
516 if (keysetsLoaded) | 532 if (keysetsLoaded) |
517 console.error('No default keyset found for ' + this.layout); | 533 console.error('No default keyset found for ' + this.layout); |
518 return false; | 534 return false; |
519 } | 535 } |
520 }); | 536 }); |
521 </script> | 537 </script> |
522 </polymer-element> | 538 </polymer-element> |
523 | 539 |
OLD | NEW |