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