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

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

Issue 15176004: Web Component Virtual Keyboard (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: review Created 7 years, 6 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 | Annotate | Revision Log
OLDNEW
(Empty)
1 <!--
2 -- Copyright (c) 2013 The Chromium Authors. All rights reserved.
3 -- Use of this source code is governed by a BSD-style license that can be
4 -- found in the LICENSE file.
5 -->
6
7 <element name="kb-keyboard" on-key-over="keyOver" on-key-up="keyUp"
8 on-key-down="keyDown" attributes="keyset rows">
9 <template>
10 <content select="#{{keyset}}"></content>
11 </template>
12 <script>
13 /**
14 * The long-press delay in milliseconds before long-press handler is
15 * invoked.
16 * @type {number}
17 */
18 var LONGPRESS_DELAY_MSEC = 500;
19
20 /**
21 * The repeat delay in milliseconds before a key starts repeating. Use the
22 * same rate as Chromebook.
23 * (See chrome/browser/chromeos/language_preferences.cc)
24 * @type {number}
25 */
26 var REPEAT_DELAY_MSEC = 500;
27
28 /**
29 * The repeat interval or number of milliseconds between subsequent
30 * keypresses. Use the same rate as Chromebook.
31 * @type {number}
32 */
33 var REPEAT_INTERVAL_MSEC = 50;
34
35 /**
36 * The boolean to decide if keyboard should transit to upper case keyset
37 * when spacebar is pressed. If a closing punctuation is followed by a
38 * spacebar, keyboard should automatically transit to upper case.
39 * @type {boolean}
40 */
41 var enterUpperOnSpace = false;
42
43 /**
44 * A structure to track the currently repeating key on the keyboard.
45 */
46 var repeatKey = {
47 /**
48 * The timer for the delay before repeating behaviour begins.
49 * @type {number|undefined}
50 */
51 timer: undefined,
52
53 /**
54 * The interval timer for issuing keypresses of a repeating key.
55 * @type {number|undefined}
56 */
57 interval: undefined,
58
59 /**
60 * The key which is currently repeating.
61 * @type {BaseKey|undefined}
62 */
63 key: undefined,
64
65 /**
66 * Cancel the repeat timers of the currently active key.
67 */
68 cancel: function() {
69 clearTimeout(this.timer);
70 clearInterval(this.interval);
71 this.timer = undefined;
72 this.interval = undefined;
73 this.key = undefined;
74 }
75 };
76
77 Polymer.register(this, {
78 lastPressedKey: null,
79 voiceInput_: null,
80
81 ready: function() {
82 this.voiceInput_ = new VoiceInput(this);
83 },
84
85 /**
86 * Handles key-down event that is sent by kb-key.
87 * @param {CustomEvent} event The key-down event dispatched by kb-key.
88 * @param {Object} detail The detail of pressed kb-key.
89 */
90 keyDown: function(event, detail) {
91 var toKeyset = detail.toKeyset;
92 if (this.lastPressedKey)
93 this.lastPressedKey.classList.remove('active');
94 this.lastPressedKey = event.target;
95 this.lastPressedKey.classList.add('active');
96 repeatKey.cancel();
97 if (detail.repeat) {
98 sendKey(detail.char);
99 repeatKey.key = this.lastPressedKey;
100 repeatKey.timer = setTimeout(function() {
101 repeatKey.timer = undefined;
102 repeatKey.interval = setInterval(function() {
103 sendKey(detail.char);
104 }, REPEAT_INTERVAL_MSEC);
105 }, Math.max(0, REPEAT_DELAY_MSEC - REPEAT_INTERVAL_MSEC));
106 }
107 },
108
109 /**
110 * Handles key-up event that is sent by kb-key.
111 * @param {CustomEvent} event The key-up event dispatched by kb-key.
112 * @param {Object} detail The detail of pressed kb-key.
113 */
114 keyUp: function(event, detail) {
115 this.lastPressedKey.classList.remove('active');
116 if (this.lastPressedKey != event.target)
117 return;
118 if (repeatKey.key == event.target) {
119 repeatKey.cancel();
120 return;
121 }
122 var toKeyset = detail.toKeyset;
123 // Keyset transtion key.
124 if (toKeyset) {
125 this.keyset = toKeyset;
126 }
127 var char = detail.char;
128 if (enterUpperOnSpace) {
129 enterUpperOnSpace = false;
130 if (char == 'Spacebar')
131 this.keyset = 'upper';
132 }
133 switch(char) {
134 case 'Shift':
135 case 'Symbol':
136 case 'More':
137 return;
138 case 'Mic':
139 this.voiceInput_.onDown();
140 return;
141 case '.':
142 case '?':
143 case '!':
144 enterUpperOnSpace = true;
145 break;
146 case 'Tab':
147 case 'Spacebar':
148 case 'Enter':
149 sendKey(char);
150 return;
151 default:
152 break;
153 }
154 for (var i = 0; i < char.length; i++) {
155 sendKey(char.charAt(i));
156 }
157 }
158 });
159 </script>
160 </element>
161
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698