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"> | 10 on-enable-dbl="enableDbl" attributes="keyset layout rows"> |
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 255 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
291 repeatKey.cancel(); | 292 repeatKey.cancel(); |
292 var toKeyset = detail.toKeyset; | 293 var toKeyset = detail.toKeyset; |
293 if (toKeyset) { | 294 if (toKeyset) { |
294 this.keyset = toKeyset; | 295 this.keyset = toKeyset; |
295 this.querySelector('#' + this.layout + '-' + this.keyset).nextKeyset = | 296 this.querySelector('#' + this.layout + '-' + this.keyset).nextKeyset = |
296 detail.nextKeyset; | 297 detail.nextKeyset; |
297 return; | 298 return; |
298 } | 299 } |
299 | 300 |
300 if (detail.repeat) { | 301 if (detail.repeat) { |
301 insertText(detail.char); | 302 this.keyTyped(detail); |
302 repeatKey.key = this.lastPressedKey; | 303 repeatKey.key = this.lastPressedKey; |
| 304 var self = this; |
303 repeatKey.timer = setTimeout(function() { | 305 repeatKey.timer = setTimeout(function() { |
304 repeatKey.timer = undefined; | 306 repeatKey.timer = undefined; |
305 repeatKey.interval = setInterval(function() { | 307 repeatKey.interval = setInterval(function() { |
306 insertText(detail.char); | 308 self.keyTyped(detail); |
307 }, REPEAT_INTERVAL_MSEC); | 309 }, REPEAT_INTERVAL_MSEC); |
308 }, Math.max(0, REPEAT_DELAY_MSEC - REPEAT_INTERVAL_MSEC)); | 310 }, Math.max(0, REPEAT_DELAY_MSEC - REPEAT_INTERVAL_MSEC)); |
309 } | 311 } |
310 }, | 312 }, |
311 | 313 |
312 /** | 314 /** |
313 * Enable/start double click/tap event recognition. | 315 * Enable/start double click/tap event recognition. |
314 * @param {CustomEvent} event The enable-dbl event dispatched by | 316 * @param {CustomEvent} event The enable-dbl event dispatched by |
315 * kb-shift-key. | 317 * kb-shift-key. |
316 * @param {Object} detail The detail of pressed kb-shift-key. | 318 * @param {Object} detail The detail of pressed kb-shift-key. |
(...skipping 112 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
429 this.voiceInput_.onDown(); | 431 this.voiceInput_.onDown(); |
430 return; | 432 return; |
431 case '.': | 433 case '.': |
432 case '?': | 434 case '?': |
433 case '!': | 435 case '!': |
434 enterUpperOnSpace = true; | 436 enterUpperOnSpace = true; |
435 break; | 437 break; |
436 default: | 438 default: |
437 break; | 439 break; |
438 } | 440 } |
439 insertText(char); | 441 if (char.length == 1) |
| 442 this.keyTyped(detail); |
| 443 else |
| 444 insertText(char); |
440 }, | 445 }, |
441 | 446 |
442 /* | 447 /* |
443 * Handles key-longpress event that is sent by kb-key-base. | 448 * Handles key-longpress event that is sent by kb-key-base. |
444 * @param {CustomEvent} event The key-longpress event dispatched by | 449 * @param {CustomEvent} event The key-longpress event dispatched by |
445 * kb-key-base. | 450 * kb-key-base. |
446 * @param {Object} detail The detail of pressed key. | 451 * @param {Object} detail The detail of pressed key. |
447 */ | 452 */ |
448 keyLongpress: function(event, detail) { | 453 keyLongpress: function(event, detail) { |
449 // If the gesture is long press, remove the pointermove listener. | 454 // If the gesture is long press, remove the pointermove listener. |
(...skipping 24 matching lines...) Expand all Loading... |
474 if (keysets) { | 479 if (keysets) { |
475 keyboard.appendChild(flattenKeysets(keysets.content)); | 480 keyboard.appendChild(flattenKeysets(keysets.content)); |
476 this.selectDefaultKeyset(); | 481 this.selectDefaultKeyset(); |
477 } else { | 482 } else { |
478 console.error('Unable to find layout ' + this.layout); | 483 console.error('Unable to find layout ' + this.layout); |
479 } | 484 } |
480 } | 485 } |
481 }, | 486 }, |
482 | 487 |
483 /** | 488 /** |
| 489 * Generates fabricated key events to simulate typing on a |
| 490 * physical keyboard. |
| 491 * @param {Object} detail Attributes of the key being typed. |
| 492 */ |
| 493 keyTyped: function(detail) { |
| 494 var builder = this.$.keyCodeMetadata; |
| 495 sendKeyEvent(builder.CreateVirtualKeyEvent(detail, "keydown")); |
| 496 sendKeyEvent(builder.CreateVirtualKeyEvent(detail, "keyup")); |
| 497 }, |
| 498 |
| 499 /** |
484 * Selects the default keyset for a layout. | 500 * Selects the default keyset for a layout. |
485 * @return {boolean} True if successful. This method can fail if the | 501 * @return {boolean} True if successful. This method can fail if the |
486 * keysets corresponding to the layout have not been injected. | 502 * keysets corresponding to the layout have not been injected. |
487 */ | 503 */ |
488 selectDefaultKeyset: function() { | 504 selectDefaultKeyset: function() { |
489 var keysets = this.querySelectorAll('kb-keyset'); | 505 var keysets = this.querySelectorAll('kb-keyset'); |
490 // Full name of the keyset is of the form 'layout-keyset'. | 506 // Full name of the keyset is of the form 'layout-keyset'. |
491 var regex = new RegExp('^' + this.layout + '-(.+)'); | 507 var regex = new RegExp('^' + this.layout + '-(.+)'); |
492 var keysetsLoaded = false; | 508 var keysetsLoaded = false; |
493 for (var i = 0; i < keysets.length; i++) { | 509 for (var i = 0; i < keysets.length; i++) { |
494 var matches = keysets[i].id.match(regex); | 510 var matches = keysets[i].id.match(regex); |
495 if (matches && matches.length == REGEX_MATCH_COUNT) { | 511 if (matches && matches.length == REGEX_MATCH_COUNT) { |
496 keysetsLoaded = true; | 512 keysetsLoaded = true; |
497 if (keysets[i].isDefault) { | 513 if (keysets[i].isDefault) { |
498 this.keyset = matches[REGEX_KEYSET_INDEX]; | 514 this.keyset = matches[REGEX_KEYSET_INDEX]; |
499 return true; | 515 return true; |
500 } | 516 } |
501 } | 517 } |
502 } | 518 } |
503 if (keysetsLoaded) | 519 if (keysetsLoaded) |
504 console.error('No default keyset found for ' + this.layout); | 520 console.error('No default keyset found for ' + this.layout); |
505 return false; | 521 return false; |
506 } | 522 } |
507 }); | 523 }); |
508 </script> | 524 </script> |
509 </polymer-element> | 525 </polymer-element> |
510 | 526 |
OLD | NEW |