OLD | NEW |
---|---|
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 /** | 5 /** |
6 * @constructor | 6 * @constructor |
7 * @param {!WebInspector.ActionRegistry} actionRegistry | 7 * @param {!WebInspector.ActionRegistry} actionRegistry |
8 */ | 8 */ |
9 WebInspector.ShortcutRegistry = function(actionRegistry) | 9 WebInspector.ShortcutRegistry = function(actionRegistry) |
10 { | 10 { |
(...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
86 * @param {number} key | 86 * @param {number} key |
87 * @param {string} keyIdentifier | 87 * @param {string} keyIdentifier |
88 * @param {!KeyboardEvent=} event | 88 * @param {!KeyboardEvent=} event |
89 */ | 89 */ |
90 handleKey: function(key, keyIdentifier, event) | 90 handleKey: function(key, keyIdentifier, event) |
91 { | 91 { |
92 var keyModifiers = key >> 8; | 92 var keyModifiers = key >> 8; |
93 var actionIds = this.applicableActions(key); | 93 var actionIds = this.applicableActions(key); |
94 if (WebInspector.GlassPane.DefaultFocusedViewStack.length > 1) { | 94 if (WebInspector.GlassPane.DefaultFocusedViewStack.length > 1) { |
95 if (actionIds.length && !isPossiblyInputKey()) | 95 if (actionIds.length && !isPossiblyInputKey()) |
96 event.consume(true); | 96 event.consume(true); |
dgozman
2014/10/16 10:28:17
drive-by: looks like |event| here may be undefined
pfeldman
2014/10/16 10:46:47
Done.
| |
97 return; | 97 return; |
98 } | 98 } |
99 | 99 |
100 for (var i = 0; i < actionIds.length; ++i) { | 100 if (!isPossiblyInputKey()) |
101 if (!isPossiblyInputKey()) { | 101 processActionIdsSequentially.call(this); |
102 if (handler.call(this, actionIds[i])) | 102 else |
103 break; | 103 this._pendingActionTimer = setTimeout(processActionIdsSequentially.b ind(this), 0); |
104 } else { | 104 |
105 this._pendingActionTimer = setTimeout(handler.bind(this, actionI ds[i]), 0); | 105 /** |
106 break; | 106 * @this {WebInspector.ShortcutRegistry} |
107 */ | |
108 function processActionIdsSequentially() | |
109 { | |
110 delete this._pendingActionTimer; | |
111 var actionId = actionIds.shift(); | |
112 if (!actionId) | |
113 return; | |
114 | |
115 this._actionRegistry.execute(actionId).then(continueIfNecessary.bind (this)); | |
116 | |
117 /** | |
118 * @this {WebInspector.ShortcutRegistry} | |
119 */ | |
120 function continueIfNecessary(result) | |
121 { | |
122 if (result) { | |
123 if (event) | |
124 event.consume(true); | |
dgozman
2014/10/16 10:28:17
How does this work when consuming event asynchrono
dgozman
2014/10/16 10:41:16
Let's comment about "best effort" you are doing he
pfeldman
2014/10/16 10:46:46
Acknowledged.
pfeldman
2014/10/16 10:46:47
Done.
| |
125 return; | |
126 } | |
127 return processActionIdsSequentially.call(this); | |
dgozman
2014/10/16 10:28:17
nit: processActionIdsSequentially does not return
pfeldman
2014/10/16 10:46:47
It actually does return a Promise.<undefined> that
pfeldman
2014/10/16 10:56:49
nm, you are right.
| |
107 } | 128 } |
108 } | 129 } |
109 | 130 |
110 /** | 131 /** |
111 * @return {boolean} | 132 * @return {boolean} |
112 */ | 133 */ |
113 function isPossiblyInputKey() | 134 function isPossiblyInputKey() |
114 { | 135 { |
115 if (!event || !WebInspector.isBeingEdited(/** @type {!Node} */ (even t.target)) || /^F\d+|Control|Shift|Alt|Meta|Win|U\+001B$/.test(keyIdentifier)) | 136 if (!event || !WebInspector.isBeingEdited(/** @type {!Node} */ (even t.target)) || /^F\d+|Control|Shift|Alt|Meta|Win|U\+001B$/.test(keyIdentifier)) |
116 return false; | 137 return false; |
117 | 138 |
118 if (!keyModifiers) | 139 if (!keyModifiers) |
119 return true; | 140 return true; |
120 | 141 |
121 var modifiers = WebInspector.KeyboardShortcut.Modifiers; | 142 var modifiers = WebInspector.KeyboardShortcut.Modifiers; |
122 if ((keyModifiers & (modifiers.Ctrl | modifiers.Alt)) === (modifiers .Ctrl | modifiers.Alt)) | 143 if ((keyModifiers & (modifiers.Ctrl | modifiers.Alt)) === (modifiers .Ctrl | modifiers.Alt)) |
123 return WebInspector.isWin(); | 144 return WebInspector.isWin(); |
124 | 145 |
125 return !hasModifier(modifiers.Ctrl) && !hasModifier(modifiers.Alt) & & !hasModifier(modifiers.Meta); | 146 return !hasModifier(modifiers.Ctrl) && !hasModifier(modifiers.Alt) & & !hasModifier(modifiers.Meta); |
126 } | 147 } |
127 | 148 |
128 /** | 149 /** |
129 * @param {number} mod | 150 * @param {number} mod |
130 * @return {boolean} | 151 * @return {boolean} |
131 */ | 152 */ |
132 function hasModifier(mod) | 153 function hasModifier(mod) |
133 { | 154 { |
134 return !!(keyModifiers & mod); | 155 return !!(keyModifiers & mod); |
135 } | 156 } |
136 | |
137 /** | |
138 * @param {string} actionId | |
139 * @return {boolean} | |
140 * @this {WebInspector.ShortcutRegistry} | |
141 */ | |
142 function handler(actionId) | |
143 { | |
144 var result = this._actionRegistry.execute(actionId); | |
145 if (result && event) | |
146 event.consume(true); | |
147 delete this._pendingActionTimer; | |
148 return result; | |
149 } | |
150 }, | 157 }, |
151 | 158 |
152 /** | 159 /** |
153 * @param {string} actionId | 160 * @param {string} actionId |
154 * @param {string} shortcut | 161 * @param {string} shortcut |
155 */ | 162 */ |
156 registerShortcut: function(actionId, shortcut) | 163 registerShortcut: function(actionId, shortcut) |
157 { | 164 { |
158 var descriptor = WebInspector.KeyboardShortcut.makeDescriptorFromBinding Shortcut(shortcut); | 165 var descriptor = WebInspector.KeyboardShortcut.makeDescriptorFromBinding Shortcut(shortcut); |
159 if (!descriptor) | 166 if (!descriptor) |
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
214 * @constructor | 221 * @constructor |
215 */ | 222 */ |
216 WebInspector.ShortcutRegistry.ForwardedShortcut = function() | 223 WebInspector.ShortcutRegistry.ForwardedShortcut = function() |
217 { | 224 { |
218 } | 225 } |
219 | 226 |
220 WebInspector.ShortcutRegistry.ForwardedShortcut.instance = new WebInspector.Shor tcutRegistry.ForwardedShortcut(); | 227 WebInspector.ShortcutRegistry.ForwardedShortcut.instance = new WebInspector.Shor tcutRegistry.ForwardedShortcut(); |
221 | 228 |
222 /** @type {!WebInspector.ShortcutRegistry} */ | 229 /** @type {!WebInspector.ShortcutRegistry} */ |
223 WebInspector.shortcutRegistry; | 230 WebInspector.shortcutRegistry; |
OLD | NEW |