OLD | NEW |
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 262 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
273 if (modifiers & WebInspector.KeyboardShortcut.Modifiers.Shift) | 273 if (modifiers & WebInspector.KeyboardShortcut.Modifiers.Shift) |
274 res += isMac ? shiftKey : "Shift + "; | 274 res += isMac ? shiftKey : "Shift + "; |
275 if (modifiers & WebInspector.KeyboardShortcut.Modifiers.Meta) | 275 if (modifiers & WebInspector.KeyboardShortcut.Modifiers.Meta) |
276 res += isMac ? cmdKey : "Win + "; | 276 res += isMac ? cmdKey : "Win + "; |
277 | 277 |
278 return res; | 278 return res; |
279 }; | 279 }; |
280 | 280 |
281 /** | 281 /** |
282 * @param {!KeyboardEvent} event | 282 * @param {!KeyboardEvent} event |
| 283 * @return {!Array.<!WebInspector.ModuleManager.Extension>} |
| 284 */ |
| 285 WebInspector.KeyboardShortcut.applicableActions = function(event) |
| 286 { |
| 287 var key = WebInspector.KeyboardShortcut.makeKeyFromEvent(event); |
| 288 var extensions = WebInspector.KeyboardShortcut._keyToAction[key]; |
| 289 if (!extensions) |
| 290 return []; |
| 291 |
| 292 return WebInspector.context.applicableExtensions(extensions).items(); |
| 293 } |
| 294 |
| 295 /** |
| 296 * @param {!KeyboardEvent} event |
283 */ | 297 */ |
284 WebInspector.KeyboardShortcut.handleShortcut = function(event) | 298 WebInspector.KeyboardShortcut.handleShortcut = function(event) |
285 { | 299 { |
286 var key = WebInspector.KeyboardShortcut.makeKeyFromEvent(event); | 300 var extensions = WebInspector.KeyboardShortcut.applicableActions(event); |
287 var extensions = WebInspector.KeyboardShortcut._keysToActionExtensions[key]; | 301 if (!extensions.length) |
288 if (!extensions) | |
289 return; | 302 return; |
290 | 303 |
| 304 for (var i = 0; i < extensions.length; ++i) { |
| 305 var extension = extensions[i]; |
| 306 var ident = event.keyIdentifier; |
| 307 if (/^F\d+|Control|Shift|Alt|Meta|Win|U\+001B$/.test(ident) || event.ctr
lKey || event.altKey || event.metaKey) { |
| 308 if (handler(extension)) |
| 309 return; |
| 310 } else { |
| 311 WebInspector.KeyboardShortcut._pendingActionTimer = setTimeout(handl
er.bind(null, extension), 0); |
| 312 break; |
| 313 } |
| 314 } |
| 315 |
| 316 /** |
| 317 * @param {!WebInspector.ModuleManager.Extension} extension |
| 318 * @return {boolean} |
| 319 */ |
291 function handler(extension) | 320 function handler(extension) |
292 { | 321 { |
293 var result = extension.instance().handleAction(event); | 322 var result = WebInspector.actionRegistry.execute(extension.descriptor()[
"actionId"], event); |
294 if (result) | 323 if (result) |
295 event.consume(true); | 324 event.consume(true); |
296 delete WebInspector.KeyboardShortcut._pendingActionTimer; | 325 delete WebInspector.KeyboardShortcut._pendingActionTimer; |
297 return result; | 326 return result; |
298 } | 327 } |
299 | |
300 for (var i = 0; i < extensions.length; ++i) { | |
301 var ident = event.keyIdentifier; | |
302 if (/^F\d+|Control|Shift|Alt|Meta|Win|U\+001B$/.test(ident) || event.ctr
lKey || event.altKey || event.metaKey) { | |
303 if (handler(extensions[i])) | |
304 return; | |
305 } else { | |
306 WebInspector.KeyboardShortcut._pendingActionTimer = setTimeout(handl
er.bind(null, extensions[i]), 0); | |
307 break; | |
308 } | |
309 } | |
310 } | 328 } |
311 | 329 |
312 WebInspector.KeyboardShortcut.SelectAll = WebInspector.KeyboardShortcut.makeKey(
"a", WebInspector.KeyboardShortcut.Modifiers.CtrlOrMeta); | 330 WebInspector.KeyboardShortcut.SelectAll = WebInspector.KeyboardShortcut.makeKey(
"a", WebInspector.KeyboardShortcut.Modifiers.CtrlOrMeta); |
313 | 331 |
314 WebInspector.KeyboardShortcut._onKeyPress = function(event) | 332 WebInspector.KeyboardShortcut._onKeyPress = function(event) |
315 { | 333 { |
316 if (!WebInspector.KeyboardShortcut._pendingActionTimer) | 334 if (!WebInspector.KeyboardShortcut._pendingActionTimer) |
317 return; | 335 return; |
318 | 336 |
319 var target = event.target; | 337 var target = event.target; |
320 if (WebInspector.isBeingEdited(event.target)) { | 338 if (WebInspector.isBeingEdited(event.target)) { |
321 clearTimeout(WebInspector.KeyboardShortcut._pendingActionTimer); | 339 clearTimeout(WebInspector.KeyboardShortcut._pendingActionTimer); |
322 delete WebInspector.KeyboardShortcut._pendingActionTimer; | 340 delete WebInspector.KeyboardShortcut._pendingActionTimer; |
323 } | 341 } |
324 } | 342 } |
325 | 343 |
326 WebInspector.KeyboardShortcut.registerActions = function() | 344 WebInspector.KeyboardShortcut.registerBindings = function() |
327 { | 345 { |
328 document.addEventListener("keypress", WebInspector.KeyboardShortcut._onKeyPr
ess, true); | 346 document.addEventListener("keypress", WebInspector.KeyboardShortcut._onKeyPr
ess, true); |
329 WebInspector.KeyboardShortcut._keysToActionExtensions = {}; | 347 WebInspector.KeyboardShortcut._keyToAction = {}; |
330 var extensions = WebInspector.moduleManager.extensions(WebInspector.ActionDe
legate); | 348 var extensions = WebInspector.moduleManager.extensions(WebInspector.ActionDe
legate); |
331 extensions.forEach(registerBindings); | 349 extensions.forEach(registerExtension); |
332 | 350 |
333 /** | 351 /** |
334 * @param {!WebInspector.ModuleManager.Extension} extension | 352 * @param {!WebInspector.ModuleManager.Extension} extension |
335 */ | 353 */ |
336 function registerBindings(extension) | 354 function registerExtension(extension) |
337 { | 355 { |
338 var bindings = extension.descriptor().bindings; | 356 var bindings = extension.descriptor()["bindings"]; |
339 for (var i = 0; bindings && i < bindings.length; ++i) { | 357 for (var i = 0; bindings && i < bindings.length; ++i) { |
340 if (!platformMatches(bindings[i].platform)) | 358 if (!platformMatches(bindings[i].platform)) |
341 continue; | 359 continue; |
342 var shortcuts = bindings[i].shortcut.split(/\s+/); | 360 var shortcuts = bindings[i].shortcut.split(/\s+/); |
343 shortcuts.forEach(registerShortcut.bind(null, extension)); | 361 shortcuts.forEach(registerShortcut.bind(null, extension)); |
344 } | 362 } |
345 } | 363 } |
346 | 364 |
347 /** | 365 /** |
348 * @param {!WebInspector.ModuleManager.Extension} extension | 366 * @param {!WebInspector.ModuleManager.Extension} extension |
349 * @param {string} shortcut | |
350 */ | 367 */ |
351 function registerShortcut(extension, shortcut) | 368 function registerShortcut(extension, shortcut) |
352 { | 369 { |
353 var key = WebInspector.KeyboardShortcut.makeKeyFromBindingShortcut(short
cut); | 370 var key = WebInspector.KeyboardShortcut.makeKeyFromBindingShortcut(short
cut); |
354 if (!key) | 371 if (!key) |
355 return; | 372 return; |
356 if (WebInspector.KeyboardShortcut._keysToActionExtensions[key]) | 373 if (WebInspector.KeyboardShortcut._keyToAction[key]) |
357 WebInspector.KeyboardShortcut._keysToActionExtensions[key].push(exte
nsion); | 374 WebInspector.KeyboardShortcut._keyToAction[key].push(extension); |
358 else | 375 else |
359 WebInspector.KeyboardShortcut._keysToActionExtensions[key] = [extens
ion]; | 376 WebInspector.KeyboardShortcut._keyToAction[key] = [extension]; |
360 } | 377 } |
361 | 378 |
362 /** | 379 /** |
363 * @param {string=} platformsString | 380 * @param {string=} platformsString |
364 * @return {boolean} | 381 * @return {boolean} |
365 */ | 382 */ |
366 function platformMatches(platformsString) | 383 function platformMatches(platformsString) |
367 { | 384 { |
368 if (!platformsString) | 385 if (!platformsString) |
369 return true; | 386 return true; |
370 var platforms = platformsString.split(","); | 387 var platforms = platformsString.split(","); |
371 var isMatch = false; | 388 var isMatch = false; |
372 var currentPlatform = WebInspector.platform(); | 389 var currentPlatform = WebInspector.platform(); |
373 for (var i = 0; !isMatch && i < platforms.length; ++i) | 390 for (var i = 0; !isMatch && i < platforms.length; ++i) |
374 isMatch = platforms[i] === currentPlatform; | 391 isMatch = platforms[i] === currentPlatform; |
375 return isMatch; | 392 return isMatch; |
376 } | 393 } |
377 } | 394 } |
OLD | NEW |