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

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: Add a test 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
« no previous file with comments | « no previous file | chrome/browser/resources/md_bookmarks/compiled_resources2.gyp » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 199 matching lines...) Expand 10 before | Expand all | Expand 10 after
210 folderId, this.getState().nodes)); 210 folderId, this.getState().nodes));
211 } else { 211 } else {
212 this.openUrls_(this.expandUrls_(itemIds), command); 212 this.openUrls_(this.expandUrls_(itemIds), command);
213 } 213 }
214 break; 214 break;
215 default: 215 default:
216 assert(false); 216 assert(false);
217 } 217 }
218 }, 218 },
219 219
220 /**
221 * @param {Event} e
222 * @param {!Set<string>} itemIds
223 * @return {boolean} True if the event was handled, triggering a keyboard
224 * shortcut.
225 */
226 handleKeyEvent: function(e, itemIds) {
227 for (var commandName in this.shortcuts_) {
228 var shortcut = this.shortcuts_[commandName];
229 if (Polymer.IronA11yKeysBehavior.keyboardEventMatchesKeys(
230 e, shortcut) &&
231 this.canExecute(commandName, itemIds)) {
232 this.handle(commandName, itemIds);
233
234 e.stopPropagation();
235 e.preventDefault();
236 return true;
237 }
238 }
239
240 return false;
241 },
242
220 //////////////////////////////////////////////////////////////////////////// 243 ////////////////////////////////////////////////////////////////////////////
221 // Private functions: 244 // Private functions:
222 245
223 /** 246 /**
224 * Minimize the set of |itemIds| by removing any node which has an ancestor 247 * Minimize the set of |itemIds| by removing any node which has an ancestor
225 * node already in the set. This ensures that instead of trying to delete 248 * node already in the set. This ensures that instead of trying to delete
226 * both a node and its descendant, we will only try to delete the topmost 249 * both a node and its descendant, we will only try to delete the topmost
227 * node, preventing an error in the bookmarkManagerPrivate.removeTrees API 250 * node, preventing an error in the bookmarkManagerPrivate.removeTrees API
228 * call. 251 * call.
229 * @param {!Set<string>} itemIds 252 * @param {!Set<string>} itemIds
(...skipping 103 matching lines...) Expand 10 before | Expand all | Expand 10 after
333 this.handle(e.target.getAttribute('command'), assert(this.menuIds_)); 356 this.handle(e.target.getAttribute('command'), assert(this.menuIds_));
334 this.closeCommandMenu(); 357 this.closeCommandMenu();
335 }, 358 },
336 359
337 /** 360 /**
338 * @param {!Event} e 361 * @param {!Event} e
339 * @private 362 * @private
340 */ 363 */
341 onKeydown_: function(e) { 364 onKeydown_: function(e) {
342 var selection = this.getState().selection.items; 365 var selection = this.getState().selection.items;
343 // TODO(tsergeant): Prevent keyboard shortcuts when a dialog is open or 366 if (e.target == document.body)
344 // text field is focused. 367 this.handleKeyEvent(e, selection);
345 for (var commandName in this.shortcuts_) {
346 var shortcut = this.shortcuts_[commandName];
347 if (Polymer.IronA11yKeysBehavior.keyboardEventMatchesKeys(
348 e, shortcut) &&
349 this.canExecute(commandName, selection)) {
350 this.handle(commandName, selection);
351
352 e.stopPropagation();
353 e.preventDefault();
354 return;
355 }
356 }
357 }, 368 },
358 369
359 /** 370 /**
360 * Close the menu on mousedown so clicks can propagate to the underlying UI. 371 * Close the menu on mousedown so clicks can propagate to the underlying UI.
361 * This allows the user to right click the list while a context menu is 372 * This allows the user to right click the list while a context menu is
362 * showing and get another context menu. 373 * showing and get another context menu.
363 * @param {Event} e 374 * @param {Event} e
364 * @private 375 * @private
365 */ 376 */
366 onMenuMousedown_: function(e) { 377 onMenuMousedown_: function(e) {
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after
425 436
426 /** @return {!bookmarks.CommandManager} */ 437 /** @return {!bookmarks.CommandManager} */
427 CommandManager.getInstance = function() { 438 CommandManager.getInstance = function() {
428 return assert(CommandManager.instance_); 439 return assert(CommandManager.instance_);
429 }; 440 };
430 441
431 return { 442 return {
432 CommandManager: CommandManager, 443 CommandManager: CommandManager,
433 }; 444 };
434 }); 445 });
OLDNEW
« no previous file with comments | « no previous file | chrome/browser/resources/md_bookmarks/compiled_resources2.gyp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698