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

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

Issue 2940233003: MD Bookmarks: Lazily render dropdown menus (Closed)
Patch Set: Flush before show 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 79 matching lines...) Expand 10 before | Expand all | Expand 10 after
90 /** 90 /**
91 * Display the command context menu at (|x|, |y|) in window co-ordinates. 91 * Display the command context menu at (|x|, |y|) in window co-ordinates.
92 * Commands will execute on |items| if given, or on the currently selected 92 * Commands will execute on |items| if given, or on the currently selected
93 * items. 93 * items.
94 * @param {number} x 94 * @param {number} x
95 * @param {number} y 95 * @param {number} y
96 * @param {Set<string>=} items 96 * @param {Set<string>=} items
97 */ 97 */
98 openCommandMenuAtPosition: function(x, y, items) { 98 openCommandMenuAtPosition: function(x, y, items) {
99 this.menuIds_ = items || this.getState().selection.items; 99 this.menuIds_ = items || this.getState().selection.items;
100 /** @type {!CrActionMenuElement} */ (this.$.dropdown) 100 var dropdown =
101 .showAtPosition({top: y, left: x}); 101 /** @type {!CrActionMenuElement} */ (this.$.dropdown.get());
102 // Ensure that the menu is fully rendered before trying to position it.
103 Polymer.dom.flush();
104 dropdown.showAtPosition({top: y, left: x});
102 }, 105 },
103 106
104 /** 107 /**
105 * Display the command context menu positioned to cover the |target| 108 * Display the command context menu positioned to cover the |target|
106 * element. Commands will execute on the currently selected items. 109 * element. Commands will execute on the currently selected items.
107 * @param {!Element} target 110 * @param {!Element} target
108 */ 111 */
109 openCommandMenuAtElement: function(target) { 112 openCommandMenuAtElement: function(target) {
110 this.menuIds_ = this.getState().selection.items; 113 this.menuIds_ = this.getState().selection.items;
111 /** @type {!CrActionMenuElement} */ (this.$.dropdown).showAt(target); 114 var dropdown =
115 /** @type {!CrActionMenuElement} */ (this.$.dropdown.get());
116 // Ensure that the menu is fully rendered before trying to position it.
117 Polymer.dom.flush();
118 dropdown.showAt(target);
112 }, 119 },
113 120
114 closeCommandMenu: function() { 121 closeCommandMenu: function() {
115 this.menuIds_ = new Set(); 122 this.menuIds_ = new Set();
116 /** @type {!CrActionMenuElement} */ (this.$.dropdown).close(); 123 /** @type {!CrActionMenuElement} */ (this.$.dropdown.get()).close();
117 }, 124 },
118 125
119 //////////////////////////////////////////////////////////////////////////// 126 ////////////////////////////////////////////////////////////////////////////
120 // Command handlers: 127 // Command handlers:
121 128
122 /** 129 /**
123 * Determine if the |command| can be executed with the given |itemIds|. 130 * Determine if the |command| can be executed with the given |itemIds|.
124 * Commands which appear in the context menu should be implemented 131 * Commands which appear in the context menu should be implemented
125 * separately using `isCommandVisible_` and `isCommandEnabled_`. 132 * separately using `isCommandVisible_` and `isCommandEnabled_`.
126 * @param {Command} command 133 * @param {Command} command
(...skipping 313 matching lines...) Expand 10 before | Expand all | Expand 10 after
440 }, 447 },
441 448
442 /** 449 /**
443 * Close the menu on mousedown so clicks can propagate to the underlying UI. 450 * Close the menu on mousedown so clicks can propagate to the underlying UI.
444 * This allows the user to right click the list while a context menu is 451 * This allows the user to right click the list while a context menu is
445 * showing and get another context menu. 452 * showing and get another context menu.
446 * @param {Event} e 453 * @param {Event} e
447 * @private 454 * @private
448 */ 455 */
449 onMenuMousedown_: function(e) { 456 onMenuMousedown_: function(e) {
450 if (e.path[0] != this.$.dropdown) 457 if (e.path[0] != this.$.dropdown.getIfExists())
451 return; 458 return;
452 459
453 this.closeCommandMenu(); 460 this.closeCommandMenu();
454 }, 461 },
455 462
456 /** 463 /**
457 * @param {Command} command 464 * @param {Command} command
458 * @return {string} 465 * @return {string}
459 * @private 466 * @private
460 */ 467 */
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after
509 516
510 /** @return {!bookmarks.CommandManager} */ 517 /** @return {!bookmarks.CommandManager} */
511 CommandManager.getInstance = function() { 518 CommandManager.getInstance = function() {
512 return assert(CommandManager.instance_); 519 return assert(CommandManager.instance_);
513 }; 520 };
514 521
515 return { 522 return {
516 CommandManager: CommandManager, 523 CommandManager: CommandManager,
517 }; 524 };
518 }); 525 });
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698