Update To 11.40.268.0
[platform/framework/web/crosswalk.git] / src / third_party / WebKit / Source / devtools / front_end / ui / ShortcutRegistry.js
index 9f64b17..b34523a 100644 (file)
@@ -5,25 +5,44 @@
 /**
  * @constructor
  * @param {!WebInspector.ActionRegistry} actionRegistry
+ * @param {!Document} document
  */
-WebInspector.ShortcutRegistry = function(actionRegistry)
+WebInspector.ShortcutRegistry = function(actionRegistry, document)
 {
     this._actionRegistry = actionRegistry;
-    this._registerBindings();
+    /** @type {!StringMultimap.<string>} */
+    this._defaultKeyToActions = new StringMultimap();
+    /** @type {!StringMultimap.<!WebInspector.KeyboardShortcut.Descriptor>} */
+    this._defaultActionToShortcut = new StringMultimap();
+    this._registerBindings(document);
 }
 
 WebInspector.ShortcutRegistry.prototype = {
     /**
      * @param {number} key
-     * @return {!Array.<!WebInspector.ModuleManager.Extension>}
+     * @return {!Array.<string>}
      */
     applicableActions: function(key)
     {
-        var extensions = this._keyToAction[key];
-        if (!extensions)
-            return [];
+        return this._actionRegistry.applicableActions(this._defaultActionsForKey(key).valuesArray(), WebInspector.context);
+    },
+
+    /**
+     * @param {number} key
+     * @return {!Set.<string>}
+     */
+    _defaultActionsForKey: function(key)
+    {
+        return this._defaultKeyToActions.get(String(key));
+    },
 
-        return WebInspector.context.applicableExtensions(extensions).items();
+    /**
+     * @param {string} actionId
+     * @return {!Array.<!WebInspector.KeyboardShortcut.Descriptor>}
+     */
+    shortcutDescriptorsForAction: function(actionId)
+    {
+        return this._defaultActionToShortcut.get(actionId).valuesArray();
     },
 
     /**
@@ -32,16 +51,11 @@ WebInspector.ShortcutRegistry.prototype = {
      */
     keysForActions: function(actionIds)
     {
-        var actionIdSet = actionIds.keySet();
         var result = [];
-        for (var key in this._keyToAction) {
-            var extensions = this._keyToAction[key];
-            extensions.some(function(extension) {
-               if (actionIdSet.hasOwnProperty(extension.descriptor()["actionId"])) {
-                   result.push(key);
-                   return true;
-               }
-            });
+        for (var i = 0; i < actionIds.length; ++i) {
+            var descriptors = this.shortcutDescriptorsForAction(actionIds[i]);
+            for (var j = 0; j < descriptors.length; ++j)
+                result.push(descriptors[j].key);
         }
         return result;
     },
@@ -61,18 +75,44 @@ WebInspector.ShortcutRegistry.prototype = {
      */
     handleKey: function(key, keyIdentifier, event)
     {
-        var extensions = this.applicableActions(key);
-        if (!extensions.length)
+        var keyModifiers = key >> 8;
+        var actionIds = this.applicableActions(key);
+        if (!actionIds.length)
             return;
+        if (WebInspector.GlassPane.DefaultFocusedViewStack.length > 1) {
+            if (event && !isPossiblyInputKey())
+                event.consume(true);
+            return;
+        }
 
-        for (var i = 0; i < extensions.length; ++i) {
-            var keyModifiers = key >> 8;
-            if (!isPossiblyInputKey()) {
-                if (handler.call(this, extensions[i]))
-                    break;
-            } else {
-                this._pendingActionTimer = setTimeout(handler.bind(this, extensions[i]), 0);
-                break;
+        if (!isPossiblyInputKey()) {
+            if (event)
+                event.consume(true);
+            processActionIdsSequentially.call(this);
+        } else {
+            this._pendingActionTimer = setTimeout(processActionIdsSequentially.bind(this), 0);
+        }
+
+        /**
+         * @this {WebInspector.ShortcutRegistry}
+         */
+        function processActionIdsSequentially()
+        {
+            delete this._pendingActionTimer;
+            var actionId = actionIds.shift();
+            if (!actionId)
+                return;
+
+            this._actionRegistry.execute(actionId).then(continueIfNecessary.bind(this));
+
+            /**
+             * @this {WebInspector.ShortcutRegistry}
+             */
+            function continueIfNecessary(result)
+            {
+                if (result)
+                    return;
+                processActionIdsSequentially.call(this);
             }
         }
 
@@ -81,7 +121,7 @@ WebInspector.ShortcutRegistry.prototype = {
          */
         function isPossiblyInputKey()
         {
-            if (!event || !WebInspector.isBeingEdited(event.target) || /^F\d+|Control|Shift|Alt|Meta|Win|U\+001B$/.test(keyIdentifier))
+            if (!event || !WebInspector.isEditing() || /^F\d+|Control|Shift|Alt|Meta|Win|U\+001B$/.test(keyIdentifier))
                 return false;
 
             if (!keyModifiers)
@@ -102,26 +142,22 @@ WebInspector.ShortcutRegistry.prototype = {
         {
             return !!(keyModifiers & mod);
         }
-
-        /**
-         * @param {!WebInspector.ModuleManager.Extension} extension
-         * @return {boolean}
-         * @this {WebInspector.ShortcutRegistry}
-         */
-        function handler(extension)
-        {
-            var result = this._actionRegistry.execute(extension.descriptor()["actionId"]);
-            if (result && event)
-                event.consume(true);
-            delete this._pendingActionTimer;
-            return result;
-        }
     },
 
     /**
-     * @param {?Event} event
+     * @param {string} actionId
+     * @param {string} shortcut
      */
-    _onInput: function(event)
+    registerShortcut: function(actionId, shortcut)
+    {
+        var descriptor = WebInspector.KeyboardShortcut.makeDescriptorFromBindingShortcut(shortcut);
+        if (!descriptor)
+            return;
+        this._defaultActionToShortcut.set(actionId, descriptor);
+        this._defaultKeyToActions.set(String(descriptor.key), actionId);
+    },
+
+    dismissPendingShortcutAction: function()
     {
         if (this._pendingActionTimer) {
             clearTimeout(this._pendingActionTimer);
@@ -129,45 +165,32 @@ WebInspector.ShortcutRegistry.prototype = {
         }
     },
 
-    _registerBindings: function()
+    /**
+     * @param {!Document} document
+     */
+    _registerBindings: function(document)
     {
-        document.addEventListener("input", this._onInput.bind(this), true);
-        this._keyToAction = {};
-        var extensions = WebInspector.moduleManager.extensions(WebInspector.ActionDelegate);
+        document.addEventListener("input", this.dismissPendingShortcutAction.bind(this), true);
+        var extensions = self.runtime.extensions(WebInspector.ActionDelegate);
         extensions.forEach(registerExtension, this);
 
         /**
-         * @param {!WebInspector.ModuleManager.Extension} extension
+         * @param {!Runtime.Extension} extension
          * @this {WebInspector.ShortcutRegistry}
          */
         function registerExtension(extension)
         {
-            var bindings = extension.descriptor()["bindings"];
+            var descriptor = extension.descriptor();
+            var bindings = descriptor["bindings"];
             for (var i = 0; bindings && i < bindings.length; ++i) {
                 if (!platformMatches(bindings[i].platform))
                     continue;
                 var shortcuts = bindings[i]["shortcut"].split(/\s+/);
-                shortcuts.forEach(registerShortcut.bind(this, extension));
+                shortcuts.forEach(this.registerShortcut.bind(this, descriptor["actionId"]));
             }
         }
 
         /**
-         * @param {!WebInspector.ModuleManager.Extension} extension
-         * @param {string} shortcut
-         * @this {WebInspector.ShortcutRegistry}
-         */
-        function registerShortcut(extension, shortcut)
-        {
-            var key = WebInspector.KeyboardShortcut.makeKeyFromBindingShortcut(shortcut);
-            if (!key)
-                return;
-            if (this._keyToAction[key])
-                this._keyToAction[key].push(extension);
-            else
-                this._keyToAction[key] = [extension];
-        }
-
-        /**
          * @param {string=} platformsString
          * @return {boolean}
          */
@@ -185,5 +208,14 @@ WebInspector.ShortcutRegistry.prototype = {
     }
 }
 
+/**
+ * @constructor
+ */
+WebInspector.ShortcutRegistry.ForwardedShortcut = function()
+{
+}
+
+WebInspector.ShortcutRegistry.ForwardedShortcut.instance = new WebInspector.ShortcutRegistry.ForwardedShortcut();
+
 /** @type {!WebInspector.ShortcutRegistry} */
 WebInspector.shortcutRegistry;