Chromium Code Reviews| OLD | NEW |
|---|---|
| 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 |
| 11 var CommandManager = Polymer({ | 11 var CommandManager = Polymer({ |
| 12 is: 'bookmarks-command-manager', | 12 is: 'bookmarks-command-manager', |
| 13 | 13 |
| 14 behaviors: [ | 14 behaviors: [ |
| 15 bookmarks.StoreClient, | 15 bookmarks.StoreClient, |
| 16 ], | 16 ], |
| 17 | 17 |
| 18 properties: { | 18 properties: { |
| 19 /** | |
| 20 * If set, this will restrict keyboard shortcuts to only execute when a | |
| 21 * child of this element (or <body>) is focused. | |
|
calamity
2017/05/19 04:09:27
This is a bit confusing. Is 'this element' the com
tsergeant
2017/06/01 03:17:05
Obsolete
| |
| 22 * @type {?Element} | |
| 23 */ | |
| 24 keyTarget: Object, | |
| 25 | |
| 19 /** @private {!Array<Command>} */ | 26 /** @private {!Array<Command>} */ |
| 20 menuCommands_: { | 27 menuCommands_: { |
| 21 type: Array, | 28 type: Array, |
| 22 value: function() { | 29 value: function() { |
| 23 return [ | 30 return [ |
| 24 Command.EDIT, | 31 Command.EDIT, |
| 25 Command.COPY, | 32 Command.COPY, |
| 26 Command.DELETE, | 33 Command.DELETE, |
| 27 // <hr> | 34 // <hr> |
| 28 Command.OPEN_NEW_TAB, | 35 Command.OPEN_NEW_TAB, |
| (...skipping 288 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 317 this.closeCommandMenu(); | 324 this.closeCommandMenu(); |
| 318 this.handle(e.target.getAttribute('command'), assert(this.menuIds_)); | 325 this.handle(e.target.getAttribute('command'), assert(this.menuIds_)); |
| 319 }, | 326 }, |
| 320 | 327 |
| 321 /** | 328 /** |
| 322 * @param {!Event} e | 329 * @param {!Event} e |
| 323 * @private | 330 * @private |
| 324 */ | 331 */ |
| 325 onKeydown_: function(e) { | 332 onKeydown_: function(e) { |
| 326 var selection = this.getState().selection.items; | 333 var selection = this.getState().selection.items; |
| 327 // TODO(tsergeant): Prevent keyboard shortcuts when a dialog is open or | 334 if (this.keyTarget && e.path[0] != document.body && |
|
calamity
2017/05/19 04:09:27
Are there other exceptions that we need here? What
tsergeant
2017/06/01 03:17:05
Done, I think?
| |
| 328 // text field is focused. | 335 e.path.indexOf(this.keyTarget) == -1) { |
| 336 return; | |
| 337 } | |
| 338 | |
| 329 for (var commandName in this.shortcuts_) { | 339 for (var commandName in this.shortcuts_) { |
| 330 var shortcut = this.shortcuts_[commandName]; | 340 var shortcut = this.shortcuts_[commandName]; |
| 331 if (Polymer.IronA11yKeysBehavior.keyboardEventMatchesKeys( | 341 if (Polymer.IronA11yKeysBehavior.keyboardEventMatchesKeys( |
| 332 e, shortcut) && | 342 e, shortcut) && |
| 333 this.canExecute(commandName, selection)) { | 343 this.canExecute(commandName, selection)) { |
| 334 this.handle(commandName, selection); | 344 this.handle(commandName, selection); |
| 335 | 345 |
| 336 e.stopPropagation(); | 346 e.stopPropagation(); |
| 337 e.preventDefault(); | 347 e.preventDefault(); |
| 338 return; | 348 return; |
| (...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 409 | 419 |
| 410 /** @return {!bookmarks.CommandManager} */ | 420 /** @return {!bookmarks.CommandManager} */ |
| 411 CommandManager.getInstance = function() { | 421 CommandManager.getInstance = function() { |
| 412 return assert(CommandManager.instance_); | 422 return assert(CommandManager.instance_); |
| 413 }; | 423 }; |
| 414 | 424 |
| 415 return { | 425 return { |
| 416 CommandManager: CommandManager, | 426 CommandManager: CommandManager, |
| 417 }; | 427 }; |
| 418 }); | 428 }); |
| OLD | NEW |