OLD | NEW |
1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file |
2 // for details. All rights reserved. Use of this source code is governed by a | 2 // for details. All rights reserved. Use of this source code is governed by a |
3 // BSD-style license that can be found in the LICENSE file. | 3 // BSD-style license that can be found in the LICENSE file. |
4 | 4 |
5 part of html; | 5 part of html; |
6 | 6 |
7 /** | 7 /** |
8 * Defines the keycode values for keys that are returned by | 8 * Defines the keycode values for keys that are returned by |
9 * KeyboardEvent.keyCode. | 9 * KeyboardEvent.keyCode. |
10 * | 10 * |
(...skipping 177 matching lines...) Loading... |
188 */ | 188 */ |
189 static const int BACKSLASH = 220; | 189 static const int BACKSLASH = 220; |
190 /** | 190 /** |
191 * CAUTION: This constant requires localization for other locales and keyboard | 191 * CAUTION: This constant requires localization for other locales and keyboard |
192 * layouts. | 192 * layouts. |
193 */ | 193 */ |
194 static const int CLOSE_SQUARE_BRACKET = 221; | 194 static const int CLOSE_SQUARE_BRACKET = 221; |
195 static const int WIN_KEY = 224; | 195 static const int WIN_KEY = 224; |
196 static const int MAC_FF_META = 224; | 196 static const int MAC_FF_META = 224; |
197 static const int WIN_IME = 229; | 197 static const int WIN_IME = 229; |
| 198 |
| 199 /** A sentinel value if the keycode could not be determined. */ |
| 200 static const int UNKNOWN = -1; |
| 201 |
| 202 /** |
| 203 * Returns true if the keyCode produces a (US keyboard) character. |
| 204 * Note: This does not (yet) cover characters on non-US keyboards (Russian, |
| 205 * Hebrew, etc.). |
| 206 */ |
| 207 static bool isCharacterKey(int keyCode) { |
| 208 if ((keyCode >= ZERO && keyCode <= NINE) || |
| 209 (keyCode >= NUM_ZERO && keyCode <= NUM_MULTIPLY) || |
| 210 (keyCode >= A && keyCode <= Z)) { |
| 211 return true; |
| 212 } |
| 213 |
| 214 // Safari sends zero key code for non-latin characters. |
| 215 if (_Device.isWebKit && keyCode == 0) { |
| 216 return true; |
| 217 } |
| 218 |
| 219 return (keyCode == SPACE || keyCode == QUESTION_MARK || keyCode == NUM_PLUS |
| 220 || keyCode == NUM_MINUS || keyCode == NUM_PERIOD || |
| 221 keyCode == NUM_DIVISION || keyCode == SEMICOLON || |
| 222 keyCode == FF_SEMICOLON || keyCode == DASH || keyCode == EQUALS || |
| 223 keyCode == FF_EQUALS || keyCode == COMMA || keyCode == PERIOD || |
| 224 keyCode == SLASH || keyCode == APOSTROPHE || keyCode == SINGLE_QUOTE || |
| 225 keyCode == OPEN_SQUARE_BRACKET || keyCode == BACKSLASH || |
| 226 keyCode == CLOSE_SQUARE_BRACKET); |
| 227 } |
198 } | 228 } |
OLD | NEW |