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

Unified Diff: Source/devtools/front_end/KeyboardShortcut.js

Issue 218613013: DevTools: Decouple shortcuts from actions, introduce shortcut contexts (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: Rebased patch Created 6 years, 8 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « Source/devtools/front_end/InspectorView.js ('k') | Source/devtools/front_end/Main.js » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: Source/devtools/front_end/KeyboardShortcut.js
diff --git a/Source/devtools/front_end/KeyboardShortcut.js b/Source/devtools/front_end/KeyboardShortcut.js
index be2262d860b5f2b1950aa4ef0408367b4b3c44d9..5171bd96a3c3306c279d070a8db9d7507be61bef 100644
--- a/Source/devtools/front_end/KeyboardShortcut.js
+++ b/Source/devtools/front_end/KeyboardShortcut.js
@@ -280,33 +280,51 @@ WebInspector.KeyboardShortcut._modifiersToString = function(modifiers)
/**
* @param {!KeyboardEvent} event
+ * @return {!Array.<!WebInspector.ModuleManager.Extension>}
*/
-WebInspector.KeyboardShortcut.handleShortcut = function(event)
+WebInspector.KeyboardShortcut.applicableActions = function(event)
{
var key = WebInspector.KeyboardShortcut.makeKeyFromEvent(event);
- var extensions = WebInspector.KeyboardShortcut._keysToActionExtensions[key];
+ var extensions = WebInspector.KeyboardShortcut._keyToAction[key];
if (!extensions)
- return;
+ return [];
- function handler(extension)
- {
- var result = extension.instance().handleAction(event);
- if (result)
- event.consume(true);
- delete WebInspector.KeyboardShortcut._pendingActionTimer;
- return result;
- }
+ return WebInspector.context.applicableExtensions(extensions).items();
+}
+
+/**
+ * @param {!KeyboardEvent} event
+ */
+WebInspector.KeyboardShortcut.handleShortcut = function(event)
+{
+ var extensions = WebInspector.KeyboardShortcut.applicableActions(event);
+ if (!extensions.length)
+ return;
for (var i = 0; i < extensions.length; ++i) {
+ var extension = extensions[i];
var ident = event.keyIdentifier;
if (/^F\d+|Control|Shift|Alt|Meta|Win|U\+001B$/.test(ident) || event.ctrlKey || event.altKey || event.metaKey) {
- if (handler(extensions[i]))
+ if (handler(extension))
return;
} else {
- WebInspector.KeyboardShortcut._pendingActionTimer = setTimeout(handler.bind(null, extensions[i]), 0);
+ WebInspector.KeyboardShortcut._pendingActionTimer = setTimeout(handler.bind(null, extension), 0);
break;
}
}
+
+ /**
+ * @param {!WebInspector.ModuleManager.Extension} extension
+ * @return {boolean}
+ */
+ function handler(extension)
+ {
+ var result = WebInspector.actionRegistry.execute(extension.descriptor()["actionId"], event);
+ if (result)
+ event.consume(true);
+ delete WebInspector.KeyboardShortcut._pendingActionTimer;
+ return result;
+ }
}
WebInspector.KeyboardShortcut.SelectAll = WebInspector.KeyboardShortcut.makeKey("a", WebInspector.KeyboardShortcut.Modifiers.CtrlOrMeta);
@@ -323,19 +341,19 @@ WebInspector.KeyboardShortcut._onKeyPress = function(event)
}
}
-WebInspector.KeyboardShortcut.registerActions = function()
+WebInspector.KeyboardShortcut.registerBindings = function()
{
document.addEventListener("keypress", WebInspector.KeyboardShortcut._onKeyPress, true);
- WebInspector.KeyboardShortcut._keysToActionExtensions = {};
+ WebInspector.KeyboardShortcut._keyToAction = {};
var extensions = WebInspector.moduleManager.extensions(WebInspector.ActionDelegate);
- extensions.forEach(registerBindings);
+ extensions.forEach(registerExtension);
/**
* @param {!WebInspector.ModuleManager.Extension} extension
*/
- function registerBindings(extension)
+ function registerExtension(extension)
{
- var bindings = extension.descriptor().bindings;
+ var bindings = extension.descriptor()["bindings"];
for (var i = 0; bindings && i < bindings.length; ++i) {
if (!platformMatches(bindings[i].platform))
continue;
@@ -346,17 +364,16 @@ WebInspector.KeyboardShortcut.registerActions = function()
/**
* @param {!WebInspector.ModuleManager.Extension} extension
- * @param {string} shortcut
*/
function registerShortcut(extension, shortcut)
{
var key = WebInspector.KeyboardShortcut.makeKeyFromBindingShortcut(shortcut);
if (!key)
return;
- if (WebInspector.KeyboardShortcut._keysToActionExtensions[key])
- WebInspector.KeyboardShortcut._keysToActionExtensions[key].push(extension);
+ if (WebInspector.KeyboardShortcut._keyToAction[key])
+ WebInspector.KeyboardShortcut._keyToAction[key].push(extension);
else
- WebInspector.KeyboardShortcut._keysToActionExtensions[key] = [extension];
+ WebInspector.KeyboardShortcut._keyToAction[key] = [extension];
}
/**
« no previous file with comments | « Source/devtools/front_end/InspectorView.js ('k') | Source/devtools/front_end/Main.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698