Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(244)

Side by Side Diff: Source/devtools/front_end/ui/KeyboardShortcut.js

Issue 377253002: DevTools: Add support for showing shortcuts based on shortcuts registry and use it for pause/resume… (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: Created 6 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 /* 1 /*
2 * Copyright (C) 2009 Apple Inc. All rights reserved. 2 * Copyright (C) 2009 Apple Inc. All rights reserved.
3 * Copyright (C) 2009 Google Inc. All rights reserved. 3 * Copyright (C) 2009 Google Inc. All rights reserved.
4 * 4 *
5 * Redistribution and use in source and binary forms, with or without 5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions 6 * modification, are permitted provided that the following conditions
7 * are met: 7 * are met:
8 * 8 *
9 * 1. Redistributions of source code must retain the above copyright 9 * 1. Redistributions of source code must retain the above copyright
10 * notice, this list of conditions and the following disclaimer. 10 * notice, this list of conditions and the following disclaimer.
(...skipping 101 matching lines...) Expand 10 before | Expand all | Expand 10 after
112 }, 112 },
113 }; 113 };
114 114
115 WebInspector.KeyboardShortcut.KeyBindings = {}; 115 WebInspector.KeyboardShortcut.KeyBindings = {};
116 116
117 (function() { 117 (function() {
118 for (var key in WebInspector.KeyboardShortcut.Keys) { 118 for (var key in WebInspector.KeyboardShortcut.Keys) {
119 var descriptor = WebInspector.KeyboardShortcut.Keys[key]; 119 var descriptor = WebInspector.KeyboardShortcut.Keys[key];
120 if (typeof descriptor === "object" && descriptor["code"]) { 120 if (typeof descriptor === "object" && descriptor["code"]) {
121 var name = typeof descriptor["name"] === "string" ? descriptor["name "] : key; 121 var name = typeof descriptor["name"] === "string" ? descriptor["name "] : key;
122 WebInspector.KeyboardShortcut.KeyBindings[name] = { code: descriptor ["code"] }; 122 WebInspector.KeyboardShortcut.KeyBindings[name] = descriptor;
123 } 123 }
124 } 124 }
125 })(); 125 })();
126 126
127 /** 127 /**
128 * Creates a number encoding keyCode in the lower 8 bits and modifiers mask in t he higher 8 bits. 128 * Creates a number encoding keyCode in the lower 8 bits and modifiers mask in t he higher 8 bits.
129 * It is useful for matching pressed keys. 129 * It is useful for matching pressed keys.
130 * 130 *
131 * @param {number|string} keyCode The code of the key, or a character "a-z" whic h is converted to a keyCode value. 131 * @param {number|string} keyCode The code of the key, or a character "a-z" whic h is converted to a keyCode value.
132 * @param {number=} modifiers Optional list of modifiers passed as additional pa rameters. 132 * @param {number=} modifiers Optional list of modifiers passed as additional pa rameters.
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after
193 WebInspector.KeyboardShortcut.makeDescriptor = function(key, modifiers) 193 WebInspector.KeyboardShortcut.makeDescriptor = function(key, modifiers)
194 { 194 {
195 return { 195 return {
196 key: WebInspector.KeyboardShortcut.makeKey(typeof key === "string" ? key : key.code, modifiers), 196 key: WebInspector.KeyboardShortcut.makeKey(typeof key === "string" ? key : key.code, modifiers),
197 name: WebInspector.KeyboardShortcut.shortcutToString(key, modifiers) 197 name: WebInspector.KeyboardShortcut.shortcutToString(key, modifiers)
198 }; 198 };
199 } 199 }
200 200
201 /** 201 /**
202 * @param {string} shortcut 202 * @param {string} shortcut
203 * @return {number} 203 * @return {?WebInspector.KeyboardShortcut.Descriptor}
204 */ 204 */
205 WebInspector.KeyboardShortcut.makeKeyFromBindingShortcut = function(shortcut) 205 WebInspector.KeyboardShortcut.makeDescriptorFromBindingShortcut = function(short cut)
206 { 206 {
207 var parts = shortcut.split(/\+(?!$)/); 207 var parts = shortcut.split(/\+(?!$)/);
208 var modifiers = 0; 208 var modifiers = 0;
209 var keyString;
209 for (var i = 0; i < parts.length; ++i) { 210 for (var i = 0; i < parts.length; ++i) {
210 if (typeof WebInspector.KeyboardShortcut.Modifiers[parts[i]] !== "undefi ned") { 211 if (typeof WebInspector.KeyboardShortcut.Modifiers[parts[i]] !== "undefi ned") {
211 modifiers |= WebInspector.KeyboardShortcut.Modifiers[parts[i]]; 212 modifiers |= WebInspector.KeyboardShortcut.Modifiers[parts[i]];
212 continue; 213 continue;
213 } 214 }
214 console.assert(i === parts.length - 1, "Modifiers-only shortcuts are not allowed (encountered <" + shortcut + ">)"); 215 console.assert(i === parts.length - 1, "Only one key other than modifier is allowed in shortcut <" + shortcut + ">");
215 var key = WebInspector.KeyboardShortcut.Keys[parts[i]] || WebInspector.K eyboardShortcut.KeyBindings[parts[i]]; 216 keyString = parts[i];
216 if (key && key.shiftKey) 217 break;
217 modifiers |= WebInspector.KeyboardShortcut.Modifiers.Shift;
218 return WebInspector.KeyboardShortcut.makeKey(key ? key.code : parts[i].t oLowerCase(), modifiers)
219 } 218 }
220 console.assert(false); 219 console.assert(keyString, "Modifiers-only shortcuts are not allowed (encount ered <" + shortcut + ">)");
221 return 0; 220 if (!keyString)
221 return null;
222
223 var key = WebInspector.KeyboardShortcut.Keys[keyString] || WebInspector.Keyb oardShortcut.KeyBindings[keyString];
224 if (key && key.shiftKey)
225 modifiers |= WebInspector.KeyboardShortcut.Modifiers.Shift;
226 return WebInspector.KeyboardShortcut.makeDescriptor(key ? key : keyString, m odifiers);
222 } 227 }
223 228
224 /** 229 /**
225 * @param {string|!WebInspector.KeyboardShortcut.Key} key 230 * @param {string|!WebInspector.KeyboardShortcut.Key} key
226 * @param {number=} modifiers 231 * @param {number=} modifiers
227 * @return {string} 232 * @return {string}
228 */ 233 */
229 WebInspector.KeyboardShortcut.shortcutToString = function(key, modifiers) 234 WebInspector.KeyboardShortcut.shortcutToString = function(key, modifiers)
230 { 235 {
231 return WebInspector.KeyboardShortcut._modifiersToString(modifiers) + WebInsp ector.KeyboardShortcut._keyName(key); 236 return WebInspector.KeyboardShortcut._modifiersToString(modifiers) + WebInsp ector.KeyboardShortcut._keyName(key);
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after
282 res += isMac ? optKey : "Alt + "; 287 res += isMac ? optKey : "Alt + ";
283 if (modifiers & WebInspector.KeyboardShortcut.Modifiers.Shift) 288 if (modifiers & WebInspector.KeyboardShortcut.Modifiers.Shift)
284 res += isMac ? shiftKey : "Shift + "; 289 res += isMac ? shiftKey : "Shift + ";
285 if (modifiers & WebInspector.KeyboardShortcut.Modifiers.Meta) 290 if (modifiers & WebInspector.KeyboardShortcut.Modifiers.Meta)
286 res += isMac ? cmdKey : "Win + "; 291 res += isMac ? cmdKey : "Win + ";
287 292
288 return res; 293 return res;
289 }; 294 };
290 295
291 WebInspector.KeyboardShortcut.SelectAll = WebInspector.KeyboardShortcut.makeKey( "a", WebInspector.KeyboardShortcut.Modifiers.CtrlOrMeta); 296 WebInspector.KeyboardShortcut.SelectAll = WebInspector.KeyboardShortcut.makeKey( "a", WebInspector.KeyboardShortcut.Modifiers.CtrlOrMeta);
OLDNEW
« no previous file with comments | « Source/devtools/front_end/main/Main.js ('k') | Source/devtools/front_end/ui/ShortcutRegistry.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698