| 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 |
| (...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 99 /** | 99 /** |
| 100 * Display the command context menu at (|x|, |y|) in window co-ordinates. | 100 * Display the command context menu at (|x|, |y|) in window co-ordinates. |
| 101 * Commands will execute on |items| if given, or on the currently selected | 101 * Commands will execute on |items| if given, or on the currently selected |
| 102 * items. | 102 * items. |
| 103 * @param {number} x | 103 * @param {number} x |
| 104 * @param {number} y | 104 * @param {number} y |
| 105 * @param {Set<string>=} items | 105 * @param {Set<string>=} items |
| 106 */ | 106 */ |
| 107 openCommandMenuAtPosition: function(x, y, items) { | 107 openCommandMenuAtPosition: function(x, y, items) { |
| 108 this.menuIds_ = items || this.getState().selection.items; | 108 this.menuIds_ = items || this.getState().selection.items; |
| 109 /** @type {!CrActionMenuElement} */ (this.$.dropdown) | 109 var dropdown = |
| 110 .showAtPosition({top: y, left: x}); | 110 /** @type {!CrActionMenuElement} */ (this.$.dropdown.get()); |
| 111 // Ensure that the menu is fully rendered before trying to position it. |
| 112 Polymer.dom.flush(); |
| 113 dropdown.showAtPosition({top: y, left: x}); |
| 111 }, | 114 }, |
| 112 | 115 |
| 113 /** | 116 /** |
| 114 * Display the command context menu positioned to cover the |target| | 117 * Display the command context menu positioned to cover the |target| |
| 115 * element. Commands will execute on the currently selected items. | 118 * element. Commands will execute on the currently selected items. |
| 116 * @param {!Element} target | 119 * @param {!Element} target |
| 117 */ | 120 */ |
| 118 openCommandMenuAtElement: function(target) { | 121 openCommandMenuAtElement: function(target) { |
| 119 this.menuIds_ = this.getState().selection.items; | 122 this.menuIds_ = this.getState().selection.items; |
| 120 /** @type {!CrActionMenuElement} */ (this.$.dropdown).showAt(target); | 123 var dropdown = |
| 124 /** @type {!CrActionMenuElement} */ (this.$.dropdown.get()); |
| 125 // Ensure that the menu is fully rendered before trying to position it. |
| 126 Polymer.dom.flush(); |
| 127 dropdown.showAt(target); |
| 121 }, | 128 }, |
| 122 | 129 |
| 123 closeCommandMenu: function() { | 130 closeCommandMenu: function() { |
| 124 this.menuIds_ = new Set(); | 131 this.menuIds_ = new Set(); |
| 125 /** @type {!CrActionMenuElement} */ (this.$.dropdown).close(); | 132 /** @type {!CrActionMenuElement} */ (this.$.dropdown.get()).close(); |
| 126 }, | 133 }, |
| 127 | 134 |
| 128 //////////////////////////////////////////////////////////////////////////// | 135 //////////////////////////////////////////////////////////////////////////// |
| 129 // Command handlers: | 136 // Command handlers: |
| 130 | 137 |
| 131 /** | 138 /** |
| 132 * Determine if the |command| can be executed with the given |itemIds|. | 139 * Determine if the |command| can be executed with the given |itemIds|. |
| 133 * Commands which appear in the context menu should be implemented | 140 * Commands which appear in the context menu should be implemented |
| 134 * separately using `isCommandVisible_` and `isCommandEnabled_`. | 141 * separately using `isCommandVisible_` and `isCommandEnabled_`. |
| 135 * @param {Command} command | 142 * @param {Command} command |
| (...skipping 314 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 450 }, | 457 }, |
| 451 | 458 |
| 452 /** | 459 /** |
| 453 * Close the menu on mousedown so clicks can propagate to the underlying UI. | 460 * Close the menu on mousedown so clicks can propagate to the underlying UI. |
| 454 * This allows the user to right click the list while a context menu is | 461 * This allows the user to right click the list while a context menu is |
| 455 * showing and get another context menu. | 462 * showing and get another context menu. |
| 456 * @param {Event} e | 463 * @param {Event} e |
| 457 * @private | 464 * @private |
| 458 */ | 465 */ |
| 459 onMenuMousedown_: function(e) { | 466 onMenuMousedown_: function(e) { |
| 460 if (e.path[0] != this.$.dropdown) | 467 if (e.path[0] != this.$.dropdown.getIfExists()) |
| 461 return; | 468 return; |
| 462 | 469 |
| 463 this.closeCommandMenu(); | 470 this.closeCommandMenu(); |
| 464 }, | 471 }, |
| 465 | 472 |
| 466 /** | 473 /** |
| 467 * @param {Command} command | 474 * @param {Command} command |
| 468 * @return {string} | 475 * @return {string} |
| 469 * @private | 476 * @private |
| 470 */ | 477 */ |
| (...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 548 | 555 |
| 549 /** @return {!bookmarks.CommandManager} */ | 556 /** @return {!bookmarks.CommandManager} */ |
| 550 CommandManager.getInstance = function() { | 557 CommandManager.getInstance = function() { |
| 551 return assert(CommandManager.instance_); | 558 return assert(CommandManager.instance_); |
| 552 }; | 559 }; |
| 553 | 560 |
| 554 return { | 561 return { |
| 555 CommandManager: CommandManager, | 562 CommandManager: CommandManager, |
| 556 }; | 563 }; |
| 557 }); | 564 }); |
| OLD | NEW |