Chromium Code Reviews| 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 // Each virtual key event is assigned a unique ID. | |
| 11 var nextRequestID = 0; | |
| 12 | |
| 10 // Keycodes have been deprecated in the KeyEvent specification, but are | 13 // Keycodes have been deprecated in the KeyEvent specification, but are |
| 11 // nonetheless required to support legacy web content. The Keycodes in the | 14 // nonetheless required to support legacy web content. The Keycodes in the |
| 12 // following table are based on subset of US-EN 101-key keyboard. These | 15 // following table are based on subset of US-EN 101-key keyboard. These |
| 13 // codes are used in the absence of explicit keycodes for kb-key and | 16 // codes are used in the absence of explicit keycodes for kb-key and |
| 14 // kb-keysequence elements. Keyboard layout authors may explicitly set the | 17 // kb-keysequence elements. Keyboard layout authors may explicitly set the |
| 15 // keyCode attribute for kb-key or kb-keysequence elements to refer to | 18 // keyCode attribute for kb-key or kb-keysequence elements to refer to |
| 16 // indices in this table in order to emulate a physical keyboard with an | 19 // indices in this table in order to emulate a physical keyboard with an |
| 17 // alternate layout. Not all keys on a virtual keyboard are required to | 20 // alternate layout. Not all keys on a virtual keyboard are required to |
| 18 // have keyCodes. | 21 // have keyCodes. |
| 19 var keyCodes = { | 22 var keyCodes = { |
| (...skipping 112 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 132 }; | 135 }; |
| 133 } | 136 } |
| 134 return { | 137 return { |
| 135 keyCode: 0, | 138 keyCode: 0, |
| 136 shiftModifier: false | 139 shiftModifier: false |
| 137 }; | 140 }; |
| 138 }, | 141 }, |
| 139 | 142 |
| 140 /** | 143 /** |
| 141 * Creates a virtual key event for use with the keyboard extension API. | 144 * Creates a virtual key event for use with the keyboard extension API. |
| 142 * @param {kb-key} key Instance of the kb-key element being pressed or | 145 * See http://www.w3.org/TR/DOM-Level-3-Events/#events-KeyboardEvent. |
| 143 * released. | 146 * @param {Object} detail Attribute of the key being pressed or released. |
| 144 * @param {string} type The type of key event, which may be keydown | 147 * @param {string} type The type of key event, which may be keydown |
| 145 * or keyreleased. | 148 * or keyup. |
| 146 * @return {keyCode: numeric, | 149 * @return {?KeyboardEvent} A KeyboardEvent object, or undefined on |
| 147 * modifiers: Array.<string>, | 150 * failure. |
| 148 * type: string, | |
| 149 * value: string} | |
| 150 */ | 151 */ |
|
bshe
2013/09/03 23:18:11
function names should start with a lower case lett
kevers
2013/09/04 13:51:20
Yes, it should have been lowercase. Fixed.
| |
| 151 CreateVirtualKeyEvent: function(key, type) { | 152 CreateVirtualKeyEvent: function(detail, type) { |
| 152 var keyCode = key.keyCode; | 153 var char = detail.char; |
| 153 var shiftModifier = key.shiftModifier; | 154 if (!char || char.length != 1) { |
| 155 console.error('Invalid key. Expected single character.'); | |
| 156 return; | |
| 157 } | |
| 158 var keyCode = detail.keyCode; | |
| 159 var shiftModifier = detail.shiftModifier; | |
| 154 if (keyCode == undefined) { | 160 if (keyCode == undefined) { |
| 155 var state = this.GetKeyCodeAndModifiers(key.charValue); | 161 var state = this.GetKeyCodeAndModifiers(char); |
| 162 if (state) { | |
| 156 keyCode = state.keyCode; | 163 keyCode = state.keyCode; |
|
bshe
2013/09/03 23:18:11
nit: indent is off
kevers
2013/09/04 13:51:20
Fixed.
| |
| 157 shiftModifier = state.shiftModifier; | 164 shiftModifier = state.shiftModifier; |
| 165 } else { | |
| 166 keyCode = 0; | |
| 167 shiftModifier = false; | |
| 168 } | |
| 158 } | 169 } |
| 159 var modifiers = []; | |
| 160 if (shiftModifier) | |
| 161 modifiers.push('shiftKey'); | |
| 162 return { | 170 return { |
| 171 type: type, | |
| 172 charValue: char.charCodeAt(0), | |
| 163 keyCode: keyCode, | 173 keyCode: keyCode, |
| 164 modifiers: modifiers, | 174 shiftKey: shiftModifier |
| 165 type: type, | |
| 166 value: key.charValue, | |
| 167 }; | 175 }; |
| 168 }, | 176 }, |
| 169 }); | 177 }); |
| 170 })(); | 178 })(); |
| 171 </script> | 179 </script> |
| 172 </polymer-element> | 180 </polymer-element> |
| OLD | NEW |