OLD | NEW |
| (Empty) |
1 /* | |
2 * Copyright (C) 2009 Apple Inc. All rights reserved. | |
3 * Copyright (C) 2009 Google Inc. All rights reserved. | |
4 * | |
5 * Redistribution and use in source and binary forms, with or without | |
6 * modification, are permitted provided that the following conditions | |
7 * are met: | |
8 * | |
9 * 1. Redistributions of source code must retain the above copyright | |
10 * notice, this list of conditions and the following disclaimer. | |
11 * 2. Redistributions in binary form must reproduce the above copyright | |
12 * notice, this list of conditions and the following disclaimer in the | |
13 * documentation and/or other materials provided with the distribution. | |
14 * 3. Neither the name of Apple Computer, Inc. ("Apple") nor the names of | |
15 * its contributors may be used to endorse or promote products derived | |
16 * from this software without specific prior written permission. | |
17 * | |
18 * THIS SOFTWARE IS PROVIDED BY APPLE AND ITS CONTRIBUTORS "AS IS" AND ANY | |
19 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED | |
20 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE | |
21 * DISCLAIMED. IN NO EVENT SHALL APPLE OR ITS CONTRIBUTORS BE LIABLE FOR ANY | |
22 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES | |
23 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; | |
24 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND | |
25 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | |
26 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF | |
27 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | |
28 */ | |
29 | |
30 WebInspector.KeyboardShortcut = function() | |
31 { | |
32 }; | |
33 | |
34 /** | |
35 * Constants for encoding modifier key set as a bit mask. | |
36 * @see #_makeKeyFromCodeAndModifiers | |
37 */ | |
38 WebInspector.KeyboardShortcut.Modifiers = { | |
39 None: 0, // Constant for empty modifiers set. | |
40 Shift: 1, | |
41 Ctrl: 2, | |
42 Alt: 4, | |
43 Meta: 8 // Command key on Mac, Win key on other platforms. | |
44 }; | |
45 | |
46 WebInspector.KeyboardShortcut.KeyCodes = { | |
47 Esc: 27, | |
48 Space: 32, | |
49 PageUp: 33, // also NUM_NORTH_EAST | |
50 PageDown: 34, // also NUM_SOUTH_EAST | |
51 End: 35, // also NUM_SOUTH_WEST | |
52 Home: 36, // also NUM_NORTH_WEST | |
53 Left: 37, // also NUM_WEST | |
54 Up: 38, // also NUM_NORTH | |
55 Right: 39, // also NUM_EAST | |
56 Down: 40, // also NUM_SOUTH | |
57 F1: 112, | |
58 F2: 113, | |
59 F3: 114, | |
60 F4: 115, | |
61 F5: 116, | |
62 F6: 117, | |
63 F7: 118, | |
64 F8: 119, | |
65 F9: 120, | |
66 F10: 121, | |
67 F11: 122, | |
68 F12: 123, | |
69 Semicolon: 186, // ; | |
70 Comma: 188, // , | |
71 Period: 190, // . | |
72 Slash: 191, // / | |
73 Apostrophe: 192, // ` | |
74 SingleQuote: 222, // ' | |
75 }; | |
76 | |
77 /** | |
78 * Creates a number encoding keyCode in the lower 8 bits and modifiers mask in t
he higher 8 bits. | |
79 * It is usefull for matching pressed keys. | |
80 * @param {number} keyCode Code of the key. | |
81 * @param {number} optModifiers Optional list of modifiers passed as additional
paramerters. | |
82 */ | |
83 WebInspector.KeyboardShortcut.makeKey = function(keyCode, optModifiers) | |
84 { | |
85 var modifiers = WebInspector.KeyboardShortcut.Modifiers.None; | |
86 for (var i = 1; i < arguments.length; i++) | |
87 modifiers |= arguments[i]; | |
88 return WebInspector.KeyboardShortcut._makeKeyFromCodeAndModifiers(keyCode, m
odifiers); | |
89 }; | |
90 | |
91 WebInspector.KeyboardShortcut.makeKeyFromEvent = function(keyboardEvent) | |
92 { | |
93 var modifiers = WebInspector.KeyboardShortcut.Modifiers.None; | |
94 if (keyboardEvent.shiftKey) | |
95 modifiers |= WebInspector.KeyboardShortcut.Modifiers.Shift; | |
96 if (keyboardEvent.ctrlKey) | |
97 modifiers |= WebInspector.KeyboardShortcut.Modifiers.Ctrl; | |
98 if (keyboardEvent.altKey) | |
99 modifiers |= WebInspector.KeyboardShortcut.Modifiers.Alt; | |
100 if (keyboardEvent.metaKey) | |
101 modifiers |= WebInspector.KeyboardShortcut.Modifiers.Meta; | |
102 return WebInspector.KeyboardShortcut._makeKeyFromCodeAndModifiers(keyboardEv
ent.keyCode, modifiers); | |
103 }; | |
104 | |
105 WebInspector.KeyboardShortcut._makeKeyFromCodeAndModifiers = function(keyCode, m
odifiers) | |
106 { | |
107 return (keyCode & 255) | (modifiers << 8); | |
108 }; | |
OLD | NEW |