Chromium Code Reviews| Index: ui/webui/resources/js/util.js |
| diff --git a/ui/webui/resources/js/util.js b/ui/webui/resources/js/util.js |
| index 048a674ed1980061b6cb9802866a25fefdd75a55..5c06646e21e840afc73b0627708e24c72c431ea9 100644 |
| --- a/ui/webui/resources/js/util.js |
| +++ b/ui/webui/resources/js/util.js |
| @@ -372,3 +372,67 @@ function elide(original, maxLength) { |
| function quoteString(str) { |
| return str.replace(/([\\\.\+\*\?\[\^\]\$\(\)\{\}\=\!\<\>\|\:])/g, '\\$1'); |
| } |
| + |
|
Dan Beam
2016/06/29 18:28:09
nit: remove extra \n
dtapuska
2016/06/29 20:09:02
Done.
|
| + |
| +// Polyfill 'key' in KeyboardEvent for iOS. |
| +// This function is not intended to be complete but should |
| +// be sufficient enough to have iOS work correctly while |
| +// it does not support key yet. |
| +if (!('key' in KeyboardEvent.prototype)) { |
|
Dan Beam
2016/06/29 18:28:09
I think it's cool that you're doing runtime featur
dtapuska
2016/06/29 20:09:02
Done.
|
| + var keyGetter = { |
|
Dan Beam
2016/06/29 18:28:09
can we just inline keyGetter? -1 global
Object.d
dtapuska
2016/06/29 20:09:02
Done.
|
| + get: function () { |
| + // 0-9 |
| + if (this.keyCode >= 0x30 && this.keyCode <= 0x39) |
| + return String.fromCharCode(this.keyCode); |
|
Dan Beam
2016/06/29 18:28:09
indent off
dtapuska
2016/06/29 20:09:02
Done.
|
| + |
| + // A-Z |
| + if (this.keyCode >= 0x41 && this.keyCode <= 0x5a) { |
| + var result = String.fromCharCode(this.keyCode).toLowerCase(); |
| + if (this.shiftKey) |
| + result = result.toUpperCase(); |
| + return result; |
|
Dan Beam
2016/06/29 18:28:09
indent off
dtapuska
2016/06/29 20:09:02
Done.
|
| + } |
| + |
| + // Special characters |
| + switch(this.keyCode) { |
| + case 0x08: return 'Backspace'; |
| + case 0x09: return 'Tab'; |
| + case 0x0d: return 'Enter'; |
| + case 0x10: return 'Shift'; |
| + case 0x11: return 'Control'; |
| + case 0x12: return 'Alt'; |
| + case 0x1b: return 'Escape'; |
| + case 0x20: return ' '; |
| + case 0x21: return 'PageUp'; |
| + case 0x22: return 'PageDown'; |
| + case 0x23: return 'End'; |
| + case 0x24: return 'Home'; |
| + case 0x25: return 'ArrowLeft'; |
| + case 0x26: return 'ArrowUp'; |
| + case 0x27: return 'ArrowRight'; |
| + case 0x28: return 'ArrowDown'; |
| + case 0x2d: return 'Insert'; |
| + case 0x2e: return 'Delete'; |
| + case 0x5b: return 'Meta'; |
| + case 0x70: return 'F1'; |
| + case 0x71: return 'F2'; |
| + case 0x72: return 'F3'; |
| + case 0x73: return 'F4'; |
| + case 0x74: return 'F5'; |
| + case 0x75: return 'F6'; |
| + case 0x76: return 'F7'; |
| + case 0x77: return 'F8'; |
| + case 0x78: return 'F9'; |
| + case 0x79: return 'F10'; |
| + case 0x7a: return 'F11'; |
| + case 0x7b: return 'F12'; |
| + case 0xbb: return '='; |
| + case 0xbd: return '-'; |
| + case 0xdb: return '['; |
| + case 0xdd: return ']'; |
| + } |
| + return 'Unidentified'; |
| + } |
| + }; |
| + Object.defineProperty(KeyboardEvent.prototype, 'key', keyGetter); |
| +} |