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

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

Issue 2885353002: MD Bookmarks: Prevent keyboard shortcuts when the toolbar/dialogs are focused (Closed)
Patch Set: Complete rewrite Created 3 years, 6 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 /** 5 /**
6 * @fileoverview Element which shows context menus and handles keyboard 6 * @fileoverview Element which shows context menus and handles keyboard
7 * shortcuts. 7 * shortcuts.
8 */ 8 */
9 cr.define('bookmarks', function() { 9 cr.define('bookmarks', function() {
10 10
(...skipping 195 matching lines...) Expand 10 before | Expand all | Expand 10 after
206 folderId, this.getState().nodes)); 206 folderId, this.getState().nodes));
207 } else { 207 } else {
208 this.openUrls_(this.expandUrls_(itemIds), command); 208 this.openUrls_(this.expandUrls_(itemIds), command);
209 } 209 }
210 break; 210 break;
211 default: 211 default:
212 assert(false); 212 assert(false);
213 } 213 }
214 }, 214 },
215 215
216 /**
217 * @param {Event} e
218 * @param {!Set<string>} itemIds
219 * @return {boolean} True if the event was handled, triggering a keyboard
220 * shortcut.
221 */
222 handleKeyEvent: function(e, itemIds) {
223 for (var commandName in this.shortcuts_) {
224 var shortcut = this.shortcuts_[commandName];
225 if (Polymer.IronA11yKeysBehavior.keyboardEventMatchesKeys(
226 e, shortcut) &&
227 this.canExecute(commandName, itemIds)) {
228 this.handle(commandName, itemIds);
229
230 e.stopPropagation();
231 e.preventDefault();
232 return true;
233 }
234 }
235
236 return false;
237 },
238
216 //////////////////////////////////////////////////////////////////////////// 239 ////////////////////////////////////////////////////////////////////////////
217 // Private functions: 240 // Private functions:
218 241
219 /** 242 /**
220 * Minimize the set of |itemIds| by removing any node which has an ancestor 243 * Minimize the set of |itemIds| by removing any node which has an ancestor
221 * node already in the set. This ensures that instead of trying to delete 244 * node already in the set. This ensures that instead of trying to delete
222 * both a node and its descendant, we will only try to delete the topmost 245 * both a node and its descendant, we will only try to delete the topmost
223 * node, preventing an error in the bookmarkManagerPrivate.removeTrees API 246 * node, preventing an error in the bookmarkManagerPrivate.removeTrees API
224 * call. 247 * call.
225 * @param {!Set<string>} itemIds 248 * @param {!Set<string>} itemIds
(...skipping 103 matching lines...) Expand 10 before | Expand all | Expand 10 after
329 this.closeCommandMenu(); 352 this.closeCommandMenu();
330 this.handle(e.target.getAttribute('command'), assert(this.menuIds_)); 353 this.handle(e.target.getAttribute('command'), assert(this.menuIds_));
331 }, 354 },
332 355
333 /** 356 /**
334 * @param {!Event} e 357 * @param {!Event} e
335 * @private 358 * @private
336 */ 359 */
337 onKeydown_: function(e) { 360 onKeydown_: function(e) {
338 var selection = this.getState().selection.items; 361 var selection = this.getState().selection.items;
339 // TODO(tsergeant): Prevent keyboard shortcuts when a dialog is open or 362 if (e.target == document.body)
340 // text field is focused. 363 this.handleKeyEvent(e, selection);
341 for (var commandName in this.shortcuts_) {
342 var shortcut = this.shortcuts_[commandName];
343 if (Polymer.IronA11yKeysBehavior.keyboardEventMatchesKeys(
344 e, shortcut) &&
345 this.canExecute(commandName, selection)) {
346 this.handle(commandName, selection);
347
348 e.stopPropagation();
349 e.preventDefault();
350 return;
351 }
352 }
353 }, 364 },
354 365
355 /** 366 /**
356 * Close the menu on mousedown so clicks can propagate to the underlying UI. 367 * Close the menu on mousedown so clicks can propagate to the underlying UI.
357 * This allows the user to right click the list while a context menu is 368 * This allows the user to right click the list while a context menu is
358 * showing and get another context menu. 369 * showing and get another context menu.
359 * @param {Event} e 370 * @param {Event} e
360 * @private 371 * @private
361 */ 372 */
362 onMenuMousedown_: function(e) { 373 onMenuMousedown_: function(e) {
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after
421 432
422 /** @return {!bookmarks.CommandManager} */ 433 /** @return {!bookmarks.CommandManager} */
423 CommandManager.getInstance = function() { 434 CommandManager.getInstance = function() {
424 return assert(CommandManager.instance_); 435 return assert(CommandManager.instance_);
425 }; 436 };
426 437
427 return { 438 return {
428 CommandManager: CommandManager, 439 CommandManager: CommandManager,
429 }; 440 };
430 }); 441 });
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698