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-key-codes"> | 7 <polymer-element name="kb-key-codes"> |
8 <script> | 8 <script> |
9 (function() { | 9 (function() { |
10 | 10 |
(...skipping 11 matching lines...) Expand all Loading... |
22 var nextRequestID = 0; | 22 var nextRequestID = 0; |
23 | 23 |
24 // Keycodes have been deprecated in the KeyEvent specification, but are | 24 // Keycodes have been deprecated in the KeyEvent specification, but are |
25 // nonetheless required to support legacy web content. The Keycodes in the | 25 // nonetheless required to support legacy web content. The Keycodes in the |
26 // following table are based on subset of US-EN 101-key keyboard. These | 26 // following table are based on subset of US-EN 101-key keyboard. These |
27 // codes are used in the absence of explicit keycodes for kb-key and | 27 // codes are used in the absence of explicit keycodes for kb-key and |
28 // kb-keysequence elements. Keyboard layout authors may explicitly set the | 28 // kb-keysequence elements. Keyboard layout authors may explicitly set the |
29 // keyCode attribute for kb-key or kb-keysequence elements to refer to | 29 // keyCode attribute for kb-key or kb-keysequence elements to refer to |
30 // indices in this table in order to emulate a physical keyboard with an | 30 // indices in this table in order to emulate a physical keyboard with an |
31 // alternate layout. Not all keys on a virtual keyboard are required to | 31 // alternate layout. Not all keys on a virtual keyboard are required to |
32 // have keyCodes. | 32 // have keyCodes. The shiftModifier specifies whether to always include or |
| 33 // exclude the shift modifer when sending key events for this key. If it's |
| 34 // undefined, it will defer to state of the keyboard. |
33 // TODO(rsadam): Correctly propagate shutdown keycode. This is currently | 35 // TODO(rsadam): Correctly propagate shutdown keycode. This is currently |
34 // ignored due to chromoting (crbug/146609) | 36 // ignored due to chromoting (crbug/146609) |
35 var keyCodes = { | 37 var keyCodes = { |
36 '\b': {keyCode: 0x08, shiftModifier: false}, | 38 '\b': {keyCode: 0x08, shiftModifier: false}, |
37 '\t': {keyCode: 0x09, shiftModifier: false}, | 39 '\t': {keyCode: 0x09, shiftModifier: false}, |
38 '\n': {keyCode: 0x0D, shiftModifier: false}, | 40 '\n': {keyCode: 0x0D, shiftModifier: false}, |
39 'Esc': {keyCode: 0x1B, shiftModifier: false}, | 41 'Esc': {keyCode: 0x1B, shiftModifier: false}, |
40 ' ': {keyCode: 0x20, shiftModifier: false}, | 42 ' ': {keyCode: 0x20, shiftModifier: false}, |
41 'Arrow-Left': {keyCode: 0x25, shiftModifier: false}, | 43 'Arrow-Left': {keyCode: 0x25, shiftModifier: undefined}, |
42 'Arrow-Up': {keyCode: 0x26, shiftModifier: false}, | 44 'Arrow-Up': {keyCode: 0x26, shiftModifier: undefined}, |
43 'Arrow-Right': {keyCode: 0x27, shiftModifier: false}, | 45 'Arrow-Right': {keyCode: 0x27, shiftModifier: undefined}, |
44 'Arrow-Down': {keyCode: 0x28, shiftModifier: false}, | 46 'Arrow-Down': {keyCode: 0x28, shiftModifier: undefined}, |
45 '0': {keyCode: 0x30, shiftModifier: false}, | 47 '0': {keyCode: 0x30, shiftModifier: false}, |
46 ')': {keyCode: 0x30, shiftModifier: true}, | 48 ')': {keyCode: 0x30, shiftModifier: true}, |
47 '1': {keyCode: 0x31, shiftModifier: false}, | 49 '1': {keyCode: 0x31, shiftModifier: false}, |
48 '!': {keyCode: 0x31, shiftModifier: true}, | 50 '!': {keyCode: 0x31, shiftModifier: true}, |
49 '2': {keyCode: 0x32, shiftModifier: false}, | 51 '2': {keyCode: 0x32, shiftModifier: false}, |
50 '@': {keyCode: 0x32, shiftModifier: true}, | 52 '@': {keyCode: 0x32, shiftModifier: true}, |
51 '3': {keyCode: 0x33, shiftModifier: false}, | 53 '3': {keyCode: 0x33, shiftModifier: false}, |
52 '#': {keyCode: 0x33, shiftModifier: true}, | 54 '#': {keyCode: 0x33, shiftModifier: true}, |
53 '4': {keyCode: 0x34, shiftModifier: false}, | 55 '4': {keyCode: 0x34, shiftModifier: false}, |
54 '$': {keyCode: 0x34, shiftModifier: true}, | 56 '$': {keyCode: 0x34, shiftModifier: true}, |
(...skipping 124 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
179 * @param {string} type The type of key event, which may be keydown | 181 * @param {string} type The type of key event, which may be keydown |
180 * or keyup. | 182 * or keyup. |
181 * @return {?KeyboardEvent} A KeyboardEvent object, or undefined on | 183 * @return {?KeyboardEvent} A KeyboardEvent object, or undefined on |
182 * failure. | 184 * failure. |
183 */ | 185 */ |
184 createVirtualKeyEvent: function(detail, type) { | 186 createVirtualKeyEvent: function(detail, type) { |
185 var char = detail.char; | 187 var char = detail.char; |
186 var keyCode = detail.keyCode; | 188 var keyCode = detail.keyCode; |
187 // The shift modifier is handled specially. Some charactares like '+' | 189 // The shift modifier is handled specially. Some charactares like '+' |
188 // {keyCode: 0xBB, shiftModifier: true}, are available on non-upper | 190 // {keyCode: 0xBB, shiftModifier: true}, are available on non-upper |
189 // keysets, and so we rely on caching the correct shiftModifier. | 191 // keysets, and so we rely on caching the correct shiftModifier. If |
| 192 // the cached value of the shiftModifier is undefined, we defer to |
| 193 // the shiftModifier in the detail. |
190 var shiftModifier = detail.shiftModifier; | 194 var shiftModifier = detail.shiftModifier; |
191 if (keyCode == undefined) { | 195 if (keyCode == undefined) { |
192 var state = this.GetKeyCodeAndModifiers(char); | 196 var state = this.GetKeyCodeAndModifiers(char); |
193 if (state) { | 197 if (state) { |
194 keyCode = state.keyCode; | 198 keyCode = state.keyCode; |
195 shiftModifier = state.shiftModifier; | 199 shiftModifier = (state.shiftModifier == undefined) ? |
| 200 shiftModifier : state.shiftModifier; |
196 } else { | 201 } else { |
197 // Keycode not defined. | 202 // Keycode not defined. |
198 return; | 203 return; |
199 } | 204 } |
200 } | 205 } |
201 var modifiers = Modifier.NONE; | 206 var modifiers = Modifier.NONE; |
202 modifiers = shiftModifier ? modifiers | Modifier.SHIFT : modifiers; | 207 modifiers = shiftModifier ? modifiers | Modifier.SHIFT : modifiers; |
203 modifiers = detail.controlModifier ? | 208 modifiers = detail.controlModifier ? |
204 modifiers | Modifier.CONTROL : modifiers; | 209 modifiers | Modifier.CONTROL : modifiers; |
205 modifiers = detail.altModifier ? modifiers | Modifier.ALT : modifiers; | 210 modifiers = detail.altModifier ? modifiers | Modifier.ALT : modifiers; |
206 return { | 211 return { |
207 type: type, | 212 type: type, |
208 charValue: char.charCodeAt(0), | 213 charValue: char.charCodeAt(0), |
209 keyCode: keyCode, | 214 keyCode: keyCode, |
210 modifiers: modifiers | 215 modifiers: modifiers |
211 }; | 216 }; |
212 }, | 217 }, |
213 }); | 218 }); |
214 })(); | 219 })(); |
215 </script> | 220 </script> |
216 </polymer-element> | 221 </polymer-element> |
OLD | NEW |