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 74 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
85 /** | 85 /** |
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 (event && actionIds.length && !isPossiblyInputKey()) |
96 event.consume(true); | 96 event.consume(true); |
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 // Note that this is a best effort solution - lazily loaded modu
les won't have a chance to |
| 123 // consume platform event. |
| 124 if (result) { |
| 125 if (event) |
| 126 event.consume(true); |
| 127 return; |
| 128 } |
| 129 processActionIdsSequentially.call(this); |
107 } | 130 } |
108 } | 131 } |
109 | 132 |
110 /** | 133 /** |
111 * @return {boolean} | 134 * @return {boolean} |
112 */ | 135 */ |
113 function isPossiblyInputKey() | 136 function isPossiblyInputKey() |
114 { | 137 { |
115 if (!event || !WebInspector.isBeingEdited(/** @type {!Node} */ (even
t.target)) || /^F\d+|Control|Shift|Alt|Meta|Win|U\+001B$/.test(keyIdentifier)) | 138 if (!event || !WebInspector.isBeingEdited(/** @type {!Node} */ (even
t.target)) || /^F\d+|Control|Shift|Alt|Meta|Win|U\+001B$/.test(keyIdentifier)) |
116 return false; | 139 return false; |
117 | 140 |
118 if (!keyModifiers) | 141 if (!keyModifiers) |
119 return true; | 142 return true; |
120 | 143 |
121 var modifiers = WebInspector.KeyboardShortcut.Modifiers; | 144 var modifiers = WebInspector.KeyboardShortcut.Modifiers; |
122 if ((keyModifiers & (modifiers.Ctrl | modifiers.Alt)) === (modifiers
.Ctrl | modifiers.Alt)) | 145 if ((keyModifiers & (modifiers.Ctrl | modifiers.Alt)) === (modifiers
.Ctrl | modifiers.Alt)) |
123 return WebInspector.isWin(); | 146 return WebInspector.isWin(); |
124 | 147 |
125 return !hasModifier(modifiers.Ctrl) && !hasModifier(modifiers.Alt) &
& !hasModifier(modifiers.Meta); | 148 return !hasModifier(modifiers.Ctrl) && !hasModifier(modifiers.Alt) &
& !hasModifier(modifiers.Meta); |
126 } | 149 } |
127 | 150 |
128 /** | 151 /** |
129 * @param {number} mod | 152 * @param {number} mod |
130 * @return {boolean} | 153 * @return {boolean} |
131 */ | 154 */ |
132 function hasModifier(mod) | 155 function hasModifier(mod) |
133 { | 156 { |
134 return !!(keyModifiers & mod); | 157 return !!(keyModifiers & mod); |
135 } | 158 } |
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 }, | 159 }, |
151 | 160 |
152 /** | 161 /** |
153 * @param {string} actionId | 162 * @param {string} actionId |
154 * @param {string} shortcut | 163 * @param {string} shortcut |
155 */ | 164 */ |
156 registerShortcut: function(actionId, shortcut) | 165 registerShortcut: function(actionId, shortcut) |
157 { | 166 { |
158 var descriptor = WebInspector.KeyboardShortcut.makeDescriptorFromBinding
Shortcut(shortcut); | 167 var descriptor = WebInspector.KeyboardShortcut.makeDescriptorFromBinding
Shortcut(shortcut); |
159 if (!descriptor) | 168 if (!descriptor) |
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
214 * @constructor | 223 * @constructor |
215 */ | 224 */ |
216 WebInspector.ShortcutRegistry.ForwardedShortcut = function() | 225 WebInspector.ShortcutRegistry.ForwardedShortcut = function() |
217 { | 226 { |
218 } | 227 } |
219 | 228 |
220 WebInspector.ShortcutRegistry.ForwardedShortcut.instance = new WebInspector.Shor
tcutRegistry.ForwardedShortcut(); | 229 WebInspector.ShortcutRegistry.ForwardedShortcut.instance = new WebInspector.Shor
tcutRegistry.ForwardedShortcut(); |
221 | 230 |
222 /** @type {!WebInspector.ShortcutRegistry} */ | 231 /** @type {!WebInspector.ShortcutRegistry} */ |
223 WebInspector.shortcutRegistry; | 232 WebInspector.shortcutRegistry; |
OLD | NEW |