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

Side by Side Diff: chrome/browser/resources/md_bookmarks/command_manager.js

Issue 2843903002: MD Bookmarks: Add keyboard shortcut support to bookmarks-command-manager (Closed)
Patch Set: More tests Created 3 years, 7 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 unified diff | Download patch
OLDNEW
1 // Copyright 2017 The Chromium Authors. All rights reserved. 1 // Copyright 2017 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 Polymer({ 5 Polymer({
6 is: 'bookmarks-command-manager', 6 is: 'bookmarks-command-manager',
7 7
8 behaviors: [ 8 behaviors: [
9 bookmarks.StoreClient, 9 bookmarks.StoreClient,
10 ], 10 ],
11 11
12 properties: { 12 properties: {
13 /** @type {Set<string>} */ 13 /** @type {Set<string>} */
14 menuIds_: Object, 14 menuIds_: Object,
15 }, 15 },
16 16
17 attached: function() { 17 attached: function() {
18 /** @private {function(!Event)} */ 18 /** @private {function(!Event)} */
19 this.boundOnOpenItemMenu_ = this.onOpenItemMenu_.bind(this); 19 this.boundOnOpenItemMenu_ = this.onOpenItemMenu_.bind(this);
20 document.addEventListener('open-item-menu', this.boundOnOpenItemMenu_); 20 document.addEventListener('open-item-menu', this.boundOnOpenItemMenu_);
21
22 /** @private {function(!Event)} */
23 this.boundOnKeydown_ = this.onKeydown_.bind(this);
24 document.addEventListener('keydown', this.boundOnKeydown_);
25
26 this.shortcuts_ = {};
calamity 2017/04/26 10:07:58 This isn't declared or annotated anywhere.
tsergeant 2017/04/27 01:42:51 Done.
27 this.shortcuts_[Command.EDIT] = cr.isMac ? 'enter' : 'f2';
28 this.shortcuts_[Command.COPY] = cr.isMac ? 'meta+c' : 'ctrl+c';
29 this.shortcuts_[Command.DELETE] = cr.isMac ? 'delete backspace' : 'delete';
21 }, 30 },
22 31
23 detached: function() { 32 detached: function() {
24 document.removeEventListener('open-item-menu', this.boundOnOpenItemMenu_); 33 document.removeEventListener('open-item-menu', this.boundOnOpenItemMenu_);
34 document.removeEventListener('keydown', this.boundOnKeydown_);
25 }, 35 },
26 36
27 /** 37 /**
28 * Display the command context menu at (|x|, |y|) in window co-ordinates. 38 * Display the command context menu at (|x|, |y|) in window co-ordinates.
29 * Commands will execute on the currently selected items. 39 * Commands will execute on the currently selected items.
30 * @param {number} x 40 * @param {number} x
31 * @param {number} y 41 * @param {number} y
32 */ 42 */
33 openCommandMenuAtPosition: function(x, y) { 43 openCommandMenuAtPosition: function(x, y) {
34 this.menuIds_ = this.getState().selection.items; 44 this.menuIds_ = this.getState().selection.items;
(...skipping 100 matching lines...) Expand 10 before | Expand all | Expand 10 after
135 /** 145 /**
136 * @param {Event} e 146 * @param {Event} e
137 * @private 147 * @private
138 */ 148 */
139 onCommandClick_: function(e) { 149 onCommandClick_: function(e) {
140 this.closeCommandMenu(); 150 this.closeCommandMenu();
141 this.handle(e.target.getAttribute('command'), assert(this.menuIds_)); 151 this.handle(e.target.getAttribute('command'), assert(this.menuIds_));
142 }, 152 },
143 153
144 /** 154 /**
155 * @param {!Event} e
156 * @private
157 */
158 onKeydown_: function(e) {
159 var selection = this.getState().selection.items;
160 // TODO(tsergeant): Prevent keyboard shortcuts when a dialog is open or text
161 // field is focused.
162 for (var commandName in this.shortcuts_) {
163 var shortcut = this.shortcuts_[commandName];
164 if (Polymer.IronA11yKeysBehavior.keyboardEventMatchesKeys(e, shortcut) &&
165 this.canExecute(commandName, selection)) {
166 this.handle(commandName, selection);
167
168 e.stopPropagation();
169 e.preventDefault();
170 return;
171 }
172 }
173 },
174
175 /**
145 * Close the menu on mousedown so clicks can propagate to the underlying UI. 176 * Close the menu on mousedown so clicks can propagate to the underlying UI.
146 * This allows the user to right click the list while a context menu is 177 * This allows the user to right click the list while a context menu is
147 * showing and get another context menu. 178 * showing and get another context menu.
148 * @param {Event} e 179 * @param {Event} e
149 * @private 180 * @private
150 */ 181 */
151 onMenuMousedown_: function(e) { 182 onMenuMousedown_: function(e) {
152 if (e.path[0] != this.$.dropdown) 183 if (e.path[0] != this.$.dropdown)
153 return; 184 return;
154 185
155 this.$.dropdown.close(); 186 this.$.dropdown.close();
156 }, 187 },
157 188
158 /** @private */ 189 /** @private */
159 getEditActionLabel_: function() { 190 getEditActionLabel_: function() {
160 if (this.menuIds_.size > 1) 191 if (this.menuIds_.size > 1)
161 return; 192 return;
162 193
163 var id = Array.from(this.menuIds_)[0]; 194 var id = Array.from(this.menuIds_)[0];
164 var itemUrl = this.getState().nodes[id].url; 195 var itemUrl = this.getState().nodes[id].url;
165 var label = itemUrl ? 'menuEdit' : 'menuRename'; 196 var label = itemUrl ? 'menuEdit' : 'menuRename';
166 return loadTimeData.getString(label); 197 return loadTimeData.getString(label);
167 }, 198 },
168 }); 199 });
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698